linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shakeel Butt <shakeelb@google.com>
To: "Michal Koutný" <mkoutny@suse.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Christian Brauner <brauner@kernel.org>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Suren Baghdasaryan <surenb@google.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Mike Christie <michael.christie@oracle.com>,
	Andrei Vagin <avagin@gmail.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Nicholas Piggin <npiggin@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Adam Majer <amajer@suse.com>, Jan Kara <jack@suse.cz>,
	Michal Hocko <mhocko@kernel.org>
Subject: Re: [RFC PATCH] mm: Sync percpu mm RSS counters before querying
Date: Thu, 8 Jun 2023 17:38:22 +0000	[thread overview]
Message-ID: <20230608173822.zezggshxhh62mxoi@google.com> (raw)
In-Reply-To: <20230608171256.17827-1-mkoutny@suse.com>

On Thu, Jun 08, 2023 at 07:12:56PM +0200, Michal Koutný 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.
> 
> In this given case (getting consumption of exited child), we can request
> percpu counter's flush without worrying about contention with updaters.
> 
> Fortunately, the commit f1a7941243c1 ("mm: convert mm's rss stats into
> percpu_counter") didn't eradicate all traces of SPLIT_RSS_COUNTING and
> this mechanism already provided some synchronization points before
> reading stats.
> Therefore, use sync_mm_rss as carrier for percpu counters refreshes and
> forget SPLIT_RSS_COUNTING macro for good.
> 
> Fixes: f1a7941243c1 ("mm: convert mm's rss stats into percpu_counter")
> Reported-by: Adam Majer <amajer@suse.com>
> Signed-off-by: Michal Koutný <mkoutny@suse.com>

The patch seems reasonable to me. Are any of the callsites of
sync_mm_rss performance sensitive?

> ---
>  include/linux/mm.h | 6 ++----
>  kernel/fork.c      | 4 ----
>  2 files changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 27ce77080c79..30cfde88d5b2 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2547,13 +2547,11 @@ static inline void setmax_mm_hiwater_rss(unsigned long *maxrss,
>  		*maxrss = hiwater_rss;
>  }
>  
> -#if defined(SPLIT_RSS_COUNTING)
> -void sync_mm_rss(struct mm_struct *mm);
> -#else
>  static inline void sync_mm_rss(struct mm_struct *mm)
>  {
> +	for (int i = 0; i < NR_MM_COUNTERS; ++i)
> +		percpu_counter_sum(&mm->rss_stat[i]);
>  }
> -#endif
>  
>  #ifndef CONFIG_ARCH_HAS_PTE_SPECIAL
>  static inline int pte_special(pte_t pte)
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 81cba91f30bb..e030eb902e4b 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -2412,10 +2412,6 @@ __latent_entropy struct task_struct *copy_process(
>  	p->io_uring = NULL;
>  #endif
>  
> -#if defined(SPLIT_RSS_COUNTING)
> -	memset(&p->rss_stat, 0, sizeof(p->rss_stat));
> -#endif
> -
>  	p->default_timer_slack_ns = current->timer_slack_ns;
>  
>  #ifdef CONFIG_PSI
> -- 
> 2.40.1
> 

      reply	other threads:[~2023-06-08 17:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-08 17:12 [RFC PATCH] mm: Sync percpu mm RSS counters before querying Michal Koutný
2023-06-08 17:38 ` Shakeel Butt [this message]

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=20230608173822.zezggshxhh62mxoi@google.com \
    --to=shakeelb@google.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=mkoutny@suse.com \
    --cc=mst@redhat.com \
    --cc=npiggin@gmail.com \
    --cc=peterz@infradead.org \
    --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;
as well as URLs for NNTP newsgroup(s).