From: Johannes Weiner <hannes@cmpxchg.org>
To: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Michal Hocko <mhocko@kernel.org>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>
Subject: Re: [PATCH v2 3/5] mm: memcg: merge multiple page_counters into a single structure
Date: Fri, 26 Jul 2024 19:31:23 -0400 [thread overview]
Message-ID: <20240726233123.GG1702603@cmpxchg.org> (raw)
In-Reply-To: <ZqLg30nOUVlerBh1@google.com>
On Thu, Jul 25, 2024 at 11:33:51PM +0000, Roman Gushchin wrote:
> Hm, Idk, I do agree with what you're saying about the self-contained
> piece of abstraction (and I had very similar thoughts in the process),
> but there are also some complications.
>
> First, funny enough, the protection calculation code was just moved to
> mm/page_counter.c by a8585ac68621 ("mm/page_counter: move calculating protection
> values to page_counter"). The commit log says that it's gonna be used by the drm
> cgroup controller, but the code is not (yet?) upstream apparently. I don't have
> any insights here. If there will be the second user for the protection
> functionality, moving it back to memcontrol.c is not feasible.
If it comes to that, I think it can be its own abstraction as well,
with a struct containing all the elow, low_usage, children_low_usage
stuff etc. and API functions to propagate and get effective protection.
Both memcg and drm can embed this into their css descriptors and use
those helpers as necessary.
> Second, I agree that it would be nice to get rid of the parent pointer in
> struct page_cgroup entirely and use one in css. But Idk how to do it
> without making the code way more messy or duplicate a lot of tree walks.
> In C++ (or another language with generics) we could make struct page_counter
> taking the number of counters and the set of features as template parameters.
It shouldn't be more than a for loop right + the unwind on failure,
right? *Somewhat* duplicative, but pretty simple code that's easy to
wrap in a controller function and have it out of the way.
Actually, we could keep a simple hierarchical version of the page
counter functions, but expose non-hiearchical ones for users that want
to do additional operations on each level.
IOW, e.g. page_counter_charge_one(), page_counter_try_charge_one()
etc, then implement page_counter_charge() et al on top of these.
swap, memsw, kmem, tcpmem, hugetlb etc. could remain unchanged. The
memory counter could have a memcg version of the charge function that
uses *charge_one() and handles protection propagation.
drm could do the same.
That would keep the page_counter->parent pointer, but would save a bit
of complexity for simple users at least.
> I feel like with memcg1 code being factored out the benefit of this reorg
> lowered, so how about me resending 2 first patches separately and spending
> more time on thinking on the best long-term strategy? I have some ideas
> here and I thought about this work as a preparatory step, but maybe you're
> right and it makes sense to approach it more comprehensively.
Sounds good to me.
Thanks!
next prev parent reply other threads:[~2024-07-26 23:31 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-24 20:20 [PATCH v2 0/5] This patchset reorganizes page_counter structures which helps to make Roman Gushchin
2024-07-24 20:20 ` [PATCH v2 1/5] mm: memcg: don't call propagate_protected_usage() needlessly Roman Gushchin
2024-07-24 20:52 ` Shakeel Butt
2024-07-24 23:13 ` Yosry Ahmed
2024-07-24 23:31 ` Roman Gushchin
2024-07-24 23:35 ` Yosry Ahmed
2024-07-24 20:21 ` [PATCH v2 2/5] mm: page_counters: put page_counter_calculate_protection() under CONFIG_MEMCG Roman Gushchin
2024-07-24 23:05 ` Shakeel Butt
2024-07-24 20:21 ` [PATCH v2 3/5] mm: memcg: merge multiple page_counters into a single structure Roman Gushchin
2024-07-24 23:43 ` Shakeel Butt
2024-07-25 21:42 ` Johannes Weiner
2024-07-25 23:33 ` Roman Gushchin
2024-07-26 23:31 ` Johannes Weiner [this message]
2024-07-24 20:21 ` [PATCH v2 4/5] mm: page_counters: initialize usage using ATOMIC_LONG_INIT() macro Roman Gushchin
2024-07-24 23:45 ` Shakeel Butt
2024-07-24 20:21 ` [PATCH v2 5/5] mm: memcg: convert enum res_type to mem_counter_type Roman Gushchin
2024-07-24 23:48 ` Shakeel Butt
2024-07-24 23:54 ` Roman Gushchin
2024-07-24 20:40 ` [PATCH v2 0/5] This patchset reorganizes page_counter structures which helps to make Roman Gushchin
2024-07-24 22:17 ` Shakeel Butt
2024-07-24 22:30 ` Roman Gushchin
2024-07-25 21:42 ` Andrew Morton
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=20240726233123.GG1702603@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.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=shakeel.butt@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.