16
16
* Copyright (c) 2009 IBM Corporation. All rights reserved.
17
17
* Copyright (c) 2013 NVIDIA Corporation. All rights reserved.
18
18
* 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
20
20
* reserved.
21
21
* Copyright (c) 2015 Research Organization for Information Science
22
22
* and Technology (RIST). All rights reserved.
@@ -265,6 +265,7 @@ int mca_rcache_vma_tree_init(mca_rcache_vma_module_t* rcache)
265
265
{
266
266
OBJ_CONSTRUCT (& rcache -> rb_tree , opal_rb_tree_t );
267
267
OBJ_CONSTRUCT (& rcache -> vma_list , opal_list_t );
268
+ OBJ_CONSTRUCT (& rcache -> vma_gc_list , opal_list_t );
268
269
rcache -> reg_cur_cache_size = 0 ;
269
270
return opal_rb_tree_init (& rcache -> rb_tree ,
270
271
mca_rcache_vma_tree_node_compare );
@@ -276,6 +277,23 @@ void mca_rcache_vma_tree_finalize(mca_rcache_vma_module_t* rcache)
276
277
mca_rcache_vma_tree_node_compare );
277
278
OBJ_DESTRUCT (& rcache -> vma_list );
278
279
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
+ }
279
297
}
280
298
281
299
mca_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,
455
473
456
474
opal_mutex_lock (& vma_rcache -> base .lock );
457
475
476
+ mca_rcache_vma_gc_clean (vma_rcache );
477
+
458
478
i = (mca_rcache_vma_t * )opal_rb_tree_find_with (& vma_rcache -> rb_tree ,
459
479
(void * )begin , mca_rcache_vma_tree_node_compare_closest );
460
480
@@ -553,7 +573,6 @@ int mca_rcache_vma_tree_insert(mca_rcache_vma_module_t* vma_rcache,
553
573
int mca_rcache_vma_tree_delete (mca_rcache_vma_module_t * vma_rcache ,
554
574
mca_mpool_base_registration_t * reg )
555
575
{
556
- opal_list_t deleted_vmas ;
557
576
mca_rcache_vma_t * vma ;
558
577
559
578
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,
564
583
565
584
opal_mutex_lock (& vma_rcache -> base .lock );
566
585
567
- OBJ_CONSTRUCT (& deleted_vmas , opal_list_t );
568
-
569
586
while (vma != (mca_rcache_vma_t * )opal_list_get_end (& vma_rcache -> vma_list )
570
587
&& vma -> start <= (uintptr_t )reg -> bound ) {
571
588
mca_rcache_vma_remove_reg (vma , reg );
@@ -576,7 +593,7 @@ int mca_rcache_vma_tree_delete(mca_rcache_vma_module_t* vma_rcache,
576
593
mca_rcache_vma_update_byte_count (vma_rcache ,
577
594
vma -> start - vma -> end - 1 );
578
595
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 );
580
597
vma = next ;
581
598
} else {
582
599
int merged ;
@@ -593,7 +610,7 @@ int mca_rcache_vma_tree_delete(mca_rcache_vma_module_t* vma_rcache,
593
610
prev -> end = vma -> end ;
594
611
opal_list_remove_item (& vma_rcache -> vma_list , & vma -> super );
595
612
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 );
597
614
vma = prev ;
598
615
merged = 1 ;
599
616
}
@@ -606,7 +623,7 @@ int mca_rcache_vma_tree_delete(mca_rcache_vma_module_t* vma_rcache,
606
623
vma -> end = next -> end ;
607
624
opal_list_remove_item (& vma_rcache -> vma_list , & next -> super );
608
625
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 );
610
627
merged = 1 ;
611
628
}
612
629
} while (merged );
@@ -616,9 +633,6 @@ int mca_rcache_vma_tree_delete(mca_rcache_vma_module_t* vma_rcache,
616
633
617
634
opal_mutex_unlock (& vma_rcache -> base .lock );
618
635
619
- /* actually free vmas now that the lock has been dropped */
620
- OPAL_LIST_DESTRUCT (& deleted_vmas );
621
-
622
636
return 0 ;
623
637
}
624
638
0 commit comments