Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 Jun 2014 16:04:04 +0000 (UTC)
From:      Alan Cox <alc@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r267917 - head/sys/vm
Message-ID:  <201406261604.s5QG44OR069092@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: alc
Date: Thu Jun 26 16:04:03 2014
New Revision: 267917
URL: http://svnweb.freebsd.org/changeset/base/267917

Log:
  Delay the call to crhold() in vm_map_insert() until we know that we won't
  have to undo it by calling crfree().  This reduces the total number of calls
  by vm_map_insert() to crhold() and crfree() by 45% in my tests.
  
  Eliminate an unnecessary variable from vm_map_insert().
  
  Reviewed by:	kib
  Tested by:	pho

Modified:
  head/sys/vm/vm_map.c

Modified: head/sys/vm/vm_map.c
==============================================================================
--- head/sys/vm/vm_map.c	Thu Jun 26 15:25:42 2014	(r267916)
+++ head/sys/vm/vm_map.c	Thu Jun 26 16:04:03 2014	(r267917)
@@ -1127,7 +1127,6 @@ vm_map_insert(vm_map_t map, vm_object_t 
 	vm_eflags_t protoeflags;
 	struct ucred *cred;
 	vm_inherit_t inheritance;
-	boolean_t charge_prev_obj;
 
 	VM_MAP_ASSERT_LOCKED(map);
 	KASSERT((object != kmem_object && object != kernel_object) ||
@@ -1180,7 +1179,6 @@ vm_map_insert(vm_map_t map, vm_object_t 
 		inheritance = VM_INHERIT_DEFAULT;
 
 	cred = NULL;
-	charge_prev_obj = FALSE;
 	if (cow & (MAP_ACC_NO_CHARGE | MAP_NOFAULT))
 		goto charged;
 	if ((cow & MAP_ACC_CHARGED) || ((prot & VM_PROT_WRITE) &&
@@ -1191,9 +1189,6 @@ vm_map_insert(vm_map_t map, vm_object_t 
 		    object->cred == NULL,
 		    ("OVERCOMMIT: vm_map_insert o %p", object));
 		cred = curthread->td_ucred;
-		crhold(cred);
-		if (object == NULL && !(protoeflags & MAP_ENTRY_NEEDS_COPY))
-			charge_prev_obj = TRUE;
 	}
 
 charged:
@@ -1224,7 +1219,8 @@ charged:
 		   vm_object_coalesce(prev_entry->object.vm_object,
 		       prev_entry->offset,
 		       (vm_size_t)(prev_entry->end - prev_entry->start),
-		       (vm_size_t)(end - prev_entry->end), charge_prev_obj)) {
+		       (vm_size_t)(end - prev_entry->end), cred != NULL &&
+		       (protoeflags & MAP_ENTRY_NEEDS_COPY) == 0)) {
 		/*
 		 * We were able to extend the object.  Determine if we
 		 * can extend the previous map entry to include the
@@ -1237,8 +1233,6 @@ charged:
 			prev_entry->end = end;
 			vm_map_entry_resize_free(map, prev_entry);
 			vm_map_simplify_entry(map, prev_entry);
-			if (cred != NULL)
-				crfree(cred);
 			return (KERN_SUCCESS);
 		}
 
@@ -1255,10 +1249,11 @@ charged:
 		if (cred != NULL && object != NULL && object->cred != NULL &&
 		    !(prev_entry->eflags & MAP_ENTRY_NEEDS_COPY)) {
 			/* Object already accounts for this uid. */
-			crfree(cred);
 			cred = NULL;
 		}
 	}
+	if (cred != NULL)
+		crhold(cred);
 
 	/*
 	 * Create a new entry



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