svn commit: r351453 - head/sys/vm

Konstantin Belousov kib at FreeBSD.org
Sat Aug 24 14:29:14 UTC 2019


Author: kib
Date: Sat Aug 24 14:29:13 2019
New Revision: 351453
URL: https://svnweb.freebsd.org/changeset/base/351453

Log:
  Make stack grow use the same gap as stack create.
  
  Store stack_guard_page * PAGE_SIZE into the gap->next_read field at
  the time of the stack creation.  This makes the used guard size
  consistent between stack creation and stack grow time.
  
  Suggested by:	alc
  Reviewed by:	alc, markj
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week
  Differential revision:	https://reviews.freebsd.org/D21384

Modified:
  head/sys/vm/vm_map.c

Modified: head/sys/vm/vm_map.c
==============================================================================
--- head/sys/vm/vm_map.c	Sat Aug 24 13:26:34 2019	(r351452)
+++ head/sys/vm/vm_map.c	Sat Aug 24 14:29:13 2019	(r351453)
@@ -4189,8 +4189,20 @@ vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos,
 	rv = vm_map_insert(map, NULL, 0, gap_bot, gap_top, VM_PROT_NONE,
 	    VM_PROT_NONE, MAP_CREATE_GUARD | (orient == MAP_STACK_GROWS_DOWN ?
 	    MAP_CREATE_STACK_GAP_DN : MAP_CREATE_STACK_GAP_UP));
-	if (rv != KERN_SUCCESS)
+	if (rv == KERN_SUCCESS) {
+		/*
+		 * Gap can never successfully handle a fault, so
+		 * read-ahead logic is never used for it.  Re-use
+		 * next_read of the gap entry to store
+		 * stack_guard_page for vm_map_growstack().
+		 */
+		if (orient == MAP_STACK_GROWS_DOWN)
+			new_entry->prev->next_read = sgp;
+		else
+			new_entry->next->next_read = sgp;
+	} else {
 		(void)vm_map_delete(map, bot, top);
+	}
 	return (rv);
 }
 
@@ -4231,7 +4243,6 @@ vm_map_growstack(vm_map_t map, vm_offset_t addr, vm_ma
 
 	MPASS(!map->system_map);
 
-	guard = stack_guard_page * PAGE_SIZE;
 	lmemlim = lim_cur(curthread, RLIMIT_MEMLOCK);
 	stacklim = lim_cur(curthread, RLIMIT_STACK);
 	vmemlim = lim_cur(curthread, RLIMIT_VMEM);
@@ -4258,6 +4269,7 @@ retry:
 	} else {
 		return (KERN_FAILURE);
 	}
+	guard = gap_entry->next_read;
 	max_grow = gap_entry->end - gap_entry->start;
 	if (guard > max_grow)
 		return (KERN_NO_SPACE);


More information about the svn-src-head mailing list