From: Shakeel Butt <shakeel.butt@linux.dev>
To: Kairui Song <kasong@tencent.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Matthew Wilcox <willy@infradead.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Nhat Pham <nphamcs@gmail.com>, Michal Hocko <mhocko@suse.com>,
Chengming Zhou <zhouchengming@bytedance.com>,
Muchun Song <muchun.song@linux.dev>,
Chris Li <chrisl@kernel.org>,
Yosry Ahmed <yosryahmed@google.com>,
"Huang, Ying" <ying.huang@intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/swap, workingset: make anon shadow nodes memcg aware
Date: Tue, 20 Aug 2024 17:21:48 -0700 [thread overview]
Message-ID: <az5fhwmdwxpsgsxb7j3ruzbjevmxqrmx5xswwzuazh6zq5ytrs@bmgbu44mz3po> (raw)
In-Reply-To: <20240820092359.97782-1-ryncsn@gmail.com>
On Tue, Aug 20, 2024 at 05:23:59PM GMT, Kairui Song wrote:
> From: Kairui Song <kasong@tencent.com>
>
> Currently, the workingset (shadow) nodes of the swap cache are not
> accounted to their corresponding memory cgroup, instead, they are
> all accounted to the root cgroup. This leads to inaccurate accounting
> and ineffective reclaiming. One cgroup could swap out a large amount
> of memory, take up a large amount of memory with shadow nodes without
> being accounted.
>
> This issue is similar to commit 7b785645e8f1 ("mm: fix page cache
> convergence regression"), where page cache shadow nodes were incorrectly
> accounted. That was due to the accidental dropping of the accounting
> flag during the XArray conversion in commit a28334862993
> ("page cache: Finish XArray conversion").
>
> However, this fix has a different cause. Swap cache shadow nodes were
> never accounted even before the XArray conversion, since they did not
> exist until commit 3852f6768ede ("mm/swapcache: support to handle the
> shadow entries"), which was years after the XArray conversion.
>
> It's worth noting that one anon shadow Xarray node may contain
> different entries from different cgroup, and it gets accounted at reclaim
> time, so it's arguable which cgroup it should be accounted to (as
> Shakeal Butt pointed out [1]). File pages may suffer similar issue
> but less common. Things like proactive memory reclaim could make thing
> more complex.
>
> So this commit still can't provide a 100% accurate accounting of anon
> shadows, but it covers the cases when one memory cgroup uses significant
> amount of swap, and in most cases memory pressure in one cgroup only
> suppose to reclaim this cgroup and children. Besides, this fix is clean and
> easy enough.
>
> Link: https://lore.kernel.org/all/7gzevefivueqtebzvikzbucnrnpurmh3scmfuiuo2tnrs37xso@haj7gzepjur2/ [1]
> Signed-off-by: Kairui Song <kasong@tencent.com>
>
Is this a real issue? Have you seen systems in the production with
large amount of memory occupied by anon shadow entries? This is still
limited to the amount of swap a cgroup is allowed to use.
The reason I am asking is that this solution is worse than the perceived
problem at least to me. With this patch, the kernel will be charging
unrelated cgroups for the memory of swap xarray nodes during global
reclaim and proactive reclaim.
You can reduce this weirdness by using set_active_memcg() in
add_to_swap_cache() using the given folio's memcg but still you have the
case of multiple unrelated folios and shadow entries of different
cgroups within the same node. For filesystem case, the userspace can
control which files are shared between different cgroups and has more
control on it. That is not the case for swap space.
thanks,
Shakeel
next prev parent reply other threads:[~2024-08-21 0:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 9:23 Kairui Song
2024-08-21 0:21 ` Shakeel Butt [this message]
2024-08-21 17:35 ` Kairui Song
2024-08-21 18:14 ` Shakeel Butt
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=az5fhwmdwxpsgsxb7j3ruzbjevmxqrmx5xswwzuazh6zq5ytrs@bmgbu44mz3po \
--to=shakeel.butt@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=chrisl@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=roman.gushchin@linux.dev \
--cc=willy@infradead.org \
--cc=ying.huang@intel.com \
--cc=yosryahmed@google.com \
--cc=zhouchengming@bytedance.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