While working on Insufficient Memory pattern for stack trace database (page 57) we noticed the expansion of certain memory regions. Of course, after some time expanding region consumes remaining free or reserved space available before some other region. Generalizing from this, we may say there can be Insufficient Memory pattern variant for any region expanding region. Region expansion may also be implemented via its move into some other position in memory virtual address space. This movement also has its limits. For example, we created this modeling application and found out it stops reallocating memory long before it reaches 2,000,000,000 byte size:
int _tmain(int argc, _TCHAR* argv[]) { int i = 100000000; void *p = malloc(i); for (i = 200000000; i < 2000000000; i+=100000000) { p = realloc(p, i); getc(stdin); } return 0; }
We took memory dumps after each loop iteration and after 6 or 8 iterations the memory size was constant, and there were no further reallocations:
0:000> !heap -s [...] Virtual block: 0000000006370000 - 0000000006370000 (size 0000000000000000) [...] 0:000> !address [...] ; Start End Size + 0`00550000 0`06370000 0`05e20000 MEM_FREE PAGE_NOACCESS Free + 0`06370000 0`1222d000 0`0bebd000 MEM_PRIVATE MEM_COMMIT PAGE_READWRITE Heap [ID: 0; Handle: 0000000000310000; Type: Large block] + 0`1222d000 0`77710000 0`654e3000 MEM_FREE PAGE_NOACCESS Free + 0`77710000 0`77711000 0`00001000 MEM_IMAGE MEM_COMMIT PAGE_READONLY Image [kernel32; "C:windowssystem32kernel32.dll"] [...] 0:000> !heap -s [...] Virtual block: 0000000012230000 - 0000000012230000 (size 0000000000000000) [...] 0:000> !address [...] + 0`005d0000 0`12230000 0`11c60000 MEM_FREE PAGE_NOACCESS Free + 0`12230000 0`2404b000 0`11e1b000 MEM_PRIVATE MEM_COMMIT PAGE_READWRITE Heap [ID: 0; Handle: 0000000000310000; Type: Large block] + 0`2404b000 0`77710000 0`536c5000 MEM_FREE PAGE_NOACCESS Free + 0`77710000 0`77711000 0`00001000 MEM_IMAGE MEM_COMMIT PAGE_READONLY Image [kernel32; "C:windowssystem32kernel32.dll"] [...] 0:000> !heap -s [...] Virtual block: 0000000024050000 - 0000000024050000 (size 0000000000000000) [...] 0:000> !address [...] + 0`00590000 0`24050000 0`23ac0000 MEM_FREE PAGE_NOACCESS Free + 0`24050000 0`3bdc9000 0`17d79000 MEM_PRIVATE MEM_COMMIT PAGE_READWRITE Heap [ID: 0; Handle: 0000000000310000; Type: Large block] + 0`3bdc9000 0`77710000 0`3b947000 MEM_FREE PAGE_NOACCESS Free + 0`77710000 0`77711000 0`00001000 MEM_IMAGE MEM_COMMIT PAGE_READONLY Image [kernel32; "C:windowssystem32kernel32.dll"] [...]
We skip a few iterations and finally come to a region that does not move and not increase:
0:000> !heap -s [...] Virtual block: 0000000041d30000 - 0000000041d30000 (size 0000000000000000) [...] 0:000> !address [...] + 0`006c0000 0`41d30000 0`41670000 MEM_FREE PAGE_NOACCESS Free + 0`41d30000 0`6b8c3000 0`29b93000 MEM_PRIVATE MEM_COMMIT PAGE_READWRITE Heap [ID: 0; Handle: 0000000000310000; Type: Large block] + 0`6b8c3000 0`77710000 0`0be4d000 MEM_FREE PAGE_NOACCESS Free + 0`77710000 0`77711000 0`00001000 MEM_IMAGE MEM_COMMIT PAGE_READONLY Image [kernel32; "C:windowssystem32kernel32.dll"] [...]
3.147.46.136