Linux-mm Archive mirror
 help / color / mirror / Atom feed
From: Shakeel Butt <shakeel.butt@linux.dev>
To: Yosry Ahmed <yosryahmed@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	 Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	 Roman Gushchin <roman.gushchin@linux.dev>,
	Muchun Song <muchun.song@linux.dev>,
	linux-mm@kvack.org,  cgroups@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	 syzbot+9319a4268a640e26b72b@syzkaller.appspotmail.com
Subject: Re: [PATCH] mm: do not update memcg stats for NR_{FILE/SHMEM}_PMDMAPPED
Date: Mon, 6 May 2024 12:25:15 -0700	[thread overview]
Message-ID: <xhytcu3lz2qm7qt2cfkp26z5h57k2ehpd7zw4jugywituldykh@spysi6qb2e3z> (raw)
In-Reply-To: <20240506170024.202111-1-yosryahmed@google.com>

On Mon, May 06, 2024 at 05:00:24PM +0000, Yosry Ahmed wrote:
> Do not use __lruvec_stat_mod_folio() when updating NR_FILE_PMDMAPPED and
> NR_SHMEM_PMDMAPPED as these stats are not maintained per-memcg. Use
> __mod_node_page_state() instead, which updates the global per-node stats
> only.
> 
> Reported-by: syzbot+9319a4268a640e26b72b@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/lkml/0000000000001b9d500617c8b23c@google.com
> Signed-off-by: Yosry Ahmed <yosryahmed@google.com>

I think we can put Fixes either for 443c077dc2ec ("memcg: cleanup
__mod_memcg_lruvec_state") or ad86c0f0e089 ("memcg: warn for unexpected
events and stats").

> ---
>  mm/rmap.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 12be4241474ab..c2cfb750d2535 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -1435,13 +1435,14 @@ static __always_inline void __folio_add_file_rmap(struct folio *folio,
>  		struct page *page, int nr_pages, struct vm_area_struct *vma,
>  		enum rmap_level level)
>  {
> +	pg_data_t *pgdat = folio_pgdat(folio);
>  	int nr, nr_pmdmapped = 0;
>  
>  	VM_WARN_ON_FOLIO(folio_test_anon(folio), folio);
>  
>  	nr = __folio_add_rmap(folio, page, nr_pages, level, &nr_pmdmapped);
>  	if (nr_pmdmapped)
> -		__lruvec_stat_mod_folio(folio, folio_test_swapbacked(folio) ?
> +		__mod_node_page_state(pgdat, folio_test_swapbacked(folio) ?
>  			NR_SHMEM_PMDMAPPED : NR_FILE_PMDMAPPED, nr_pmdmapped);
>  	if (nr)
>  		__lruvec_stat_mod_folio(folio, NR_FILE_MAPPED, nr);
> @@ -1493,6 +1494,7 @@ static __always_inline void __folio_remove_rmap(struct folio *folio,
>  		enum rmap_level level)
>  {
>  	atomic_t *mapped = &folio->_nr_pages_mapped;
> +	pg_data_t *pgdat = folio_pgdat(folio);
>  	int last, nr = 0, nr_pmdmapped = 0;
>  	bool partially_mapped = false;
>  	enum node_stat_item idx;
> @@ -1540,13 +1542,14 @@ static __always_inline void __folio_remove_rmap(struct folio *folio,
>  	}
>  
>  	if (nr_pmdmapped) {
> +		/* NR_{FILE/SHMEM}_PMDMAPPED are not maintained per-memcg */
>  		if (folio_test_anon(folio))
> -			idx = NR_ANON_THPS;
> -		else if (folio_test_swapbacked(folio))
> -			idx = NR_SHMEM_PMDMAPPED;
> +			__lruvec_stat_mod_folio(folio, NR_ANON_THPS, -nr_pmdmapped);
>  		else
> -			idx = NR_FILE_PMDMAPPED;
> -		__lruvec_stat_mod_folio(folio, idx, -nr_pmdmapped);
> +			__mod_node_page_state(pgdat,
> +					folio_test_swapbacked(folio) ?
> +					NR_SHMEM_PMDMAPPED : NR_FILE_PMDMAPPED,
> +					nr_pmdmapped);

After the above fixed, you can add:

Acked-by: Shakeel Butt <shakeel.butt@linux.dev>



      parent reply	other threads:[~2024-05-06 19:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-06 17:00 [PATCH] mm: do not update memcg stats for NR_{FILE/SHMEM}_PMDMAPPED Yosry Ahmed
2024-05-06 17:01 ` Yosry Ahmed
2024-05-06 18:35 ` David Hildenbrand
2024-05-06 18:52   ` Yosry Ahmed
2024-05-06 19:18     ` David Hildenbrand
2024-05-06 19:22       ` Yosry Ahmed
2024-05-06 19:25 ` 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=xhytcu3lz2qm7qt2cfkp26z5h57k2ehpd7zw4jugywituldykh@spysi6qb2e3z \
    --to=shakeel.butt@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=syzbot+9319a4268a640e26b72b@syzkaller.appspotmail.com \
    --cc=yosryahmed@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 read-only IMAP folder(s) and NNTP newsgroup(s).