Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Apr 2012 16:41:19 +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: r233954 - head/sys/amd64/amd64
Message-ID:  <201204061641.q36GfJkI017531@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: alc
Date: Fri Apr  6 16:41:19 2012
New Revision: 233954
URL: http://svn.freebsd.org/changeset/base/233954

Log:
  Micro-optimize free_pv_entry() for the expected case.

Modified:
  head/sys/amd64/amd64/pmap.c

Modified: head/sys/amd64/amd64/pmap.c
==============================================================================
--- head/sys/amd64/amd64/pmap.c	Fri Apr  6 16:32:29 2012	(r233953)
+++ head/sys/amd64/amd64/pmap.c	Fri Apr  6 16:41:19 2012	(r233954)
@@ -2095,7 +2095,6 @@ pmap_collect(pmap_t locked_pmap, struct 
 	}
 }
 
-
 /*
  * free the pv_entry back to the free list
  */
@@ -2116,13 +2115,16 @@ free_pv_entry(pmap_t pmap, pv_entry_t pv
 	field = idx / 64;
 	bit = idx % 64;
 	pc->pc_map[field] |= 1ul << bit;
-	/* move to head of list */
-	TAILQ_REMOVE(&pmap->pm_pvchunk, pc, pc_list);
 	if (pc->pc_map[0] != PC_FREE0 || pc->pc_map[1] != PC_FREE1 ||
 	    pc->pc_map[2] != PC_FREE2) {
-		TAILQ_INSERT_HEAD(&pmap->pm_pvchunk, pc, pc_list);
+		/* 98% of the time, pc is already at the head of the list. */
+		if (__predict_false(pc != TAILQ_FIRST(&pmap->pm_pvchunk))) {
+			TAILQ_REMOVE(&pmap->pm_pvchunk, pc, pc_list);
+			TAILQ_INSERT_HEAD(&pmap->pm_pvchunk, pc, pc_list);
+		}
 		return;
 	}
+	TAILQ_REMOVE(&pmap->pm_pvchunk, pc, pc_list);
 	PV_STAT(pv_entry_spare -= _NPCPV);
 	PV_STAT(pc_chunk_count--);
 	PV_STAT(pc_chunk_frees++);



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