Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-9]: src/sys/uvm Pull up following revision(s) (requested by riast...



details:   https://anonhg.NetBSD.org/src/rev/6c10e9e44ff2
branches:  netbsd-9
changeset: 374112:6c10e9e44ff2
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Apr 01 16:03:48 2023 +0000

description:
Pull up following revision(s) (requested by riastradh in ticket #1623):

        sys/uvm/uvm_map.c: revision 1.396

uvm(9): Fix mmap optimization for topdown case.

PR kern/51393

diffstat:

 sys/uvm/uvm_map.c |  35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)

diffs (56 lines):

diff -r f63314f171e3 -r 6c10e9e44ff2 sys/uvm/uvm_map.c
--- a/sys/uvm/uvm_map.c Sat Apr 01 16:00:28 2023 +0000
+++ b/sys/uvm/uvm_map.c Sat Apr 01 16:03:48 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_map.c,v 1.362.2.3 2023/04/01 16:00:28 martin Exp $ */
+/*     $NetBSD: uvm_map.c,v 1.362.2.4 2023/04/01 16:03:48 martin Exp $ */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.362.2.3 2023/04/01 16:00:28 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.362.2.4 2023/04/01 16:03:48 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_pax.h"
@@ -1940,7 +1940,36 @@ uvm_map_findspace(struct vm_map *map, va
         * it, there would be four cases).
         */
 
-       if ((flags & UVM_FLAG_FIXED) == 0 && hint == vm_map_min(map)) {
+       if ((flags & UVM_FLAG_FIXED) == 0 &&
+           hint == (topdown ? vm_map_max(map) : vm_map_min(map))) {
+               /*
+                * The uvm_map_findspace algorithm is monotonic -- for
+                * topdown VM it starts with a high hint and returns a
+                * lower free address; for !topdown VM it starts with a
+                * low hint and returns a higher free address.  As an
+                * optimization, start with the first (highest for
+                * topdown, lowest for !topdown) free address.
+                *
+                * XXX This `optimization' probably doesn't actually do
+                * much in practice unless userland explicitly passes
+                * the VM map's minimum or maximum address, which
+                * varies from machine to machine (VM_MAX/MIN_ADDRESS,
+                * e.g. 0x7fbfdfeff000 on amd64 but 0xfffffffff000 on
+                * aarch64) and may vary according to other factors
+                * like sysctl vm.user_va0_disable.  In particular, if
+                * the user specifies 0 as a hint to mmap, then mmap
+                * will choose a default address which is usually _not_
+                * VM_MAX/MIN_ADDRESS but something else instead like
+                * VM_MAX_ADDRESS - stack size - guard page overhead,
+                * in which case this branch is never hit.
+                *
+                * In fact, this branch appears to have been broken for
+                * two decades between when topdown was introduced in
+                * ~2003 and when it was adapted to handle the topdown
+                * case without violating the monotonicity assertion in
+                * 2022.  Maybe Someone^TM should either ditch the
+                * optimization or find a better way to do it.
+                */
                entry = map->first_free;
        } else {
                if (uvm_map_lookup_entry(map, hint, &entry)) {



Home | Main Index | Thread Index | Old Index