[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <y2trzz53wb43da2dsdlz44mlyla527zqqslxqgmbgqy753tl62@f7awfhhnfuk2>
Date: Wed, 5 Mar 2025 19:37:28 -0800
From: Shakeel Butt <shakeel.butt@...ux.dev>
To: SeongJae Park <sj@...nel.org>
Cc: "Liam R. Howlett" <howlett@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>, David Hildenbrand <david@...hat.com>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>, Vlastimil Babka <vbabka@...e.cz>, kernel-team@...a.com,
linux-kernel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [RFC PATCH 05/16] mm/madvise: define and use madvise_behavior
struct for madvise_do_behavior()
On Wed, Mar 05, 2025 at 03:56:32PM -0800, SeongJae Park wrote:
> On Wed, 5 Mar 2025 13:40:17 -0800 Shakeel Butt <shakeel.butt@...ux.dev> wrote:
>
> >
> > +struct madvise_walk_param {
> > + int behavior;
> > + struct anon_vma_name *anon_name;
> > +};
>
> Only madvise_vma_behavior() will use 'behavior' field. And only
> madvise_vma_anon_name() will use 'anon_name' field. But I will have to assume
> both function _might_ use both fields when reading the madvise_walk_vmas()
> function code. That doesn't make my humble code reading that simple and
> straightforward.
>
> Also populating and passing a data structure that has data that would not
> really be used seems not very efficient to me.
>
This is not a new pattern. You can find a lot of examples in kernel
where a struct encapsulates multiple fields and its pointer is passed
around rather than those fields (or subset of them). You can check out
zap_details, vm_fault, fs_parameter. If some fields are mutually
exclusive you can have union in the struct. Also I am not sure what do
you mean by "not efficient" here. Inefficient in what sense? Unused
memory or something else?
> [...]
> > @@ -1666,8 +1674,10 @@ static bool is_memory_populate(int behavior)
> > }
> >
> > static int madvise_do_behavior(struct mm_struct *mm,
> > - unsigned long start, size_t len_in, int behavior)
> > + unsigned long start, size_t len_in,
> > + struct madvise_walk_param *arg)
> > {
> > + int behavior = arg->behavior;
> > struct blk_plug plug;
> > unsigned long end;
> > int error;
> > @@ -1681,7 +1691,7 @@ static int madvise_do_behavior(struct mm_struct *mm,
> > if (is_memory_populate(behavior))
> > error = madvise_populate(mm, start, end, behavior);
>
> 'arg' is for madvise_walk_vmas() visit function, but we're using it as a
> capsule for passing an information that will be used for madvise_do_behavior().
> This also seems not very straightforward to my humble perspective.
Here we can keep behavior as parameter to madvise_walk_vmas() and define
struct madvise_walk_param inside it with the passed behavior. Anyways
this is a very common pattern in kernel.
>
> I have no strong opinion and maybe my humble taste is too peculiar. But, if
> this is not a blocker for tlb flushes batcing, I'd like to suggest keep this
> part as is for now, and revisit for more code cleanup later. What do you
> think, Shakeel?
>
Squashing patches 5 to 8 into one is the main request from me. My other
suggestion you can ignore but let's see what other says.
Powered by blists - more mailing lists