mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Randy Dunlap <rdunlap@xenotime.net>,
	Naveen Yadav <yad.naveen@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 4/5] rtth: maintain nr_allocated atomically
Date: Fri, 16 Dec 2011 23:57:44 -0800 (PST)	[thread overview]
Message-ID: <alpine.LSU.2.00.1112162356310.1981@eggly.anvils> (raw)
In-Reply-To: <alpine.LSU.2.00.1112162347440.1981@eggly.anvils>

Someone has been worrying about radix_tree_node leaks, and inserted a
lot of nr_allocated printfs; but it often came out negative because it
was not manipulated atomically.  We're already using userspace-rcu, so
use its uatomic implementation on nr_allocated (but the count still
doesn't go down to zero at the end).

Signed-off-by: Hugh Dickins <hughd@google.com>
---

 linux.c |    5 +++--
 main.c  |    4 +++-
 2 files changed, 6 insertions(+), 3 deletions(-)

--- rtth3/linux.c	2010-08-25 13:30:45.000000000 -0700
+++ rtth4/linux.c	2011-12-16 18:44:05.587897075 -0800
@@ -6,6 +6,7 @@
 
 #include <linux/mempool.h>
 #include <linux/slab.h>
+#include <urcu/uatomic_arch.h>
 
 int nr_allocated;
 
@@ -35,14 +36,14 @@ void *kmem_cache_alloc(struct kmem_cache
 	void *ret = malloc(cachep->size);
 	if (cachep->ctor)
 		cachep->ctor(ret);
-	nr_allocated++;
+	uatomic_inc(&nr_allocated);
 	return ret;
 }
 
 void kmem_cache_free(struct kmem_cache *cachep, void *objp)
 {
 	assert(objp);
-	nr_allocated--;
+	uatomic_dec(&nr_allocated);
 	memset(objp, 0, cachep->size);
 	free(objp);
 }
--- rtth3/main.c	2011-01-24 22:12:10.000000000 -0800
+++ rtth4/main.c	2011-12-16 18:44:05.587897075 -0800
@@ -261,8 +261,10 @@ int main()
 
 	regression1_test();
 	regression2_test();
-
 	single_thread_tests();
 
+	sleep(1);
+	printf("after sleep(1): %d allocated\n", nr_allocated);
+
 	exit(0);
 }

  parent reply	other threads:[~2011-12-17  7:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-17  7:51 [PATCH 0/5] rtth: Radix Tree Test Harness fixes Hugh Dickins
2011-12-17  7:53 ` [PATCH 1/5] rtth: fix Segmentation fault Hugh Dickins
2011-12-17  7:55 ` [PATCH 2/5] rtth: fix 32-bit build Hugh Dickins
2011-12-17  7:56 ` [PATCH 3/5] rtth: copy current radix_tree source Hugh Dickins
2011-12-17  7:57 ` Hugh Dickins [this message]
2011-12-17  7:59 ` [PATCH 5/5] rtth: advance to userspace-rcu-0.6.7 Hugh Dickins
2011-12-19  6:43 ` [PATCH 6/5] rtth: copy latest radix_tree source Hugh Dickins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LSU.2.00.1112162356310.1981@eggly.anvils \
    --to=hughd@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@xenotime.net \
    --cc=yad.naveen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®