linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Michal Koutný" <mkoutny@suse.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	 Christian Brauner <brauner@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	 "Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Mike Christie <michael.christie@oracle.com>,
	 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Peter Zijlstra <peterz@infradead.org>,
	 Nicholas Piggin <npiggin@gmail.com>,
	Andrei Vagin <avagin@gmail.com>,
	 Shakeel Butt <shakeelb@google.com>, Adam Majer <amajer@suse.com>,
	Jan Kara <jack@suse.cz>,  Michal Hocko <mhocko@kernel.org>
Subject: Re: [PATCH] mm: Sync percpu mm RSS counters before querying
Date: Mon, 19 Jun 2023 14:53:13 +0200	[thread overview]
Message-ID: <b4zbdp4wq35nvq34njzdscqj72nk6e5vmy63n4csakcxnonpc5@kqvtacyg6n4i> (raw)
In-Reply-To: <20230616123144.bd2a8120dab25736c5c37297@linux-foundation.org>

[-- Attachment #1: Type: text/plain, Size: 2166 bytes --]

On Fri, Jun 16, 2023 at 12:31:44PM -0700, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Fri, 16 Jun 2023 20:07:18 +0200 Michal Koutný <mkoutny@suse.com> wrote:
> 
> > An issue was observed with stats collected in struct rusage on ppc64le
> > with 64kB pages. The percpu counters use batching with
> > 	percpu_counter_batch = max(32, nr*2) # in PAGE_SIZE
> > i.e. with larger pages but similar RSS consumption (bytes), there'll be
> > less flushes and error more noticeable.
> 
> A fully detailed description of the issue would be helpful.  Obviously
> "inaccuracy", but how bad?

Any reader of get_mm_counter() could see the inaccuracy given by the
formula.
In this particular case it is detected by a testsuite of time(1) utility
that feeds from rusage:

> FAIL: tests/time-max-rss
> ========================
> 
> time(1) failed to detect 5MB allcoation.
>   mem-baseline(kb): 0
>   mem-5MB(kb):      4096
>   delta(kb):        4096
> FAIL tests/time-max-rss.sh (exit status: 1)

(i.e. 1MB missing)

> Far too large to be inlined!  For six callsites it adds 1kb of text.

Ah, thanks, I can change that.

> Why even modify the counter?  Can't <whatever this issue is> be
> addressed by using percpu_counter_sum() in an appropriate place?

I considered modifying get_mm_counter(), however, I decided not to put
the per-cpu summing there as it'd incur the impact to many more places
than sync_mm_rss().

> For unknown reasons percpu_counter_set() uses for_each_possible_cpu(). 
> Probably just a mistake - percpu_counters are hotplug-aware and
> for_each_online_cpu should suffice.

Yeah, that could be cleaned up in another patch (cf mask in
__percpu_counter_sum).

> I'm really not liking percpu_counter_set().  It's only safe in
> situations where the caller knows that no other CPU can be modifying
> the counter.  I wonder if all the callers know that.

I admit I only considered the do_exit() path (and even that isn't
granted in a multithreaded process) -- so I don't like
percpu_counter_set() in this current form neither.
I will need to review effects of parallel updates more.

Thanks,
Michal

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2023-06-19 12:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-16 18:07 Michal Koutný
2023-06-16 19:31 ` Andrew Morton
2023-06-19 12:53   ` Michal Koutný [this message]
2023-06-19 13:10 ` Michal Hocko

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=b4zbdp4wq35nvq34njzdscqj72nk6e5vmy63n4csakcxnonpc5@kqvtacyg6n4i \
    --to=mkoutny@suse.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=amajer@suse.com \
    --cc=avagin@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhocko@kernel.org \
    --cc=michael.christie@oracle.com \
    --cc=npiggin@gmail.com \
    --cc=peterz@infradead.org \
    --cc=shakeelb@google.com \
    --cc=surenb@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