From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Jann Horn <jannh@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/5] mm: further refactor commit_merge()
Date: Tue, 28 Jan 2025 16:07:00 +0000 [thread overview]
Message-ID: <e1db515e-03aa-46f0-904a-c49be2fdda2f@lucifer.local> (raw)
In-Reply-To: <09484ff8-1b0c-4101-a793-e869aa8a6eeb@suse.cz>
On Tue, Jan 28, 2025 at 04:45:01PM +0100, Vlastimil Babka wrote:
> On 1/27/25 16:50, Lorenzo Stoakes wrote:
> > --- a/mm/vma.h
> > +++ b/mm/vma.h
> > @@ -67,6 +67,16 @@ enum vma_merge_flags {
> > * at the gap.
> > */
> > VMG_FLAG_JUST_EXPAND = 1 << 0,
> > + /*
> > + * Internal flag used during the merge operation to indicate we will
> > + * remove vmg->middle.
> > + */
> > + __VMG_FLAG_REMOVE_MIDDLE = 1 << 1,
> > + /*
> > + * Internal flag used during the merge operationr to indicate we will
> > + * remove vmg->next.
> > + */
> > + __VMG_FLAG_REMOVE_NEXT = 1 << 2,
> > };
>
> Hm this is actually kinda weird? It's an enum, but the values of it are
> defined as different bits. And then struct vma_merge_struct has a "enum
> vma_merge_flags merge_flags;" but we don't store to it a single "enum
> vma_merge_flags" value defined above, but a combination of those. Is that
> even legal to do in C?
Yes it's legal to do. And we already did it. And other parts of the kernel do
it.
I get that it breaks a switch (enum val) { case ... } statement but we don't do
that.
>
> AFAIK the more common pattern is enum that has normal incremental values
> that are used for the shifts.
>
> But I don't think we need all of this at all here? Just have bitfields in
> struct vma_merge_struct?
>
> bool just_expand : 1;
> bool remove_middle : 1;
I find that ugly, and it necessitates the addition of a new field for every new
flag.
It also prevents any masking stuff going forward and clutters everything.
It also makes the interface confusiing, because now you have users having to
know there's a field that lets you do X rather than just a simple flags field
that can encapsulate all state.
And some of those fields are now internal...
If you were to insist we have to change this, then I'd pefer a set of defines
and the but then it'd be a question of whether we typedef something for that or
just pass an unsigned long.
I prefer having the type safety of the enum even if it pedantically 'not
correct'.
C doesn't give you many sane choices for this. I am doing my part to make rust
more of a thing in mm which will help on this front ;)
> ...
>
> > /*
> > diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c
> > index 3c0572120e94..8cce67237d86 100644
> > --- a/tools/testing/vma/vma.c
> > +++ b/tools/testing/vma/vma.c
> > @@ -154,6 +154,9 @@ static void vmg_set_range(struct vma_merge_struct *vmg, unsigned long start,
> > vmg->end = end;
> > vmg->pgoff = pgoff;
> > vmg->flags = flags;
> > +
> > + vmg->merge_flags = VMG_FLAG_DEFAULT;
> > + vmg->target = NULL;
> > }
> >
> > /*
>
next prev parent reply other threads:[~2025-01-28 16:07 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-27 15:50 [PATCH 0/5] mm: further simplify VMA merge operation Lorenzo Stoakes
2025-01-27 15:50 ` [PATCH 1/5] mm: simplify vma merge structure and expand comments Lorenzo Stoakes
2025-01-28 11:38 ` Vlastimil Babka
2025-01-28 14:05 ` Lorenzo Stoakes
2025-01-27 15:50 ` [PATCH 2/5] mm: further refactor commit_merge() Lorenzo Stoakes
2025-01-28 15:05 ` Vlastimil Babka
2025-01-28 15:45 ` Vlastimil Babka
2025-01-28 16:07 ` Lorenzo Stoakes [this message]
2025-01-28 16:42 ` Lorenzo Stoakes
2025-01-27 15:50 ` [PATCH 3/5] mm: eliminate adj_start parameter from commit_merge() Lorenzo Stoakes
2025-01-29 14:13 ` Vlastimil Babka
2025-01-29 14:19 ` Lorenzo Stoakes
2025-01-27 15:50 ` [PATCH 4/5] mm: make vmg->target consistent and further simplify commit_merge() Lorenzo Stoakes
2025-01-29 14:45 ` Vlastimil Babka
2025-01-29 14:51 ` Lorenzo Stoakes
2025-01-29 15:19 ` Vlastimil Babka
2025-01-29 15:30 ` Lorenzo Stoakes
2025-01-27 15:50 ` [PATCH 5/5] mm: completely abstract unnecessary adj_start calculation Lorenzo Stoakes
2025-01-27 18:50 ` kernel test robot
2025-01-27 18:56 ` Lorenzo Stoakes
2025-01-27 19:58 ` Lorenzo Stoakes
2025-01-27 20:13 ` kernel test robot
2025-01-27 20:35 ` kernel test robot
2025-01-28 7:54 ` kernel test robot
2025-01-29 15:42 ` Vlastimil Babka
2025-01-29 16:19 ` Lorenzo Stoakes
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=e1db515e-03aa-46f0-904a-c49be2fdda2f@lucifer.local \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--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