From owner-svn-src-user@FreeBSD.ORG  Tue Dec  6 19:04:46 2011
Return-Path: <owner-svn-src-user@FreeBSD.ORG>
Delivered-To: svn-src-user@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 15A5D106566C;
	Tue,  6 Dec 2011 19:04:46 +0000 (UTC)
	(envelope-from attilio@FreeBSD.org)
Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c])
	by mx1.freebsd.org (Postfix) with ESMTP id E092F8FC0A;
	Tue,  6 Dec 2011 19:04:45 +0000 (UTC)
Received: from svn.freebsd.org (localhost [127.0.0.1])
	by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id pB6J4j8K004326;
	Tue, 6 Dec 2011 19:04:45 GMT (envelope-from attilio@svn.freebsd.org)
Received: (from attilio@localhost)
	by svn.freebsd.org (8.14.4/8.14.4/Submit) id pB6J4jTO004323;
	Tue, 6 Dec 2011 19:04:45 GMT (envelope-from attilio@svn.freebsd.org)
Message-Id: <201112061904.pB6J4jTO004323@svn.freebsd.org>
From: Attilio Rao <attilio@FreeBSD.org>
Date: Tue, 6 Dec 2011 19:04:45 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-user@freebsd.org
X-SVN-Group: user
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Cc: 
Subject: svn commit: r228312 - user/attilio/vmcontention/sys/vm
X-BeenThere: svn-src-user@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: "SVN commit messages for the experimental &quot; user&quot;
	src tree" <svn-src-user.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-user>,
	<mailto:svn-src-user-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-user>
List-Post: <mailto:svn-src-user@freebsd.org>
List-Help: <mailto:svn-src-user-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/svn-src-user>,
	<mailto:svn-src-user-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 06 Dec 2011 19:04:46 -0000

Author: attilio
Date: Tue Dec  6 19:04:45 2011
New Revision: 228312
URL: http://svn.freebsd.org/changeset/base/228312

Log:
  - Make rn_count 32-bits as it will naturally pad for 32-bit arches
  - Avoid to use atomic to manipulate it at level0 because it seems
    unneeded and introduces a bug on big-endian architectures where only
    the top half (2 bits) of the double-words are written (as sparc64,
    for example, doesn't support atomics at 16-bits) heading to a wrong
    handling of rn_count.
  
  Reported by:	flo, andreast
  Found by:	marius
  No answer by:	jeff

Modified:
  user/attilio/vmcontention/sys/vm/vm_radix.c
  user/attilio/vmcontention/sys/vm/vm_radix.h

Modified: user/attilio/vmcontention/sys/vm/vm_radix.c
==============================================================================
--- user/attilio/vmcontention/sys/vm/vm_radix.c	Tue Dec  6 18:01:09 2011	(r228311)
+++ user/attilio/vmcontention/sys/vm/vm_radix.c	Tue Dec  6 19:04:45 2011	(r228312)
@@ -344,7 +344,7 @@ vm_radix_insert(struct vm_radix *rtree, 
 	    rnode->rn_child[slot], (u_long)index));
 	val = (void *)((uintptr_t)val | VM_RADIX_BLACK);
 	rnode->rn_child[slot] = val;
-	atomic_add_int((volatile int *)&rnode->rn_count, 1);
+	rnode->rn_count++;
 	CTR6(KTR_VM,
 	    "insert: tree %p, index %ju, level %d, slot %d, rnode %p, count %u",
 	    rtree, (uintmax_t)index, level, slot, rnode, rnode->rn_count);
@@ -681,14 +681,7 @@ vm_radix_remove(struct vm_radix *rtree, 
 		    (rnode != NULL) ? rnode->rn_child[slot] : NULL,
 		    (rnode != NULL) ? rnode->rn_count : 0);
 		rnode->rn_child[slot] = NULL;
-		/*
-		 * Use atomics for the last level since red and black
-		 * will both adjust it.
-		 */
-		if (level == 0)
-			atomic_add_int((volatile int *)&rnode->rn_count, -1);
-		else
-			rnode->rn_count--;
+		rnode->rn_count--;
 		/*
 		 * Only allow black removes to prune the tree.
 		 */

Modified: user/attilio/vmcontention/sys/vm/vm_radix.h
==============================================================================
--- user/attilio/vmcontention/sys/vm/vm_radix.h	Tue Dec  6 18:01:09 2011	(r228311)
+++ user/attilio/vmcontention/sys/vm/vm_radix.h	Tue Dec  6 19:04:45 2011	(r228312)
@@ -61,8 +61,8 @@ struct vm_radix {
 CTASSERT(VM_RADIX_HEIGHT >= VM_RADIX_LIMIT);
 
 struct vm_radix_node {
-	void	*rn_child[VM_RADIX_COUNT];	/* Child nodes. */
-    	volatile uint16_t rn_count;		/* Valid children. */
+	void		*rn_child[VM_RADIX_COUNT];	/* Child nodes. */
+    	uint32_t	 rn_count;			/* Valid children. */
 };
 
 void	vm_radix_init(void);