From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Michal Hocko <mhocko@suse.com>, Johannes Weiner <hannes@cmpxchg.org>
Cc: Qu Wenruo <wqu@suse.com>,
linux-btrfs@vger.kernel.org, roman.gushchin@linux.dev,
shakeel.butt@linux.dev, muchun.song@linux.dev,
cgroups@vger.kernel.org, linux-mm@kvack.org,
Vlastimil Babka <vbabka@kernel.org>
Subject: Re: [PATCH v7 2/3] btrfs: always uses root memcgroup for filemap_add_folio()
Date: Wed, 24 Jul 2024 13:16:39 +0930 [thread overview]
Message-ID: <b01886c2-d9ba-4797-a188-7bc1c83eef71@gmx.com> (raw)
In-Reply-To: <Zpqs0HdfPCy2hfDh@tiehlicka>
在 2024/7/20 03:43, Michal Hocko 写道:
[...]
>
>>> + set_active_memcg(old_memcg);
>>
>> It looks correct. But it's going through all dance to set up
>> current->active_memcg, then have the charge path look that up,
>> css_get(), call try_charge() only to bail immediately, css_put(), then
>> update current->active_memcg again. All those branches are necessary
>> when we want to charge to a "real" other cgroup. But in this case, we
>> always know we're not charging, so it seems uncalled for.
>>
>> Wouldn't it be a lot simpler (and cheaper) to have a
>> filemap_add_folio_nocharge()?
>
> Yes, that would certainly simplify things. From the previous discussion
> I understood that there would be broader scopes which would opt-out from
> charging. If this is really about a single filemap_add_folio call then
> having a variant without doesn't call mem_cgroup_charge sounds like a
> much more viable option and also it doesn't require to make any memcg
> specific changes.
>
Talking about skipping mem cgroup charging, I still have a question.
[MEMCG AT FOLIO EVICTION TIME]
Even we completely skip the mem cgroup charging, we cannot really escape
the eviction time handling.
In fact if we just skip the mem_cgroup_charge(), kernel would crash when
evicting the folio.
As in lru_gen_eviction(), folio_memcg() would just return NULL, and
mem_cgroup_id(memcg) would trigger a NULL pointer dereference.
That's why I sent out a patch fixing that first:
https://lore.kernel.org/linux-mm/e1036b9cc8928be9a7dec150ab3a0317bd7180cf.1720572937.git.wqu@suse.com/
I'm not sure if it's going to cause any extra problems even with the
above fix.
And just for the sake of consistency, it looks more sane to have
root_mem_cgroup for the filemap_add_folio() operation, other than leave
it empty, especially since most filemaps still need proper memcg handling.
[REALLY EXPENSIVE?]
Another question is, is the set_active_memcg() and later handling really
that expensive?
set_active_memcg() is small enough to be an inline function, so is the
active_memcg(), css_get() and the root memcg path of try_charge().
Later commit part is not that expensive either, mostly simple member or
per-cpu assignment.
According to my very little knowledge about mem cgroup, most of the
heavy lifting part is in the slow path of try_charge_memcg().
Even with all the set_active_memcg(), the whole extra overhead still
look very tiny.
And it should already be a big win for btrfs to opt-out the regular
charging routine.
Thanks,
Qu
next prev parent reply other threads:[~2024-07-24 3:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-19 10:28 [PATCH v7 0/3] btrfs: try to allocate larger folios for metadata Qu Wenruo
2024-07-19 10:28 ` [PATCH v7 1/3] memcontrol: define root_mem_cgroup for CONFIG_MEMCG=n cases Qu Wenruo
2024-07-19 11:13 ` Michal Hocko
2024-07-19 21:58 ` Qu Wenruo
2024-07-22 7:32 ` Michal Hocko
2024-07-19 10:28 ` [PATCH v7 2/3] btrfs: always uses root memcgroup for filemap_add_folio() Qu Wenruo
2024-07-19 17:02 ` Johannes Weiner
2024-07-19 17:25 ` Roman Gushchin
2024-07-19 18:13 ` Michal Hocko
2024-07-19 22:11 ` Qu Wenruo
2024-07-22 7:34 ` Michal Hocko
2024-07-22 8:08 ` Qu Wenruo
2024-07-24 3:46 ` Qu Wenruo [this message]
2024-07-19 10:28 ` [PATCH v7 3/3] btrfs: prefer to allocate larger folio for metadata Qu Wenruo
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=b01886c2-d9ba-4797-a188-7bc1c83eef71@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-mm@kvack.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