linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Suren Baghdasaryan <surenb@google.com>, bpf <bpf@vger.kernel.org>,
	 linux-mm <linux-mm@kvack.org>, Vlastimil Babka <vbabka@suse.cz>,
	Harry Yoo <harry.yoo@oracle.com>,  Michal Hocko <mhocko@suse.com>,
	Sebastian Sewior <bigeasy@linutronix.de>,
	 Andrii Nakryiko <andrii@kernel.org>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	 Steven Rostedt <rostedt@goodmis.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	 Roman Gushchin <roman.gushchin@linux.dev>
Subject: Re: [PATCH slab v5 5/6] slab: Reuse first bit for OBJEXTS_ALLOC_FAIL
Date: Fri, 12 Sep 2025 17:07:59 -0700	[thread overview]
Message-ID: <CAADnVQJuAo5K417ZZ77AA1LM5uZr5O2v1dRrEEue-v39zGVyVw@mail.gmail.com> (raw)
In-Reply-To: <e7nh3cxyhmlxds4b2ko36gnxbdfclcxu3eae5irvrd2m6qzqoj@gor7vopfe47z>

On Fri, Sep 12, 2025 at 5:02 PM Shakeel Butt <shakeel.butt@linux.dev> wrote:
>
> On Fri, Sep 12, 2025 at 02:59:08PM -0700, Alexei Starovoitov wrote:
> > On Fri, Sep 12, 2025 at 2:44 PM Shakeel Butt <shakeel.butt@linux.dev> wrote:
> > >
> > > On Fri, Sep 12, 2025 at 02:31:47PM -0700, Alexei Starovoitov wrote:
> > > > On Fri, Sep 12, 2025 at 2:29 PM Shakeel Butt <shakeel.butt@linux.dev> wrote:
> > > > >
> > > > > On Fri, Sep 12, 2025 at 02:24:26PM -0700, Alexei Starovoitov wrote:
> > > > > > On Fri, Sep 12, 2025 at 2:03 PM Suren Baghdasaryan <surenb@google.com> wrote:
> > > > > > >
> > > > > > > On Fri, Sep 12, 2025 at 12:27 PM Shakeel Butt <shakeel.butt@linux.dev> wrote:
> > > > > > > >
> > > > > > > > +Suren, Roman
> > > > > > > >
> > > > > > > > On Mon, Sep 08, 2025 at 06:00:06PM -0700, Alexei Starovoitov wrote:
> > > > > > > > > From: Alexei Starovoitov <ast@kernel.org>
> > > > > > > > >
> > > > > > > > > Since the combination of valid upper bits in slab->obj_exts with
> > > > > > > > > OBJEXTS_ALLOC_FAIL bit can never happen,
> > > > > > > > > use OBJEXTS_ALLOC_FAIL == (1ull << 0) as a magic sentinel
> > > > > > > > > instead of (1ull << 2) to free up bit 2.
> > > > > > > > >
> > > > > > > > > Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> > > > > > > >
> > > > > > > > Are we low on bits that we need to do this or is this good to have
> > > > > > > > optimization but not required?
> > > > > > >
> > > > > > > That's a good question. After this change MEMCG_DATA_OBJEXTS and
> > > > > > > OBJEXTS_ALLOC_FAIL will have the same value and they are used with the
> > > > > > > same field (page->memcg_data and slab->obj_exts are aliases). Even if
> > > > > > > page_memcg_data_flags can never be used for slab pages I think
> > > > > > > overlapping these bits is not a good idea and creates additional
> > > > > > > risks. Unless there is a good reason to do this I would advise against
> > > > > > > it.
> > > > > >
> > > > > > Completely disagree. You both missed the long discussion
> > > > > > during v4. The other alternative was to increase alignment
> > > > > > and waste memory. Saving the bit is obviously cleaner.
> > > > > > The next patch is using the saved bit.
> > > > >
> > > > > I will check out that discussion and it would be good to summarize that
> > > > > in the commit message.
> > > >
> > > > Disgaree. It's not a job of a small commit to summarize all options
> > > > that were discussed on the list. That's what the cover letter is for
> > > > and there there are links to all previous threads.
> > >
> > > Currently the commit message is only telling what the patch is doing and
> > > is missing the 'why' part and I think adding the 'why' part would make it
> > > better for future readers i.e. less effort to find why this is being
> > > done this way. (Anyways this is just a nit from me)
> >
> > I think 'why' here is obvious. Free the bit to use it later.
> > From time to time people add a sentence like
> > "this bit will be used in the next patch",
> > but I never do this and sometimes remove it from other people's
> > commits, since "in the next patch" is plenty ambiguous and not helpful.
>
> Yes, the part about the freed bit being used in later patch was clear.
> The part about if we really need it was not obvious and if I understand
> the discussion at [1] (relevant text below), it was not required but
> good to have.
> ```
>         > I was going to say "add a new flag to enum objext_flags",
>         > but all lower 3 bits of slab->obj_exts pointer are already in use? oh...
>         >
>         > Maybe need a magic trick to add one more flag,
>         > like always align the size with 16?
>         >
>         > In practice that should not lead to increase in memory consumption
>         > anyway because most of the kmalloc-* sizes are already at least
>         > 16 bytes aligned.
>
>         Yes. That's an option, but I think we can do better.
>         OBJEXTS_ALLOC_FAIL doesn't need to consume the bit.
> ```
>
> Anyways no objection from me but Harry had a followup request [2]:
> ```
>         This will work, but it would be helpful to add a comment clarifying that
>         when bit 0 is set with valid upper bits, it indicates
>         MEMCG_DATA_OBJEXTS, but when the upper bits are all zero, it indicates
>         OBJEXTS_ALLOC_FAIL.
>
>         When someone looks at the code without checking history it might not
>         be obvious at first glance.
> ```
>
> I think the above requested comment would be really useful.

... and that comment was added. pretty much verbatim copy paste
of the above. Don't you see it in the patch?

> Suren is
> fixing the condition of VM_BUG_ON_PAGE() in slab_obj_exts(). With this
> patch, I think, that condition will need to be changed again.

That's orthogonal and I'm not convinced it's correct.
slab_obj_exts() is doing the right thing. afaict.


  reply	other threads:[~2025-09-13  0:08 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-09  1:00 [PATCH slab v5 0/6] slab: Re-entrant kmalloc_nolock() Alexei Starovoitov
2025-09-09  1:00 ` [PATCH slab v5 1/6] locking/local_lock: Introduce local_lock_is_locked() Alexei Starovoitov
2025-09-09  1:00 ` [PATCH slab v5 2/6] mm: Allow GFP_ACCOUNT to be used in alloc_pages_nolock() Alexei Starovoitov
2025-09-12 17:11   ` Shakeel Butt
2025-09-12 17:15     ` Matthew Wilcox
2025-09-12 17:34       ` Alexei Starovoitov
2025-09-12 17:46         ` Shakeel Butt
2025-09-12 17:47   ` Shakeel Butt
2025-09-15  5:25   ` Harry Yoo
2025-09-09  1:00 ` [PATCH slab v5 3/6] mm: Introduce alloc_frozen_pages_nolock() Alexei Starovoitov
2025-09-12 17:15   ` Shakeel Butt
2025-09-15  5:17   ` Harry Yoo
2025-09-09  1:00 ` [PATCH slab v5 4/6] slab: Make slub local_(try)lock more precise for LOCKDEP Alexei Starovoitov
2025-09-09  1:00 ` [PATCH slab v5 5/6] slab: Reuse first bit for OBJEXTS_ALLOC_FAIL Alexei Starovoitov
2025-09-12 19:27   ` Shakeel Butt
2025-09-12 21:03     ` Suren Baghdasaryan
2025-09-12 21:11       ` Shakeel Butt
2025-09-12 21:26         ` Suren Baghdasaryan
2025-09-12 21:24       ` Alexei Starovoitov
2025-09-12 21:29         ` Shakeel Butt
2025-09-12 21:31           ` Alexei Starovoitov
2025-09-12 21:44             ` Shakeel Butt
2025-09-12 21:59               ` Alexei Starovoitov
2025-09-13  0:01                 ` Shakeel Butt
2025-09-13  0:07                   ` Alexei Starovoitov [this message]
2025-09-13  0:33                     ` Shakeel Butt
2025-09-13  0:36                       ` Suren Baghdasaryan
2025-09-13  1:12                         ` Alexei Starovoitov
2025-09-15  7:51                           ` Vlastimil Babka
2025-09-15 15:06                             ` Suren Baghdasaryan
2025-09-15 15:11                               ` Vlastimil Babka
2025-09-15 15:25                                 ` Suren Baghdasaryan
2025-09-15 20:10                                   ` Suren Baghdasaryan
2025-09-13  1:16   ` Shakeel Butt
2025-09-15  6:14   ` Harry Yoo
2025-09-09  1:00 ` [PATCH slab v5 6/6] slab: Introduce kmalloc_nolock() and kfree_nolock() Alexei Starovoitov
2025-09-15 12:52   ` Harry Yoo
2025-09-15 14:39     ` Vlastimil Babka
2025-09-16  0:56       ` Alexei Starovoitov
2025-09-16  9:55         ` Vlastimil Babka
2025-09-16  1:00     ` Alexei Starovoitov
2025-09-24  0:40   ` Harry Yoo
2025-09-24  7:43     ` Alexei Starovoitov
2025-09-24 11:07       ` Harry Yoo
2025-09-12  9:33 ` [PATCH slab v5 0/6] slab: Re-entrant kmalloc_nolock() Vlastimil Babka

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=CAADnVQJuAo5K417ZZ77AA1LM5uZr5O2v1dRrEEue-v39zGVyVw@mail.gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=bpf@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=harry.yoo@oracle.com \
    --cc=linux-mm@kvack.org \
    --cc=memxor@gmail.com \
    --cc=mhocko@suse.com \
    --cc=peterz@infradead.org \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    /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