Skip to content

Commit

Permalink
[mycpp/runtime] Make Pools about 16 KiB each
Browse files Browse the repository at this point in the history
Rather than 4 KiB each.  The 16 bytes of "slack" actually seems useful
for the malloc() header.

Showed up as a VERY slight improvement on benchmarks2/uftrace!

Should also look at memory usage, though in theory it can't change much.
  • Loading branch information
Andy C committed Aug 13, 2023
1 parent 8433565 commit 45b08c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 10 additions & 1 deletion cpp/obj_layout_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,18 @@ TEST malloc_address_test() {
// 4. diff = 8
// 5. diff = 8

// 2023-08: If I pass 4096, I get 4112, so 16 byte diff
// 2023-08: If I pass 4080, I get 4096

// int alloc_size = 24 * 682; // 16368 is close to 16384 - 16 bytes again
int alloc_size = 48 * 341; // heap 2 is the same size

//int alloc_size = 4080;
//int alloc_size = 1;

char *p[20];
for (int i = 0; i < 20; ++i) {
p[i] = static_cast<char *>(malloc(1));
p[i] = static_cast<char *>(malloc(alloc_size));
if (i != 0) {
char *prev = p[i - 1];
log("%2d. diff = %d", i, p[i] - prev);
Expand Down
10 changes: 6 additions & 4 deletions mycpp/mark_sweep_heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,12 @@ class MarkSweepHeap {
double total_gc_millis_ = 0.0;

#ifndef NO_POOL_ALLOC
// 4096 / 24 bytes = 170 cells (rounded), 4080 bytes
// 4096 / 48 bytes = 85 cells (rounded), 4080 bytes
Pool<170, 24> pool1_;
Pool<85, 48> pool2_;
// 16,384 / 24 bytes = 682 cells (rounded), 16,368 bytes
// 16,384 / 48 bytes = 341 cells (rounded), 16,368 bytes
// Conveniently, the glibc malloc header is 16 bytes, giving exactly 16 Ki
// differences
Pool<682, 24> pool1_;
Pool<341, 48> pool2_;
#endif

std::vector<RawObject**> roots_;
Expand Down

0 comments on commit 45b08c2

Please sign in to comment.