Skip to content

Commit 1b13bf3

Browse files
authored
Merge pull request #4042 from hjelmn/v2.x_fix_3685
v2.x: hook madvaise to fix threading memory allocation issues
2 parents eb0a6ae + d000c70 commit 1b13bf3

8 files changed

+124
-40
lines changed

opal/mca/memory/patcher/memory_patcher_component.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* University of Stuttgart. All rights reserved.
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
13-
* Copyright (c) 2009-2016 Cisco Systems, Inc. All rights reserved.
13+
* Copyright (c) 2009-2017 Cisco Systems, Inc. All rights reserved
1414
* Copyright (c) 2013-2017 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* Copyright (c) 2016 Research Organization for Information Science
@@ -496,16 +496,12 @@ static int patcher_open (void)
496496
}
497497
#endif
498498

499-
/* NTH: we can't currently allow madvise to be intercepted due to a deadlock when running with glibc. in
500-
* the future we may re-enable this hook if the deadlock can be resolved. */
501-
#if 0
502499
#if defined (SYS_madvise)
503500
rc = opal_patcher->patch_symbol ("madvise", (uintptr_t)intercept_madvise, (uintptr_t *) &original_madvise);
504501
if (OPAL_SUCCESS != rc) {
505502
return rc;
506503
}
507504
#endif
508-
#endif
509505

510506
#if defined(SYS_shmdt) && defined(__linux__)
511507
rc = opal_patcher->patch_symbol ("shmdt", (uintptr_t) intercept_shmdt, (uintptr_t *) &original_shmdt);

opal/mca/rcache/base/base.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ OPAL_DECLSPEC mca_rcache_base_component_t *mca_rcache_base_component_lookup(cons
5858
OPAL_DECLSPEC mca_rcache_base_module_t *mca_rcache_base_module_lookup (const char *name);
5959
OPAL_DECLSPEC int mca_rcache_base_module_destroy(mca_rcache_base_module_t *module);
6060

61+
extern opal_free_list_t mca_rcache_base_vma_tree_items;
62+
extern bool mca_rcache_base_vma_tree_items_inited;
63+
extern unsigned int mca_rcache_base_vma_tree_items_min;
64+
extern int mca_rcache_base_vma_tree_items_max;
65+
extern unsigned int mca_rcache_base_vma_tree_items_inc;
66+
6167
/* only used within base -- no need to DECLSPEC */
6268
extern int mca_rcache_base_used_mem_hooks;
6369

opal/mca/rcache/base/rcache_base_create.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "opal/mca/rcache/rcache.h"
3030
#include "opal/mca/rcache/base/base.h"
3131
#include "opal/mca/rcache/base/rcache_base_mem_cb.h"
32+
#include "rcache_base_vma_tree.h"
3233
#include "opal/util/show_help.h"
3334
#include "opal/util/proc.h"
3435

opal/mca/rcache/base/rcache_base_frame.c

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@
2727

2828
#include "opal/mca/mca.h"
2929
#include "opal/mca/base/base.h"
30+
#include "opal/mca/base/mca_base_pvar.h"
3031
#include "opal/mca/rcache/rcache.h"
3132
#include "opal/mca/rcache/base/base.h"
3233
#include "opal/memoryhooks/memory.h"
3334
#include "opal/constants.h"
3435
#include "rcache_base_mem_cb.h"
3536

37+
/* two-level macro for stringifying a number */
38+
#define STRINGIFYX(x) #x
39+
#define STRINGIFY(x) STRINGIFYX(x)
40+
3641
/*
3742
* The following file was created by configure. It contains extern
3843
* statements and the definition of an array of pointers to each
@@ -59,12 +64,19 @@ static void mca_rcache_base_registration_constructor( mca_rcache_base_registrati
5964
OBJ_CLASS_INSTANCE(mca_rcache_base_registration_t, opal_free_list_item_t,
6065
mca_rcache_base_registration_constructor, NULL);
6166

67+
#define TREE_ITEMS_MIN 2048
68+
#define TREE_ITEMS_MAX 16384
69+
#define TREE_ITEMS_INC 2048
6270

6371
/*
6472
* Global variables
6573
*/
6674
opal_list_t mca_rcache_base_modules = {{0}};
67-
75+
opal_free_list_t mca_rcache_base_vma_tree_items = {{0}};
76+
bool mca_rcache_base_vma_tree_items_inited = false;
77+
unsigned int mca_rcache_base_vma_tree_items_min = TREE_ITEMS_MIN;
78+
int mca_rcache_base_vma_tree_items_max = TREE_ITEMS_MAX;
79+
unsigned int mca_rcache_base_vma_tree_items_inc = TREE_ITEMS_INC;
6880

6981
OBJ_CLASS_INSTANCE(mca_rcache_base_selected_module_t, opal_list_item_t, NULL, NULL);
7082

@@ -100,8 +112,11 @@ static int mca_rcache_base_close(void)
100112
time between now and end of application (even post main()!) */
101113
(void) mca_base_framework_close (&opal_memory_base_framework);
102114
}
103-
/* All done */
104115

116+
OBJ_DESTRUCT(&mca_rcache_base_vma_tree_items);
117+
mca_rcache_base_vma_tree_items_inited = false;
118+
119+
/* All done */
105120
/* Close all remaining available components */
106121
return mca_base_framework_components_close(&opal_rcache_base_framework, NULL);
107122
}
@@ -117,11 +132,42 @@ static int mca_rcache_base_open(mca_base_open_flag_t flags)
117132

118133
OBJ_CONSTRUCT(&mca_rcache_base_modules, opal_list_t);
119134

135+
/* the free list is only initialized when a VMA tree is created */
136+
OBJ_CONSTRUCT(&mca_rcache_base_vma_tree_items, opal_free_list_t);
137+
120138
/* Open up all available components */
121139
return mca_base_framework_components_open(&opal_rcache_base_framework, flags);
122140
}
123141

124-
MCA_BASE_FRAMEWORK_DECLARE(opal, rcache, "OPAL Registration Cache", NULL,
142+
static int mca_rcache_base_register_mca_variables (mca_base_register_flag_t flags)
143+
{
144+
145+
mca_rcache_base_vma_tree_items_min = TREE_ITEMS_MIN;
146+
(void) mca_base_framework_var_register (&opal_rcache_base_framework, "vma_tree_items_min",
147+
"Minimum number of VMA tree items to allocate (default: "
148+
STRINGIFY(TREE_ITEMS_MIN) ")", MCA_BASE_VAR_TYPE_UNSIGNED_INT,
149+
NULL, MCA_BASE_VAR_BIND_NO_OBJECT, 0, OPAL_INFO_LVL_6,
150+
MCA_BASE_VAR_SCOPE_READONLY, &mca_rcache_base_vma_tree_items_min);
151+
152+
mca_rcache_base_vma_tree_items_max = TREE_ITEMS_MAX;
153+
(void) mca_base_framework_var_register (&opal_rcache_base_framework, "vma_tree_items_max",
154+
"Maximum number of VMA tree items to allocate (default: "
155+
STRINGIFY(TREE_ITEMS_MAX) ", -1: unlimited)", MCA_BASE_VAR_TYPE_INT,
156+
NULL, MCA_BASE_VAR_BIND_NO_OBJECT, 0, OPAL_INFO_LVL_6,
157+
MCA_BASE_VAR_SCOPE_READONLY, &mca_rcache_base_vma_tree_items_max);
158+
159+
mca_rcache_base_vma_tree_items_inc = TREE_ITEMS_INC;
160+
(void) mca_base_framework_var_register (&opal_rcache_base_framework, "vma_tree_items_inc",
161+
"Number of VMA tree items to allocate at a time (default: "
162+
STRINGIFY(TREE_ITEMS_INC) ")", MCA_BASE_VAR_TYPE_UNSIGNED_INT,
163+
NULL, MCA_BASE_VAR_BIND_NO_OBJECT, 0, OPAL_INFO_LVL_6,
164+
MCA_BASE_VAR_SCOPE_READONLY, &mca_rcache_base_vma_tree_items_inc);
165+
166+
return OPAL_SUCCESS;
167+
}
168+
169+
MCA_BASE_FRAMEWORK_DECLARE(opal, rcache, "OPAL Registration Cache",
170+
mca_rcache_base_register_mca_variables,
125171
mca_rcache_base_open, mca_rcache_base_close,
126172
mca_rcache_base_static_components, 0);
127173

opal/mca/rcache/base/rcache_base_vma.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 2009-2013 Cisco Systems, Inc. All rights reserved.
1515
* Copyright (c) 2009 IBM Corporation. All rights reserved.
1616
* Copyright (c) 2013 NVIDIA Corporation. All rights reserved.
17-
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
17+
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
1818
* reserved.
1919
*
2020
* $COPYRIGHT$
@@ -31,6 +31,7 @@
3131
#include "opal/mca/rcache/rcache.h"
3232
#include "rcache_base_vma.h"
3333
#include "rcache_base_vma_tree.h"
34+
#include "opal/mca/rcache/base/base.h"
3435

3536
/**
3637
* Initialize the rcache
@@ -52,6 +53,14 @@ OBJ_CLASS_INSTANCE(mca_rcache_base_vma_module_t, opal_object_t,
5253

5354
mca_rcache_base_vma_module_t *mca_rcache_base_vma_module_alloc (void)
5455
{
56+
if (!mca_rcache_base_vma_tree_items_inited) {
57+
opal_free_list_init (&mca_rcache_base_vma_tree_items, sizeof (mca_rcache_base_vma_item_t),
58+
8, OBJ_CLASS(mca_rcache_base_vma_item_t), 0, 8,
59+
mca_rcache_base_vma_tree_items_min, mca_rcache_base_vma_tree_items_max,
60+
mca_rcache_base_vma_tree_items_inc, NULL, 0, NULL, NULL, NULL);
61+
mca_rcache_base_vma_tree_items_inited = true;
62+
}
63+
5564
return OBJ_NEW(mca_rcache_base_vma_module_t);
5665
}
5766

opal/mca/rcache/base/rcache_base_vma.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct mca_rcache_base_vma_module_t {
4444
opal_object_t super;
4545
opal_rb_tree_t rb_tree;
4646
opal_list_t vma_list;
47-
opal_list_t vma_gc_list;
47+
opal_lifo_t vma_gc_lifo;
4848
size_t reg_cur_cache_size;
4949
opal_mutex_t vma_lock;
5050
};

0 commit comments

Comments
 (0)