Bug 4369 – Multiple bugs in GC minimize()

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-06-22T19:58:00Z
Last change time
2010-08-14T21:20:12Z
Keywords
patch
Assigned to
sean
Creator
leandro.lucarella

Comments

Comment #0 by leandro.lucarella — 2010-06-22T19:58:53Z
This is basically the same bug I reported to Tango: http://www.dsource.org/projects/tango/ticket/1941 I found a couple of bugs in the minimize() function of the GC. Here is some kind of patch that fixes the bugs (and add a little enhancement), with inline comments (this is found in gc/gcx.d): --- /** * Minimizes physical memory usage by returning free pools to the OS. */ void minimize() { size_t n; size_t pn; Pool* pool; size_t ncommitted; for (n = 0; n < npools; n++) { pool = pooltable[n]; ncommitted = pool.ncommitted; for (pn = 0; pn < ncommitted; pn++) { if (cast(Bins)pool.pagetable[pn] != B_FREE) break; } if (pn < ncommitted) { - n++; // n++ is done by the for loop, this skips a pool continue; } pool.Dtor(); cstdlib.free(pool); cstring.memmove(pooltable + n, pooltable + n + 1, (--npools - n) * (Pool*).sizeof); + n--; // without this, we are skipping the first moved pool - minAddr = pooltable[0].baseAddr; - maxAddr = pooltable[npools - 1].topAddr; } + minAddr = pooltable[0].baseAddr; // there is no point on doing + maxAddr = pooltable[npools - 1].topAddr; // this for each moved pool } ---
Comment #1 by dsimcha — 2010-08-14T21:20:12Z
Fixed 2.048.