* [PATCH v2] mmap.2: fix description of treatment of the hint
@ 2019-02-14 16:18 Jann Horn
2019-02-14 17:13 ` Michal Hocko
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jann Horn @ 2019-02-14 16:18 UTC (permalink / raw)
To: mtk.manpages, jannh; +Cc: linux-man, linux-mm, Michal Hocko
The current manpage reads to me as if the kernel will always pick a free
space close to the requested address, but that's not the case:
mmap(0x600000000000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x600000000000
mmap(0x600000000000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x7f5042859000
You can also see this in the various implementations of
->get_unmapped_area() - if the specified address isn't available, the
kernel basically ignores the hint (apart from the 5level paging hack).
Clarify how this works a bit.
Signed-off-by: Jann Horn <jannh@google.com>
---
changed in v2:
- be less specific about what the kernel does when the requested address
is unavailable to avoid constraining future behavior changes
(Michal Hocko)
man2/mmap.2 | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/man2/mmap.2 b/man2/mmap.2
index fccfb9b3e..dbcae59be 100644
--- a/man2/mmap.2
+++ b/man2/mmap.2
@@ -71,7 +71,12 @@ If
.I addr
is not NULL,
then the kernel takes it as a hint about where to place the mapping;
-on Linux, the mapping will be created at a nearby page boundary.
+on Linux, the kernel will pick a nearby page boundary (but always above
+or equal to the value specified by
+.IR /proc/sys/vm/mmap_min_addr )
+and attempt to create the mapping there.
+If another mapping already exists there, the kernel picks a new address that
+may or may not depend on the hint.
.\" Before Linux 2.6.24, the address was rounded up to the next page
.\" boundary; since 2.6.24, it is rounded down!
The address of the new mapping is returned as the result of the call.
--
2.21.0.rc0.258.g878e2cd30e-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mmap.2: fix description of treatment of the hint
2019-02-14 16:18 [PATCH v2] mmap.2: fix description of treatment of the hint Jann Horn
@ 2019-02-14 17:13 ` Michal Hocko
2019-02-25 14:58 ` Michael Kerrisk (man-pages)
2019-02-27 14:37 ` William Kucharski
2 siblings, 0 replies; 5+ messages in thread
From: Michal Hocko @ 2019-02-14 17:13 UTC (permalink / raw)
To: Jann Horn; +Cc: mtk.manpages, linux-man, linux-mm
On Thu 14-02-19 17:18:36, Jann Horn wrote:
> The current manpage reads to me as if the kernel will always pick a free
> space close to the requested address, but that's not the case:
>
> mmap(0x600000000000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
> -1, 0) = 0x600000000000
> mmap(0x600000000000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
> -1, 0) = 0x7f5042859000
>
> You can also see this in the various implementations of
> ->get_unmapped_area() - if the specified address isn't available, the
> kernel basically ignores the hint (apart from the 5level paging hack).
>
> Clarify how this works a bit.
>
> Signed-off-by: Jann Horn <jannh@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Thanks!
> ---
> changed in v2:
> - be less specific about what the kernel does when the requested address
> is unavailable to avoid constraining future behavior changes
> (Michal Hocko)
>
> man2/mmap.2 | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/man2/mmap.2 b/man2/mmap.2
> index fccfb9b3e..dbcae59be 100644
> --- a/man2/mmap.2
> +++ b/man2/mmap.2
> @@ -71,7 +71,12 @@ If
> .I addr
> is not NULL,
> then the kernel takes it as a hint about where to place the mapping;
> -on Linux, the mapping will be created at a nearby page boundary.
> +on Linux, the kernel will pick a nearby page boundary (but always above
> +or equal to the value specified by
> +.IR /proc/sys/vm/mmap_min_addr )
> +and attempt to create the mapping there.
> +If another mapping already exists there, the kernel picks a new address that
> +may or may not depend on the hint.
> .\" Before Linux 2.6.24, the address was rounded up to the next page
> .\" boundary; since 2.6.24, it is rounded down!
> The address of the new mapping is returned as the result of the call.
> --
> 2.21.0.rc0.258.g878e2cd30e-goog
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mmap.2: fix description of treatment of the hint
2019-02-14 16:18 [PATCH v2] mmap.2: fix description of treatment of the hint Jann Horn
2019-02-14 17:13 ` Michal Hocko
@ 2019-02-25 14:58 ` Michael Kerrisk (man-pages)
2019-02-27 14:37 ` William Kucharski
2 siblings, 0 replies; 5+ messages in thread
From: Michael Kerrisk (man-pages) @ 2019-02-25 14:58 UTC (permalink / raw)
To: Jann Horn; +Cc: mtk.manpages, linux-man, linux-mm, Michal Hocko
On 2/14/19 5:18 PM, Jann Horn wrote:
> The current manpage reads to me as if the kernel will always pick a free
> space close to the requested address, but that's not the case:
>
> mmap(0x600000000000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
> -1, 0) = 0x600000000000
> mmap(0x600000000000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
> -1, 0) = 0x7f5042859000
>
> You can also see this in the various implementations of
> ->get_unmapped_area() - if the specified address isn't available, the
> kernel basically ignores the hint (apart from the 5level paging hack).
>
> Clarify how this works a bit.
>
> Signed-off-by: Jann Horn <jannh@google.com>
Thanks, Jann. Patch applied. And thanks for the review, Michal.
Cheers,
Michael
> ---
> changed in v2:
> - be less specific about what the kernel does when the requested address
> is unavailable to avoid constraining future behavior changes
> (Michal Hocko)
>
> man2/mmap.2 | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/man2/mmap.2 b/man2/mmap.2
> index fccfb9b3e..dbcae59be 100644
> --- a/man2/mmap.2
> +++ b/man2/mmap.2
> @@ -71,7 +71,12 @@ If
> .I addr
> is not NULL,
> then the kernel takes it as a hint about where to place the mapping;
> -on Linux, the mapping will be created at a nearby page boundary.
> +on Linux, the kernel will pick a nearby page boundary (but always above
> +or equal to the value specified by
> +.IR /proc/sys/vm/mmap_min_addr )
> +and attempt to create the mapping there.
> +If another mapping already exists there, the kernel picks a new address that
> +may or may not depend on the hint.
> .\" Before Linux 2.6.24, the address was rounded up to the next page
> .\" boundary; since 2.6.24, it is rounded down!
> The address of the new mapping is returned as the result of the call.
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mmap.2: fix description of treatment of the hint
2019-02-14 16:18 [PATCH v2] mmap.2: fix description of treatment of the hint Jann Horn
2019-02-14 17:13 ` Michal Hocko
2019-02-25 14:58 ` Michael Kerrisk (man-pages)
@ 2019-02-27 14:37 ` William Kucharski
2019-02-27 14:39 ` Michael Kerrisk (man-pages)
2 siblings, 1 reply; 5+ messages in thread
From: William Kucharski @ 2019-02-27 14:37 UTC (permalink / raw)
To: Jann Horn; +Cc: mtk.manpages, linux-man, linux-mm, Michal Hocko
Thanks for updating the man page!
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mmap.2: fix description of treatment of the hint
2019-02-27 14:37 ` William Kucharski
@ 2019-02-27 14:39 ` Michael Kerrisk (man-pages)
0 siblings, 0 replies; 5+ messages in thread
From: Michael Kerrisk (man-pages) @ 2019-02-27 14:39 UTC (permalink / raw)
To: William Kucharski; +Cc: Jann Horn, linux-man, Linux-MM, Michal Hocko
On Wed, 27 Feb 2019 at 15:37, William Kucharski
<william.kucharski@oracle.com> wrote:
>
>
> Thanks for updating the man page!
>
> Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Thanks for the review, William.
Cheers,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-02-27 14:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-14 16:18 [PATCH v2] mmap.2: fix description of treatment of the hint Jann Horn
2019-02-14 17:13 ` Michal Hocko
2019-02-25 14:58 ` Michael Kerrisk (man-pages)
2019-02-27 14:37 ` William Kucharski
2019-02-27 14:39 ` Michael Kerrisk (man-pages)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox