diff --git a/opal/mca/memory/configure.m4 b/opal/mca/memory/configure.m4 new file mode 100644 index 0000000000..2a936564e3 --- /dev/null +++ b/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) diff --git a/opal/mca/memory/darwin/configure.params b/opal/mca/memory/darwin/configure.params index 895d40c2a9..e35f4e51bd 100644 --- a/opal/mca/memory/darwin/configure.params +++ b/opal/mca/memory/darwin/configure.params @@ -17,4 +17,5 @@ # Specific to this module +PARAM_CONFIG_PRIORITY=20 PARAM_CONFIG_FILES="Makefile" diff --git a/opal/mca/memory/malloc_hooks/Makefile.am b/opal/mca/memory/malloc_hooks/Makefile.am index 23b9e3a962..ed40cb7db8 100644 --- a/opal/mca/memory/malloc_hooks/Makefile.am +++ b/opal/mca/memory/malloc_hooks/Makefile.am @@ -20,5 +20,6 @@ noinst_LTLIBRARIES = libmca_memory_malloc_hooks.la # Source code files libmca_memory_malloc_hooks_la_SOURCES = \ - malloc_hooks.c \ - malloc_hooks_component.c + memory_malloc_hooks.c \ + memory_malloc_hooks_component.c +libmca_memory_malloc_hooks_la_LIBADD = $(memory_malloc_hooks_LIBS) diff --git a/opal/mca/memory/malloc_hooks/configure.m4 b/opal/mca/memory/malloc_hooks/configure.m4 index 4916cd0d82..26b6d169bf 100644 --- a/opal/mca/memory/malloc_hooks/configure.m4 +++ b/opal/mca/memory/malloc_hooks/configure.m4 @@ -64,9 +64,23 @@ AC_DEFUN([MCA_memory_malloc_hooks_CONFIG],[ [memory_malloc_hooks_happy="yes"], [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 \ "$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"], [$1], [$2]) diff --git a/opal/mca/memory/malloc_hooks/configure.params b/opal/mca/memory/malloc_hooks/configure.params index 895d40c2a9..e35f4e51bd 100644 --- a/opal/mca/memory/malloc_hooks/configure.params +++ b/opal/mca/memory/malloc_hooks/configure.params @@ -17,4 +17,5 @@ # Specific to this module +PARAM_CONFIG_PRIORITY=20 PARAM_CONFIG_FILES="Makefile" diff --git a/opal/mca/memory/malloc_hooks/malloc_hooks.c b/opal/mca/memory/malloc_hooks/memory_malloc_hooks.c similarity index 100% rename from opal/mca/memory/malloc_hooks/malloc_hooks.c rename to opal/mca/memory/malloc_hooks/memory_malloc_hooks.c diff --git a/opal/mca/memory/malloc_hooks/malloc_hooks_component.c b/opal/mca/memory/malloc_hooks/memory_malloc_hooks_component.c similarity index 100% rename from opal/mca/memory/malloc_hooks/malloc_hooks_component.c rename to opal/mca/memory/malloc_hooks/memory_malloc_hooks_component.c diff --git a/opal/mca/memory/malloc_interpose/Makefile.am b/opal/mca/memory/malloc_interpose/Makefile.am new file mode 100644 index 0000000000..f76b3921bc --- /dev/null +++ b/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) diff --git a/opal/mca/memory/malloc_interpose/configure.m4 b/opal/mca/memory/malloc_interpose/configure.m4 new file mode 100644 index 0000000000..9d66a4d630 --- /dev/null +++ b/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]) +]) diff --git a/opal/mca/memory/malloc_interpose/configure.params b/opal/mca/memory/malloc_interpose/configure.params new file mode 100644 index 0000000000..bf63a82c11 --- /dev/null +++ b/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" diff --git a/opal/mca/memory/malloc_interpose/memory_malloc_interpose.c b/opal/mca/memory/malloc_interpose/memory_malloc_interpose.c new file mode 100644 index 0000000000..9f2668d32c --- /dev/null +++ b/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 +#include +#include +#include + +#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); +} diff --git a/opal/mca/memory/ptmalloc2/configure.params b/opal/mca/memory/ptmalloc2/configure.params index 895d40c2a9..e35f4e51bd 100644 --- a/opal/mca/memory/ptmalloc2/configure.params +++ b/opal/mca/memory/ptmalloc2/configure.params @@ -17,4 +17,5 @@ # Specific to this module +PARAM_CONFIG_PRIORITY=20 PARAM_CONFIG_FILES="Makefile"