Changeset 5665

Show
Ignore:
Timestamp:
11/02/09 17:31:00 (3 weeks ago)
Author:
goodell
Message:

Fix GREQ_CLASS leaks in the generalized request extensions.

This commit adds a finalize callback to cleanup all of the classes
created by MPIX_Grequest_class_create. This currently isn't thread-safe
under fine-grained threading.

Reviewed by balaji@.

Location:
mpich2/trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • mpich2/trunk/src/include/mpiimpl.h

    r5623 r5665  
    21682168 
    21692169#define MPIR_FINALIZE_CALLBACK_PRIO 5 
     2170#define MPIR_FINALIZE_CALLBACK_HANDLE_CHECK_PRIO 1 
     2171#define MPIR_FINALIZE_CALLBACK_DEFAULT_PRIO 0 
    21702172#define MPIR_FINALIZE_CALLBACK_MAX_PRIO 10 
    21712173 
     
    31523154     MPIX_Grequest_poll_function *poll_fn; 
    31533155     MPIX_Grequest_wait_function *wait_fn; 
     3156     struct MPID_Grequest_class *next; 
    31543157} MPID_Grequest_class; 
    31553158 
  • mpich2/trunk/src/mpi/pt2pt/greq_start.c

    r5355 r5665  
    1717/* -- End Profiling Symbol Block */ 
    1818 
     19PMPI_LOCAL int MPIR_Grequest_free_classes_on_finalize(void *extra_data); 
     20 
    1921/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build 
    2022   the MPI routines.  You can use USE_WEAK_SYMBOLS to see if MPICH is 
     
    3638                                               MPID_GREQ_CLASS_PREALLOC, }; 
    3739 
     40/* We jump through some minor hoops to manage the list of classes ourselves and 
     41 * only register a single finalizer to avoid hitting limitations in the current 
     42 * finalizer code.  If the finalizer implementation is ever revisited this code 
     43 * is a good candidate for registering one callback per greq class and trimming 
     44 * some of this logic. */ 
     45int MPIR_Grequest_registered_finalizer = 0; 
     46MPID_Grequest_class *MPIR_Grequest_class_list = NULL; 
     47 
    3848/* Any internal routines can go here.  Make them static if possible.  If they 
    3949   are used by both the MPI and PMPI versions, use PMPI_LOCAL instead of  
    4050   static; this macro expands into "static" if weak symbols are supported and 
    4151   into nothing otherwise. */ 
     52PMPI_LOCAL int MPIR_Grequest_free_classes_on_finalize(void *extra_data ATTRIBUTE((unused))) 
     53{ 
     54    int mpi_errno = MPI_SUCCESS; 
     55    MPID_Grequest_class *last = NULL; 
     56    MPID_Grequest_class *cur = MPIR_Grequest_class_list; 
     57 
     58    /* FIXME MT this function is not thread safe when using fine-grained threading */ 
     59    MPIR_Grequest_class_list = NULL; 
     60    while (cur) { 
     61        last = cur; 
     62        cur = last->next; 
     63        MPIU_Handle_obj_free(&MPID_Grequest_class_mem, last); 
     64    } 
     65 
     66    return mpi_errno; 
     67} 
     68 
    4269#else 
    4370extern MPID_Grequest_class MPID_Grequest_class_direct[]; 
    4471extern MPIU_Object_alloc_t MPID_Grequest_class_mem; 
     72extern int MPIR_Grequest_registered_finalizer; 
     73extern MPID_Grequest_class *MPIR_Grequest_class_list; 
    4574#endif 
    4675 
     
    226255        MPIU_Object_set_ref(class_ptr, 1); 
    227256 
     257        if (MPIR_Grequest_class_list == NULL) { 
     258            class_ptr->next = NULL; 
     259        } 
     260        else { 
     261            class_ptr->next = MPIR_Grequest_class_list; 
     262        } 
     263        MPIR_Grequest_class_list = class_ptr; 
     264        if (!MPIR_Grequest_registered_finalizer) { 
     265            /* must run before (w/ higher priority than) the handle check 
     266             * finalizer in order avoid being flagged as a leak */ 
     267            MPIR_Add_finalize(&MPIR_Grequest_free_classes_on_finalize, 
     268                              NULL, 
     269                              MPIR_FINALIZE_CALLBACK_HANDLE_CHECK_PRIO+1); 
     270            MPIR_Grequest_registered_finalizer = 1; 
     271        } 
     272 
    228273        /* ... end of body of routine ... */ 
    229274fn_exit: 
  • mpich2/trunk/src/util/mem/handlemem.c

    r5524 r5665  
    354354               the priority of the callback that frees the objmem direct and  
    355355               indirect storage. */ 
    356             MPIR_Add_finalize(MPIU_CheckHandlesOnFinalize, objmem, 1); 
     356            MPIR_Add_finalize(MPIU_CheckHandlesOnFinalize, objmem, MPIR_FINALIZE_CALLBACK_HANDLE_CHECK_PRIO); 
    357357#endif 
    358358            /* ptr points to object to allocate */