Commit d359148
committed
perf(pqueue): grow geometrically so Size and Belady can stop reserving 64MB
Size_init and Belady_init each called pqueue_init(8e6), reserving 8 million
pointers -- 64MB -- before a single object was cached. MINISIM builds one
cache per profile point and holds them all at once, so at the default
--size=0.01,1,100 that reservation was paid a hundred times over. Measured on
cloudPhysicsIO.oracleGeneral, peak virtual memory for the same curve:
lru 859 MiB
size 6976 MiB
belady 6970 MiB
about 6.1GB of address space neither run had any use for.
It never appeared in RSS -- the block is malloc'd and never touched, so the
pages stay unmapped -- which is why this was easy to miss. It is not free
though: under `ulimit -v 2g`, the shape a scheduler or container commonly
imposes, size and belady abort where lru completes.
The reservation could not simply be shrunk, because pqueue grew by adding a
fixed q->step, and step is the initial capacity. Starting small and reaching
8M entries that way would have cost thousands of reallocs and hundreds of GB
of memcpy -- from 1024, 7803 reallocs and roughly 250GB. Doubling instead
makes the same growth 13 reallocs and 67MB, so the initial guess only has to
cover the common case rather than the worst one, and both caches now reserve
512KB.
Doubling does not cost memory in the steady state either. The old policy
reserved the full step whether it was needed or not; doubling lands just
above what the queue actually holds -- 67MB for one that ends at 8M entries
against the 64MB reserved unconditionally, and far less for every queue that
stays smaller than its initial guess. q->step is left as the record of the
initial capacity, which pqueue_duplicate still copies.
After: size 914 MiB and belady 913 MiB against lru's 859 -- the 100 caches
add the 51MB the reservations account for -- and both complete under
`ulimit -v 2g`. Miss ratios are byte-identical with and without the change
(size 0.5017/0.5923, belady 0.4301/0.4647 at 1GB), the PG prefetcher -- the
third pqueue user, which inits with 2 and relied on that linear growth --
still runs, and the suite passes 10/10 with 185 CLI checks.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YUq1vM4g82TkaX2jvLmuQc1 parent 5b4dd39 commit d359148
3 files changed
Lines changed: 38 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
56 | 66 | | |
57 | 67 | | |
58 | 68 | | |
| |||
70 | 80 | | |
71 | 81 | | |
72 | 82 | | |
73 | | - | |
| 83 | + | |
74 | 84 | | |
75 | 85 | | |
76 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
| |||
68 | 78 | | |
69 | 79 | | |
70 | 80 | | |
71 | | - | |
| 81 | + | |
72 | 82 | | |
73 | 83 | | |
74 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
136 | 151 | | |
137 | 152 | | |
138 | 153 | | |
| |||
0 commit comments