浏览代码

Fix main memory leak on multiple unregister/re-register.

Samuel Thibault 12 年之前
父节点
当前提交
8ed9249cd9
共有 5 个文件被更改,包括 26 次插入11 次删除
  1. 1 0
      ChangeLog
  2. 2 2
      src/datawizard/filters.c
  3. 2 2
      src/datawizard/interfaces/data_interface.c
  4. 19 5
      src/datawizard/memalloc.c
  5. 2 2
      src/datawizard/memalloc.h

+ 1 - 0
ChangeLog

@@ -47,6 +47,7 @@ Changes:
   - Virtual SOCL device has been removed
   - Automatic scheduling still available with command queues not assigned to
     any device
+  * Fix main memory leak on multiple unregister/re-register.
 
 Small changes:
   * STARPU_NCPU should now be used instead of STARPU_NCPUS. STARPU_NCPUS is

+ 2 - 2
src/datawizard/filters.c

@@ -353,7 +353,7 @@ void starpu_data_unpartition(starpu_data_handle_t root_handle, uint32_t gatherin
 
 			if (local->allocated && local->automatically_allocated)
 				/* free the child data copy in a lazy fashion */
-				_starpu_request_mem_chunk_removal(&root_handle->children[child], node);
+				_starpu_request_mem_chunk_removal(&root_handle->children[child], node, 1);
 		}
 
 		if (!root_handle->per_node[node].allocated)
@@ -363,7 +363,7 @@ void starpu_data_unpartition(starpu_data_handle_t root_handle, uint32_t gatherin
 
 		if (!isvalid && root_handle->per_node[node].allocated && root_handle->per_node[node].automatically_allocated)
 			/* free the data copy in a lazy fashion */
-			_starpu_request_mem_chunk_removal(root_handle, node);
+			_starpu_request_mem_chunk_removal(root_handle, node, 1);
 
 		/* if there was no invalid copy, the node still has a valid copy */
 		still_valid[node] = isvalid;

+ 2 - 2
src/datawizard/interfaces/data_interface.c

@@ -595,7 +595,7 @@ static void _starpu_data_unregister(starpu_data_handle_t handle, unsigned cohere
 	for (node = 0; node < STARPU_MAXNODES; node++)
 	{
 		/* free the data copy in a lazy fashion */
-		_starpu_request_mem_chunk_removal(handle, node);
+		_starpu_request_mem_chunk_removal(handle, node, 1);
 	}
 
 	_starpu_data_requester_list_delete(handle->req_list);
@@ -636,7 +636,7 @@ static void _starpu_data_invalidate(void *data)
 		if (local->allocated && local->automatically_allocated)
 		{
 			/* free the data copy in a lazy fashion */
-			_starpu_request_mem_chunk_removal(handle, node);
+			_starpu_request_mem_chunk_removal(handle, node, 0);
 		}
 
 		local->state = STARPU_INVALID;

+ 19 - 5
src/datawizard/memalloc.c

@@ -666,8 +666,11 @@ static void register_mem_chunk(struct _starpu_data_replicate *replicate, size_t
 
 /* This function is called when the handle is destroyed (eg. when calling
  * unregister or unpartition). It puts all the memchunks that refer to the
- * specified handle into the cache. */
-void _starpu_request_mem_chunk_removal(starpu_data_handle_t handle, unsigned node)
+ * specified handle into the cache.
+ * handle_deleted specifies whether the handle is deleted or not (and thus we
+ * need to update it)
+ */
+void _starpu_request_mem_chunk_removal(starpu_data_handle_t handle, unsigned node, int handle_deleted)
 {
 	_STARPU_PTHREAD_RWLOCK_WRLOCK(&mc_rwlock[node]);
 
@@ -682,13 +685,24 @@ void _starpu_request_mem_chunk_removal(starpu_data_handle_t handle, unsigned nod
 		if (mc->data == handle)
 		{
 			/* we found the data */
-			mc->data_was_deleted = 1;
+			mc->data_was_deleted = handle_deleted;
 
 			/* remove it from the main list */
 			_starpu_mem_chunk_list_erase(mc_list[node], mc);
 
-			/* put it in the list of buffers to be removed */
-			_starpu_mem_chunk_list_push_front(memchunk_cache[node], mc);
+			/* We would never flush the node 0 cache, unless
+			 * malloc() returns NULL, which is very unlikely... */
+			/* This is particularly important when
+			 * STARPU_USE_ALLOCATION_CACHE is not enabled, as we
+			 * wouldn't even re-use these allocations! */
+			if (starpu_node_get_kind(node) == STARPU_CPU_RAM) {
+				free_memory_on_node(mc, node);
+
+				free(mc->chunk_interface);
+				_starpu_mem_chunk_delete(mc);
+			} else
+				/* put it in the list of buffers to be removed */
+				_starpu_mem_chunk_list_push_front(memchunk_cache[node], mc);
 
 			/* Note that we do not stop here because there can be
 			 * multiple replicates associated to the same handle on

+ 2 - 2
src/datawizard/memalloc.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010  Université de Bordeaux 1
+ * Copyright (C) 2009, 2010, 2012  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -58,7 +58,7 @@ LIST_TYPE(_starpu_mem_chunk_lru,
 
 void _starpu_init_mem_chunk_lists(void);
 void _starpu_deinit_mem_chunk_lists(void);
-void _starpu_request_mem_chunk_removal(starpu_data_handle_t handle, unsigned node);
+void _starpu_request_mem_chunk_removal(starpu_data_handle_t handle, unsigned node, int handle_deleted);
 int _starpu_allocate_memory_on_node(starpu_data_handle_t handle, struct _starpu_data_replicate *replicate, unsigned is_prefetch);
 size_t _starpu_free_all_automatically_allocated_buffers(uint32_t node);
 void _starpu_memchunk_recently_used(struct _starpu_mem_chunk *mc, unsigned node);