* Add malloc_interpose memory manager intercept functions that should work
on all glibc systems (tested with x86 and x86_64 with a couple of C++ compilers). While not as ideal as the malloc_hooks method, it does have the advantage of working with threads. * Modified malloc_hooks component to properly follow prefix rule. No functionality changes * Make the memory framework only chose one component, and modify all components to set priority to 20, except malloc-interpose, which is at 10. This means that on Linux, malloc_hooks will be used unless threads are enabled, since I think malloc_hooks is a better design choice when we can use it This commit was SVN r6949.
Этот коммит содержится в:
родитель
27bb12f665
Коммит
f2769f14e8
19
opal/mca/memory/configure.m4
Обычный файл
19
opal/mca/memory/configure.m4
Обычный файл
@ -0,0 +1,19 @@
|
|||||||
|
dnl -*- shell-script -*-
|
||||||
|
dnl
|
||||||
|
dnl Copyright (c) 2004-2005 The Trustees of Indiana University.
|
||||||
|
dnl All rights reserved.
|
||||||
|
dnl Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
||||||
|
dnl All rights reserved.
|
||||||
|
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
||||||
|
dnl University of Stuttgart. All rights reserved.
|
||||||
|
dnl Copyright (c) 2004-2005 The Regents of the University of California.
|
||||||
|
dnl All rights reserved.
|
||||||
|
dnl $COPYRIGHT$
|
||||||
|
dnl
|
||||||
|
dnl Additional copyrights may follow
|
||||||
|
dnl
|
||||||
|
dnl $HEADER$
|
||||||
|
dnl
|
||||||
|
|
||||||
|
dnl we only want one :)
|
||||||
|
m4_define(MCA_memory_CONFIGURE_MODE, STOP_AT_FIRST)
|
@ -17,4 +17,5 @@
|
|||||||
|
|
||||||
# Specific to this module
|
# Specific to this module
|
||||||
|
|
||||||
|
PARAM_CONFIG_PRIORITY=20
|
||||||
PARAM_CONFIG_FILES="Makefile"
|
PARAM_CONFIG_FILES="Makefile"
|
||||||
|
@ -20,5 +20,6 @@ noinst_LTLIBRARIES = libmca_memory_malloc_hooks.la
|
|||||||
|
|
||||||
# Source code files
|
# Source code files
|
||||||
libmca_memory_malloc_hooks_la_SOURCES = \
|
libmca_memory_malloc_hooks_la_SOURCES = \
|
||||||
malloc_hooks.c \
|
memory_malloc_hooks.c \
|
||||||
malloc_hooks_component.c
|
memory_malloc_hooks_component.c
|
||||||
|
libmca_memory_malloc_hooks_la_LIBADD = $(memory_malloc_hooks_LIBS)
|
||||||
|
@ -64,9 +64,23 @@ AC_DEFUN([MCA_memory_malloc_hooks_CONFIG],[
|
|||||||
[memory_malloc_hooks_happy="yes"],
|
[memory_malloc_hooks_happy="yes"],
|
||||||
[memory_malloc_hooks_happy="no"])])
|
[memory_malloc_hooks_happy="no"])])
|
||||||
|
|
||||||
|
memory_malloc_hooks_LIBS_SAVE="$LIBS"
|
||||||
|
AS_IF([test "$memory_malloc_hooks_happy" = "yes"],
|
||||||
|
[AC_CHECK_LIB([dl],
|
||||||
|
[dlsym],
|
||||||
|
[memory_malloc_hooks_happy="yes"],
|
||||||
|
[memory_malloc_hooks_happy="no"])])
|
||||||
|
LIBS="$memory_malloc_hooks_LIBS_SAVE"
|
||||||
|
|
||||||
|
AS_IF([test "$memory_malloc_hooks_happy" = "yes"],
|
||||||
|
[memory_malloc_hooks_WRAPPER_EXTRA_LIBS="-ldl"
|
||||||
|
memory_malloc_hooks_LIBS="-ldl"])
|
||||||
|
|
||||||
AS_IF([test "$memory_malloc_hooks_happy" = "no" -a \
|
AS_IF([test "$memory_malloc_hooks_happy" = "no" -a \
|
||||||
"$memory_malloc_hoooks_should_use" = "1"],
|
"$memory_malloc_hoooks_should_use" = "1"],
|
||||||
[AC_MSG_ERROR([malloc_hooks memory management requested but not available. Aborting.])])
|
[AC_MSG_ERROR([malloc hooks memory management requested but not available. Aborting.])])
|
||||||
|
|
||||||
|
AC_SUBST(memory_malloc_hooks_LIBS)
|
||||||
|
|
||||||
AS_IF([test "$memory_malloc_hooks_happy" = "yes"],
|
AS_IF([test "$memory_malloc_hooks_happy" = "yes"],
|
||||||
[$1], [$2])
|
[$1], [$2])
|
||||||
|
@ -17,4 +17,5 @@
|
|||||||
|
|
||||||
# Specific to this module
|
# Specific to this module
|
||||||
|
|
||||||
|
PARAM_CONFIG_PRIORITY=20
|
||||||
PARAM_CONFIG_FILES="Makefile"
|
PARAM_CONFIG_FILES="Makefile"
|
||||||
|
24
opal/mca/memory/malloc_interpose/Makefile.am
Обычный файл
24
opal/mca/memory/malloc_interpose/Makefile.am
Обычный файл
@ -0,0 +1,24 @@
|
|||||||
|
#
|
||||||
|
# Copyright (c) 2004-2005 The Trustees of Indiana University.
|
||||||
|
# All rights reserved.
|
||||||
|
# Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
||||||
|
# All rights reserved.
|
||||||
|
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
||||||
|
# University of Stuttgart. All rights reserved.
|
||||||
|
# Copyright (c) 2004-2005 The Regents of the University of California.
|
||||||
|
# All rights reserved.
|
||||||
|
# $COPYRIGHT$
|
||||||
|
#
|
||||||
|
# Additional copyrights may follow
|
||||||
|
#
|
||||||
|
# $HEADER$
|
||||||
|
#
|
||||||
|
|
||||||
|
include $(top_srcdir)/config/Makefile.options
|
||||||
|
|
||||||
|
noinst_LTLIBRARIES = libmca_memory_malloc_interpose.la
|
||||||
|
|
||||||
|
# Source code files
|
||||||
|
libmca_memory_malloc_interpose_la_SOURCES = \
|
||||||
|
memory_malloc_interpose.c
|
||||||
|
libmca_memory_malloc_interpose_la_LIBADD = $(memory_malloc_interpose_LIBS)
|
73
opal/mca/memory/malloc_interpose/configure.m4
Обычный файл
73
opal/mca/memory/malloc_interpose/configure.m4
Обычный файл
@ -0,0 +1,73 @@
|
|||||||
|
# -*- shell-script -*-
|
||||||
|
#
|
||||||
|
# Copyright (c) 2004-2005 The Trustees of Indiana University.
|
||||||
|
# All rights reserved.
|
||||||
|
# Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
||||||
|
# All rights reserved.
|
||||||
|
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
||||||
|
# University of Stuttgart. All rights reserved.
|
||||||
|
# Copyright (c) 2004-2005 The Regents of the University of California.
|
||||||
|
# All rights reserved.
|
||||||
|
# $COPYRIGHT$
|
||||||
|
#
|
||||||
|
# Additional copyrights may follow
|
||||||
|
#
|
||||||
|
# $HEADER$
|
||||||
|
#
|
||||||
|
|
||||||
|
AC_DEFUN([MCA_memory_malloc_interpose_COMPILE_MODE], [
|
||||||
|
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
|
||||||
|
$4="static"
|
||||||
|
AC_MSG_RESULT([$$4])
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
# MCA_memory_malloc_interpose_CONFIG(action-if-can-compile,
|
||||||
|
# [action-if-cant-compile])
|
||||||
|
# ------------------------------------------------
|
||||||
|
AC_DEFUN([MCA_memory_malloc_interpose_CONFIG],[
|
||||||
|
AC_ARG_WITH([memory-manager],
|
||||||
|
[AC_HELP_STRING([--with-memory-manager=TYPE],
|
||||||
|
[Use TYPE for intercepting memory management
|
||||||
|
calls to control memory pinning.])])
|
||||||
|
|
||||||
|
AS_IF([test "$with_memory_manager" = "malloc_interpose"],
|
||||||
|
[memory_malloc_interpose_happy="yes"
|
||||||
|
memory_malloc_interpose_should_use=1],
|
||||||
|
[memory_malloc_interpose_should_use=0
|
||||||
|
AS_IF([test "$with_memory_manager" = ""],
|
||||||
|
[memory_malloc_interpose_happy="yes"],
|
||||||
|
[memory_malloc_interpose_happy="no"])])
|
||||||
|
|
||||||
|
AS_IF([test "$memory_malloc_interpose_happy" = "yes"],
|
||||||
|
[# check for malloc.h
|
||||||
|
AC_CHECK_HEADER([malloc.h],
|
||||||
|
[memory_malloc_interpose_happy="yes"],
|
||||||
|
[memory_malloc_interpose_happy="no"])])
|
||||||
|
|
||||||
|
AS_IF([test "$memory_malloc_interpose_happy" = "yes"],
|
||||||
|
[AC_CHECK_FUNC([malloc_usable_size],
|
||||||
|
[memory_malloc_interpose_happy="yes"],
|
||||||
|
[memory_malloc_interpose_happy="no"])])
|
||||||
|
|
||||||
|
memory_malloc_interpose_LIBS_SAVE="$LIBS"
|
||||||
|
AS_IF([test "$memory_malloc_interpose_happy" = "yes"],
|
||||||
|
[AC_CHECK_LIB([dl],
|
||||||
|
[dlsym],
|
||||||
|
[memory_malloc_interpose_happy="yes"],
|
||||||
|
[memory_malloc_interpose_happy="no"])])
|
||||||
|
LIBS="$memory_malloc_interpose_LIBS_SAVE"
|
||||||
|
|
||||||
|
AS_IF([test "$memory_malloc_interpose_happy" = "yes"],
|
||||||
|
[memory_malloc_interpose_WRAPPER_EXTRA_LIBS="-ldl"
|
||||||
|
memory_malloc_interpose_LIBS="-ldl"])
|
||||||
|
|
||||||
|
AS_IF([test "$memory_malloc_interpose_happy" = "no" -a \
|
||||||
|
"$memory_malloc_interpose_should_use" = "1"],
|
||||||
|
[AC_MSG_ERROR([malloc interpose memory management requested but not available. Aborting.])])
|
||||||
|
|
||||||
|
AC_SUBST(memory_malloc_interpose_LIBS)
|
||||||
|
|
||||||
|
AS_IF([test "$memory_malloc_interpose_happy" = "yes"],
|
||||||
|
[$1], [$2])
|
||||||
|
])
|
21
opal/mca/memory/malloc_interpose/configure.params
Обычный файл
21
opal/mca/memory/malloc_interpose/configure.params
Обычный файл
@ -0,0 +1,21 @@
|
|||||||
|
# -*- shell-script -*-
|
||||||
|
#
|
||||||
|
# Copyright (c) 2004-2005 The Trustees of Indiana University.
|
||||||
|
# All rights reserved.
|
||||||
|
# Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
||||||
|
# All rights reserved.
|
||||||
|
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
||||||
|
# University of Stuttgart. All rights reserved.
|
||||||
|
# Copyright (c) 2004-2005 The Regents of the University of California.
|
||||||
|
# All rights reserved.
|
||||||
|
# $COPYRIGHT$
|
||||||
|
#
|
||||||
|
# Additional copyrights may follow
|
||||||
|
#
|
||||||
|
# $HEADER$
|
||||||
|
#
|
||||||
|
|
||||||
|
# Specific to this module
|
||||||
|
|
||||||
|
PARAM_CONFIG_PRIORITY=10
|
||||||
|
PARAM_CONFIG_FILES="Makefile"
|
132
opal/mca/memory/malloc_interpose/memory_malloc_interpose.c
Обычный файл
132
opal/mca/memory/malloc_interpose/memory_malloc_interpose.c
Обычный файл
@ -0,0 +1,132 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
||||||
|
* All rights reserved.
|
||||||
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
||||||
|
* All rights reserved.
|
||||||
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
||||||
|
* University of Stuttgart. All rights reserved.
|
||||||
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||||
|
* All rights reserved.
|
||||||
|
* $COPYRIGHT$
|
||||||
|
*
|
||||||
|
* Additional copyrights may follow
|
||||||
|
*
|
||||||
|
* $HEADER$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define OMPI_DISABLE_ENABLE_MEM_DEBUG 1
|
||||||
|
#include "ompi_config.h"
|
||||||
|
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
|
#include "opal/include/constants.h"
|
||||||
|
#include "opal/mca/memory/memory.h"
|
||||||
|
#include "opal/memory/memory_internal.h"
|
||||||
|
|
||||||
|
static int opal_memory_malloc_interpose_open(void);
|
||||||
|
|
||||||
|
const opal_memory_base_component_1_0_0_t mca_memory_malloc_interpose_component = {
|
||||||
|
/* First, the mca_component_t struct containing meta information
|
||||||
|
about the component itself */
|
||||||
|
{
|
||||||
|
/* Indicate that we are a memory v1.0.0 component (which also
|
||||||
|
implies a specific MCA version) */
|
||||||
|
OPAL_MEMORY_BASE_VERSION_1_0_0,
|
||||||
|
|
||||||
|
/* Component name and version */
|
||||||
|
"malloc_interpose",
|
||||||
|
OPAL_MAJOR_VERSION,
|
||||||
|
OPAL_MINOR_VERSION,
|
||||||
|
OPAL_RELEASE_VERSION,
|
||||||
|
|
||||||
|
/* Component open and close functions */
|
||||||
|
opal_memory_malloc_interpose_open,
|
||||||
|
NULL
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Next the MCA v1.0.0 component meta data */
|
||||||
|
{
|
||||||
|
/* Whether the component is checkpointable or not */
|
||||||
|
true
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
#define FIND_REALFREE() \
|
||||||
|
do { \
|
||||||
|
if (NULL == realfree) { \
|
||||||
|
realfree = (void (*)(void*)) dlsym(RTLD_NEXT, "free"); \
|
||||||
|
} \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
#define FIND_REALREALLOC() \
|
||||||
|
do { \
|
||||||
|
if (NULL == realrealloc) { \
|
||||||
|
realrealloc = (void* (*)(void*, size_t)) dlsym(RTLD_NEXT, "realloc"); \
|
||||||
|
} \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
#define FIND_REALMUNMAP() \
|
||||||
|
do { \
|
||||||
|
if (NULL == realmunmap) { \
|
||||||
|
realmunmap = (int (*)(void*, size_t)) dlsym(RTLD_NEXT, "munmap"); \
|
||||||
|
} \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
static void (*realfree)(void*);
|
||||||
|
static void* (*realrealloc)(void*, size_t);
|
||||||
|
static int (*realmunmap)(void*, size_t);
|
||||||
|
|
||||||
|
static int
|
||||||
|
opal_memory_malloc_interpose_open(void)
|
||||||
|
{
|
||||||
|
opal_mem_free_set_free_support(1);
|
||||||
|
|
||||||
|
FIND_REALFREE();
|
||||||
|
FIND_REALREALLOC();
|
||||||
|
FIND_REALMUNMAP();
|
||||||
|
|
||||||
|
if (NULL == realfree || NULL == realrealloc || NULL == realmunmap) {
|
||||||
|
/* this shoudl really never happen */
|
||||||
|
fprintf(stderr,
|
||||||
|
"Could not find real memory functions. Aborting in dispair\n");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
return OPAL_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
free(void *ptr)
|
||||||
|
{
|
||||||
|
FIND_REALFREE();
|
||||||
|
|
||||||
|
/* dispatch about the pending release */
|
||||||
|
opal_mem_free_release_hook(ptr, malloc_usable_size(ptr));
|
||||||
|
realfree(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void*
|
||||||
|
realloc(void *ptr, size_t size)
|
||||||
|
{
|
||||||
|
FIND_REALREALLOC();
|
||||||
|
|
||||||
|
/* dispatch about the pending release */
|
||||||
|
opal_mem_free_release_hook(ptr, malloc_usable_size(ptr));
|
||||||
|
return realrealloc(ptr, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
munmap(void *start, size_t length)
|
||||||
|
{
|
||||||
|
FIND_REALMUNMAP();
|
||||||
|
|
||||||
|
/* dispatch about the pending release */
|
||||||
|
opal_mem_free_release_hook(start, length);
|
||||||
|
return realmunmap(start, length);
|
||||||
|
}
|
@ -17,4 +17,5 @@
|
|||||||
|
|
||||||
# Specific to this module
|
# Specific to this module
|
||||||
|
|
||||||
|
PARAM_CONFIG_PRIORITY=20
|
||||||
PARAM_CONFIG_FILES="Makefile"
|
PARAM_CONFIG_FILES="Makefile"
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user