2011-12-07 22:20:44 +04:00
|
|
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
|
2006-12-17 15:26:41 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2007-12-21 09:02:00 +03:00
|
|
|
* Copyright (c) 2004-2007 The University of Tennessee and The University
|
2006-12-17 15:26:41 +03:00
|
|
|
* of Tennessee Research Foundation. 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.
|
2010-05-12 01:43:19 +04:00
|
|
|
* Copyright (c) 2006-2009 Cisco Systems, Inc. All rights reserved.
|
2006-12-17 15:26:41 +03:00
|
|
|
* Copyright (c) 2006 Voltaire. All rights reserved.
|
2007-07-23 20:18:36 +04:00
|
|
|
* Copyright (c) 2007 Mellanox Technologies. All rights reserved.
|
2010-03-25 06:14:21 +03:00
|
|
|
* Copyright (c) 2010 IBM Corporation. All rights reserved.
|
2011-12-07 22:20:44 +04:00
|
|
|
* Copyright (c) 2011 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
2006-12-17 15:26:41 +03:00
|
|
|
*
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2009-05-07 00:11:28 +04:00
|
|
|
#define OPAL_DISABLE_ENABLE_MEM_DEBUG 1
|
2006-12-17 15:26:41 +03:00
|
|
|
#include "ompi_config.h"
|
2009-03-12 22:21:11 +03:00
|
|
|
#include "opal/align.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
#include "orte/util/name_fns.h"
|
|
|
|
#include "orte/runtime/orte_globals.h"
|
2006-12-17 15:26:41 +03:00
|
|
|
#include "ompi/mca/mpool/rdma/mpool_rdma.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2006-12-17 20:28:59 +03:00
|
|
|
#ifdef HAVE_MALLOC_H
|
2006-12-17 15:26:41 +03:00
|
|
|
#include <malloc.h>
|
2006-12-17 20:28:59 +03:00
|
|
|
#endif
|
2006-12-17 15:26:41 +03:00
|
|
|
#include "ompi/mca/rcache/rcache.h"
|
|
|
|
#include "ompi/mca/rcache/base/base.h"
|
|
|
|
#include "ompi/mca/mpool/base/base.h"
|
2008-07-25 02:51:26 +04:00
|
|
|
#include "ompi/runtime/params.h"
|
2006-12-17 15:26:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes the mpool module.
|
|
|
|
*/
|
|
|
|
void mca_mpool_rdma_module_init(mca_mpool_rdma_module_t* mpool)
|
|
|
|
{
|
|
|
|
mpool->super.mpool_component = &mca_mpool_rdma_component.super;
|
|
|
|
mpool->super.mpool_base = NULL; /* no base .. */
|
|
|
|
mpool->super.mpool_alloc = mca_mpool_rdma_alloc;
|
|
|
|
mpool->super.mpool_realloc = mca_mpool_rdma_realloc;
|
|
|
|
mpool->super.mpool_free = mca_mpool_rdma_free;
|
|
|
|
mpool->super.mpool_register = mca_mpool_rdma_register;
|
|
|
|
mpool->super.mpool_find = mca_mpool_rdma_find;
|
|
|
|
mpool->super.mpool_deregister = mca_mpool_rdma_deregister;
|
|
|
|
mpool->super.mpool_release_memory = mca_mpool_rdma_release_memory;
|
2007-07-23 20:18:36 +04:00
|
|
|
mpool->super.mpool_finalize = mca_mpool_rdma_finalize;
|
2008-10-16 19:09:00 +04:00
|
|
|
mpool->super.mpool_ft_event = mca_mpool_rdma_ft_event;
|
2006-12-17 15:26:41 +03:00
|
|
|
mpool->super.rcache =
|
|
|
|
mca_rcache_base_module_create(mca_mpool_rdma_component.rcache_name);
|
|
|
|
mpool->super.flags = MCA_MPOOL_FLAGS_MPI_ALLOC_MEM;
|
|
|
|
|
|
|
|
OBJ_CONSTRUCT(&mpool->reg_list, ompi_free_list_t);
|
2007-11-02 02:38:50 +03:00
|
|
|
ompi_free_list_init_new(&mpool->reg_list, mpool->resources.sizeof_reg,
|
2010-07-06 18:33:36 +04:00
|
|
|
opal_cache_line_size,
|
2007-11-02 02:38:50 +03:00
|
|
|
OBJ_CLASS(mca_mpool_base_registration_t),
|
2010-07-06 18:33:36 +04:00
|
|
|
0,opal_cache_line_size,
|
2007-11-02 02:38:50 +03:00
|
|
|
0, -1, 32, NULL);
|
2011-12-07 22:20:44 +04:00
|
|
|
OBJ_CONSTRUCT(&mpool->lru_list, opal_list_t);
|
2008-01-08 11:55:42 +03:00
|
|
|
OBJ_CONSTRUCT(&mpool->gc_list, opal_list_t);
|
2006-12-17 15:26:41 +03:00
|
|
|
mpool->stat_cache_hit = mpool->stat_cache_miss = mpool->stat_evicted = 0;
|
|
|
|
mpool->stat_cache_found = mpool->stat_cache_notfound = 0;
|
2008-07-25 02:51:26 +04:00
|
|
|
|
|
|
|
/* Set this here (vs in component.c) because
|
|
|
|
ompi_mpi_leave_pinned* may have been set after MCA params were
|
|
|
|
read (e.g., by the openib btl) */
|
|
|
|
mca_mpool_rdma_component.leave_pinned = (int)
|
2008-09-17 02:06:14 +04:00
|
|
|
(1 == ompi_mpi_leave_pinned || ompi_mpi_leave_pinned_pipeline);
|
2006-12-17 15:26:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int dereg_mem(mca_mpool_base_module_t *mpool,
|
|
|
|
mca_mpool_base_registration_t *reg)
|
|
|
|
{
|
|
|
|
mca_mpool_rdma_module_t *mpool_rdma = (mca_mpool_rdma_module_t *)mpool;
|
|
|
|
|
|
|
|
assert(reg->ref_count == 0);
|
|
|
|
return mpool_rdma->resources.deregister_mem(mpool_rdma->resources.reg_data,
|
|
|
|
reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* allocate function
|
|
|
|
*/
|
|
|
|
void* mca_mpool_rdma_alloc(mca_mpool_base_module_t *mpool, size_t size,
|
|
|
|
size_t align, uint32_t flags, mca_mpool_base_registration_t **reg)
|
|
|
|
{
|
2006-12-18 13:52:18 +03:00
|
|
|
void *base_addr, *addr;
|
|
|
|
|
|
|
|
if(0 == align)
|
|
|
|
align = mca_mpool_base_page_size;
|
2006-12-17 15:26:41 +03:00
|
|
|
|
2012-01-12 17:00:42 +04:00
|
|
|
#if OMPI_CUDA_SUPPORT
|
|
|
|
/* CUDA cannot handle registering overlapping regions, so make
|
|
|
|
* sure each region is page sized and page aligned. */
|
|
|
|
align = mca_mpool_base_page_size;
|
|
|
|
size = OPAL_ALIGN(size, mca_mpool_base_page_size, size_t);
|
|
|
|
#endif
|
|
|
|
|
2006-12-17 20:28:59 +03:00
|
|
|
#ifdef HAVE_POSIX_MEMALIGN
|
2006-12-18 13:52:18 +03:00
|
|
|
if((errno = posix_memalign(&base_addr, align, size)) != 0)
|
2006-12-17 15:26:41 +03:00
|
|
|
return NULL;
|
2006-12-18 13:52:18 +03:00
|
|
|
|
|
|
|
addr = base_addr;
|
2006-12-17 20:28:59 +03:00
|
|
|
#else
|
2006-12-18 13:52:18 +03:00
|
|
|
base_addr = malloc(size + align);
|
|
|
|
if(NULL == base_addr)
|
2006-12-17 20:28:59 +03:00
|
|
|
return NULL;
|
2006-12-18 13:52:18 +03:00
|
|
|
|
|
|
|
addr = (void*)OPAL_ALIGN((uintptr_t)base_addr, align, uintptr_t);
|
2006-12-17 20:28:59 +03:00
|
|
|
#endif
|
2006-12-17 15:26:41 +03:00
|
|
|
|
|
|
|
if(OMPI_SUCCESS != mca_mpool_rdma_register(mpool, addr, size, flags, reg)) {
|
2006-12-18 13:52:18 +03:00
|
|
|
free(base_addr);
|
2006-12-17 15:26:41 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-09-08 19:39:30 +04:00
|
|
|
(*reg)->alloc_base = (unsigned char *) base_addr;
|
2006-12-17 15:26:41 +03:00
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2010-02-23 14:31:58 +03:00
|
|
|
/* This function must be called with the rcache lock held */
|
2008-01-08 11:55:42 +03:00
|
|
|
static void do_unregistration_gc(struct mca_mpool_base_module_t *mpool)
|
|
|
|
{
|
|
|
|
mca_mpool_rdma_module_t *mpool_rdma = (mca_mpool_rdma_module_t*)mpool;
|
|
|
|
mca_mpool_base_registration_t *reg;
|
|
|
|
|
|
|
|
do {
|
2010-02-23 14:31:58 +03:00
|
|
|
/* Remove registration from garbage collection list
|
|
|
|
before deregistering it */
|
2008-01-08 11:55:42 +03:00
|
|
|
reg = (mca_mpool_base_registration_t *)
|
|
|
|
opal_list_remove_first(&mpool_rdma->gc_list);
|
|
|
|
mpool->rcache->rcache_delete(mpool->rcache, reg);
|
2010-02-23 14:31:58 +03:00
|
|
|
|
|
|
|
/* Drop the rcache lock before calling dereg_mem as there
|
|
|
|
may be memory allocations */
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
|
|
|
dereg_mem(mpool, reg);
|
|
|
|
OPAL_THREAD_LOCK(&mpool->rcache->lock);
|
|
|
|
|
2008-01-08 11:55:42 +03:00
|
|
|
OMPI_FREE_LIST_RETURN(&mpool_rdma->reg_list,
|
|
|
|
(ompi_free_list_item_t*)reg);
|
|
|
|
} while(!opal_list_is_empty(&mpool_rdma->gc_list));
|
|
|
|
}
|
|
|
|
|
2006-12-17 15:26:41 +03:00
|
|
|
static int register_cache_bypass(mca_mpool_base_module_t *mpool,
|
|
|
|
void *addr, size_t size, uint32_t flags,
|
|
|
|
mca_mpool_base_registration_t **reg)
|
|
|
|
{
|
|
|
|
mca_mpool_rdma_module_t *mpool_rdma = (mca_mpool_rdma_module_t*)mpool;
|
|
|
|
mca_mpool_base_registration_t *rdma_reg;
|
|
|
|
ompi_free_list_item_t *item;
|
|
|
|
unsigned char *base, *bound;
|
|
|
|
int rc;
|
|
|
|
|
2008-09-08 19:39:30 +04:00
|
|
|
base = (unsigned char *) down_align_addr(addr, mca_mpool_base_page_size_log);
|
|
|
|
bound = (unsigned char *) up_align_addr( (void*) ((char*) addr + size - 1),
|
2006-12-17 15:26:41 +03:00
|
|
|
mca_mpool_base_page_size_log);
|
|
|
|
OMPI_FREE_LIST_GET(&mpool_rdma->reg_list, item, rc);
|
|
|
|
if(OMPI_SUCCESS != rc) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
rdma_reg = (mca_mpool_base_registration_t*)item;
|
|
|
|
|
|
|
|
rdma_reg->mpool = mpool;
|
|
|
|
rdma_reg->base = base;
|
|
|
|
rdma_reg->bound = bound;
|
|
|
|
rdma_reg->flags = flags;
|
|
|
|
|
|
|
|
rc = mpool_rdma->resources.register_mem(mpool_rdma->resources.reg_data,
|
|
|
|
base, bound - base + 1, rdma_reg);
|
|
|
|
|
|
|
|
if(rc != OMPI_SUCCESS) {
|
|
|
|
OMPI_FREE_LIST_RETURN(&mpool_rdma->reg_list, item);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
*reg = rdma_reg;
|
|
|
|
(*reg)->ref_count++;
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-12-07 22:20:44 +04:00
|
|
|
static inline bool mca_mpool_rdma_deregister_lru (mca_mpool_base_module_t *mpool) {
|
|
|
|
mca_mpool_rdma_module_t *mpool_rdma = (mca_mpool_rdma_module_t *) mpool;
|
|
|
|
mca_mpool_base_registration_t *old_reg;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Remove the registration from the cache and list before
|
|
|
|
deregistering the memory */
|
|
|
|
old_reg = (mca_mpool_base_registration_t*)
|
|
|
|
opal_list_remove_first (&mpool_rdma->lru_list);
|
|
|
|
if (NULL == old_reg) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mpool->rcache->rcache_delete(mpool->rcache, old_reg);
|
|
|
|
|
|
|
|
/* Drop the rcache lock while we deregister the memory */
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
|
|
|
rc = dereg_mem(mpool, old_reg);
|
|
|
|
OPAL_THREAD_LOCK(&mpool->rcache->lock);
|
|
|
|
|
|
|
|
/* This introduces a potential leak of registrations if
|
|
|
|
the deregistration fails to occur as we no longer have
|
|
|
|
a reference to it. Is this possible? */
|
|
|
|
if (OMPI_SUCCESS != rc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPI_FREE_LIST_RETURN(&mpool_rdma->reg_list,
|
|
|
|
(ompi_free_list_item_t*)old_reg);
|
|
|
|
mpool_rdma->stat_evicted++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-12-17 15:26:41 +03:00
|
|
|
/*
|
|
|
|
* register memory
|
|
|
|
*/
|
|
|
|
int mca_mpool_rdma_register(mca_mpool_base_module_t *mpool, void *addr,
|
|
|
|
size_t size, uint32_t flags,
|
|
|
|
mca_mpool_base_registration_t **reg)
|
|
|
|
{
|
|
|
|
mca_mpool_rdma_module_t *mpool_rdma = (mca_mpool_rdma_module_t*)mpool;
|
|
|
|
mca_mpool_base_registration_t *rdma_reg;
|
|
|
|
ompi_free_list_item_t *item;
|
|
|
|
unsigned char *base, *bound;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* if cache bypass is requested don't use the cache */
|
|
|
|
if(flags & MCA_MPOOL_FLAGS_CACHE_BYPASS) {
|
|
|
|
return register_cache_bypass(mpool, addr, size, flags, reg);
|
|
|
|
}
|
|
|
|
|
2008-09-08 19:39:30 +04:00
|
|
|
base = (unsigned char *) down_align_addr(addr, mca_mpool_base_page_size_log);
|
|
|
|
bound = (unsigned char *) up_align_addr((void*)((char*) addr + size - 1),
|
2006-12-17 15:26:41 +03:00
|
|
|
mca_mpool_base_page_size_log);
|
|
|
|
OPAL_THREAD_LOCK(&mpool->rcache->lock);
|
2008-01-08 11:55:42 +03:00
|
|
|
if(!opal_list_is_empty(&mpool_rdma->gc_list))
|
|
|
|
do_unregistration_gc(mpool);
|
|
|
|
|
2006-12-17 15:26:41 +03:00
|
|
|
/* look through existing regs if not persistent registration requested.
|
|
|
|
* Persistent registration are always registered and placed in the cache */
|
|
|
|
if(!(flags & MCA_MPOOL_FLAGS_PERSIST)) {
|
|
|
|
/* check to see if memory is registered */
|
|
|
|
mpool->rcache->rcache_find(mpool->rcache, addr, size, reg);
|
|
|
|
if(*reg != NULL &&
|
|
|
|
(mca_mpool_rdma_component.leave_pinned ||
|
|
|
|
((*reg)->flags & MCA_MPOOL_FLAGS_PERSIST) ||
|
|
|
|
((*reg)->base == base && (*reg)->bound == bound))) {
|
|
|
|
if(0 == (*reg)->ref_count &&
|
|
|
|
mca_mpool_rdma_component.leave_pinned) {
|
2011-12-07 22:20:44 +04:00
|
|
|
opal_list_remove_item(&mpool_rdma->lru_list,
|
2006-12-17 15:26:41 +03:00
|
|
|
(opal_list_item_t*)(*reg));
|
|
|
|
}
|
|
|
|
mpool_rdma->stat_cache_hit++;
|
|
|
|
(*reg)->ref_count++;
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
2009-03-17 23:21:36 +03:00
|
|
|
return OMPI_SUCCESS;
|
2006-12-17 15:26:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mpool_rdma->stat_cache_miss++;
|
|
|
|
*reg = NULL; /* in case previous find found something */
|
|
|
|
|
|
|
|
/* If no suitable registration is in cache and leave_pinned isn't
|
|
|
|
* set and size of registration cache is unlimited don't use the cache.
|
|
|
|
* This is optimisation in case limit is not set. If limit is set we
|
|
|
|
* have to put registration into the cache to determine when we hit
|
|
|
|
* memory registration limit.
|
|
|
|
* NONE: cache is still used for persistent registrations so previous
|
|
|
|
* find can find something */
|
|
|
|
if(!mca_mpool_rdma_component.leave_pinned &&
|
|
|
|
mca_mpool_rdma_component.rcache_size_limit == 0) {
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
|
|
|
return register_cache_bypass(mpool, addr, size, flags, reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPI_FREE_LIST_GET(&mpool_rdma->reg_list, item, rc);
|
|
|
|
if(OMPI_SUCCESS != rc) {
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
rdma_reg = (mca_mpool_base_registration_t*)item;
|
|
|
|
|
|
|
|
rdma_reg->mpool = mpool;
|
|
|
|
rdma_reg->base = base;
|
|
|
|
rdma_reg->bound = bound;
|
|
|
|
rdma_reg->flags = flags;
|
|
|
|
|
|
|
|
while((rc = mpool->rcache->rcache_insert(mpool->rcache, rdma_reg,
|
|
|
|
mca_mpool_rdma_component.rcache_size_limit)) ==
|
|
|
|
OMPI_ERR_TEMP_OUT_OF_RESOURCE) {
|
|
|
|
/* try to remove one unused reg and retry */
|
2011-12-07 22:20:44 +04:00
|
|
|
if (!mca_mpool_rdma_deregister_lru (mpool)) {
|
2006-12-17 15:26:41 +03:00
|
|
|
break;
|
2011-12-07 22:20:44 +04:00
|
|
|
}
|
2006-12-17 15:26:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(rc != OMPI_SUCCESS) {
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
|
|
|
OMPI_FREE_LIST_RETURN(&mpool_rdma->reg_list, item);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-12-07 22:20:44 +04:00
|
|
|
while (OMPI_ERR_OUT_OF_RESOURCE ==
|
|
|
|
(rc = mpool_rdma->resources.register_mem(mpool_rdma->resources.reg_data,
|
|
|
|
base, bound - base + 1, rdma_reg))) {
|
|
|
|
/* try to remove one unused reg and retry */
|
|
|
|
if (!mca_mpool_rdma_deregister_lru (mpool)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-12-17 15:26:41 +03:00
|
|
|
|
|
|
|
if(rc != OMPI_SUCCESS) {
|
|
|
|
mpool->rcache->rcache_delete(mpool->rcache, rdma_reg);
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
|
|
|
OMPI_FREE_LIST_RETURN(&mpool_rdma->reg_list, item);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
*reg = rdma_reg;
|
|
|
|
(*reg)->ref_count++;
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
2010-02-22 14:19:15 +03:00
|
|
|
|
|
|
|
/* Cleanup any vmas that we have deferred deletion on */
|
|
|
|
mpool->rcache->rcache_clean(mpool->rcache);
|
2006-12-17 15:26:41 +03:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* realloc function
|
|
|
|
*/
|
|
|
|
void* mca_mpool_rdma_realloc(mca_mpool_base_module_t *mpool, void *addr,
|
|
|
|
size_t size, mca_mpool_base_registration_t **reg)
|
|
|
|
{
|
|
|
|
mca_mpool_base_registration_t *old_reg = *reg;
|
|
|
|
void *new_mem = mca_mpool_rdma_alloc(mpool, size, 0, old_reg->flags, reg);
|
|
|
|
memcpy(new_mem, addr, old_reg->bound - old_reg->base + 1);
|
|
|
|
mca_mpool_rdma_free(mpool, addr, old_reg);
|
|
|
|
|
|
|
|
return new_mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* free function
|
|
|
|
*/
|
|
|
|
void mca_mpool_rdma_free(mca_mpool_base_module_t *mpool, void *addr,
|
|
|
|
mca_mpool_base_registration_t *registration)
|
|
|
|
{
|
2007-08-30 14:52:38 +04:00
|
|
|
void *alloc_base = registration->alloc_base;
|
2006-12-17 15:26:41 +03:00
|
|
|
mca_mpool_rdma_deregister(mpool, registration);
|
2007-08-30 14:52:38 +04:00
|
|
|
free(alloc_base);
|
2006-12-17 15:26:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int mca_mpool_rdma_find(struct mca_mpool_base_module_t *mpool, void *addr,
|
|
|
|
size_t size, mca_mpool_base_registration_t **reg)
|
|
|
|
{
|
|
|
|
mca_mpool_rdma_module_t *mpool_rdma = (mca_mpool_rdma_module_t*)mpool;
|
|
|
|
int rc;
|
|
|
|
unsigned char *base, *bound;
|
|
|
|
|
2008-09-08 19:39:30 +04:00
|
|
|
base = (unsigned char *) down_align_addr(addr, mca_mpool_base_page_size_log);
|
|
|
|
bound = (unsigned char *) up_align_addr((void*)((char*) addr + size - 1),
|
2006-12-17 15:26:41 +03:00
|
|
|
mca_mpool_base_page_size_log);
|
|
|
|
|
|
|
|
OPAL_THREAD_LOCK(&mpool->rcache->lock);
|
|
|
|
rc = mpool->rcache->rcache_find(mpool->rcache, addr, size, reg);
|
|
|
|
if(*reg != NULL &&
|
|
|
|
(mca_mpool_rdma_component.leave_pinned ||
|
|
|
|
((*reg)->flags & MCA_MPOOL_FLAGS_PERSIST) ||
|
|
|
|
((*reg)->base == base && (*reg)->bound == bound))) {
|
|
|
|
assert(((void*)(*reg)->bound) >= addr);
|
|
|
|
if(0 == (*reg)->ref_count &&
|
|
|
|
mca_mpool_rdma_component.leave_pinned) {
|
2011-12-07 22:20:44 +04:00
|
|
|
opal_list_remove_item(&mpool_rdma->lru_list,
|
2006-12-17 15:26:41 +03:00
|
|
|
(opal_list_item_t*)(*reg));
|
|
|
|
}
|
|
|
|
mpool_rdma->stat_cache_found++;
|
|
|
|
(*reg)->ref_count++;
|
|
|
|
} else {
|
|
|
|
mpool_rdma->stat_cache_notfound++;
|
|
|
|
}
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-01-08 11:55:42 +03:00
|
|
|
static inline bool registration_is_cachebale(mca_mpool_base_registration_t *reg)
|
|
|
|
{
|
|
|
|
return !(reg->flags &
|
|
|
|
(MCA_MPOOL_FLAGS_CACHE_BYPASS |
|
|
|
|
MCA_MPOOL_FLAGS_PERSIST |
|
|
|
|
MCA_MPOOL_FLAGS_INVALID));
|
|
|
|
}
|
|
|
|
|
2006-12-17 15:26:41 +03:00
|
|
|
int mca_mpool_rdma_deregister(struct mca_mpool_base_module_t *mpool,
|
|
|
|
mca_mpool_base_registration_t *reg)
|
|
|
|
{
|
|
|
|
mca_mpool_rdma_module_t *mpool_rdma = (mca_mpool_rdma_module_t*)mpool;
|
|
|
|
int rc = OMPI_SUCCESS;
|
|
|
|
assert(reg->ref_count > 0);
|
|
|
|
|
|
|
|
OPAL_THREAD_LOCK(&mpool->rcache->lock);
|
|
|
|
reg->ref_count--;
|
|
|
|
if(reg->ref_count > 0) {
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
2008-01-08 11:55:42 +03:00
|
|
|
if(mca_mpool_rdma_component.leave_pinned && registration_is_cachebale(reg))
|
|
|
|
{
|
2006-12-17 15:26:41 +03:00
|
|
|
/* if leave_pinned is set don't deregister memory, but put it
|
2011-12-07 22:20:44 +04:00
|
|
|
* on LRU list for future use */
|
|
|
|
opal_list_append(&mpool_rdma->lru_list, (opal_list_item_t*)reg);
|
2006-12-17 15:26:41 +03:00
|
|
|
} else {
|
2010-02-23 14:31:58 +03:00
|
|
|
/* Remove from rcache first */
|
|
|
|
if(!(reg->flags & MCA_MPOOL_FLAGS_CACHE_BYPASS))
|
|
|
|
mpool->rcache->rcache_delete(mpool->rcache, reg);
|
|
|
|
|
|
|
|
/* Drop the rcache lock before deregistring the memory */
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
2006-12-17 15:26:41 +03:00
|
|
|
rc = dereg_mem(mpool, reg);
|
2010-02-23 14:31:58 +03:00
|
|
|
OPAL_THREAD_LOCK(&mpool->rcache->lock);
|
|
|
|
|
2006-12-17 15:26:41 +03:00
|
|
|
if(OMPI_SUCCESS == rc) {
|
|
|
|
OMPI_FREE_LIST_RETURN(&mpool_rdma->reg_list,
|
|
|
|
(ompi_free_list_item_t*)reg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
|
|
|
|
2010-02-22 14:19:15 +03:00
|
|
|
/* Cleanup any vmas that we have deferred deletion on */
|
|
|
|
mpool->rcache->rcache_clean(mpool->rcache);
|
|
|
|
|
2006-12-17 15:26:41 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-01-08 11:55:42 +03:00
|
|
|
#define RDMA_MPOOL_NREGS 100
|
|
|
|
|
2006-12-17 15:26:41 +03:00
|
|
|
int mca_mpool_rdma_release_memory(struct mca_mpool_base_module_t *mpool,
|
|
|
|
void *base, size_t size)
|
|
|
|
{
|
|
|
|
mca_mpool_rdma_module_t *mpool_rdma = (mca_mpool_rdma_module_t*)mpool;
|
|
|
|
mca_mpool_base_registration_t *reg;
|
2008-01-08 11:55:42 +03:00
|
|
|
mca_mpool_base_registration_t *regs[RDMA_MPOOL_NREGS];
|
2006-12-17 15:26:41 +03:00
|
|
|
int reg_cnt, i, err = 0;
|
|
|
|
|
|
|
|
OPAL_THREAD_LOCK(&mpool->rcache->lock);
|
2008-01-08 11:55:42 +03:00
|
|
|
do {
|
|
|
|
reg_cnt = mpool->rcache->rcache_find_all(mpool->rcache, base, size,
|
|
|
|
regs, RDMA_MPOOL_NREGS);
|
|
|
|
|
|
|
|
for(i = 0; i < reg_cnt; i++) {
|
|
|
|
reg = regs[i];
|
|
|
|
|
|
|
|
reg->flags |= MCA_MPOOL_FLAGS_INVALID;
|
|
|
|
if(reg->ref_count) {
|
|
|
|
/* memory is being freed, but there are registration in use that
|
|
|
|
* covers the memory. This can happen even in a correct program,
|
|
|
|
* but may also be an user error. We can't tell. Mark the
|
|
|
|
* registration as invalid. It will not be used any more and
|
|
|
|
* will be unregistered when ref_count will become zero */
|
|
|
|
err++; /* tell caller that something was wrong */
|
2006-12-17 15:26:41 +03:00
|
|
|
continue;
|
|
|
|
}
|
2008-01-08 11:55:42 +03:00
|
|
|
|
2011-12-07 22:20:44 +04:00
|
|
|
opal_list_remove_item(&mpool_rdma->lru_list,(opal_list_item_t*)reg);
|
2008-01-08 11:55:42 +03:00
|
|
|
opal_list_append(&mpool_rdma->gc_list, (opal_list_item_t*)reg);
|
2006-12-17 15:26:41 +03:00
|
|
|
}
|
2008-01-08 11:55:42 +03:00
|
|
|
} while(reg_cnt == RDMA_MPOOL_NREGS);
|
|
|
|
|
2006-12-17 15:26:41 +03:00
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
|
|
|
|
2008-01-08 11:55:42 +03:00
|
|
|
return err ? OMPI_ERROR : OMPI_SUCCESS;
|
2006-12-17 15:26:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void mca_mpool_rdma_finalize(struct mca_mpool_base_module_t *mpool)
|
|
|
|
{
|
|
|
|
mca_mpool_rdma_module_t *mpool_rdma = (mca_mpool_rdma_module_t*)mpool;
|
2007-07-23 20:18:36 +04:00
|
|
|
mca_mpool_base_registration_t *reg;
|
2008-01-08 11:55:42 +03:00
|
|
|
mca_mpool_base_registration_t *regs[RDMA_MPOOL_NREGS];
|
2007-07-23 20:18:36 +04:00
|
|
|
int reg_cnt, i;
|
2010-02-23 14:31:58 +03:00
|
|
|
int rc;
|
2007-07-23 20:18:36 +04:00
|
|
|
|
|
|
|
/* Statistic */
|
|
|
|
if(true == mca_mpool_rdma_component.print_stats) {
|
2008-06-09 18:53:58 +04:00
|
|
|
opal_output(0, "%s rdma: stats "
|
2007-07-23 20:18:36 +04:00
|
|
|
"(hit/miss/found/not found/evicted): %d/%d/%d/%d/%d\n",
|
2009-03-06 00:50:47 +03:00
|
|
|
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
|
2007-07-23 20:18:36 +04:00
|
|
|
mpool_rdma->stat_cache_hit, mpool_rdma->stat_cache_miss,
|
|
|
|
mpool_rdma->stat_cache_found, mpool_rdma->stat_cache_notfound,
|
|
|
|
mpool_rdma->stat_evicted);
|
|
|
|
}
|
|
|
|
|
|
|
|
OPAL_THREAD_LOCK(&mpool->rcache->lock);
|
2008-01-08 11:55:42 +03:00
|
|
|
if(!opal_list_is_empty(&mpool_rdma->gc_list))
|
|
|
|
do_unregistration_gc(mpool);
|
|
|
|
do {
|
|
|
|
reg_cnt = mpool->rcache->rcache_find_all(mpool->rcache, 0, (size_t)-1,
|
|
|
|
regs, RDMA_MPOOL_NREGS);
|
|
|
|
|
|
|
|
for(i = 0; i < reg_cnt; i++) {
|
|
|
|
reg = regs[i];
|
|
|
|
|
|
|
|
if(reg->ref_count) {
|
|
|
|
reg->ref_count = 0; /* otherway dereg will fail on assert */
|
|
|
|
} else if (mca_mpool_rdma_component.leave_pinned) {
|
2011-12-07 22:20:44 +04:00
|
|
|
opal_list_remove_item(&mpool_rdma->lru_list,
|
2008-01-08 11:55:42 +03:00
|
|
|
(opal_list_item_t*)reg);
|
|
|
|
}
|
2007-07-23 20:18:36 +04:00
|
|
|
|
2010-02-23 14:31:58 +03:00
|
|
|
/* Remove from rcache first */
|
|
|
|
mpool->rcache->rcache_delete(mpool->rcache, reg);
|
|
|
|
|
|
|
|
/* Drop lock before deregistering memory */
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
|
|
|
rc = dereg_mem(mpool, reg);
|
|
|
|
OPAL_THREAD_LOCK(&mpool->rcache->lock);
|
|
|
|
|
|
|
|
if(rc != OMPI_SUCCESS) {
|
|
|
|
/* Potentially lose track of registrations
|
|
|
|
do we have to put it back? */
|
2008-01-08 11:55:42 +03:00
|
|
|
continue;
|
|
|
|
}
|
2007-07-23 20:18:36 +04:00
|
|
|
|
2008-01-08 11:55:42 +03:00
|
|
|
OMPI_FREE_LIST_RETURN(&mpool_rdma->reg_list,
|
|
|
|
(ompi_free_list_item_t*)reg);
|
2007-07-23 20:18:36 +04:00
|
|
|
}
|
2008-01-08 11:55:42 +03:00
|
|
|
} while(reg_cnt == RDMA_MPOOL_NREGS);
|
2007-07-23 20:18:36 +04:00
|
|
|
|
2011-12-07 22:20:44 +04:00
|
|
|
OBJ_DESTRUCT(&mpool_rdma->lru_list);
|
2008-01-08 11:55:42 +03:00
|
|
|
OBJ_DESTRUCT(&mpool_rdma->gc_list);
|
2007-07-23 20:18:36 +04:00
|
|
|
OBJ_DESTRUCT(&mpool_rdma->reg_list);
|
|
|
|
OPAL_THREAD_UNLOCK(&mpool->rcache->lock);
|
2010-02-22 14:19:15 +03:00
|
|
|
|
|
|
|
/* Cleanup any vmas that we have deferred deletion on */
|
|
|
|
mpool->rcache->rcache_clean(mpool->rcache);
|
|
|
|
|
2006-12-17 15:26:41 +03:00
|
|
|
}
|
2008-10-16 19:09:00 +04:00
|
|
|
|
|
|
|
int mca_mpool_rdma_ft_event(int state) {
|
|
|
|
if(OPAL_CRS_CHECKPOINT == state) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else if(OPAL_CRS_CONTINUE == state) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else if(OPAL_CRS_RESTART == state ||
|
|
|
|
OPAL_CRS_RESTART_PRE == state) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else if(OPAL_CRS_TERM == state ) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|