All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Clean index map on exit
@ 2014-04-11 16:58 Hannes Weisbach
       [not found] ` <EB3C2705-3925-49DD-8DB2-07BAE9E60A05-hi6Y0CQ0nG0@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Hannes Weisbach @ 2014-04-11 16:58 UTC (permalink / raw)
  To: linux-rdma-u79uwXL29TY76Z2rM5mHXA

This patch adds the function idm_free() to free all entries of an index
map. A call to this function is added in the ucma_cleanup destructor.
The ucma_idm struct index_map is cleaned.

Signed-off-by: Hannes Weisbach <hannes_weisbach-hi6Y0CQ0nG0@public.gmane.org>
---
 src/cma.c     | 1 +
 src/indexer.c | 8 ++++++++
 src/indexer.h | 1 +
 3 files changed, 10 insertions(+)

diff --git a/src/cma.c b/src/cma.c
index 0cf4203..a533bf9 100644
--- a/src/cma.c
+++ b/src/cma.c
@@ -139,6 +139,7 @@ static void ucma_cleanup(void)
 			ibv_close_device(cma_dev_array[cma_dev_cnt].verbs);
 		}
 
+		idm_free(&ucma_idm);
 		fastlock_destroy(&idm_lock);
 		free(cma_dev_array);
 		cma_dev_cnt = 0;
diff --git a/src/indexer.c b/src/indexer.c
index c8e8bce..4d1fd77 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -164,3 +164,11 @@ void *idm_clear(struct index_map *idm, int index)
 	entry[idx_entry_index(index)] = NULL;
 	return item;
 }
+
+void idm_free(struct index_map *idm)
+{
+	size_t i;
+	for (i = 0; i < IDX_ARRAY_SIZE; i++) {
+	free(idm->array[i]);
+	}
+}
diff --git a/src/indexer.h b/src/indexer.h
index 0c5f388..829d46b 100644
--- a/src/indexer.h
+++ b/src/indexer.h
@@ -89,6 +89,7 @@ struct index_map
 
 int idm_set(struct index_map *idm, int index, void *item);
 void *idm_clear(struct index_map *idm, int index);
+void idm_free(struct index_map *idm);
 
 static inline void *idm_at(struct index_map *idm, int index)
 {
-- 
1.8.5.5


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Clean index map on exit
       [not found] ` <EB3C2705-3925-49DD-8DB2-07BAE9E60A05-hi6Y0CQ0nG0@public.gmane.org>
@ 2014-04-11 17:06   ` Yann Droneaud
       [not found]     ` <1397235970.29001.23.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Yann Droneaud @ 2014-04-11 17:06 UTC (permalink / raw)
  To: Hannes Weisbach; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA

Le vendredi 11 avril 2014 à 18:58 +0200, Hannes Weisbach a écrit :
> This patch adds the function idm_free() to free all entries of an index
> map. A call to this function is added in the ucma_cleanup destructor.
> The ucma_idm struct index_map is cleaned.
> 

Please explain the purpose: what's your goal ?

> Signed-off-by: Hannes Weisbach <hannes_weisbach-hi6Y0CQ0nG0@public.gmane.org>
> ---
>  src/cma.c     | 1 +
>  src/indexer.c | 8 ++++++++
>  src/indexer.h | 1 +
>  3 files changed, 10 insertions(+)
> 
> diff --git a/src/cma.c b/src/cma.c
> index 0cf4203..a533bf9 100644
> --- a/src/cma.c
> +++ b/src/cma.c
> @@ -139,6 +139,7 @@ static void ucma_cleanup(void)
>  			ibv_close_device(cma_dev_array[cma_dev_cnt].verbs);
>  		}
>  
> +		idm_free(&ucma_idm);
>  		fastlock_destroy(&idm_lock);
>  		free(cma_dev_array);
>  		cma_dev_cnt = 0;
> diff --git a/src/indexer.c b/src/indexer.c
> index c8e8bce..4d1fd77 100644
> --- a/src/indexer.c
> +++ b/src/indexer.c
> @@ -164,3 +164,11 @@ void *idm_clear(struct index_map *idm, int index)
>  	entry[idx_entry_index(index)] = NULL;
>  	return item;
>  }
> +
> +void idm_free(struct index_map *idm)
> +{
> +	size_t i;
> +	for (i = 0; i < IDX_ARRAY_SIZE; i++) {
> +	free(idm->array[i]);
> +	}
> +}

Is the array always full ? is the maximum index of the array
IDX_ARRAY_SIZE or could it be lower ?

And what about idm, is it free()'d somewhere else ?

> diff --git a/src/indexer.h b/src/indexer.h
> index 0c5f388..829d46b 100644
> --- a/src/indexer.h
> +++ b/src/indexer.h
> @@ -89,6 +89,7 @@ struct index_map
>  
>  int idm_set(struct index_map *idm, int index, void *item);
>  void *idm_clear(struct index_map *idm, int index);
> +void idm_free(struct index_map *idm);
>  
>  static inline void *idm_at(struct index_map *idm, int index)
>  {

Regards.

-- 
Yann Droneaud
OPTEYA


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Clean index map on exit
       [not found]     ` <1397235970.29001.23.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2014-04-11 17:55       ` Hannes Weisbach
  0 siblings, 0 replies; 3+ messages in thread
From: Hannes Weisbach @ 2014-04-11 17:55 UTC (permalink / raw)
  To: Yann Droneaud; +Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA


> 
> Is the array always full ?
No, but it has to be zero-initialized and free(NULL) is fine.

idm_set() does:
if (!idm->array[idx_array_index(index)]) {
		if (idm_grow(idm, index) < 0)
(idm_grow does calloc().)

So I concluded unused entries have to be zero already and I don't put
a new constraint on struct index_map.

> is the maximum index of the array
> IDX_ARRAY_SIZE or could it be lower ?
It's fixed:
struct index_map
{
	void **array[IDX_ARRAY_SIZE];
};

> And what about idm, is it free()'d somewhere else ?
The owner has to take care of its struct index_map.  I can only free
the resources the map itself holds.
For what it's worth: all struct index_maps are declared statically.

Again, thank you for your quick feedback.

Best regards,
Hannes
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-11 17:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-11 16:58 [PATCH] Clean index map on exit Hannes Weisbach
     [not found] ` <EB3C2705-3925-49DD-8DB2-07BAE9E60A05-hi6Y0CQ0nG0@public.gmane.org>
2014-04-11 17:06   ` Yann Droneaud
     [not found]     ` <1397235970.29001.23.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2014-04-11 17:55       ` Hannes Weisbach

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.