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 E5072C5B543 for ; Wed, 4 Jun 2025 12:46:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8218B6B05D1; Wed, 4 Jun 2025 08:46:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D2D56B05D3; Wed, 4 Jun 2025 08:46:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E8736B05D4; Wed, 4 Jun 2025 08:46:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4D9056B05D1 for ; Wed, 4 Jun 2025 08:46:15 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DB95E120FD7 for ; Wed, 4 Jun 2025 12:46:14 +0000 (UTC) X-FDA: 83517691068.18.5F9DBE4 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by imf30.hostedemail.com (Postfix) with ESMTP id 1E63180005 for ; Wed, 4 Jun 2025 12:46:11 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=aP0TCoLo; spf=pass (imf30.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749041173; 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=TPLFxmuO1Q5FsFGt4jj6PdsNEZVTzIdznxUKQp9Xs4o=; b=WhhzgLvN+nANcge5phJNxXoeEBbR8bYE/0yKRok8QHNFoFiqBqxZdo1Ab54Rr+8jIbi7O4 hQPWQUnEjmdx+4RfU9/GsN35zM2U7EP4hbipO1cAw7uNKzVT9P8WzzxXiRnqqQz2V/BV79 U0G8SXBh/zhmzjXZzO5nxoQxwc0DB0o= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=aP0TCoLo; spf=pass (imf30.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.133 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749041173; a=rsa-sha256; cv=none; b=pXWuVPU0UqJ4ou51+4hkGINmKN38kFwWoNnSNTVPpLonqcOZ/FF6K6UU3eeVeryN6AZHcE B8CaVVD7Q9DyHIuMpZZfh8jQqOFWbtFIqiFNfimi4RyzBQMejnLL5IPsgW9eYoG700Z/Nq isAyTNyql0xISG6DckkpKvv/4FhYQ+I= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1749041169; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=TPLFxmuO1Q5FsFGt4jj6PdsNEZVTzIdznxUKQp9Xs4o=; b=aP0TCoLo+hrHR3m6LmEXykmRNzuv/qqlwIe5N2b5VaP8UvceZeIJbqYYVB9Uu4b+vuF4fJl/nwseLLtQ2/arykUp/7v5SQsGKSFKKp8y+LYXegJZP8hgEKCxZ6LleiYaTqMSjDjQBKnXOqT0wT2ZiKk4id1q2LaKmtjnysy90ng= Received: from 30.121.8.237(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Wd4RjKR_1749041167 cluster:ay36) by smtp.aliyun-inc.com; Wed, 04 Jun 2025 20:46:07 +0800 Message-ID: <250ec733-8b2d-4c56-858c-6aada9544a55@linux.alibaba.com> Date: Wed, 4 Jun 2025 20:46:02 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm: fix the inaccurate memory statistics issue for users To: Shakeel Butt , Michal Hocko Cc: Andrew Morton , david@redhat.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, donettom@linux.ibm.com, aboorvad@linux.ibm.com, sj@kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org References: <4f0fd51eb4f48c1a34226456b7a8b4ebff11bf72.1748051851.git.baolin.wang@linux.alibaba.com> <20250529205313.a1285b431bbec2c54d80266d@linux-foundation.org> <72f0dc8c-def3-447c-b54e-c390705f8c26@linux.alibaba.com> <7307bb7a-7c45-43f7-b073-acd9e1389000@linux.alibaba.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1E63180005 X-Stat-Signature: 1qk3oo4hwsi6o9i11f87rwk49ncx9ki8 X-Rspam-User: X-HE-Tag: 1749041171-44852 X-HE-Meta: U2FsdGVkX1/J/wnvCv5LMUq5cJcYc4WXGwH2ezeMvVdhevbCCHTXlOPCz94ygAd81jr7e2w30ZPYHX/t2tgEeAi60m9CbL88zt4CjyIu+Wh892fUjHyeI/wZsZlNInbJyQOMg483AkqiRlz23SanlY6a3DKcVLgO6qDCchhRvPR0fTo2hNzf/ujDCWFaH0zLbhKtASwyEhMFq8K70Cux8XXyB3pMirTAbtieC+WAKZ5nEDp0aZqhqF82udYEqqSeaK/hCedP94Gb8/SX5SYAVEr1vFiO8hSQsJHCZI+cNvUh8YcswX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.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2025/6/4 01:29, Shakeel Butt wrote: > On Tue, Jun 03, 2025 at 04:48:08PM +0200, Michal Hocko wrote: >> On Tue 03-06-25 22:22:46, Baolin Wang wrote: >>> Let me try to clarify further. >>> >>> The 'mm->rss_stat' is updated by using add_mm_counter(), >>> dec/inc_mm_counter(), which are all wrappers around >>> percpu_counter_add_batch(). In percpu_counter_add_batch(), there is percpu >>> batch caching to avoid 'fbc->lock' contention. >> >> OK, this is exactly the line of argument I was looking for. If _all_ >> updates done in the kernel are using batching and therefore the lock is >> only held every N (percpu_counter_batch) updates then a risk of locking >> contention would be decreased. This is worth having a note in the >> changelog. OK. >>> This patch changes task_mem() >>> and task_statm() to get the accurate mm counters under the 'fbc->lock', but >>> this will not exacerbate kernel 'mm->rss_stat' lock contention due to the >>> the percpu batch caching of the mm counters. >>> >>> You might argue that my test cases cannot demonstrate an actual lock >>> contention, but they have already shown that there is no significant >>> 'fbc->lock' contention when the kernel updates 'mm->rss_stat'. >> >> I was arguing that `top -d 1' doesn't really represent a potential >> adverse usage. These proc files are generally readable so I would be >> expecting something like busy loop read while process tries to update >> counters to see the worst case scenario. If that is barely visible then >> we can conclude a normal use wouldn't even notice. OK. > Baolin, please run stress-ng command that stresses minor anon page > faults in multiple threads and then run multiple bash scripts which cat > /proc/pidof(stress-ng)/status. That should be how much the stress-ng > process is impacted by the parallel status readers versus without them. Sure. Thanks Shakeel. I run the stress-ng with the 'stress-ng --fault 32 --perf -t 1m' command, while simultaneously running the following scripts to read the /proc/pidof(stress-ng)/status for each thread. From the following data, I did not observe any obvious impact of this patch on the stress-ng tests when repeatedly reading the /proc/pidof(stress-ng)/status. w/o patch stress-ng: info: [6891] 3,993,235,331,584 CPU Cycles 59.767 B/sec stress-ng: info: [6891] 1,472,101,565,760 Instructions 22.033 B/sec (0.369 instr. per cycle) stress-ng: info: [6891] 36,287,456 Page Faults Total 0.543 M/sec stress-ng: info: [6891] 36,287,456 Page Faults Minor 0.543 M/sec w/ patch stress-ng: info: [6872] 4,018,592,975,968 CPU Cycles 60.177 B/sec stress-ng: info: [6872] 1,484,856,150,976 Instructions 22.235 B/sec (0.369 instr. per cycle) stress-ng: info: [6872] 36,547,456 Page Faults Total 0.547 M/sec stress-ng: info: [6872] 36,547,456 Page Faults Minor 0.547 M/sec ========================= #!/bin/bash # Get the PIDs of stress-ng processes PIDS=$(pgrep stress-ng) # Loop through each PID and monitor /proc/[pid]/status for PID in $PIDS; do while true; do cat /proc/$PID/status usleep 100000 done & done