ref: 6ddb81f706b6780bfad00c3d203a1bc7ea1f247b
parent: 2f53fe1fb0d524696058f1d15a58fdcf5fc2203a
author: Ori Bernstein <[email protected]>
date: Fri Jan 5 19:32:45 EST 2018
Rename cache => bigcache. We have two unrelated caches. Let's not make the naming unnecessarily confusing.
--- a/lib/std/bytealloc.myr
+++ b/lib/std/bytealloc.myr
@@ -38,7 +38,7 @@
var buckets : bucket[32] /* excessive */
var trace : bool
var tracefd : std.fd
-var cache : cacheelt[32]
+var bigcache : cacheelt[32]
type bucket = struct
sz : size /* aligned size */
@@ -179,21 +179,21 @@
/* check our cache */
lock(memlck)
- for var i = 0; i < cache.len; i++
- if sz > cache[i].sz
+ for var i = 0; i < bigcache.len; i++
+ if sz > bigcache[i].sz
continue
;;
- p = cache[i].p
+ 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 - cache[i].sz > Bktmax
- cache[i].sz -= sz
- cache[i].p = ((p : intptr) + (sz : intptr) : byte#)
+ if sz - bigcache[i].sz > Bktmax
+ bigcache[i].sz -= sz
+ bigcache[i].p = ((p : intptr) + (sz : intptr) : byte#)
else
- cache[i].sz = 0
- cache[i].p = (0 : byte#)
+ bigcache[i].sz = 0
+ bigcache[i].p = (0 : byte#)
;;
break
;;
@@ -220,33 +220,33 @@
evictsz = sz
endp = ((p : intptr) + (sz : intptr) : byte#)
lock(memlck)
- for var i = 0; i < cache.len; i++
- endblk = ((cache[i].p : intptr) + (sz : intptr) : byte#)
+ for var i = 0; i < bigcache.len; i++
+ endblk = ((bigcache[i].p : intptr) + (bigcache[i].sz : intptr) : byte#)
/* merge in front of existing block */
- if cache[i].p == endp
- cache[i].sz += sz
- cache[i].p = p
+ if bigcache[i].p == endp
+ bigcache[i].sz += sz
+ bigcache[i].p = p
evictidx = -1
evictsz = 0
break
/* merge in behind existing block */
elif endblk == p
- cache[i].sz += sz
+ bigcache[i].sz += sz
evictidx = -1
evictsz = 0
break
;;
/* evict */
- if cache[i].sz < evictsz
+ if bigcache[i].sz < evictsz
evictidx = i
- evictsz = cache[i].sz
- evictp = cache[i].p
+ evictsz = bigcache[i].sz
+ evictp = bigcache[i].p
;;
;;
if evictidx != -1
- cache[evictidx].p = p
- cache[evictidx].sz = sz
+ bigcache[evictidx].p = p
+ bigcache[evictidx].sz = sz
;;
unlock(memlck)
--- a/support/dumpleak.myr
+++ b/support/dumpleak.myr
@@ -3,13 +3,14 @@
var stackaggr = 10
var summary
+var allocstats
type memstats = struct
- allocs : uint64
- allocsz : uint64
- frees : uint64
- freesz : uint64
- tab : std.htab(uint64, (uint64, uint64[:]))#
+ allocs : std.size
+ allocsz : std.size
+ frees : std.size
+ freesz : std.size
+ tab : std.htab(std.size, (std.size, std.size[:]))#
;;
@@ -20,6 +21,7 @@
cmd = std.optparse(args, &[
.argdesc="dumps...",
.opts=[
+ [.opt='a', .arg="", .desc="show all allocations, regardless of frees"],
[.opt='d', .arg="depth", .desc="aggregate by at most `depth` stack elements"],
[.opt='s', .arg="", .desc="only show a summary of memory activity"],
][:]
@@ -27,6 +29,8 @@
for opt : cmd.opts
match opt
+ | ('a',""):
+ allocstats = true
| ('d', depth):
match std.intparse(depth)
| `std.Some d: stackaggr = d
@@ -34,10 +38,12 @@
;;
| ('s', ""):
summary = true
- | _: std.die("unreachable")
+ | _:
+ std.die("unreachable")
;;
;;
+ std.clear(&stats)
stats.tab = std.mkht()
for d : cmd.args
match bio.open(d, bio.Rd)
@@ -91,8 +97,8 @@
ptr = get64(path, f)
sz = get64(path, f)
- stats.allocs++
- stats.allocsz += sz
+ stats.frees++
+ stats.freesz += sz
std.htdel(stats.tab, ptr)
}