[PATCH v5 3/3] man/man2/mremap.2: describe previously undocumented shrink behaviour

Lorenzo Stoakes posted 3 patches 1 month, 3 weeks ago
[PATCH v5 3/3] man/man2/mremap.2: describe previously undocumented shrink behaviour
Posted by Lorenzo Stoakes 1 month, 3 weeks ago
There is pre-existing logic that appears to be undocumented for an mremap()
shrink operation, where it turns out that the usual 'input range must span
a single mapping' requirement no longer applies.

In fact, it turns out that the input range specified by [old_address,
old_address + old_size) may span any number of mappings.

If shrinking in-place (that is, neither the MREMAP_FIXED nor
MREMAP_DONTUNMAP flags are specified), then the new span may also span any
number of VMAs - [old_address, old_address + new_size).

If shrinking and moving, the range specified by [old_address, old_address +
new_size) must span a single VMA.

There must be at least one VMA contained within the [old_address,
old_address + old_size) range, and old_address must be within the range of
a VMA.

Explicitly document this.

Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
 man/man2/mremap.2 | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/man/man2/mremap.2 b/man/man2/mremap.2
index 6d14bf627..53d4eda29 100644
--- a/man/man2/mremap.2
+++ b/man/man2/mremap.2
@@ -47,8 +47,35 @@ The
 .B MREMAP_DONTUNMAP
 flag may also be specified.
 .P
-If the operation is not
-simply moving mappings,
+Equally, if the operation performs a shrink,
+that is if
+.I old_size
+is greater than
+.IR new_size ,
+then
+.I old_size
+may also span multiple mappings
+which do not have to be
+adjacent to one another.
+If this shrink is performed
+in-place,
+that is,
+neither
+.BR MREMAP_FIXED ,
+nor
+.B MREMAP_DONTUNMAP
+are specified,
+.I new_size
+may also span multiple VMAs.
+However, if the range is moved,
+then
+.I new_size
+must span only a single mapping.
+.P
+If the operation is neither a
+.B MREMAP_FIXED
+move
+nor a shrink,
 then
 .I old_size
 must span only a single mapping.
-- 
2.50.1
Re: [PATCH v5 3/3] man/man2/mremap.2: describe previously undocumented shrink behaviour
Posted by Alejandro Colomar 1 month, 2 weeks ago
Hi Lorenzo,

On Mon, Aug 11, 2025 at 03:59:39PM +0100, Lorenzo Stoakes wrote:
> There is pre-existing logic that appears to be undocumented for an mremap()
> shrink operation, where it turns out that the usual 'input range must span
> a single mapping' requirement no longer applies.
> 
> In fact, it turns out that the input range specified by [old_address,
> old_address + old_size) may span any number of mappings.
> 
> If shrinking in-place (that is, neither the MREMAP_FIXED nor
> MREMAP_DONTUNMAP flags are specified), then the new span may also span any
> number of VMAs - [old_address, old_address + new_size).
> 
> If shrinking and moving, the range specified by [old_address, old_address +
> new_size) must span a single VMA.
> 
> There must be at least one VMA contained within the [old_address,
> old_address + old_size) range, and old_address must be within the range of
> a VMA.
> 
> Explicitly document this.
> 
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> ---
>  man/man2/mremap.2 | 31 +++++++++++++++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/man/man2/mremap.2 b/man/man2/mremap.2
> index 6d14bf627..53d4eda29 100644
> --- a/man/man2/mremap.2
> +++ b/man/man2/mremap.2
> @@ -47,8 +47,35 @@ The
>  .B MREMAP_DONTUNMAP
>  flag may also be specified.
>  .P
> -If the operation is not
> -simply moving mappings,
> +Equally, if the operation performs a shrink,
> +that is if

Missing comma.

> +.I old_size
> +is greater than
> +.IR new_size ,
> +then
> +.I old_size
> +may also span multiple mappings
> +which do not have to be
> +adjacent to one another.

I'm wondering if there's a missing comma or not before 'which'.
The meaning of the sentence would be different.

So, I should ask:

Does old_size > new_size mean that old_size may span multiple mappings
and you're commenting that multiple mappings need not be adjacent?

Or are multiple mappings always allowed and old_size > new_size allows
non-adjacent ones?

I suspect it's the former, right?  Then, it's missing a comma, right?


Other than this, the patch looks good.


Have a lovely night!
Alex

> +If this shrink is performed
> +in-place,
> +that is,
> +neither
> +.BR MREMAP_FIXED ,
> +nor
> +.B MREMAP_DONTUNMAP
> +are specified,
> +.I new_size
> +may also span multiple VMAs.
> +However, if the range is moved,
> +then
> +.I new_size
> +must span only a single mapping.
> +.P
> +If the operation is neither a
> +.B MREMAP_FIXED
> +move
> +nor a shrink,
>  then
>  .I old_size
>  must span only a single mapping.
> -- 
> 2.50.1
> 

-- 
<https://www.alejandro-colomar.es/>
Re: [PATCH v5 3/3] man/man2/mremap.2: describe previously undocumented shrink behaviour
Posted by Lorenzo Stoakes 1 month, 2 weeks ago
On Fri, Aug 15, 2025 at 11:36:26PM +0200, Alejandro Colomar wrote:
> Hi Lorenzo,
>
> On Mon, Aug 11, 2025 at 03:59:39PM +0100, Lorenzo Stoakes wrote:
> > There is pre-existing logic that appears to be undocumented for an mremap()
> > shrink operation, where it turns out that the usual 'input range must span
> > a single mapping' requirement no longer applies.
> >
> > In fact, it turns out that the input range specified by [old_address,
> > old_address + old_size) may span any number of mappings.
> >
> > If shrinking in-place (that is, neither the MREMAP_FIXED nor
> > MREMAP_DONTUNMAP flags are specified), then the new span may also span any
> > number of VMAs - [old_address, old_address + new_size).
> >
> > If shrinking and moving, the range specified by [old_address, old_address +
> > new_size) must span a single VMA.
> >
> > There must be at least one VMA contained within the [old_address,
> > old_address + old_size) range, and old_address must be within the range of
> > a VMA.
> >
> > Explicitly document this.
> >
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> > ---
> >  man/man2/mremap.2 | 31 +++++++++++++++++++++++++++++--
> >  1 file changed, 29 insertions(+), 2 deletions(-)
> >
> > diff --git a/man/man2/mremap.2 b/man/man2/mremap.2
> > index 6d14bf627..53d4eda29 100644
> > --- a/man/man2/mremap.2
> > +++ b/man/man2/mremap.2
> > @@ -47,8 +47,35 @@ The
> >  .B MREMAP_DONTUNMAP
> >  flag may also be specified.
> >  .P
> > -If the operation is not
> > -simply moving mappings,
> > +Equally, if the operation performs a shrink,
> > +that is if
>
> Missing comma.

Could you fix that up? Thnks!

>
> > +.I old_size
> > +is greater than
> > +.IR new_size ,
> > +then
> > +.I old_size
> > +may also span multiple mappings
> > +which do not have to be
> > +adjacent to one another.
>
> I'm wondering if there's a missing comma or not before 'which'.
> The meaning of the sentence would be different.
>
> So, I should ask:
>
> Does old_size > new_size mean that old_size may span multiple mappings
> and you're commenting that multiple mappings need not be adjacent?

Yes.

>
> Or are multiple mappings always allowed and old_size > new_size allows
> non-adjacent ones?

No.

>
> I suspect it's the former, right?  Then, it's missing a comma, right?

Yes could you fix that up?

>
>
> Other than this, the patch looks good.

Thanks!

>
>
> Have a lovely night!
> Alex
>
> > +If this shrink is performed
> > +in-place,
> > +that is,
> > +neither
> > +.BR MREMAP_FIXED ,
> > +nor
> > +.B MREMAP_DONTUNMAP
> > +are specified,
> > +.I new_size
> > +may also span multiple VMAs.
> > +However, if the range is moved,
> > +then
> > +.I new_size
> > +must span only a single mapping.
> > +.P
> > +If the operation is neither a
> > +.B MREMAP_FIXED
> > +move
> > +nor a shrink,
> >  then
> >  .I old_size
> >  must span only a single mapping.
> > --
> > 2.50.1
> >
>
> --
> <https://www.alejandro-colomar.es/>
Re: [PATCH v5 3/3] man/man2/mremap.2: describe previously undocumented shrink behaviour
Posted by Alejandro Colomar 1 month, 2 weeks ago
Hi Lorenzo,

On Tue, Aug 19, 2025 at 09:37:39PM +0100, Lorenzo Stoakes wrote:
> > > diff --git a/man/man2/mremap.2 b/man/man2/mremap.2
> > > index 6d14bf627..53d4eda29 100644
> > > --- a/man/man2/mremap.2
> > > +++ b/man/man2/mremap.2
> > > @@ -47,8 +47,35 @@ The
> > >  .B MREMAP_DONTUNMAP
> > >  flag may also be specified.
> > >  .P
> > > -If the operation is not
> > > -simply moving mappings,
> > > +Equally, if the operation performs a shrink,

I've changed s/Equally/Similarly/

> > > +that is if
> >
> > Missing comma.
> 
> Could you fix that up? Thnks!
> 
> >
> > > +.I old_size
> > > +is greater than
> > > +.IR new_size ,
> > > +then
> > > +.I old_size
> > > +may also span multiple mappings
> > > +which do not have to be
> > > +adjacent to one another.
> >
> > I'm wondering if there's a missing comma or not before 'which'.
> > The meaning of the sentence would be different.
> >
> > So, I should ask:
> >
> > Does old_size > new_size mean that old_size may span multiple mappings
> > and you're commenting that multiple mappings need not be adjacent?
> 
> Yes.
> 
> >
> > Or are multiple mappings always allowed and old_size > new_size allows
> > non-adjacent ones?
> 
> No.
> 
> >
> > I suspect it's the former, right?  Then, it's missing a comma, right?
> 
> Yes could you fix that up?

Yup.

> 
> >
> >
> > Other than this, the patch looks good.
> 
> Thanks!

Thanks for the patch!  I've applied it with those amendments.
<https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=21b1c7188ce1d66ef294eb1681361315a35e8070>


Have a lovely day!
Alex

-- 
<https://www.alejandro-colomar.es/>
Re: [PATCH v5 3/3] man/man2/mremap.2: describe previously undocumented shrink behaviour
Posted by Lorenzo Stoakes 1 month, 2 weeks ago
On Wed, Aug 20, 2025 at 12:50:25PM +0200, Alejandro Colomar wrote:
> Hi Lorenzo,
>
> On Tue, Aug 19, 2025 at 09:37:39PM +0100, Lorenzo Stoakes wrote:
> > > > diff --git a/man/man2/mremap.2 b/man/man2/mremap.2
> > > > index 6d14bf627..53d4eda29 100644
> > > > --- a/man/man2/mremap.2
> > > > +++ b/man/man2/mremap.2
> > > > @@ -47,8 +47,35 @@ The
> > > >  .B MREMAP_DONTUNMAP
> > > >  flag may also be specified.
> > > >  .P
> > > > -If the operation is not
> > > > -simply moving mappings,
> > > > +Equally, if the operation performs a shrink,
>
> I've changed s/Equally/Similarly/
>
> > > > +that is if
> > >
> > > Missing comma.
> >
> > Could you fix that up? Thnks!
> >
> > >
> > > > +.I old_size
> > > > +is greater than
> > > > +.IR new_size ,
> > > > +then
> > > > +.I old_size
> > > > +may also span multiple mappings
> > > > +which do not have to be
> > > > +adjacent to one another.
> > >
> > > I'm wondering if there's a missing comma or not before 'which'.
> > > The meaning of the sentence would be different.
> > >
> > > So, I should ask:
> > >
> > > Does old_size > new_size mean that old_size may span multiple mappings
> > > and you're commenting that multiple mappings need not be adjacent?
> >
> > Yes.
> >
> > >
> > > Or are multiple mappings always allowed and old_size > new_size allows
> > > non-adjacent ones?
> >
> > No.
> >
> > >
> > > I suspect it's the former, right?  Then, it's missing a comma, right?
> >
> > Yes could you fix that up?
>
> Yup.
>
> >
> > >
> > >
> > > Other than this, the patch looks good.
> >
> > Thanks!
>
> Thanks for the patch!  I've applied it with those amendments.
> <https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=21b1c7188ce1d66ef294eb1681361315a35e8070>

All sounds good, thanks for doing that and also for applies for other patches in
series :)

Cheers, Lorenzo

>
>
> Have a lovely day!
> Alex
>
> --
> <https://www.alejandro-colomar.es/>