"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/mpid/ch3/channels/common/src/reg_cache/dreg.c" between
mvapich2-2.3.1.tar.gz and mvapich2-2.3.2.tar.gz

About: MVAPICH2 offers "MPI over InfiniBand, 10GigE/iWARP and RDMA over Converged Ethernet (RoCE)" to achieve best performance, scalability and fault tolerance for high-end computing systems and servers.

dreg.c  (mvapich2-2.3.1):dreg.c  (mvapich2-2.3.2)
skipping to change at line 897 skipping to change at line 897
if(n_dereg_mr == 0 || have_dreg() || have_dereg()) { if(n_dereg_mr == 0 || have_dreg() || have_dereg()) {
return; return;
} }
lock_dreg(); lock_dreg();
lock_dereg(); lock_dereg();
for(j = 0; j < n_dereg_mr; j++) { for(j = 0; j < n_dereg_mr; j++) {
d = deregister_mr_array[j]; d = deregister_mr_array[j];
PRINT_DEBUG(DEBUG_DREG_verbose, "Trying to free dreg %p. ref_count = %d,
valid = %d, npages = %lu, pagenum = %lu\n",
d, d->refcount, d->is_valid, d->npages, d->pagenum);
MPIU_Assert(d->is_valid == 0); MPIU_Assert(d->is_valid == 0);
MPIU_Assert(d->refcount == 0); MPIU_Assert(d->refcount == 0);
#ifdef NEMESIS_BUILD #ifdef NEMESIS_BUILD
for (k = 0; k < ib_hca_num_hcas; k++) { for (k = 0; k < ib_hca_num_hcas; k++) {
#else #else
for (k = 0; k < rdma_num_hcas; k++) { for (k = 0; k < rdma_num_hcas; k++) {
#endif #endif
if(d->memhandle[k]) { if(d->memhandle[k]) {
if (deregister_memory(d->memhandle[k])) if (deregister_memory(d->memhandle[k]))
skipping to change at line 921 skipping to change at line 923
} }
#ifdef NEMESIS_BUILD #ifdef NEMESIS_BUILD
if(process_info.has_lazy_mem_unregister) { if(process_info.has_lazy_mem_unregister) {
#else #else
if(mv2_MPIDI_CH3I_RDMA_Process.has_lazy_mem_unregister) { if(mv2_MPIDI_CH3I_RDMA_Process.has_lazy_mem_unregister) {
#endif #endif
DREG_REMOVE_FROM_UNUSED_LIST(d); DREG_REMOVE_FROM_UNUSED_LIST(d);
} }
d->in_deregister_mr_array = 0;
PRINT_DEBUG(DEBUG_DREG_verbose, "Adding dreg %p to free list. ref_co
unt = %d, valid = %d, npages = %lu, pagenum = %lu\n",
d, d->refcount, d->is_valid, d->npages, d->pagenum);
DREG_ADD_TO_FREE_LIST(d); DREG_ADD_TO_FREE_LIST(d);
} }
n_dereg_mr = 0; n_dereg_mr = 0;
unlock_dereg(); unlock_dereg();
unlock_dreg(); unlock_dreg();
MPIDI_FUNC_EXIT(MPID_GEN2_FLUSH_DREG_MRS_EXTERNALS); MPIDI_FUNC_EXIT(MPID_GEN2_FLUSH_DREG_MRS_EXTERNALS);
} }
#endif /* !defined(DISABLE_PTMALLOC) */ #endif /* !defined(DISABLE_PTMALLOC) */
skipping to change at line 955 skipping to change at line 960
#if !defined(DISABLE_PTMALLOC) #if !defined(DISABLE_PTMALLOC)
lock_dreg(); lock_dreg();
#endif /* !defined(DISABLE_PTMALLOC) */ #endif /* !defined(DISABLE_PTMALLOC) */
struct dreg_entry* d = dreg_find(buf, len); struct dreg_entry* d = dreg_find(buf, len);
if (d != NULL) if (d != NULL)
{ {
++dreg_stat_cache_hit; ++dreg_stat_cache_hit;
dreg_incr_refcount(d); dreg_incr_refcount(d);
PRINT_DEBUG(DEBUG_DREG_verbose, "Dreg hit with dreg %p for buf %p, ref_c
ount = %d, valid = %d, npages = %lu, pagenum = %lu\n",
d, buf, d->refcount, d->is_valid, d->npages, d->pagenum);
MPIR_T_PVAR_COUNTER_INC(MV2, mv2_reg_cache_hits, 1); MPIR_T_PVAR_COUNTER_INC(MV2, mv2_reg_cache_hits, 1);
} }
else else
{ {
++dreg_stat_cache_miss; ++dreg_stat_cache_miss;
MPIR_T_PVAR_COUNTER_INC(MV2, mv2_reg_cache_misses, 1); MPIR_T_PVAR_COUNTER_INC(MV2, mv2_reg_cache_misses, 1);
while ((d = dreg_new_entry(buf, len)) == NULL) while ((d = dreg_new_entry(buf, len)) == NULL)
{ {
/* either was not able to obtain a dreg_entry data strucrure /* either was not able to obtain a dreg_entry data strucrure
skipping to change at line 978 skipping to change at line 985
rc = dreg_evict(); rc = dreg_evict();
if (rc == 0) if (rc == 0)
{ {
/* could not evict anything, will not be able to /* could not evict anything, will not be able to
* register this memory. Return failure. * register this memory. Return failure.
*/ */
#if !defined(DISABLE_PTMALLOC) #if !defined(DISABLE_PTMALLOC)
unlock_dreg(); unlock_dreg();
#endif /* !defined(DISABLE_PTMALLOC) */ #endif /* !defined(DISABLE_PTMALLOC) */
PRINT_DEBUG(DEBUG_DREG_verbose, "Eviction failed\n");
return NULL; return NULL;
} }
PRINT_DEBUG(DEBUG_DREG_verbose, "Eviction sucessful\n");
/* eviction successful, try again */ /* eviction successful, try again */
} }
dreg_incr_refcount(d); dreg_incr_refcount(d);
PRINT_DEBUG(DEBUG_DREG_verbose, "Dreg miss for %p. Dreg = %p ref_count =
%d, valid = %d, npages = %lu, pagenum = %lu\n",
buf, d, d->refcount, d->is_valid, d->npages, d->pagenum);
} }
#if !defined(DISABLE_PTMALLOC) #if !defined(DISABLE_PTMALLOC)
unlock_dreg(); unlock_dreg();
#endif /* !defined(DISABLE_PTMALLOC) */ #endif /* !defined(DISABLE_PTMALLOC) */
MPIDI_FUNC_EXIT(MPID_GEN2_DREG_REGISTER); MPIDI_FUNC_EXIT(MPID_GEN2_DREG_REGISTER);
return d; return d;
} }
skipping to change at line 1027 skipping to change at line 1037
*/ */
dreg_entry* dreg_get(void) dreg_entry* dreg_get(void)
{ {
dreg_entry *d = NULL; dreg_entry *d = NULL;
DREG_GET_FROM_FREE_LIST(d); DREG_GET_FROM_FREE_LIST(d);
if (d != NULL) if (d != NULL)
{ {
d->refcount = 0; d->refcount = 0;
d->in_deregister_mr_array = 0;
d->next_unused = NULL; d->next_unused = NULL;
d->prev_unused = NULL; d->prev_unused = NULL;
d->next = NULL; d->next = NULL;
PRINT_DEBUG(DEBUG_DREG_verbose, "Got Dreg %p from free list. ref_count =
%d, valid = %d, npages = %lu, pagenum = %lu\n",
d, d->refcount, d->is_valid, d->npages, d->pagenum);
} }
#if defined(DEBUG) #if defined(DEBUG)
else else
{ {
DEBUG_PRINT("dreg_get: no free dreg entries"); PRINT_DEBUG(DEBUG_DREG_verbose, "No free dreg entries\n");
} }
#endif /* defined(DEBUG) */ #endif /* defined(DEBUG) */
return d; return d;
} }
void dreg_release(dreg_entry* d) void dreg_release(dreg_entry* d)
{ {
/* note this correctly handles appending to empty free list */ /* note this correctly handles appending to empty free list */
d->next = dreg_free_list; d->next = dreg_free_list;
dreg_free_list = d; dreg_free_list = d;
skipping to change at line 1058 skipping to change at line 1071
* Decrement reference count on a dreg entry. If ref count goes to * Decrement reference count on a dreg entry. If ref count goes to
* zero, don't free it, but put it on the unused list so we * zero, don't free it, but put it on the unused list so we
* can evict it if necessary. Put on head of unused list. * can evict it if necessary. Put on head of unused list.
*/ */
void dreg_decr_refcount(dreg_entry* d) void dreg_decr_refcount(dreg_entry* d)
{ {
int i = 0; int i = 0;
MPIU_Assert(d->refcount > 0); MPIU_Assert(d->refcount > 0);
--d->refcount; --d->refcount;
PRINT_DEBUG(DEBUG_DREG_verbose, "Decrementing refcount for dreg %p. ref_coun
t = %d, valid = %d, npages = %lu, pagenum = %lu\n",
d, d->refcount, d->is_valid, d->npages, d->pagenum);
if (d->refcount == 0) if (d->refcount == 0)
{ {
#ifdef NEMESIS_BUILD #ifdef NEMESIS_BUILD
if (process_info.has_lazy_mem_unregister) if (process_info.has_lazy_mem_unregister)
#else #else
if (mv2_MPIDI_CH3I_RDMA_Process.has_lazy_mem_unregister) if (mv2_MPIDI_CH3I_RDMA_Process.has_lazy_mem_unregister)
#endif #endif
{ {
DREG_ADD_TO_UNUSED_LIST(d); DREG_ADD_TO_UNUSED_LIST(d);
} }
skipping to change at line 1089 skipping to change at line 1104
if (deregister_memory(d->memhandle[i])) if (deregister_memory(d->memhandle[i]))
{ {
ibv_error_abort(IBV_RETURN_ERR, "deregister fails\n"); ibv_error_abort(IBV_RETURN_ERR, "deregister fails\n");
} }
} }
d->memhandle[i] = NULL; d->memhandle[i] = NULL;
} }
dreg_remove(d); dreg_remove(d);
PRINT_DEBUG(DEBUG_DREG_verbose, "Adding dreg %p to free list. ref_co
unt = %d, valid = %d, npages = %lu, pagenum = %lu\n",
d, d->refcount, d->is_valid, d->npages, d->pagenum);
DREG_ADD_TO_FREE_LIST(d); DREG_ADD_TO_FREE_LIST(d);
} }
} }
} }
/* /*
* Increment reference count on a dreg entry. If reference count * Increment reference count on a dreg entry. If reference count
* was zero and it was on the unused list (meaning it had been * was zero and it was on the unused list (meaning it had been
* previously used, and the refcount had been decremented), * previously used, and the refcount had been decremented),
* we should take it off * we should take it off
skipping to change at line 1111 skipping to change at line 1128
void dreg_incr_refcount(dreg_entry* d) void dreg_incr_refcount(dreg_entry* d)
{ {
MPIU_Assert(d != NULL); MPIU_Assert(d != NULL);
if (d->refcount == 0) if (d->refcount == 0)
{ {
DREG_REMOVE_FROM_UNUSED_LIST(d); DREG_REMOVE_FROM_UNUSED_LIST(d);
} }
++d->refcount; ++d->refcount;
PRINT_DEBUG(DEBUG_DREG_verbose, "Incrementing refcount for dreg %p. ref_coun
t = %d, valid = %d, npages = %lu, pagenum = %lu\n",
d, d->refcount, d->is_valid, d->npages, d->pagenum);
} }
/* /*
* Evict a registration. This means delete it from the unused list, * Evict a registration. This means delete it from the unused list,
* add it to the free list, and deregister the associated memory. * add it to the free list, and deregister the associated memory.
* Return 1 if success, 0 if nothing to evict. * Return 1 if success, 0 if nothing to evict.
* *
* If PTMALLOC is defined, its OK to call flush_dereg_mrs() * If PTMALLOC is defined, its OK to call flush_dereg_mrs()
* since dreg_evict() is called from within dreg_register() * since dreg_evict() is called from within dreg_register()
* which has the dreg_lock. Otherwise, it can only be called * which has the dreg_lock. Otherwise, it can only be called
* from finalize, where there's only one thread executing * from finalize, where there's only one thread executing
* anyways. * anyways.
*/ */
int dreg_evict() int dreg_evict()
{ {
int hca_index = 0; int hca_index = 0;
dreg_entry* d = dreg_unused_tail; dreg_entry* d = dreg_unused_tail;
while (d && d->in_deregister_mr_array) {
d = d->next_unused;
}
if (d == NULL) if (d == NULL)
{ {
/* no entries left on unused list, return failure */ /* no entries left on unused list, return failure */
return 0; return 0;
} }
DREG_REMOVE_FROM_UNUSED_LIST(d); DREG_REMOVE_FROM_UNUSED_LIST(d);
#if defined(CHANNEL_MRAIL) #if defined(CHANNEL_MRAIL)
MPIU_Assert(d->refcount == 0 || mv2_is_in_finalize); MPIU_Assert(d->refcount == 0 || mv2_is_in_finalize);
#else #else
MPIU_Assert(d->refcount == 0); MPIU_Assert(d->refcount == 0);
#endif #endif
PRINT_DEBUG(DEBUG_DREG_verbose, "Trying to evict dreg %p. ref_count = %d, va
lid = %d, npages = %lu, pagenum = %lu\n",
d, d->refcount, d->is_valid, d->npages, d->pagenum);
#ifdef NEMESIS_BUILD #ifdef NEMESIS_BUILD
for (; hca_index < ib_hca_num_hcas; ++hca_index) for (; hca_index < ib_hca_num_hcas; ++hca_index)
#else #else
for (; hca_index < rdma_num_hcas; ++hca_index) for (; hca_index < rdma_num_hcas; ++hca_index)
#endif #endif
{ {
if (d->memhandle[hca_index]) if (d->memhandle[hca_index])
{ {
d->is_valid = 0; d->is_valid = 0;
PRINT_DEBUG(DEBUG_DREG_verbose, "Unregistering dreg %p: ref_count =
%d, valid = %d, npages = %lu, pagenum = %lu\n",
d, d->refcount, d->is_valid, d->npages, d->pagenum);
if (deregister_memory(d->memhandle[hca_index])) if (deregister_memory(d->memhandle[hca_index]))
{ {
ibv_error_abort(IBV_RETURN_ERR, "Deregister fails\n"); ibv_error_abort(IBV_RETURN_ERR, "Deregister fails\n");
} }
} }
} }
dreg_remove(d); dreg_remove(d);
PRINT_DEBUG(DEBUG_DREG_verbose, "Adding dreg %p to free list: ref_count = %d
, valid = %d, npages = %lu, pagenum = %lu\n",
d, d->refcount, d->is_valid, d->npages, d->pagenum);
DREG_ADD_TO_FREE_LIST(d); DREG_ADD_TO_FREE_LIST(d);
++dreg_stat_evicted; ++dreg_stat_evicted;
return 1; return 1;
} }
/* /*
* dreg_new_entry is called only when we have already * dreg_new_entry is called only when we have already
* found that the memory isn't registered. Register it * found that the memory isn't registered. Register it
* and put it in the hash table * and put it in the hash table
*/ */
skipping to change at line 1336 skipping to change at line 1365
if (d->refcount !=0 || d->is_valid == 0) { if (d->refcount !=0 || d->is_valid == 0) {
/* This memory area is still being referenced /* This memory area is still being referenced
* by other pending MPI operations, which are * by other pending MPI operations, which are
* expected to call dreg_unregister and thus * expected to call dreg_unregister and thus
* unpin the buffer. We cannot deregister this * unpin the buffer. We cannot deregister this
* page, since other ops are pending from here. */ * page, since other ops are pending from here. */
/* OR: This memory region is in the process of /* OR: This memory region is in the process of
* being deregistered. Leave it alone! */ * being deregistered. Leave it alone! */
PRINT_DEBUG(DEBUG_DREG_verbose, "Not freeing dreg %p. ref_count
= %d, valid = %d, npages = %lu, pagenum = %lu\n",
d, d->refcount, d->is_valid, d->npages, d->pagenum);
break; break;
} }
deregister_mr_array[n_dereg_mr] = d; deregister_mr_array[n_dereg_mr] = d;
d->in_deregister_mr_array = 1;
d->is_valid = 0; d->is_valid = 0;
PRINT_DEBUG(DEBUG_DREG_verbose, "Trying to free associated dreg %p.
ref_count = %d, valid = %d, npages = %lu, pagenum = %lu\n",
d, d->refcount, d->is_valid, d->npages, d->pagenum);
/* /*
* dreg_remove can call free() while removing vma_entry * dreg_remove can call free() while removing vma_entry
* It can lead to resursion here. but, still we have added * It can lead to resursion here. but, still we have added
* this here on the assumption that dreg_lookup will fail * this here on the assumption that dreg_lookup will fail
*/ */
dreg_remove (d); dreg_remove (d);
n_dereg_mr++; n_dereg_mr++;
} }
} }
 End of changes. 20 change blocks. 
2 lines changed or deleted 49 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)