Browse Source

Account cached allocation size

Samuel Thibault 10 years ago
parent
commit
5f4256410a
3 changed files with 28 additions and 11 deletions
  1. 14 0
      src/datawizard/memalloc.c
  2. 4 2
      src/datawizard/memalloc.h
  3. 10 9
      tools/gdbinit

+ 14 - 0
src/datawizard/memalloc.c

@@ -37,6 +37,8 @@ struct mc_cache_entry
 	uint32_t footprint;
 };
 static struct mc_cache_entry *mc_cache[STARPU_MAXNODES];
+static int mc_cache_nb[STARPU_MAXNODES];
+static ssize_t mc_cache_size[STARPU_MAXNODES];
 
 
 /* When reclaiming memory to allocate, we reclaim MAX(what_is_to_reclaim_on_device, data_size_coefficient*data_size) */
@@ -68,6 +70,8 @@ void _starpu_deinit_mem_chunk_lists(void)
 			_starpu_mem_chunk_list_delete(entry->list);
 			free(entry);
 		}
+		STARPU_ASSERT(mc_cache_nb[i] == 0);
+		STARPU_ASSERT(mc_cache_size[i] == 0);
 		_starpu_spin_destroy(&mc_lock[i]);
 	}
 }
@@ -530,6 +534,10 @@ static struct _starpu_mem_chunk *_starpu_memchunk_cache_lookup_locked(unsigned n
 
 		/* Remove from the cache */
 		_starpu_mem_chunk_list_erase(entry->list, mc);
+		mc_cache_nb[node]--;
+		STARPU_ASSERT(mc_cache_nb[node] >= 0);
+		mc_cache_size[node] -= mc->size;
+		STARPU_ASSERT(mc_cache_size[node] >= 0);
 		return mc;
 	}
 
@@ -606,6 +614,10 @@ static size_t flush_memchunk_cache(unsigned node, size_t reclaim)
 					continue;
 				}
 
+			mc_cache_nb[node]--;
+			STARPU_ASSERT(mc_cache_nb[node] >= 0);
+			mc_cache_size[node] -= mc->size;
+			STARPU_ASSERT(mc_cache_size[node] >= 0);
 			freed += free_memory_on_node(mc, node);
 			if (handle)
 				_starpu_spin_unlock(&handle->header_lock);
@@ -834,6 +846,8 @@ void _starpu_request_mem_chunk_removal(starpu_data_handle_t handle, struct _star
 			entry->footprint = footprint;
 			HASH_ADD(hh, mc_cache[node], footprint, sizeof(entry->footprint), entry);
 		}
+		mc_cache_nb[node]++;
+		mc_cache_size[node] += mc->size;
 		_starpu_mem_chunk_list_push_front(entry->list, mc);
 		_starpu_spin_unlock(&mc_lock[node]);
 	}

+ 4 - 2
src/datawizard/memalloc.h

@@ -47,8 +47,10 @@ LIST_TYPE(_starpu_mem_chunk,
 	unsigned automatically_allocated;
 
 	/* the size of the data is only set when calling _starpu_request_mem_chunk_removal(),
-         * it is needed by free_memory_on_node() which is called when
-         * the handle is no longer valid. It should not be used otherwise.
+	 * it is needed to estimate how much memory is in mc_cache, and by
+	 * free_memory_on_node() which is called when the handle is no longer
+	 * valid.
+	 * It should not be used otherwise.
 	 */
 	size_t size;
 

+ 10 - 9
tools/gdbinit

@@ -515,7 +515,7 @@ define starpu-memusage
   set scheduler-locking on
   set $node = 0
   while $node < descr.nnodes
-    printf "Node %u:\n", $node
+    printf "\n\nNode %u:\n", $node
     set $total = 0
     set $total_b = 0
     set $wt = 0
@@ -572,14 +572,15 @@ define starpu-memusage
       end
       set $mc = $mc->_next
     end
-    printf "  Total: %u, %u\n", $total, $total_b
-    printf "  WT: %u, %u\n", $wt, $wt_b
-    printf "  home: %u, %u\n", $home, $home_b
-    printf "  redux: %u, %u\n", $redux, $redux_b
-    printf "  relax: %u, %u\n", $relax, $relax_b
-    printf "  noref: %u, %u\n", $noref, $noref_b
-    printf "  nosubdataref: %u, %u\n", $nosubdataref, $nosubdataref_b
-    printf "  nodataref: %u, %u\n", $nodataref, $nodataref_b
+    printf "  Total used: %u, %uMiB\n", $total, $total_b / 1048576
+    printf "  WT: %u, %uMiB\n", $wt, $wt_b / 1048576
+    printf "  home: %u, %uMiB\n", $home, $home_b / 1048576
+    printf "  redux: %u, %uMiB\n", $redux, $redux_b / 1048576
+    printf "  relax: %u, %uMiB\n", $relax, $relax_b / 1048576
+    printf "  noref: %u, %uMiB\n", $noref, $noref_b / 1048576
+    printf "  nosubdataref: %u, %uMiB\n", $nosubdataref, $nosubdataref_b / 1048576
+    printf "  nodataref: %u, %uMiB\n", $nodataref, $nodataref_b / 1048576
+    printf "\n  cached: %u, %uMiB\n", mc_cache_nb[$node], mc_cache_size[$node] / 1048576
     set $node = $node + 1
   end
 end