lkml.org 
[lkml]   [2011]   [Dec]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 4/5] rtth: maintain nr_allocated atomically
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);
}

\
 
 \ /
  Last update: 2011-12-17 09:01    [W:0.052 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site