1616 * Copyright (c) 2009 IBM Corporation. All rights reserved.
1717 * Copyright (c) 2013 NVIDIA Corporation. All rights reserved.
1818 * Copyright (c) 2013 Cisco Systems, Inc. All rights reserved.
19- * Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
19+ * Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
2020 * reserved.
2121 * Copyright (c) 2015 Research Organization for Information Science
2222 * and Technology (RIST). All rights reserved.
@@ -265,6 +265,7 @@ int mca_rcache_vma_tree_init(mca_rcache_vma_module_t* rcache)
265265{
266266 OBJ_CONSTRUCT (& rcache -> rb_tree , opal_rb_tree_t );
267267 OBJ_CONSTRUCT (& rcache -> vma_list , opal_list_t );
268+ OBJ_CONSTRUCT (& rcache -> vma_gc_list , opal_list_t );
268269 rcache -> reg_cur_cache_size = 0 ;
269270 return opal_rb_tree_init (& rcache -> rb_tree ,
270271 mca_rcache_vma_tree_node_compare );
@@ -276,6 +277,23 @@ void mca_rcache_vma_tree_finalize(mca_rcache_vma_module_t* rcache)
276277 mca_rcache_vma_tree_node_compare );
277278 OBJ_DESTRUCT (& rcache -> vma_list );
278279 OBJ_DESTRUCT (& rcache -> rb_tree );
280+ OPAL_LIST_DESTRUCT (& rcache -> vma_gc_list );
281+ }
282+
283+ /**
284+ * Clean the vma garbage collection list
285+ *
286+ * This function releases any deleted vma structures. It MUST be called
287+ * with the VMA lock help and MAY NOT be called from a function that can
288+ * be called by a memory hook.
289+ */
290+ static void mca_rcache_vma_gc_clean (mca_rcache_vma_module_t * rcache )
291+ {
292+ opal_list_item_t * item ;
293+
294+ while (NULL != (item = opal_list_remove_first (& rcache -> vma_gc_list ))) {
295+ OBJ_RELEASE (item );
296+ }
279297}
280298
281299mca_mpool_base_registration_t * mca_rcache_vma_tree_find (
@@ -455,6 +473,8 @@ int mca_rcache_vma_tree_insert(mca_rcache_vma_module_t* vma_rcache,
455473
456474 opal_mutex_lock (& vma_rcache -> base .lock );
457475
476+ mca_rcache_vma_gc_clean (vma_rcache );
477+
458478 i = (mca_rcache_vma_t * )opal_rb_tree_find_with (& vma_rcache -> rb_tree ,
459479 (void * )begin , mca_rcache_vma_tree_node_compare_closest );
460480
@@ -553,7 +573,6 @@ int mca_rcache_vma_tree_insert(mca_rcache_vma_module_t* vma_rcache,
553573int mca_rcache_vma_tree_delete (mca_rcache_vma_module_t * vma_rcache ,
554574 mca_mpool_base_registration_t * reg )
555575{
556- opal_list_t deleted_vmas ;
557576 mca_rcache_vma_t * vma ;
558577
559578 vma = (mca_rcache_vma_t * )opal_rb_tree_find_with (& vma_rcache -> rb_tree , reg -> base ,
@@ -564,8 +583,6 @@ int mca_rcache_vma_tree_delete(mca_rcache_vma_module_t* vma_rcache,
564583
565584 opal_mutex_lock (& vma_rcache -> base .lock );
566585
567- OBJ_CONSTRUCT (& deleted_vmas , opal_list_t );
568-
569586 while (vma != (mca_rcache_vma_t * )opal_list_get_end (& vma_rcache -> vma_list )
570587 && vma -> start <= (uintptr_t )reg -> bound ) {
571588 mca_rcache_vma_remove_reg (vma , reg );
@@ -576,7 +593,7 @@ int mca_rcache_vma_tree_delete(mca_rcache_vma_module_t* vma_rcache,
576593 mca_rcache_vma_update_byte_count (vma_rcache ,
577594 vma -> start - vma -> end - 1 );
578595 opal_list_remove_item (& vma_rcache -> vma_list , & vma -> super );
579- opal_list_append (& deleted_vmas , & vma -> super );
596+ opal_list_append (& vma_rcache -> vma_gc_list , & vma -> super );
580597 vma = next ;
581598 } else {
582599 int merged ;
@@ -593,7 +610,7 @@ int mca_rcache_vma_tree_delete(mca_rcache_vma_module_t* vma_rcache,
593610 prev -> end = vma -> end ;
594611 opal_list_remove_item (& vma_rcache -> vma_list , & vma -> super );
595612 opal_rb_tree_delete (& vma_rcache -> rb_tree , vma );
596- opal_list_append (& deleted_vmas , & vma -> super );
613+ opal_list_append (& vma_rcache -> vma_gc_list , & vma -> super );
597614 vma = prev ;
598615 merged = 1 ;
599616 }
@@ -606,7 +623,7 @@ int mca_rcache_vma_tree_delete(mca_rcache_vma_module_t* vma_rcache,
606623 vma -> end = next -> end ;
607624 opal_list_remove_item (& vma_rcache -> vma_list , & next -> super );
608625 opal_rb_tree_delete (& vma_rcache -> rb_tree , next );
609- opal_list_append (& deleted_vmas , & next -> super );
626+ opal_list_append (& vma_rcache -> vma_gc_list , & next -> super );
610627 merged = 1 ;
611628 }
612629 } while (merged );
@@ -616,9 +633,6 @@ int mca_rcache_vma_tree_delete(mca_rcache_vma_module_t* vma_rcache,
616633
617634 opal_mutex_unlock (& vma_rcache -> base .lock );
618635
619- /* actually free vmas now that the lock has been dropped */
620- OPAL_LIST_DESTRUCT (& deleted_vmas );
621-
622636 return 0 ;
623637}
624638
0 commit comments