From a3af10a801a40fe990ee5db63c6dd6cb97713e4c Mon Sep 17 00:00:00 2001 From: Jeff Darcy Date: Tue, 28 Apr 2015 04:40:00 -0400 Subject: 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: http://review.gluster.org/10417 Tested-by: Gluster Build System Reviewed-by: Krishnan Parthasarathi Reviewed-by: Niels de Vos Reviewed-by: Pranith Kumar Karampuri Reviewed-on: http://review.gluster.org/10723 Tested-by: NetBSD Build System --- api/src/glfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/src/glfs.c') diff --git a/api/src/glfs.c b/api/src/glfs.c index d6a6fe9c850..897d3eab809 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -965,7 +965,7 @@ glusterfs_ctx_destroy (glusterfs_ctx_t *ctx) return 0; /* For all the graphs, crawl through the xlator_t structs and free - * all its members except for the mem_acct.rec member, + * all its members except for the mem_acct member, * as GF_FREE will be referencing it. */ list_for_each_entry_safe (trav_graph, tmp, &ctx->graphs, list) { -- cgit