[PATCH v2 3/4] mm, madvise: move madvise_set_anon_name() down the file

Vlastimil Babka posted 4 patches 3 months, 2 weeks ago
[PATCH v2 3/4] mm, madvise: move madvise_set_anon_name() down the file
Posted by Vlastimil Babka 3 months, 2 weeks ago
Preparatory change so that we can use madvise_lock()/unlock() in the
function without forward declarations or more thorough shuffling.

Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
 mm/madvise.c | 64 ++++++++++++++++++++++++++++++------------------------------
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 7e8819b5e9a0f183213ffe19d7e52bd5fda5f49d..cae064479cdf908707c45b941bd03d43d095eab6 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -133,38 +133,6 @@ static int replace_anon_vma_name(struct vm_area_struct *vma,
 
 	return 0;
 }
-
-static int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
-		unsigned long len_in, struct anon_vma_name *anon_name)
-{
-	unsigned long end;
-	unsigned long len;
-	struct madvise_behavior madv_behavior = {
-		.mm = mm,
-		.behavior = __MADV_SET_ANON_VMA_NAME,
-		.lock_mode = MADVISE_MMAP_WRITE_LOCK,
-		.anon_name = anon_name,
-	};
-
-	if (start & ~PAGE_MASK)
-		return -EINVAL;
-	len = (len_in + ~PAGE_MASK) & PAGE_MASK;
-
-	/* Check to see whether len was rounded up from small -ve to zero */
-	if (len_in && !len)
-		return -EINVAL;
-
-	end = start + len;
-	if (end < start)
-		return -EINVAL;
-
-	if (end == start)
-		return 0;
-
-	madv_behavior.range.start = start;
-	madv_behavior.range.end = end;
-	return madvise_walk_vmas(&madv_behavior);
-}
 #else /* CONFIG_ANON_VMA_NAME */
 static int replace_anon_vma_name(struct vm_area_struct *vma,
 				 struct anon_vma_name *anon_name)
@@ -2109,6 +2077,38 @@ static inline bool is_valid_name_char(char ch)
 		!strchr(ANON_VMA_NAME_INVALID_CHARS, ch);
 }
 
+static int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
+		unsigned long len_in, struct anon_vma_name *anon_name)
+{
+	unsigned long end;
+	unsigned long len;
+	struct madvise_behavior madv_behavior = {
+		.mm = mm,
+		.behavior = __MADV_SET_ANON_VMA_NAME,
+		.lock_mode = MADVISE_MMAP_WRITE_LOCK,
+		.anon_name = anon_name,
+	};
+
+	if (start & ~PAGE_MASK)
+		return -EINVAL;
+	len = (len_in + ~PAGE_MASK) & PAGE_MASK;
+
+	/* Check to see whether len was rounded up from small -ve to zero */
+	if (len_in && !len)
+		return -EINVAL;
+
+	end = start + len;
+	if (end < start)
+		return -EINVAL;
+
+	if (end == start)
+		return 0;
+
+	madv_behavior.range.start = start;
+	madv_behavior.range.end = end;
+	return madvise_walk_vmas(&madv_behavior);
+}
+
 int set_anon_vma_name(unsigned long addr, unsigned long size,
 		      const char __user *uname)
 {

-- 
2.50.0
Re: [PATCH v2 3/4] mm, madvise: move madvise_set_anon_name() down the file
Posted by Vlastimil Babka 3 months, 2 weeks ago
On 6/24/25 15:03, Vlastimil Babka wrote:
> Preparatory change so that we can use madvise_lock()/unlock() in the
> function without forward declarations or more thorough shuffling.

additional paragraph here:

No functional change. Move as a separate commit helps git heuristics to
detect it properly.


> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Re: [PATCH v2 3/4] mm, madvise: move madvise_set_anon_name() down the file
Posted by Lorenzo Stoakes 3 months, 2 weeks ago
On Tue, Jun 24, 2025 at 03:03:47PM +0200, Vlastimil Babka wrote:
> Preparatory change so that we can use madvise_lock()/unlock() in the
> function without forward declarations or more thorough shuffling.
>
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>

Fine, but I think this is small enough of a move to be safely combined with 4/4
as David says.

Either way:

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
>  mm/madvise.c | 64 ++++++++++++++++++++++++++++++------------------------------
>  1 file changed, 32 insertions(+), 32 deletions(-)
>
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 7e8819b5e9a0f183213ffe19d7e52bd5fda5f49d..cae064479cdf908707c45b941bd03d43d095eab6 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -133,38 +133,6 @@ static int replace_anon_vma_name(struct vm_area_struct *vma,
>
>  	return 0;
>  }
> -
> -static int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
> -		unsigned long len_in, struct anon_vma_name *anon_name)
> -{
> -	unsigned long end;
> -	unsigned long len;
> -	struct madvise_behavior madv_behavior = {
> -		.mm = mm,
> -		.behavior = __MADV_SET_ANON_VMA_NAME,
> -		.lock_mode = MADVISE_MMAP_WRITE_LOCK,
> -		.anon_name = anon_name,
> -	};
> -
> -	if (start & ~PAGE_MASK)
> -		return -EINVAL;
> -	len = (len_in + ~PAGE_MASK) & PAGE_MASK;
> -
> -	/* Check to see whether len was rounded up from small -ve to zero */
> -	if (len_in && !len)
> -		return -EINVAL;
> -
> -	end = start + len;
> -	if (end < start)
> -		return -EINVAL;
> -
> -	if (end == start)
> -		return 0;
> -
> -	madv_behavior.range.start = start;
> -	madv_behavior.range.end = end;
> -	return madvise_walk_vmas(&madv_behavior);
> -}
>  #else /* CONFIG_ANON_VMA_NAME */
>  static int replace_anon_vma_name(struct vm_area_struct *vma,
>  				 struct anon_vma_name *anon_name)
> @@ -2109,6 +2077,38 @@ static inline bool is_valid_name_char(char ch)
>  		!strchr(ANON_VMA_NAME_INVALID_CHARS, ch);
>  }
>
> +static int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
> +		unsigned long len_in, struct anon_vma_name *anon_name)
> +{
> +	unsigned long end;
> +	unsigned long len;
> +	struct madvise_behavior madv_behavior = {
> +		.mm = mm,
> +		.behavior = __MADV_SET_ANON_VMA_NAME,
> +		.lock_mode = MADVISE_MMAP_WRITE_LOCK,
> +		.anon_name = anon_name,
> +	};
> +
> +	if (start & ~PAGE_MASK)
> +		return -EINVAL;
> +	len = (len_in + ~PAGE_MASK) & PAGE_MASK;
> +
> +	/* Check to see whether len was rounded up from small -ve to zero */
> +	if (len_in && !len)
> +		return -EINVAL;
> +
> +	end = start + len;
> +	if (end < start)
> +		return -EINVAL;
> +
> +	if (end == start)
> +		return 0;
> +
> +	madv_behavior.range.start = start;
> +	madv_behavior.range.end = end;
> +	return madvise_walk_vmas(&madv_behavior);
> +}
> +
>  int set_anon_vma_name(unsigned long addr, unsigned long size,
>  		      const char __user *uname)
>  {
>
> --
> 2.50.0
>
Re: [PATCH v2 3/4] mm, madvise: move madvise_set_anon_name() down the file
Posted by David Hildenbrand 3 months, 2 weeks ago
On 24.06.25 15:03, Vlastimil Babka wrote:
> Preparatory change so that we can use madvise_lock()/unlock() in the
> function without forward declarations or more thorough shuffling.
> 
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> ---
>   mm/madvise.c | 64 ++++++++++++++++++++++++++++++------------------------------
>   1 file changed, 32 insertions(+), 32 deletions(-)
> 
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 7e8819b5e9a0f183213ffe19d7e52bd5fda5f49d..cae064479cdf908707c45b941bd03d43d095eab6 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -133,38 +133,6 @@ static int replace_anon_vma_name(struct vm_area_struct *vma,
>   
>   	return 0;
>   }
> -
> -static int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
> -		unsigned long len_in, struct anon_vma_name *anon_name)
> -{
> -	unsigned long end;
> -	unsigned long len;
> -	struct madvise_behavior madv_behavior = {
> -		.mm = mm,
> -		.behavior = __MADV_SET_ANON_VMA_NAME,
> -		.lock_mode = MADVISE_MMAP_WRITE_LOCK,
> -		.anon_name = anon_name,
> -	};
> -
> -	if (start & ~PAGE_MASK)
> -		return -EINVAL;
> -	len = (len_in + ~PAGE_MASK) & PAGE_MASK;
> -
> -	/* Check to see whether len was rounded up from small -ve to zero */
> -	if (len_in && !len)
> -		return -EINVAL;
> -
> -	end = start + len;
> -	if (end < start)
> -		return -EINVAL;
> -
> -	if (end == start)
> -		return 0;
> -
> -	madv_behavior.range.start = start;
> -	madv_behavior.range.end = end;
> -	return madvise_walk_vmas(&madv_behavior);
> -}
>   #else /* CONFIG_ANON_VMA_NAME */
>   static int replace_anon_vma_name(struct vm_area_struct *vma,
>   				 struct anon_vma_name *anon_name)
> @@ -2109,6 +2077,38 @@ static inline bool is_valid_name_char(char ch)
>   		!strchr(ANON_VMA_NAME_INVALID_CHARS, ch);
>   }
>   
> +static int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
> +		unsigned long len_in, struct anon_vma_name *anon_name)
> +{
> +	unsigned long end;
> +	unsigned long len;
> +	struct madvise_behavior madv_behavior = {
> +		.mm = mm,
> +		.behavior = __MADV_SET_ANON_VMA_NAME,
> +		.lock_mode = MADVISE_MMAP_WRITE_LOCK,
> +		.anon_name = anon_name,
> +	};
> +
> +	if (start & ~PAGE_MASK)
> +		return -EINVAL;
> +	len = (len_in + ~PAGE_MASK) & PAGE_MASK;
> +
> +	/* Check to see whether len was rounded up from small -ve to zero */
> +	if (len_in && !len)
> +		return -EINVAL;
> +
> +	end = start + len;
> +	if (end < start)
> +		return -EINVAL;
> +
> +	if (end == start)
> +		return 0;
> +
> +	madv_behavior.range.start = start;
> +	madv_behavior.range.end = end;
> +	return madvise_walk_vmas(&madv_behavior);
> +}
> +
>   int set_anon_vma_name(unsigned long addr, unsigned long size,
>   		      const char __user *uname)
>   {
> 

Personally, I would squash that into #4, given that #4 is pretty small ;)

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb
Re: [PATCH v2 3/4] mm, madvise: move madvise_set_anon_name() down the file
Posted by Vlastimil Babka 3 months, 2 weeks ago
On 6/24/25 16:05, David Hildenbrand wrote:
> On 24.06.25 15:03, Vlastimil Babka wrote:
> 
> Personally, I would squash that into #4, given that #4 is pretty small ;)
> 
> Acked-by: David Hildenbrand <david@redhat.com>

Right, the advantages of pure move commits is that git diff can colorize
them so it's immediately obvious, and git blame -C or -M can also recognize
pure moves and ignore them. Mixing moves with changes tends to break these
heuristics. But if Andrew wants to squash, feel free.
Re: [PATCH v2 3/4] mm, madvise: move madvise_set_anon_name() down the file
Posted by Suren Baghdasaryan 3 months, 2 weeks ago
On Tue, Jun 24, 2025 at 7:05 AM David Hildenbrand <david@redhat.com> wrote:
>
> On 24.06.25 15:03, Vlastimil Babka wrote:
> > Preparatory change so that we can use madvise_lock()/unlock() in the
> > function without forward declarations or more thorough shuffling.

If you respin the series please add a note that there is no functional
change here.

> >
> > Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> > ---
> >   mm/madvise.c | 64 ++++++++++++++++++++++++++++++------------------------------
> >   1 file changed, 32 insertions(+), 32 deletions(-)
> >
> > diff --git a/mm/madvise.c b/mm/madvise.c
> > index 7e8819b5e9a0f183213ffe19d7e52bd5fda5f49d..cae064479cdf908707c45b941bd03d43d095eab6 100644
> > --- a/mm/madvise.c
> > +++ b/mm/madvise.c
> > @@ -133,38 +133,6 @@ static int replace_anon_vma_name(struct vm_area_struct *vma,
> >
> >       return 0;
> >   }
> > -
> > -static int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
> > -             unsigned long len_in, struct anon_vma_name *anon_name)
> > -{
> > -     unsigned long end;
> > -     unsigned long len;
> > -     struct madvise_behavior madv_behavior = {
> > -             .mm = mm,
> > -             .behavior = __MADV_SET_ANON_VMA_NAME,
> > -             .lock_mode = MADVISE_MMAP_WRITE_LOCK,
> > -             .anon_name = anon_name,
> > -     };
> > -
> > -     if (start & ~PAGE_MASK)
> > -             return -EINVAL;
> > -     len = (len_in + ~PAGE_MASK) & PAGE_MASK;
> > -
> > -     /* Check to see whether len was rounded up from small -ve to zero */
> > -     if (len_in && !len)
> > -             return -EINVAL;
> > -
> > -     end = start + len;
> > -     if (end < start)
> > -             return -EINVAL;
> > -
> > -     if (end == start)
> > -             return 0;
> > -
> > -     madv_behavior.range.start = start;
> > -     madv_behavior.range.end = end;
> > -     return madvise_walk_vmas(&madv_behavior);
> > -}
> >   #else /* CONFIG_ANON_VMA_NAME */
> >   static int replace_anon_vma_name(struct vm_area_struct *vma,
> >                                struct anon_vma_name *anon_name)
> > @@ -2109,6 +2077,38 @@ static inline bool is_valid_name_char(char ch)
> >               !strchr(ANON_VMA_NAME_INVALID_CHARS, ch);
> >   }
> >
> > +static int madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
> > +             unsigned long len_in, struct anon_vma_name *anon_name)
> > +{
> > +     unsigned long end;
> > +     unsigned long len;
> > +     struct madvise_behavior madv_behavior = {
> > +             .mm = mm,
> > +             .behavior = __MADV_SET_ANON_VMA_NAME,
> > +             .lock_mode = MADVISE_MMAP_WRITE_LOCK,
> > +             .anon_name = anon_name,
> > +     };
> > +
> > +     if (start & ~PAGE_MASK)
> > +             return -EINVAL;
> > +     len = (len_in + ~PAGE_MASK) & PAGE_MASK;
> > +
> > +     /* Check to see whether len was rounded up from small -ve to zero */
> > +     if (len_in && !len)
> > +             return -EINVAL;
> > +
> > +     end = start + len;
> > +     if (end < start)
> > +             return -EINVAL;
> > +
> > +     if (end == start)
> > +             return 0;
> > +
> > +     madv_behavior.range.start = start;
> > +     madv_behavior.range.end = end;
> > +     return madvise_walk_vmas(&madv_behavior);
> > +}
> > +
> >   int set_anon_vma_name(unsigned long addr, unsigned long size,
> >                     const char __user *uname)
> >   {
> >
>
> Personally, I would squash that into #4, given that #4 is pretty small ;)
>
> Acked-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Suren Baghdasaryan <surenb@google.com>

>
> --
> Cheers,
>
> David / dhildenb
>