D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4369 - Multiple bugs in GC minimize()
Summary: Multiple bugs in GC minimize()
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: Sean Kelly
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2010-06-22 19:58 UTC by Leandro Lucarella
Modified: 2010-08-14 21:20 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Leandro Lucarella 2010-06-22 19:58:53 UTC
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 David Simcha 2010-08-14 21:20:12 UTC
Fixed 2.048.