linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>,
	Andrew Morton <akpm@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
	Christoph Lameter <cl@linux.com>,
	Martin Liu <liumartin@google.com>,
	David Rientjes <rientjes@google.com>,
	Jani Nikula <jani.nikula@intel.com>,
	Sweet Tea Dorminy <sweettea@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Christian Brauner <brauner@kernel.org>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Suren Baghdasaryan <surenb@google.com>,
	"Liam R . Howlett" <Liam.Howlett@Oracle.com>,
	Wei Yang <richard.weiyang@gmail.com>,
	David Hildenbrand <david@redhat.com>,
	Miaohe Lin <linmiaohe@huawei.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	Matthew Wilcox <willy@infradead.org>,
	paulmck <paulmck@kernel.org>
Cc: Yu Zhao <yuzhao@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Greg Thelen <gthelen@google.com>
Subject: Re: [PATCH] mm: use per-numa-node atomics instead of percpu_counters
Date: Wed, 26 Mar 2025 15:56:15 -0400	[thread overview]
Message-ID: <67e2a6a1-8c9b-43d0-b960-10cd47c08873@efficios.com> (raw)
In-Reply-To: <20250325221550.396212-1-sweettea-kernel@dorminy.me>

On 2025-03-25 18:15, Sweet Tea Dorminy wrote:
> From: Sweet Tea Dorminy <sweettea@google.com>
> 
> Recently, several internal services had an RSS usage regression as part of a
> kernel upgrade. Previously, they were on a pre-6.2 kernel and were able to
> read RSS statistics in a backup watchdog process to monitor and decide if
> they'd overrun their memory budget. Now, however, a representative service
> with five threads, expected to use about a hundred MB of memory, on a 250-cpu
> machine had memory usage tens of megabytes different from the expected amount
> -- this constituted a significant percentage of inaccuracy, causing the
> watchdog to act.
> 

I suspect the culprit sits here:

int percpu_counter_batch __read_mostly = 32;
EXPORT_SYMBOL(percpu_counter_batch);

static int compute_batch_value(unsigned int cpu)
{
         int nr = num_online_cpus();

         percpu_counter_batch = max(32, nr*2);
         return 0;
}

So correct me if I'm wrong, but in this case the worse-case
inaccuracy for a 256 cpu machine would be
"+/- percpu_counter_batch" within each percpu counter,
thus globally:

+/- (256 * 2) * 256, or 131072 pages, meaning an inaccuracy
of +/- 512MB with 4kB pages. This is quite significant.

So I understand that the batch size is scaled up as the
number of CPUs increases to minimize contention on the
percpu_counter lock. Unfortunately, as the number of CPUs
increases, the inaccuracy increases with the square of the
number of cpus.

Have you tried decreasing this percpu_counter_batch value on
larger machines to see if it helps ?

Thanks,

Mathieu

[...]

> 
> base-commit: b0cb56cbbdb4754918c28d6d7c294d56e28a3dd5
> prerequisite-patch-id: b7b47d1b9aa3fd887dd718ab276581f120e516e6

[...][ cutting the gazillions prerequisite-patch-id, please review you use
   of tooling when preparing/sending patches. ]

-- 
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com


  reply	other threads:[~2025-03-26 19:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-25 22:15 Sweet Tea Dorminy
2025-03-26 19:56 ` Mathieu Desnoyers [this message]
2025-03-26 21:54   ` Mateusz Guzik
2025-03-26 23:36 ` Mateusz Guzik
2025-03-27 20:35   ` Mathieu Desnoyers
2025-03-31 12:32 ` Lorenzo Stoakes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=67e2a6a1-8c9b-43d0-b960-10cd47c08873@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=Liam.Howlett@Oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=cl@linux.com \
    --cc=david@redhat.com \
    --cc=dennis@kernel.org \
    --cc=gthelen@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=jani.nikula@intel.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=liumartin@google.com \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhiramat@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=richard.weiyang@gmail.com \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=surenb@google.com \
    --cc=sweettea-kernel@dorminy.me \
    --cc=sweettea@google.com \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    --cc=yuzhao@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox