From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93559C4332F for ; Wed, 2 Nov 2022 21:10:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD6DC8E0002; Wed, 2 Nov 2022 17:10:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D87A58E0001; Wed, 2 Nov 2022 17:10:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C27E68E0002; Wed, 2 Nov 2022 17:10:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B363D8E0001 for ; Wed, 2 Nov 2022 17:10:02 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 88AF4ABB94 for ; Wed, 2 Nov 2022 21:10:02 +0000 (UTC) X-FDA: 80089744644.27.0369BCB Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by imf12.hostedemail.com (Postfix) with ESMTP id 9CA9940008 for ; Wed, 2 Nov 2022 21:10:01 +0000 (UTC) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20221102210959euoutp02af583649f8ff1a47bf8815f7dbcd9a54~j4L9Gk5md0126501265euoutp02d for ; Wed, 2 Nov 2022 21:09:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20221102210959euoutp02af583649f8ff1a47bf8815f7dbcd9a54~j4L9Gk5md0126501265euoutp02d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1667423399; bh=Kg/3YSQS2ju6IWjYQjmxTOS7Mgb/Tgi9X6kUI85rHJo=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=DUlC3Q50KFLoNUhVWR4nm9vS2xLFPzGkXsNnczG3FVD0lBW4Qzwo3qAarL/HeLrOH wv9JfLwGX15mbdR4nB3LBGxKJGI8gM3ogOv+qC6DGB6OOfKVE0FuwuQU0+OCpHF7tt CT1M68mu9nrl8nvHTPr/NgbEq6L99xORGikwhzk8= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20221102210958eucas1p1d49b35487b4da87e8134b8ffe55ea948~j4L8J36VP1568615686eucas1p1E; Wed, 2 Nov 2022 21:09:58 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 76.F6.07817.6ACD2636; Wed, 2 Nov 2022 21:09:58 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20221102210957eucas1p2915f88d8b923ccf79f0e8770d208a1bd~j4L74XeyT2854128541eucas1p2S; Wed, 2 Nov 2022 21:09:57 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20221102210957eusmtrp22a9cb8b5a466ef1663cc2c06f55e1be7~j4L7yS4iL0448804488eusmtrp2x; Wed, 2 Nov 2022 21:09:57 +0000 (GMT) X-AuditID: cbfec7f4-893ff70000011e89-a3-6362dca62d48 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id AA.B3.07473.5ACD2636; Wed, 2 Nov 2022 21:09:57 +0000 (GMT) Received: from [106.210.134.192] (unknown [106.210.134.192]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20221102210957eusmtip257a1995496edf59b19eab9669c7f2726~j4L7etzJc2005020050eusmtip2-; Wed, 2 Nov 2022 21:09:57 +0000 (GMT) Message-ID: Date: Wed, 2 Nov 2022 22:09:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH] mm: convert mm's rss stats into percpu_counter Content-Language: en-US To: Shakeel Butt , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org From: Marek Szyprowski In-Reply-To: <20221024052841.3291983-1-shakeelb@google.com> Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupgleLIzCtJLcpLzFFi42LZduzned1ld5KSDdpXsFvMWb+GzeLyrjls FvfW/Ge1OHjtNaMDi8eCTaUemz5NYvc4MeM3i8fnTXIBLFFcNimpOZllqUX6dglcGVOOnWcv eC5W8X/HZrYGxmlCXYycHBICJhLrl5xl6mLk4hASWMEosfrVS3YI5wujxN41q6Aynxkl5k28 yQTTcmP+QqjEckaJpkVvoFo+MkrseHYZyGHn4BWwk5hTA1LPIqAi8WfbRlYQm1dAUOLkzCcs ILaoQIrE7u5tYLawgLPEsaVTwWxmAXGJW0/mg+0SEQiWWPbkCDNE3ETifutDsDlsAoYSXW+7 2EBsTgFriaUzdrJC1MhLbH87hxnkHAmBIxwSd+5eYIQ42kXi08NPbBC2sMSr41vYIWwZif87 5zNBNLQzSiz4fR/KmcAo0fD8FlS3tcSdc7+AujmAVmhKrN+lDxF2lLi6bi4LSFhCgE/ixltB iCP4JCZtm84MEeaV6GiDBrWaxKzj6+DWHrxwiXkCo9IspGCZheT9WUjemYWwdwEjyypG8dTS 4tz01GKjvNRyveLE3OLSvHS95PzcTYzAxHL63/EvOxiXv/qod4iRiYPxEKMEB7OSCG/92ehk Id6UxMqq1KL8+KLSnNTiQ4zSHCxK4rxsM7SShQTSE0tSs1NTC1KLYLJMHJxSDUzZZ3jf5ezc VCDiFzF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aOeN9p1SVt7n7z9XmqP4/lXc2cmMcfnd 3z0vxc2bWXM77q0YV84CI//qF32Ouaa3tW91TElfyaj4T9Bk58H5t4uqKvxT4sVTiu+f0inU mJrGnXbqr6X0UvePajJxXX9XLL7+XK9oUcI5lrCSCs6WkmlRawQn+3rzP/a5fHuP69pVrwXN FiQq6qhtnHiBddmHMy8Ontc72snpb93GMFtTb5nfgYTqnYz2egtEwxfkTTmTFbZEbNK5by29 Yuxaa0z3GAW09rz1+9/I2FIuKXpSZN4zt9J1Kb5PCwNXz951PrdR6cgby81bTiixFGckGmox FxUnAgDXRWACKgMAAA== X-CMS-MailID: 20221102210957eucas1p2915f88d8b923ccf79f0e8770d208a1bd X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20221102210957eucas1p2915f88d8b923ccf79f0e8770d208a1bd X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20221102210957eucas1p2915f88d8b923ccf79f0e8770d208a1bd References: <20221024052841.3291983-1-shakeelb@google.com> ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=DUlC3Q50; spf=pass (imf12.hostedemail.com: domain of m.szyprowski@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=m.szyprowski@samsung.com; dmarc=pass (policy=none) header.from=samsung.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667423402; a=rsa-sha256; cv=none; b=XbZPNLg/oqBQL56QIJ/rNw4UZjboh92okntCYAiddca7Tzb0iyNRzH7qA3zXXNMjUhPrzc cgrv3wm7iH/oB0qjD1BGI0TQHPZPWD8J6bUL8MPfZbnUtNaSrs4Np6hXMDiSdII+S5oeoN TQ4bZjeLTw3oegqojUu68KhLikmk1OM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667423402; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Kg/3YSQS2ju6IWjYQjmxTOS7Mgb/Tgi9X6kUI85rHJo=; b=poUm8MPP2qIP0UQ7sh6N3pGLzuBLm/cB4BaGyG78A3mIEDavSioEN9zfn03dJjATiuEs44 DCstczsjEn9ZGWCMjBW3MD7R7rDkwYR9fS77RHMDiH1Yn7lxri7zCh7aZ3MoRhEc/CeUvl Uuip4H1a/bioZioGJ7pXpawplxxp6KU= X-Stat-Signature: yuxzut37j16db8jewuaz8tpjo3ji4f4c X-Rspamd-Queue-Id: 9CA9940008 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=samsung.com header.s=mail20170921 header.b=DUlC3Q50; spf=pass (imf12.hostedemail.com: domain of m.szyprowski@samsung.com designates 210.118.77.12 as permitted sender) smtp.mailfrom=m.szyprowski@samsung.com; dmarc=pass (policy=none) header.from=samsung.com X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1667423401-621448 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi On 24.10.2022 07:28, Shakeel Butt wrote: > Currently mm_struct maintains rss_stats which are updated on page fault > and the unmapping codepaths. For page fault codepath the updates are > cached per thread with the batch of TASK_RSS_EVENTS_THRESH which is 64. > The reason for caching is performance for multithreaded applications > otherwise the rss_stats updates may become hotspot for such > applications. > > However this optimization comes with the cost of error margin in the rss > stats. The rss_stats for applications with large number of threads can > be very skewed. At worst the error margin is (nr_threads * 64) and we > have a lot of applications with 100s of threads, so the error margin can > be very high. Internally we had to reduce TASK_RSS_EVENTS_THRESH to 32. > > Recently we started seeing the unbounded errors for rss_stats for > specific applications which use TCP rx0cp. It seems like > vm_insert_pages() codepath does not sync rss_stats at all. > > This patch converts the rss_stats into percpu_counter to convert the > error margin from (nr_threads * 64) to approximately (nr_cpus ^ 2). > However this conversion enable us to get the accurate stats for > situations where accuracy is more important than the cpu cost. Though > this patch does not make such tradeoffs. > > Signed-off-by: Shakeel Butt This patch landed recently in linux-next as commit d59f19a7a068 ("mm: convert mm's rss stats into percpu_counter"). Unfortunately it causes a regression on my test systems. I've noticed that it triggers a 'BUG: Bad rss-counter state' warning from time to time for random processes. This is somehow related to CPU hot-plug and/or system suspend/resume. The easiest way to reproduce this issue (although not always) on my test systems (ARM or ARM64 based) is to run the following commands: root@target:~# for i in /sys/devices/system/cpu/cpu[1-9]; do echo 0 >$i/online; BUG: Bad rss-counter state mm:f04c7160 type:MM_FILEPAGES val:1 BUG: Bad rss-counter state mm:50f1f502 type:MM_FILEPAGES val:2 BUG: Bad rss-counter state mm:50f1f502 type:MM_ANONPAGES val:15 BUG: Bad rss-counter state mm:63660fd0 type:MM_FILEPAGES val:2 BUG: Bad rss-counter state mm:63660fd0 type:MM_ANONPAGES val:15 Let me know if I can help debugging this somehow or testing a fix. > --- > include/linux/mm.h | 26 ++++-------- > include/linux/mm_types.h | 7 +--- > include/linux/mm_types_task.h | 13 ------ > include/linux/percpu_counter.h | 1 - > include/linux/sched.h | 3 -- > include/trace/events/kmem.h | 8 ++-- > kernel/fork.c | 16 +++++++- > mm/memory.c | 73 +++++----------------------------- > 8 files changed, 40 insertions(+), 107 deletions(-) > > ... Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland