From: Roman Gushchin <roman.gushchin@linux.dev>
To: "T.J. Mercier" <tjmercier@google.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Muchun Song <muchun.song@linux.dev>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Frank van der Linden <fvdl@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/4] mm: memcg: merge multiple page_counters into a single structure
Date: Tue, 7 May 2024 19:07:22 -0700 [thread overview]
Message-ID: <C4D5522D-592F-4E55-AEFD-845D7165F89D@linux.dev> (raw)
In-Reply-To: <CABdmKX1NfkogiKQ4VGC8WoK4WLEG552QttNSUzLWRT46i2mQmw@mail.gmail.com>
> On May 7, 2024, at 5:26 PM, T.J. Mercier <tjmercier@google.com> wrote:
>
> On Fri, May 3, 2024 at 2:18 PM Roman Gushchin <roman.gushchin@linux.dev> wrote:
>>
>>> On Fri, May 03, 2024 at 02:11:17PM -0700, Shakeel Butt wrote:
>>>> On Fri, May 03, 2024 at 01:18:33PM -0700, Roman Gushchin wrote:
>>> [...]
>>>> enum mem_counter_type {
>>>> +#ifdef CONFIG_MEMCG
>>>> MCT_MEMORY, /* cgroup v1 and v2 */
>>>> MCT_SWAP, /* cgroup v2 only */
>>>> MCT_MEMSW = MCT_SWAP, /* cgroup v1 only */
>>>> MCT_KMEM, /* cgroup v1 only */
>>>> MCT_TCPMEM, /* cgroup v1 only */
>>>> +#endif
>>>> +#ifdef CONFIG_CGROUP_HUGETLB
>>>> + MCT_HUGETLB_MAX = __MCT_HUGETLB_MAX,
>>>> +#endif
>>>> + __MCT_NR_ITEMS,
>>>> };
>>>>
>>>
>>> Thanks for the awesome work. I haven't gone through all the patches yet
>>> but wanted to ask a quick question. In the above enum are you trying to
>>> do a union between memcg and hugetlb? It gave me a big pause to
>>> understand what you are trying to do.
>>
>> Yep, sort of. So the page_counter structure supports N independent
>> counters, where N is sufficient enough for both memcg and hugetlb cases.
>>
>> MCT_MEMORY, MCT_SWAP etc are used directly in the memcontrol.c code,
>> while hugetlb code just indexes. MCT_HUGETLB_MAX magic is needed to define
>> N at the compile time.
>
> Where N is __MCT_NR_ITEMS for all the counter array lengths? That
> doesn't look like it works if MCT_HUGETLB_MAX is small... i.e. there
> is both CONFIG_MEMCG and CONFIG_CGROUP_HUGETLB and (__MCT_HUGETLB_MAX
> = 1 or 3) since MCT_HUGETLB_MAX would be < MCT_TCPMEM and then
> __MCT_NR_ITEMS would be wrong?
>
> If so, what about:
>
> enum mem_counter_type {
> #ifdef CONFIG_MEMCG
> MCT_MEMORY, /* cgroup v1 and v2 */
> MCT_SWAP, /* cgroup v2 only */
> MCT_MEMSW = MCT_SWAP, /* cgroup v1 only */
> MCT_KMEM, /* cgroup v1 only */
> MCT_TCPMEM, /* cgroup v1 only */
> #endif
> MCT_MEMCG_NR_ITEMS,
> #ifdef CONFIG_CGROUP_HUGETLB
> MCT_HUGETLB_MAX = MCT_MEMCG_NR_ITEMS + __MCT_HUGETLB_MAX,
> #else
> MCT_HUGETLB_MAX = 0,
> #endif
> __MCT_NR_ITEMS = MAX(MCT_MEMCG_NR_ITEMS, MCT_HUGETLB_MAX)
> };
The page_counter structure is not shared between memory and hugetlb cgroups, so N should be big enough to accommodate 4 memcg counters __or__ 2 * HUGE_MAX_STATE hugetlb counters. Your version has enough space for both.
Thanks!
next prev parent reply other threads:[~2024-05-08 2:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-03 20:18 [PATCH v1 0/4] Page counters optimizations Roman Gushchin
2024-05-03 20:18 ` [PATCH v1 1/4] mm: memcg: convert enum res_type to mem_counter_type Roman Gushchin
2024-05-03 20:18 ` [PATCH v1 2/4] mm: memcg: merge multiple page_counters into a single structure Roman Gushchin
2024-05-03 21:11 ` Shakeel Butt
2024-05-03 21:18 ` Roman Gushchin
2024-05-08 0:26 ` T.J. Mercier
2024-05-08 2:07 ` Roman Gushchin [this message]
2024-05-10 7:15 ` kernel test robot
2024-05-03 20:18 ` [PATCH v1 3/4] mm: memcg: don't call propagate_protected_usage() needlessly Roman Gushchin
2024-05-03 20:18 ` [PATCH v1 4/4] mm: page_counters: initialize usage using ATOMIC_LONG_INIT() macro Roman Gushchin
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=C4D5522D-592F-4E55-AEFD-845D7165F89D@linux.dev \
--to=roman.gushchin@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=fvdl@google.com \
--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=shakeel.butt@linux.dev \
--cc=tjmercier@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