root/opal/mca/rcache/base/rcache_base_mem_cb.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mca_rcache_base_mem_cb

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2007 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2009      Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2012-2015 Los Alamos National Security, LLC.
  15  *                         All rights reserved.
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 /**
  23  * @file
  24  */
  25 #include "opal_config.h"
  26 
  27 #ifdef HAVE_UNISTD_H
  28 #include <unistd.h>
  29 #endif
  30 
  31 #include "opal/util/show_help.h"
  32 #include "opal/util/proc.h"
  33 #include "opal/runtime/opal_params.h"
  34 
  35 #include "opal/mca/rcache/base/rcache_base_mem_cb.h"
  36 #include "opal/mca/rcache/base/base.h"
  37 
  38 #include "opal/mca/mca.h"
  39 #include "opal/memoryhooks/memory.h"
  40 
  41 static char msg[512];
  42 
  43 
  44 /*
  45  *  memory hook callback, called when memory is free'd out from under
  46  *  us.  Be wary of the from_alloc flag -- if you're called with
  47  *  from_alloc==true, then you cannot call malloc (or any of its
  48  *  friends)!
  49  */
  50 void mca_rcache_base_mem_cb (void* base, size_t size, void* cbdata, bool from_alloc)
  51 {
  52     mca_rcache_base_selected_module_t* current;
  53     int rc;
  54 
  55     /* Only do anything meaningful if the OPAL layer is up and running
  56        and size != 0 */
  57     if ((from_alloc && (!opal_initialized)) || size == 0) {
  58         return;
  59     }
  60 
  61     OPAL_LIST_FOREACH(current, &mca_rcache_base_modules, mca_rcache_base_selected_module_t) {
  62         if (current->rcache_module->rcache_invalidate_range != NULL) {
  63             rc = current->rcache_module->rcache_invalidate_range (current->rcache_module,
  64                                                                   base, size);
  65             if (rc != OPAL_SUCCESS) {
  66                 if (from_alloc) {
  67                     int len;
  68                     len = snprintf(msg, sizeof(msg), "[%s:%05d] Attempt to free memory that is still in "
  69                                    "use by an ongoing MPI communication (buffer %p, size %lu).  MPI job "
  70                                    "will now abort.\n", opal_proc_local_get()->proc_hostname,
  71                                    getpid(), base, (unsigned long) size);
  72                     msg[sizeof(msg) - 1] = '\0';
  73                     write(2, msg, len);
  74                 } else {
  75                     opal_show_help("help-rcache-base.txt",
  76                                    "cannot deregister in-use memory", true,
  77                                    current->rcache_component->rcache_version.mca_component_name,
  78                                    opal_proc_local_get()->proc_hostname,
  79                                    base, (unsigned long) size);
  80                 }
  81 
  82                 /* We're in a callback from somewhere; we can't do
  83                    anything meaningful to pass an error back up.  :-(
  84                    So just exit.  Call _exit() so that we don't try to
  85                    call anything on the way out -- just exit!
  86                    (remember that we're in a callback, and state may
  87                    be very undefined at this point...) */
  88                 _exit(1);
  89             }
  90         }
  91     }
  92 }

/* [<][>][^][v][top][bottom][index][help] */