path: root/xlators/cluster/dht
diff options
authorJeff Darcy <>2015-04-28 04:40:00 -0400
committerNiels de Vos <>2015-05-09 14:27:36 -0700
commita3af10a801a40fe990ee5db63c6dd6cb97713e4c (patch)
tree937a8588aeea9465fa56da53950664efb2b34bf1 /xlators/cluster/dht
parentec055e1e6908ac829efc103deb548cc0a774cf23 (diff)
core: use reference counting for mem_acct structures
When freeing memory, our memory-accounting code expects to be able to dereference from the (previously) allocated block to its owning translator. However, as we have already found once in option validation and twice in logging, that translator might itself have been freed and the dereference attempt causes on of our daemons to crash with SIGSEGV. This patch attempts to fix that as follows: * We no longer embed a struct mem_acct directly in a struct xlator, but instead allocate it separately. * Allocated memory blocks now contain a pointer to the mem_acct instead of the xlator. * The mem_acct structure contains a reference count, manipulated in both the normal and translator allocate/free code using atomic increments and decrements. * Because it's now a separate structure, we can defer freeing the mem_acct until its reference count reaches zero (either way). * Some unit tests were disabled, because they embedded their own copies of the implementation for what they were supposedly testing. Life's too short to spend time fixing tests that seem designed to impede progress by requiring a certain implementation as well as behavior. Change-Id: Id929b11387927136f78626901729296b6c0d0fd7 BUG: 1219026 Signed-off-by: Jeff Darcy <> Reviewed-on: Tested-by: Gluster Build System <> Reviewed-by: Krishnan Parthasarathi <> Reviewed-by: Niels de Vos <> Reviewed-by: Pranith Kumar Karampuri <> Reviewed-on: Tested-by: NetBSD Build System
Diffstat (limited to 'xlators/cluster/dht')
2 files changed, 4 insertions, 12 deletions
diff --git a/xlators/cluster/dht/src/ b/xlators/cluster/dht/src/
index a8e1ec0d286..f6c9ef2607a 100644
--- a/xlators/cluster/dht/src/
+++ b/xlators/cluster/dht/src/
@@ -53,13 +53,4 @@ if UNITTEST
CLEANFILES += *.gcda *.gcno *_xunit.xml
noinst_PROGRAMS =
-dht_layout_unittest_CPPFLAGS = $(AM_CPPFLAGS)
-dht_layout_unittest_SOURCES = unittest/dht_layout_unittest.c \
- unittest/dht_layout_mock.c \
- dht-layout.c
-dht_layout_unittest_CFLAGS = $(AM_CFLAGS) $(UNITTEST_CFLAGS)
-dht_layout_unittest_LDFLAGS = $(UNITTEST_LDFLAGS)
-noinst_PROGRAMS += dht_layout_unittest
-TESTS += dht_layout_unittest
diff --git a/xlators/cluster/dht/src/unittest/dht_layout_unittest.c b/xlators/cluster/dht/src/unittest/dht_layout_unittest.c
index 3702af366f9..84a89160e38 100644
--- a/xlators/cluster/dht/src/unittest/dht_layout_unittest.c
+++ b/xlators/cluster/dht/src/unittest/dht_layout_unittest.c
@@ -33,9 +33,10 @@ helper_xlator_init(uint32_t num_types)
xl = test_calloc(1, sizeof(xlator_t));
- xl->mem_acct.num_types = num_types;
- xl->mem_acct.rec = test_calloc(num_types, sizeof(struct mem_acct_rec));
- assert_non_null(xl->mem_acct.rec);
+ xl->mem_acct->num_types = num_types;
+ xl->mem_acct = test_calloc (sizeof(struct mem_acct)
+ + sizeof(struct mem_acct_rec) + num_types);
+ assert_non_null(xl->mem_acct);
xl->ctx = test_calloc(1, sizeof(glusterfs_ctx_t));