Browse Source

Add starpu_data_can_evict function for smarter eviction strategies

Samuel Thibault 4 years ago
parent
commit
d09ec6759b
2 changed files with 23 additions and 10 deletions
  1. 5 0
      include/starpu_data.h
  2. 18 10
      src/datawizard/memalloc.c

+ 5 - 0
include/starpu_data.h

@@ -558,6 +558,11 @@ void starpu_data_set_user_data(starpu_data_handle_t handle, void* user_data);
 */
 void *starpu_data_get_user_data(starpu_data_handle_t handle);
 
+/**
+  Check whether data \p handle can be evicted now from node \p node
+*/
+int starpu_data_can_evict(starpu_data_handle_t handle, unsigned node);
+
 /** @} */
 
 #ifdef __cplusplus

+ 18 - 10
src/datawizard/memalloc.c

@@ -545,17 +545,8 @@ static void reuse_mem_chunk(unsigned node, struct _starpu_data_replicate *new_re
 	free(mc);
 }
 
-/* This function is called for memory chunks that are possibly in used (ie. not
- * in the cache). They should therefore still be associated to a handle. */
-/* mc_lock is held and may be temporarily released! */
-static size_t try_to_throw_mem_chunk(struct _starpu_mem_chunk *mc, unsigned node, struct _starpu_data_replicate *replicate, unsigned is_already_in_mc_list, enum _starpu_is_prefetch is_prefetch)
+int starpu_data_can_evict(starpu_data_handle_t handle, unsigned node)
 {
-	size_t freed = 0;
-
-	starpu_data_handle_t handle;
-	handle = mc->data;
-	STARPU_ASSERT(handle);
-
 	/* This data should be written through to this node, avoid dropping it! */
 	if (handle->wt_mask & (1<<node))
 		return 0;
@@ -569,6 +560,23 @@ static size_t try_to_throw_mem_chunk(struct _starpu_mem_chunk *mc, unsigned node
 		&& starpu_memory_nodes_get_numa_count() == 1)
 		return 0;
 
+	return 1;
+}
+
+/* This function is called for memory chunks that are possibly in used (ie. not
+ * in the cache). They should therefore still be associated to a handle. */
+/* mc_lock is held and may be temporarily released! */
+static size_t try_to_throw_mem_chunk(struct _starpu_mem_chunk *mc, unsigned node, struct _starpu_data_replicate *replicate, unsigned is_already_in_mc_list, enum _starpu_is_prefetch is_prefetch)
+{
+	size_t freed = 0;
+
+	starpu_data_handle_t handle;
+	handle = mc->data;
+	STARPU_ASSERT(handle);
+
+	if (!starpu_data_can_evict(handle, node))
+		return 0;
+
 	if (diduse_barrier && !mc->diduse)
 		/* Hasn't been used yet, avoid evicting it */
 		return 0;