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.
@@ -241,6 +241,7 @@ int mca_rcache_base_vma_tree_init (mca_rcache_base_vma_module_t *vma_module)
241241{
242242 OBJ_CONSTRUCT (& vma_module -> rb_tree , opal_rb_tree_t );
243243 OBJ_CONSTRUCT (& vma_module -> vma_list , opal_list_t );
244+ OBJ_CONSTRUCT (& vma_module -> vma_gc_list , opal_list_t );
244245 vma_module -> reg_cur_cache_size = 0 ;
245246 return opal_rb_tree_init (& vma_module -> rb_tree , mca_rcache_base_vma_tree_node_compare );
246247}
@@ -249,6 +250,7 @@ void mca_rcache_base_vma_tree_finalize (mca_rcache_base_vma_module_t *vma_module
249250{
250251 opal_rb_tree_init (& vma_module -> rb_tree , mca_rcache_base_vma_tree_node_compare );
251252 OBJ_DESTRUCT (& vma_module -> vma_list );
253+ OBJ_DESTRUCT (& vma_module -> vma_gc_list );
252254 OBJ_DESTRUCT (& vma_module -> rb_tree );
253255}
254256
@@ -412,6 +414,20 @@ static inline int mca_rcache_base_vma_can_insert (mca_rcache_base_vma_module_t *
412414 return (0 == limit || vma_module -> reg_cur_cache_size + nbytes <= limit );
413415}
414416
417+ /**
418+ * Free deleted vmas. This can not be done when they are deleted without running
419+ * into deadlock problems with some libc versions. The caller MUST hold the vma_lock
420+ * when calling this function.
421+ */
422+ static void mca_rcache_base_vma_cleanup (mca_rcache_base_vma_module_t * vma_module )
423+ {
424+ opal_list_item_t * item ;
425+
426+ while (NULL != (item = opal_list_remove_first (& vma_module -> vma_gc_list ))) {
427+ OBJ_RELEASE (item );
428+ }
429+ }
430+
415431int mca_rcache_base_vma_tree_insert (mca_rcache_base_vma_module_t * vma_module ,
416432 mca_rcache_base_registration_t * reg , size_t limit )
417433{
@@ -420,6 +436,8 @@ int mca_rcache_base_vma_tree_insert (mca_rcache_base_vma_module_t *vma_module,
420436
421437 opal_mutex_lock (& vma_module -> vma_lock );
422438
439+ mca_rcache_base_vma_cleanup (vma_module );
440+
423441 i = (mca_rcache_base_vma_item_t * ) opal_rb_tree_find_with (& vma_module -> rb_tree ,
424442 (void * ) begin , mca_rcache_base_vma_tree_node_compare_closest );
425443
@@ -529,7 +547,6 @@ int mca_rcache_base_vma_tree_delete (mca_rcache_base_vma_module_t *vma_module,
529547 mca_rcache_base_registration_t * reg )
530548{
531549 mca_rcache_base_vma_item_t * vma ;
532- opal_list_t deleted_vmas ;
533550
534551 opal_mutex_lock (& vma_module -> vma_lock );
535552
@@ -542,8 +559,6 @@ int mca_rcache_base_vma_tree_delete (mca_rcache_base_vma_module_t *vma_module,
542559 return OPAL_ERROR ;
543560 }
544561
545- OBJ_CONSTRUCT (& deleted_vmas , opal_list_t );
546-
547562 while (vma != (mca_rcache_base_vma_item_t * ) opal_list_get_end (& vma_module -> vma_list )
548563 && vma -> start <= (uintptr_t ) reg -> bound ) {
549564 mca_rcache_base_vma_remove_reg (vma , reg );
@@ -555,7 +570,7 @@ int mca_rcache_base_vma_tree_delete (mca_rcache_base_vma_module_t *vma_module,
555570 mca_rcache_base_vma_update_byte_count (vma_module ,
556571 vma -> start - vma -> end - 1 );
557572 opal_list_remove_item (& vma_module -> vma_list , & vma -> super );
558- opal_list_append (& deleted_vmas , & vma -> super );
573+ opal_list_append (& vma_module -> vma_gc_list , & vma -> super );
559574 vma = next ;
560575 } else {
561576 int merged ;
@@ -573,7 +588,7 @@ int mca_rcache_base_vma_tree_delete (mca_rcache_base_vma_module_t *vma_module,
573588 prev -> end = vma -> end ;
574589 opal_list_remove_item (& vma_module -> vma_list , & vma -> super );
575590 opal_rb_tree_delete (& vma_module -> rb_tree , vma );
576- opal_list_append (& deleted_vmas , & vma -> super );
591+ opal_list_append (& vma_module -> vma_gc_list , & vma -> super );
577592 vma = prev ;
578593 merged = 1 ;
579594 }
@@ -587,7 +602,7 @@ int mca_rcache_base_vma_tree_delete (mca_rcache_base_vma_module_t *vma_module,
587602 vma -> end = next -> end ;
588603 opal_list_remove_item (& vma_module -> vma_list , & next -> super );
589604 opal_rb_tree_delete (& vma_module -> rb_tree , next );
590- opal_list_append (& deleted_vmas , & next -> super );
605+ opal_list_append (& vma_module -> vma_gc_list , & next -> super );
591606 merged = 1 ;
592607 }
593608 } while (merged );
@@ -598,9 +613,6 @@ int mca_rcache_base_vma_tree_delete (mca_rcache_base_vma_module_t *vma_module,
598613
599614 opal_mutex_unlock (& vma_module -> vma_lock );
600615
601- /* actually free vmas now that the lock has been dropped */
602- OPAL_LIST_DESTRUCT (& deleted_vmas );
603-
604616 return 0 ;
605617}
606618
0 commit comments