Hello,
I found one more problem with ptmalloc and registration cache.
In arena.c:grow_heap() when heap is shrinking ptmalloc tries to be smart
and is using mmap() to change pages protection instead of mprotect() because
as a side effect mmap() drops underlying pages. In the case the area is
registered we cannot drop pages without notifying registration cache.
I see two solutions either change mmap() to mprotect() or call
opal_mem_hooks_release_hook() after mmap() to remove the area from
cache. I think first approach is better but both patch are included for
your consideration :)
Index: opal/mca/memory/ptmalloc2/arena.c
===================================================================
--- opal/mca/memory/ptmalloc2/arena.c (revision 8727)
+++ opal/mca/memory/ptmalloc2/arena.c (working copy)
@@ -614,10 +614,8 @@
new_size = (long)h->size + diff;
if(new_size < (long)sizeof(*h))
return -1;
- /* Try to re-map the extra heap space freshly to save memory, and
- make it inaccessible. */
- if((char *)MMAP((char *)h + new_size, -diff, PROT_NONE,
- MAP_PRIVATE|MAP_FIXED) == (char *) MAP_FAILED)
+
+ if(mprotect((char *)h + new_size, -diff, PROT_NONE) != 0)
return -2;
/*fprintf(stderr, "shrink %p %08lx\n", h, new_size);*/
}
Index: opal/mca/memory/ptmalloc2/arena.c
===================================================================
--- opal/mca/memory/ptmalloc2/arena.c (revision 8727)
+++ opal/mca/memory/ptmalloc2/arena.c (working copy)
@@ -619,6 +619,8 @@
if((char *)MMAP((char *)h + new_size, -diff, PROT_NONE,
MAP_PRIVATE|MAP_FIXED) == (char *) MAP_FAILED)
return -2;
+
+ opal_mem_hooks_release_hook ((char *)h + new_size, -diff, 1);
/*fprintf(stderr, "shrink %p %08lx\n", h, new_size);*/
}
h->size = new_size;
--
Gleb.