Process virtual memory cleanup takes quite a lot of time

Originator:ramosian.glider
Number:rdar://10699643 Date Originated:16-Jan-2012 07:07 PM
Status:Open Resolved:
Product: Product Version:
Classification: Reproducible:
 
16-Jan-2012 07:07 PM Alexander Potapenko:
Summary: Process virtual memory cleanup takes quite a lot of time

Steps to Reproduce:
=====================
$ cat p.c
#include <sys/mman.h>
int main() {
 void *t = mmap(0, 0x00000fffffffffffUL, PROT_READ| PROT_WRITE,
MAP_ANON | MAP_PRIVATE | MAP_NORESERVE, -1, 0);
}
=====================

runs for half a second on my 64-bit Snow Leopard machine:
=====================
$ time ./p

real    0m0.545s
user    0m0.000s
sys     0m0.544s
=====================

According to Shark, most of the time is spent in pmap_remove at exit time:
=====================
# Report 5 - session_008.mshark - Time Profile of PID #98012
SharkProfileViewer
# Generated from the visible portion of the outline view
+ 59.9%, pmap_remove, mach_kernel
| + 59.9%, vm_map_lookup_locked, mach_kernel
| | + 59.9%, vm_map_remove, mach_kernel
| | | + 59.9%, task_terminate_internal, mach_kernel
| | | | + 59.9%, exit1, mach_kernel
| | | | | + 59.9%, exit, mach_kernel
| | | | | |   59.9%, unix_syscall64, mach_kernel
- 12.0%, pmap64_pde, mach_kernel
- 10.7%, pmap64_pdpt, mach_kernel
- 5.0%, vm_map_lookup_locked, mach_kernel
- 2.7%, zalloc_canblock, mach_kernel
- 2.2%, pmap_pde, mach_kernel
- 1.8%, lck_mtx_lock_spin, mach_kernel
- 1.6%, vm_map_entry_insert, mach_kernel
- 1.0%, lck_mtx_unlock_darwin10, mach_kernel
- 0.5%, hw_lock_to, mach_kernel
=====================

Expected Results:
The program runs for milliseconds, as this should be safe to drop all the mappings on process shutdown.

Actual Results:
The program runs for half a second.

Regression:

Notes:
AddressSanitizer (http://code.google.com/p/address-sanitizer/) maps such a huge amount of memory to shadow the address space of the process being debugged.
The shutdown time for the process being tested affects the testing experience a bit.

16-Jan-2012 07:08 PM Alexander Potapenko:
$ uname -a
Darwin hostname 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!