From: Lorenzo Stoakes Date: Mon, 11 Aug 2025 14:59:39 +0000 (+0100) Subject: man/man2/mremap.2: Describe previously undocumented shrink behaviour X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;p=thirdparty%2Fman-pages.git man/man2/mremap.2: Describe previously undocumented shrink behaviour 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 Message-ID: Signed-off-by: Alejandro Colomar --- diff --git a/man/man2/mremap.2 b/man/man2/mremap.2 index 65b4d5f58..2bdb5799c 100644 --- a/man/man2/mremap.2 +++ b/man/man2/mremap.2 @@ -47,8 +47,37 @@ The .B MREMAP_DONTUNMAP flag may also be specified. .P -If the operation is not -simply moving mappings, +Similarly, +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.