diff options
author | Ori Bernstein <ori@eigenstate.org> | 2018-01-06 01:20:01 -0800 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2018-01-06 01:20:01 -0800 |
commit | 93db6a9fd69794d74e56cbdfc7796b46da407812 (patch) | |
tree | 91fc5a61d93ea5480afe2e6c06fe19a4b00229a5 | |
parent | 6ddb81f706b6780bfad00c3d203a1bc7ea1f247b (diff) | |
download | mc-93db6a9fd69794d74e56cbdfc7796b46da407812.tar.gz |
Fix bug in big alloc cache.
-rw-r--r-- | lib/std/bytealloc.myr | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/std/bytealloc.myr b/lib/std/bytealloc.myr index ca1f7e5..4d2c921 100644 --- a/lib/std/bytealloc.myr +++ b/lib/std/bytealloc.myr @@ -180,22 +180,20 @@ const bigalloc = {sz /* check our cache */ lock(memlck) for var i = 0; i < bigcache.len; i++ - if sz > bigcache[i].sz - continue - ;; - p = bigcache[i].p - /* - There's no point splitting a chunk if it's smaller than - bktmax, since the allocator will never try using it. - */ - if sz - bigcache[i].sz > Bktmax + if sz < bigcache[i].sz + /* + While the allocator may never use a small chunk, we need + to keep it together so when unmapping it in the free call, + end up unmapping the whole thing. We can't return a larger + size here than requested, because we don't track the size. + + Eviction takes care of freeing it. + */ + p = bigcache[i].p bigcache[i].sz -= sz bigcache[i].p = ((p : intptr) + (sz : intptr) : byte#) - else - bigcache[i].sz = 0 - bigcache[i].p = (0 : byte#) + break ;; - break ;; unlock(memlck) if p != Failmem |