Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp481687rwi; Wed, 2 Nov 2022 14:20:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Do7aHdSCIQBidS/nw643EzixOXflaHNst2ye8tgr9/obuCybRgQn1dw8/s4CLk19trmYk X-Received: by 2002:a05:6a00:4504:b0:56b:3ed4:1fac with SMTP id cw4-20020a056a00450400b0056b3ed41facmr27084058pfb.73.1667424045745; Wed, 02 Nov 2022 14:20:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667424045; cv=none; d=google.com; s=arc-20160816; b=xgUggQb4pIb9aF+FF7zbeo7V9snh9F0cdkHMLtD8pDkJrfKg9fsvBUlNf/IgbMIUEr TQ7132jwDn394VhoAsKU/ZJ/Uz9MB/g+mBWC+t35+Aa54CS8LMTreCbumaR4y5xjiwQa aOF3LeT9qtlkeKEZKz54xgGMW6uk8HgOPFtg4tv/Ffzj/GAacWoGWAFMdxeQgXMEnmcs 6uZjh9LHZRZE/3uonqKCGD2xff94yfGKGOKEeaifxszKYcSME2JUYsYlq98BSXkq2ald iy1zy3749quhWWM0otHy0fOHc+phWxVB7BW+xWgYUpoPVVn3bB5y+0yf51Gx+8gsLVHZ gIRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :in-reply-to:from:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature:dkim-filter; bh=Kg/3YSQS2ju6IWjYQjmxTOS7Mgb/Tgi9X6kUI85rHJo=; b=Fw4ojaFZzCHtgNpben9U6mvhV/LvulpCjfrh1WsQKThsqVLU4sbKX5YMbeoU76HK51 AfLCVOgtivAKEbVqfWOU9qwZdR0O3W8sS1XYa969SKV5QbzqZxEMIQj4uHXZuh9pYsND Os1X60mI6HLFQ27t+jd/Emm5mGSgEvJKQNgu3HG1ibRm8Ye3/BgxGei6bv38fajGo29n 2IgAngeW5+cRZC2ngtNFHp+s7SUR7gwkZyqvpCYI8GiWb/8DUvib6MejZqcSxPXF0m1E OlOrILUzFYT6fytfmv5s2bmmLnZGSQx+xzQbosoK0fJ8qN5hmMElVCZUuI12+UPnqfRe a8Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=DUlC3Q50; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n66-20020a634045000000b004276c7b2253si17485083pga.584.2022.11.02.14.20.32; Wed, 02 Nov 2022 14:20:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=DUlC3Q50; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230502AbiKBVKJ (ORCPT + 98 others); Wed, 2 Nov 2022 17:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230242AbiKBVKH (ORCPT ); Wed, 2 Nov 2022 17:10:07 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55756DEE2 for ; Wed, 2 Nov 2022 14:10:05 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20221102210959euoutp0193aba5429eeec5e50b20aac83a982306~j4L9GiRvq2701027010euoutp01w for ; Wed, 2 Nov 2022 21:09:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20221102210959euoutp0193aba5429eeec5e50b20aac83a982306~j4L9GiRvq2701027010euoutp01w 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+lDxF2lLi6bi4L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NQtIyC0nLAkaWVYwiqaXFuem5xYZ6xYm5xaV56XrJ+bmbGIEx tO3Yz807GOe9+qh3iJGJg/EQowQHs5IIb/3Z6GQh3pTEyqrUovz4otKc1OJDjKbAkJjILCWa nA+M4rySeEMzA1NDEzNLA1NLM2MlcV7Pgo5EIYH0xJLU7NTUgtQimD4mDk6pBiYhQ5XNp6y5 LSadED9aelEh+OzEwzI3O58IC99ju5RQ/knrmWpTaOeN9p1SVt7n7z9XmqP4/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> X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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