From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Christoph Hellwig <hch@infradead.org>, Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org, hannes@cmpxchg.org,
mhocko@kernel.org, roman.gushchin@linux.dev,
shakeel.butt@linux.dev, muchun.song@linux.dev,
akpm@linux-foundation.org, cgroups@vger.kernel.org,
linux-mm@kvack.org, Michal Hocko <mhocko@suse.com>,
"Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Subject: Re: [PATCH] btrfs: root memcgroup for metadata filemap_add_folio()
Date: Tue, 1 Oct 2024 19:10:07 +0930 [thread overview]
Message-ID: <5d3f4dca-f7f3-4228-8645-ad92c7a1e5ac@gmx.com> (raw)
In-Reply-To: <Zvu-n6NFL8wo4cOA@infradead.org>
在 2024/10/1 18:49, Christoph Hellwig 写道:
> On Sat, Sep 28, 2024 at 02:15:56PM +0930, Qu Wenruo wrote:
>> [BACKGROUND]
>> The function filemap_add_folio() charges the memory cgroup,
>> as we assume all page caches are accessible by user space progresses
>> thus needs the cgroup accounting.
>>
>> However btrfs is a special case, it has a very large metadata thanks to
>> its support of data csum (by default it's 4 bytes per 4K data, and can
>> be as large as 32 bytes per 4K data).
>> This means btrfs has to go page cache for its metadata pages, to take
>> advantage of both cache and reclaim ability of filemap.
>
> FYI, in general reclaims for metadata work much better with a shrinker
> than through the pagecache, because it can be object based and
> prioritized.
>
>> [ENHANCEMENT]
>> Instead of relying on __GFP_NOFAIL to avoid charge failure, use root
>> memory cgroup to attach metadata pages.
>>
>> Although this needs to export the symbol mem_root_cgroup for
>> CONFIG_MEMCG, or define mem_root_cgroup as NULL for !CONFIG_MEMCG.
>>
>> With root memory cgroup, we directly skip the charging part, and only
>> rely on __GFP_NOFAIL for the real memory allocation part.
>
> This looks pretty ugly. What speaks against a version of
> filemap_add_folio that doesn't charge the memcg?
>
Because there is so far only one caller has such requirement.
Furthermore I believe the folio API doesn't prefer too many different
functions doing similar things.
E.g. the new folio interfaces only provides filemap_get_folio(),
filemap_lock_folio(), and the more generic __filemap_get_folio().
Meanwhile there are tons of page based interfaces, find_get_page(),
find_or_create_page(), find_lock_page() and flags version etc.
Thus I think something like filemap_add_folio_no_memcg_charge() will be
rejected.
Finally, it's not feasible to go with a new GFP flag either.
We already have __GFP_ACCOUNT for memcg charging purposes, but for
filemap_add_folio() even if we do not pass __GFP_ACCOUNT, the memcg will
still be charged.
It will be even more ugly if we add a __GFP_NO_ACCOUNT, and such attempt
is already rejected before IIRC.
Thanks,
Qu
next prev parent reply other threads:[~2024-10-01 9:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-28 4:45 Qu Wenruo
2024-09-30 17:23 ` Shakeel Butt
2024-09-30 22:00 ` Qu Wenruo
2024-10-01 1:37 ` Shakeel Butt
2024-10-01 2:03 ` Qu Wenruo
2024-10-01 9:19 ` Christoph Hellwig
2024-10-01 9:40 ` Qu Wenruo [this message]
2024-10-02 7:41 ` Christoph Hellwig
2024-10-03 8:07 ` Michal Hocko
2024-10-03 20:39 ` Shakeel Butt
2024-10-03 8:11 ` Qu Wenruo
2024-10-03 8:22 ` Michal Hocko
2024-10-03 8:23 ` Qu Wenruo
2024-10-03 20:58 ` Johannes Weiner
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=5d3f4dca-f7f3-4228-8645-ad92c7a1e5ac@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hch@infradead.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=vbabka@kernel.org \
--cc=wqu@suse.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