More memory hooks tweaks... Set a flag on callbacks if the allocation /
deallocation came from the allocator (malloc, fee, etc) or somewhere else (the user calling mmap/munmap, etc). Going to be used by Galen to determine if it is worth searching the allocations tree Set flag if it is possible to intercept mmap (not always possible due to a circular dependency between mmap, dlsym, and calloc) This commit was SVN r8521.
Этот коммит содержится в:
родитель
83d34c8435
Коммит
b42bb3d8e8
@ -30,7 +30,8 @@ extern uint32_t mca_mpool_base_page_size_log;
|
|||||||
/*
|
/*
|
||||||
* memory hook callback, called when memory is free'd out from under us
|
* memory hook callback, called when memory is free'd out from under us
|
||||||
*/
|
*/
|
||||||
void mca_mpool_base_mem_cb(void* base, size_t size, void* cbdata)
|
void mca_mpool_base_mem_cb(void* base, size_t size, void* cbdata,
|
||||||
|
bool from_alloc)
|
||||||
{
|
{
|
||||||
uint32_t i, cnt;
|
uint32_t i, cnt;
|
||||||
ompi_pointer_array_t regs;
|
ompi_pointer_array_t regs;
|
||||||
|
@ -37,7 +37,8 @@ extern "C" {
|
|||||||
/*
|
/*
|
||||||
* memory hook callback, called when memory is free'd out from under us
|
* memory hook callback, called when memory is free'd out from under us
|
||||||
*/
|
*/
|
||||||
void mca_mpool_base_mem_cb(void* base, size_t size, void* cbdata);
|
void mca_mpool_base_mem_cb(void* base, size_t size, void* cbdata,
|
||||||
|
bool from_alloc);
|
||||||
|
|
||||||
#if defined(c_plusplus) || defined(__cplusplus)
|
#if defined(c_plusplus) || defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
@ -472,6 +472,9 @@ ptmalloc_init __MALLOC_P((void))
|
|||||||
#if defined(HAVE___MMAP) || defined(HAVE_DLSYM)
|
#if defined(HAVE___MMAP) || defined(HAVE_DLSYM)
|
||||||
OPAL_MEMORY_MALLOC_SUPPORT |
|
OPAL_MEMORY_MALLOC_SUPPORT |
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(HAVE___MMAP)
|
||||||
|
OPAL_MEMORY_MMAP_SUPPORT |
|
||||||
|
#endif
|
||||||
#if OMPI_MEMORY_PTMALLOC2_OPT_SBRK
|
#if OMPI_MEMORY_PTMALLOC2_OPT_SBRK
|
||||||
OPAL_MEMORY_CHUNK_SUPPORT
|
OPAL_MEMORY_CHUNK_SUPPORT
|
||||||
#else
|
#else
|
||||||
|
@ -24,22 +24,22 @@ opal_mem_free_ptmalloc2_sbrk(int inc)
|
|||||||
{
|
{
|
||||||
if (inc < 0) {
|
if (inc < 0) {
|
||||||
long oldp = (long) sbrk(0);
|
long oldp = (long) sbrk(0);
|
||||||
opal_mem_hooks_release_hook((void*) (oldp + inc), -inc);
|
opal_mem_hooks_release_hook((void*) (oldp + inc), -inc, 1);
|
||||||
#if defined(HAVE___MMAP) || defined(HAVE_DLSYM)
|
#if defined(HAVE___MMAP) || defined(HAVE_DLSYM)
|
||||||
} else if (inc > 0) {
|
} else if (inc > 0) {
|
||||||
long oldp = (long) sbrk(0);
|
long oldp = (long) sbrk(0);
|
||||||
opal_mem_hooks_alloc_hook((void*) oldp, inc);
|
opal_mem_hooks_alloc_hook((void*) oldp, inc, 1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return sbrk(inc);
|
return sbrk(inc);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int opal_mem_free_ptmalloc2_munmap(void *start, size_t length);
|
extern int opal_mem_free_ptmalloc2_munmap(void *start, size_t length, int from_alloc);
|
||||||
#if defined(HAVE___MMAP) || defined(HAVE_DLSYM)
|
#if defined(HAVE___MMAP) || defined(HAVE_DLSYM)
|
||||||
extern void* opal_mem_free_ptmalloc2_mmap(void *start, size_t length,
|
extern void* opal_mem_free_ptmalloc2_mmap(void *start, size_t length,
|
||||||
int prot, int flags,
|
int prot, int flags,
|
||||||
int fd, off_t offset);
|
int fd, off_t offset, int from_alloc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* if we are trying to catch only allocations from and releases to the
|
/* if we are trying to catch only allocations from and releases to the
|
||||||
@ -47,9 +47,9 @@ extern void* opal_mem_free_ptmalloc2_mmap(void *start, size_t length,
|
|||||||
intercept every call to malloc/realloc/free/etc., don't do this, as
|
intercept every call to malloc/realloc/free/etc., don't do this, as
|
||||||
we need to add something into each of those calls anyway. */
|
we need to add something into each of those calls anyway. */
|
||||||
#define MORECORE opal_mem_free_ptmalloc2_sbrk
|
#define MORECORE opal_mem_free_ptmalloc2_sbrk
|
||||||
#define munmap(a,b) opal_mem_free_ptmalloc2_munmap(a,b)
|
#define munmap(a,b) opal_mem_free_ptmalloc2_munmap(a,b,1)
|
||||||
#if defined(HAVE___MMAP) || defined(HAVE_DLSYM)
|
#if defined(HAVE___MMAP) || defined(HAVE_DLSYM)
|
||||||
#define mmap(a,b,c,d,e,f) opal_mem_free_ptmalloc2_mmap(a,b,c,d,e,f)
|
#define mmap(a,b,c,d,e,f) opal_mem_free_ptmalloc2_mmap(a,b,c,d,e,f,1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* OMPI_MEMORY_PTMALLOC2_OPT_SBRK */
|
#endif /* OMPI_MEMORY_PTMALLOC2_OPT_SBRK */
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
/*
|
/*
|
||||||
* munmap is always intercepted
|
* munmap is always intercepted
|
||||||
*/
|
*/
|
||||||
int opal_mem_free_ptmalloc2_munmap(void *start, size_t length);
|
int opal_mem_free_ptmalloc2_munmap(void *start, size_t length, int from_alloc);
|
||||||
#if defined(HAVE___MUNMAP)
|
#if defined(HAVE___MUNMAP)
|
||||||
int __munmap(void* addr, size_t len);
|
int __munmap(void* addr, size_t len);
|
||||||
#endif
|
#endif
|
||||||
@ -48,7 +48,7 @@ int __munmap(void* addr, size_t len);
|
|||||||
int
|
int
|
||||||
munmap(void* addr, size_t len)
|
munmap(void* addr, size_t len)
|
||||||
{
|
{
|
||||||
return opal_mem_free_ptmalloc2_munmap(addr, len);
|
return opal_mem_free_ptmalloc2_munmap(addr, len, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -57,13 +57,13 @@ munmap(void* addr, size_t len)
|
|||||||
possible, try calling __munmap from munmap and let __munmap go. If
|
possible, try calling __munmap from munmap and let __munmap go. If
|
||||||
that doesn't work, try dlsym */
|
that doesn't work, try dlsym */
|
||||||
int
|
int
|
||||||
opal_mem_free_ptmalloc2_munmap(void *start, size_t length)
|
opal_mem_free_ptmalloc2_munmap(void *start, size_t length, int from_alloc)
|
||||||
{
|
{
|
||||||
#if !defined(HAVE___MUNMAP) && defined(HAVE_DLSYM)
|
#if !defined(HAVE___MUNMAP) && defined(HAVE_DLSYM)
|
||||||
static int (*realmunmap)(void*, size_t);
|
static int (*realmunmap)(void*, size_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
opal_mem_hooks_release_hook(start, length);
|
opal_mem_hooks_release_hook(start, length, from_alloc);
|
||||||
|
|
||||||
#if defined(HAVE___MUNMAP)
|
#if defined(HAVE___MUNMAP)
|
||||||
return __munmap(start, length);
|
return __munmap(start, length);
|
||||||
@ -93,7 +93,8 @@ opal_mem_free_ptmalloc2_munmap(void *start, size_t length)
|
|||||||
*/
|
*/
|
||||||
void* opal_mem_free_ptmalloc2_mmap(void *start, size_t length,
|
void* opal_mem_free_ptmalloc2_mmap(void *start, size_t length,
|
||||||
int prot, int flags,
|
int prot, int flags,
|
||||||
int fd, off_t offset);
|
int fd, off_t offset,
|
||||||
|
int from_alloc);
|
||||||
|
|
||||||
#if defined(HAVE___MMAP)
|
#if defined(HAVE___MMAP)
|
||||||
void* __mmap(void *start, size_t length, int prot, int flags,
|
void* __mmap(void *start, size_t length, int prot, int flags,
|
||||||
@ -105,7 +106,7 @@ mmap(void *start, size_t length, int prot, int flags,
|
|||||||
int fd, off_t offset)
|
int fd, off_t offset)
|
||||||
{
|
{
|
||||||
return opal_mem_free_ptmalloc2_mmap(start, length, prot, flags,
|
return opal_mem_free_ptmalloc2_mmap(start, length, prot, flags,
|
||||||
fd, offset);
|
fd, offset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* defined(HAVE___MMAP) */
|
#endif /* defined(HAVE___MMAP) */
|
||||||
@ -113,7 +114,8 @@ mmap(void *start, size_t length, int prot, int flags,
|
|||||||
|
|
||||||
void* opal_mem_free_ptmalloc2_mmap(void *start, size_t length,
|
void* opal_mem_free_ptmalloc2_mmap(void *start, size_t length,
|
||||||
int prot, int flags,
|
int prot, int flags,
|
||||||
int fd, off_t offset)
|
int fd, off_t offset,
|
||||||
|
int from_alloc)
|
||||||
{
|
{
|
||||||
void *tmp;
|
void *tmp;
|
||||||
|
|
||||||
@ -123,7 +125,7 @@ void* opal_mem_free_ptmalloc2_mmap(void *start, size_t length,
|
|||||||
tmp = mmap(start, length, prot, flags, fd, offset);
|
tmp = mmap(start, length, prot, flags, fd, offset);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
opal_mem_hooks_alloc_hook(tmp, length);
|
opal_mem_hooks_alloc_hook(tmp, length, from_alloc);
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ opal_mem_hooks_set_support(int support)
|
|||||||
|
|
||||||
/* called from the memory manager / memory-manager specific hooks */
|
/* called from the memory manager / memory-manager specific hooks */
|
||||||
void
|
void
|
||||||
opal_mem_hooks_alloc_hook(void *buf, size_t length)
|
opal_mem_hooks_alloc_hook(void *buf, size_t length, int from_alloc)
|
||||||
{
|
{
|
||||||
opal_list_item_t *item;
|
opal_list_item_t *item;
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ opal_mem_hooks_alloc_hook(void *buf, size_t length)
|
|||||||
item = next;
|
item = next;
|
||||||
|
|
||||||
opal_atomic_unlock(&alloc_lock);
|
opal_atomic_unlock(&alloc_lock);
|
||||||
cbitem.cbfunc(buf, length, cbitem.cbdata);
|
cbitem.cbfunc(buf, length, cbitem.cbdata, (bool) from_alloc);
|
||||||
opal_atomic_lock(&alloc_lock);
|
opal_atomic_lock(&alloc_lock);
|
||||||
}
|
}
|
||||||
opal_atomic_unlock(&alloc_lock);
|
opal_atomic_unlock(&alloc_lock);
|
||||||
@ -153,7 +153,7 @@ opal_mem_hooks_alloc_hook(void *buf, size_t length)
|
|||||||
|
|
||||||
/* called from the memory manager / memory-manager specific hooks */
|
/* called from the memory manager / memory-manager specific hooks */
|
||||||
void
|
void
|
||||||
opal_mem_hooks_release_hook(void *buf, size_t length)
|
opal_mem_hooks_release_hook(void *buf, size_t length, int from_alloc)
|
||||||
{
|
{
|
||||||
opal_list_item_t *item;
|
opal_list_item_t *item;
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ opal_mem_hooks_release_hook(void *buf, size_t length)
|
|||||||
item = next;
|
item = next;
|
||||||
|
|
||||||
opal_atomic_unlock(&release_lock);
|
opal_atomic_unlock(&release_lock);
|
||||||
cbitem.cbfunc(buf, length, cbitem.cbdata);
|
cbitem.cbfunc(buf, length, cbitem.cbdata, (bool) from_alloc);
|
||||||
opal_atomic_lock(&release_lock);
|
opal_atomic_lock(&release_lock);
|
||||||
}
|
}
|
||||||
opal_atomic_unlock(&release_lock);
|
opal_atomic_unlock(&release_lock);
|
||||||
|
@ -89,10 +89,17 @@ int opal_mem_hooks_finalize(void);
|
|||||||
*
|
*
|
||||||
* @retval OPAL_MEMORY_FREE_SUPPORT Memory hooks subsytem can trigger
|
* @retval OPAL_MEMORY_FREE_SUPPORT Memory hooks subsytem can trigger
|
||||||
* callback events when memory is going
|
* callback events when memory is going
|
||||||
* to be released by the process.
|
* to be released by the process, either
|
||||||
|
* by the user calling an allocator
|
||||||
|
* function or mmap.
|
||||||
* @retval OPAL_MEMORY_MALLOC_SUPPORT Memory hooks subsystem can trigger
|
* @retval OPAL_MEMORY_MALLOC_SUPPORT Memory hooks subsystem can trigger
|
||||||
* callback events when memory is being
|
* callback events when memory is being
|
||||||
* allocated by the process.
|
* allocated by the process through the
|
||||||
|
* traditional allocator (malloc,
|
||||||
|
* calloc, etc.)
|
||||||
|
* @retval OPAL_MEMORY_MMAP_SUPPORT Memory hooks subsystem can trigger
|
||||||
|
* callback events when memory is being
|
||||||
|
* allocated by the process through mmap.
|
||||||
* @retval OPAL_MEMORY_CHUNK_SUPPORT Memory hooks subsystem will only
|
* @retval OPAL_MEMORY_CHUNK_SUPPORT Memory hooks subsystem will only
|
||||||
* trigger callback events when the
|
* trigger callback events when the
|
||||||
* process is giving memory back to the
|
* process is giving memory back to the
|
||||||
@ -116,9 +123,12 @@ int opal_mem_hooks_support_level(void);
|
|||||||
* @param lentgh Length of the allocation
|
* @param lentgh Length of the allocation
|
||||||
* @param cbdata Data passed to memory hooks when callback
|
* @param cbdata Data passed to memory hooks when callback
|
||||||
* was registered
|
* was registered
|
||||||
|
* @param from_alloc True if the callback is caused by a call to the
|
||||||
|
* general allocation routines (malloc, calloc, free,
|
||||||
|
* etc.) or directly from the user (mmap, munmap, etc.)
|
||||||
*/
|
*/
|
||||||
typedef void (opal_mem_hooks_callback_fn_t)(void *buf, size_t length,
|
typedef void (opal_mem_hooks_callback_fn_t)(void *buf, size_t length,
|
||||||
void *cbdata);
|
void *cbdata, bool from_alloc);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#define OPAL_MEMORY_FREE_SUPPORT 0x0001
|
#define OPAL_MEMORY_FREE_SUPPORT 0x0001
|
||||||
#define OPAL_MEMORY_MALLOC_SUPPORT 0x0002
|
#define OPAL_MEMORY_MALLOC_SUPPORT 0x0002
|
||||||
#define OPAL_MEMORY_CHUNK_SUPPORT 0x0004
|
#define OPAL_MEMORY_CHUNK_SUPPORT 0x0004
|
||||||
|
#define OPAL_MEMORY_MMAP_SUPPORT 0x0008
|
||||||
|
|
||||||
#if defined(c_plusplus) || defined(__cplusplus)
|
#if defined(c_plusplus) || defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -29,8 +30,8 @@ extern "C" {
|
|||||||
|
|
||||||
void opal_mem_hooks_set_support(int support);
|
void opal_mem_hooks_set_support(int support);
|
||||||
|
|
||||||
void opal_mem_hooks_release_hook(void *buf, size_t length);
|
void opal_mem_hooks_release_hook(void *buf, size_t length, int from_alloc);
|
||||||
void opal_mem_hooks_alloc_hook(void *buf, size_t length);
|
void opal_mem_hooks_alloc_hook(void *buf, size_t length, int from_alloc);
|
||||||
|
|
||||||
#if defined(c_plusplus) || defined(__cplusplus)
|
#if defined(c_plusplus) || defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user