Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Feb 2019 15:45:53 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r344128 - head/sys/vm
Message-ID:  <201902141545.x1EFjrm2033989@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Thu Feb 14 15:45:53 2019
New Revision: 344128
URL: https://svnweb.freebsd.org/changeset/base/344128

Log:
  Make anon clustering more compatible.
  
  Make the clustering enabling knob more fine-grained by providing a
  setting where the allocation with hint is not clustered. This is aimed
  to be somewhat more compatible with e.g. go 1.4 which expects that
  hinted mmap without MAP_FIXED does not change the allocation address.
  
  Now the vm.cluster_anon can be set to 1 to only cluster when no hints,
  and to 2 to always cluster.  Default value is 1.
  
  Requested by: peter
  Reviewed by:	emaste, markj
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 month
  Differential revision:	https://reviews.freebsd.org/D19194

Modified:
  head/sys/vm/vm_map.c

Modified: head/sys/vm/vm_map.c
==============================================================================
--- head/sys/vm/vm_map.c	Thu Feb 14 15:42:29 2019	(r344127)
+++ head/sys/vm/vm_map.c	Thu Feb 14 15:45:53 2019	(r344128)
@@ -1487,8 +1487,23 @@ static const int aslr_pages_rnd_32[2] = {0x100, 0x4};
 static int cluster_anon = 1;
 SYSCTL_INT(_vm, OID_AUTO, cluster_anon, CTLFLAG_RW,
     &cluster_anon, 0,
-    "Cluster anonymous mappings");
+    "Cluster anonymous mappings: 0 = no, 1 = yes if no hint, 2 = always");
 
+static bool
+clustering_anon_allowed(vm_offset_t addr)
+{
+
+	switch (cluster_anon) {
+	case 0:
+		return (false);
+	case 1:
+		return (addr == 0);
+	case 2:
+	default:
+		return (true);
+	}
+}
+
 static long aslr_restarts;
 SYSCTL_LONG(_vm, OID_AUTO, aslr_restarts, CTLFLAG_RD,
     &aslr_restarts, 0,
@@ -1593,7 +1608,7 @@ vm_map_find(vm_map_t map, vm_object_t object, vm_ooffs
 	} else
 		alignment = 0;
 	en_aslr = (map->flags & MAP_ASLR) != 0;
-	update_anon = cluster = cluster_anon != 0 &&
+	update_anon = cluster = clustering_anon_allowed(*addr) &&
 	    (map->flags & MAP_IS_SUB_MAP) == 0 && max_addr == 0 &&
 	    find_space != VMFS_NO_SPACE && object == NULL &&
 	    (cow & (MAP_INHERIT_SHARE | MAP_STACK_GROWS_UP |



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201902141545.x1EFjrm2033989>