Skip to content

v3.0.x: hook madvaise to fix threading memory allocation issues #4041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions opal/mca/memory/patcher/memory_patcher_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ static int patcher_query (int *);

static int mca_memory_patcher_priority;

/* NTH: we can't currently allow madvise to be intercepted due to a
* deadlock when running with glibc. In the future, we may re-enable
* this hook if the deadlock can be resolved. */
#define WANT_INTERCEPT_MADVISE 0

opal_memory_patcher_component_t mca_memory_patcher_component = {
.super = {
.memoryc_version = {
Expand Down Expand Up @@ -249,7 +244,6 @@ static void *intercept_mremap (void *start, size_t oldlen, void *new_address, si

#endif

#if WANT_INTERCEPT_MADVISE
#if defined (SYS_madvise)

static int (*original_madvise) (void *, size_t, int);
Expand Down Expand Up @@ -284,7 +278,6 @@ static int intercept_madvise (void *start, size_t length, int advice)
}

#endif
#endif // WANT_INTERCEPT_MADVISE

#if defined SYS_brk

Expand Down Expand Up @@ -503,14 +496,12 @@ static int patcher_open (void)
}
#endif

#if WANT_INTERCEPT_MADVISE
#if defined (SYS_madvise)
rc = opal_patcher->patch_symbol ("madvise", (uintptr_t)intercept_madvise, (uintptr_t *) &original_madvise);
if (OPAL_SUCCESS != rc) {
return rc;
}
#endif
#endif // WANT_INTERCEPT_MADVISE

#if defined(SYS_shmdt) && defined(__linux__)
rc = opal_patcher->patch_symbol ("shmdt", (uintptr_t) intercept_shmdt, (uintptr_t *) &original_shmdt);
Expand Down
6 changes: 6 additions & 0 deletions opal/mca/rcache/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ OPAL_DECLSPEC mca_rcache_base_component_t *mca_rcache_base_component_lookup(cons
OPAL_DECLSPEC mca_rcache_base_module_t *mca_rcache_base_module_lookup (const char *name);
OPAL_DECLSPEC int mca_rcache_base_module_destroy(mca_rcache_base_module_t *module);

extern opal_free_list_t mca_rcache_base_vma_tree_items;
extern bool mca_rcache_base_vma_tree_items_inited;
extern unsigned int mca_rcache_base_vma_tree_items_min;
extern int mca_rcache_base_vma_tree_items_max;
extern unsigned int mca_rcache_base_vma_tree_items_inc;

/* only used within base -- no need to DECLSPEC */
extern int mca_rcache_base_used_mem_hooks;

Expand Down
1 change: 1 addition & 0 deletions opal/mca/rcache/base/rcache_base_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "opal/mca/rcache/rcache.h"
#include "opal/mca/rcache/base/base.h"
#include "opal/mca/rcache/base/rcache_base_mem_cb.h"
#include "rcache_base_vma_tree.h"
#include "opal/util/show_help.h"
#include "opal/util/proc.h"

Expand Down
52 changes: 49 additions & 3 deletions opal/mca/rcache/base/rcache_base_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@

#include "opal/mca/mca.h"
#include "opal/mca/base/base.h"
#include "opal/mca/base/mca_base_pvar.h"
#include "opal/mca/rcache/rcache.h"
#include "opal/mca/rcache/base/base.h"
#include "opal/memoryhooks/memory.h"
#include "opal/constants.h"
#include "rcache_base_mem_cb.h"

/* two-level macro for stringifying a number */
#define STRINGIFYX(x) #x
#define STRINGIFY(x) STRINGIFYX(x)

/*
* The following file was created by configure. It contains extern
* statements and the definition of an array of pointers to each
Expand All @@ -59,12 +64,19 @@ static void mca_rcache_base_registration_constructor( mca_rcache_base_registrati
OBJ_CLASS_INSTANCE(mca_rcache_base_registration_t, opal_free_list_item_t,
mca_rcache_base_registration_constructor, NULL);

#define TREE_ITEMS_MIN 2048
#define TREE_ITEMS_MAX 16384
#define TREE_ITEMS_INC 2048

/*
* Global variables
*/
opal_list_t mca_rcache_base_modules = {{0}};

opal_free_list_t mca_rcache_base_vma_tree_items = {{0}};
bool mca_rcache_base_vma_tree_items_inited = false;
unsigned int mca_rcache_base_vma_tree_items_min = TREE_ITEMS_MIN;
int mca_rcache_base_vma_tree_items_max = TREE_ITEMS_MAX;
unsigned int mca_rcache_base_vma_tree_items_inc = TREE_ITEMS_INC;

OBJ_CLASS_INSTANCE(mca_rcache_base_selected_module_t, opal_list_item_t, NULL, NULL);

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

OBJ_DESTRUCT(&mca_rcache_base_vma_tree_items);
mca_rcache_base_vma_tree_items_inited = false;

/* All done */
/* Close all remaining available components */
return mca_base_framework_components_close(&opal_rcache_base_framework, NULL);
}
Expand All @@ -117,11 +132,42 @@ static int mca_rcache_base_open(mca_base_open_flag_t flags)

OBJ_CONSTRUCT(&mca_rcache_base_modules, opal_list_t);

/* the free list is only initialized when a VMA tree is created */
OBJ_CONSTRUCT(&mca_rcache_base_vma_tree_items, opal_free_list_t);

/* Open up all available components */
return mca_base_framework_components_open(&opal_rcache_base_framework, flags);
}

MCA_BASE_FRAMEWORK_DECLARE(opal, rcache, "OPAL Registration Cache", NULL,
static int mca_rcache_base_register_mca_variables (mca_base_register_flag_t flags)
{

mca_rcache_base_vma_tree_items_min = TREE_ITEMS_MIN;
(void) mca_base_framework_var_register (&opal_rcache_base_framework, "vma_tree_items_min",
"Minimum number of VMA tree items to allocate (default: "
STRINGIFY(TREE_ITEMS_MIN) ")", MCA_BASE_VAR_TYPE_UNSIGNED_INT,
NULL, MCA_BASE_VAR_BIND_NO_OBJECT, 0, OPAL_INFO_LVL_6,
MCA_BASE_VAR_SCOPE_READONLY, &mca_rcache_base_vma_tree_items_min);

mca_rcache_base_vma_tree_items_max = TREE_ITEMS_MAX;
(void) mca_base_framework_var_register (&opal_rcache_base_framework, "vma_tree_items_max",
"Maximum number of VMA tree items to allocate (default: "
STRINGIFY(TREE_ITEMS_MAX) ", -1: unlimited)", MCA_BASE_VAR_TYPE_INT,
NULL, MCA_BASE_VAR_BIND_NO_OBJECT, 0, OPAL_INFO_LVL_6,
MCA_BASE_VAR_SCOPE_READONLY, &mca_rcache_base_vma_tree_items_max);

mca_rcache_base_vma_tree_items_inc = TREE_ITEMS_INC;
(void) mca_base_framework_var_register (&opal_rcache_base_framework, "vma_tree_items_inc",
"Number of VMA tree items to allocate at a time (default: "
STRINGIFY(TREE_ITEMS_INC) ")", MCA_BASE_VAR_TYPE_UNSIGNED_INT,
NULL, MCA_BASE_VAR_BIND_NO_OBJECT, 0, OPAL_INFO_LVL_6,
MCA_BASE_VAR_SCOPE_READONLY, &mca_rcache_base_vma_tree_items_inc);

return OPAL_SUCCESS;
}

MCA_BASE_FRAMEWORK_DECLARE(opal, rcache, "OPAL Registration Cache",
mca_rcache_base_register_mca_variables,
mca_rcache_base_open, mca_rcache_base_close,
mca_rcache_base_static_components, 0);

11 changes: 10 additions & 1 deletion opal/mca/rcache/base/rcache_base_vma.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Copyright (c) 2009-2013 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2009 IBM Corporation. All rights reserved.
* Copyright (c) 2013 NVIDIA Corporation. All rights reserved.
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
* reserved.
*
* $COPYRIGHT$
Expand All @@ -31,6 +31,7 @@
#include "opal/mca/rcache/rcache.h"
#include "rcache_base_vma.h"
#include "rcache_base_vma_tree.h"
#include "opal/mca/rcache/base/base.h"

/**
* Initialize the rcache
Expand All @@ -52,6 +53,14 @@ OBJ_CLASS_INSTANCE(mca_rcache_base_vma_module_t, opal_object_t,

mca_rcache_base_vma_module_t *mca_rcache_base_vma_module_alloc (void)
{
if (!mca_rcache_base_vma_tree_items_inited) {
opal_free_list_init (&mca_rcache_base_vma_tree_items, sizeof (mca_rcache_base_vma_item_t),
8, OBJ_CLASS(mca_rcache_base_vma_item_t), 0, 8,
mca_rcache_base_vma_tree_items_min, mca_rcache_base_vma_tree_items_max,
mca_rcache_base_vma_tree_items_inc, NULL, 0, NULL, NULL, NULL);
mca_rcache_base_vma_tree_items_inited = true;
}

return OBJ_NEW(mca_rcache_base_vma_module_t);
}

Expand Down
Loading