-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update mpool and humansize tests #511
Conversation
The mpool changes are needed for FreeBSD 14.0 with clang; evidently, they improved the malloc speed. (The previous limits were still fine for freebsd 14.0 with gcc.) The humansize changes are incidental; I happened to look at the logfile, saw:
and then wondered what SI prefix |
tests/mpool/test_mpool.sh
Outdated
@@ -116,14 +116,14 @@ printf "sets\treps\tratio\n" | |||
|
|||
# Test with full benefit from malloc pool (the binary begins with an | |||
# initial pool of 100). | |||
cmp_methods 10000 100 200 "full" | |||
cmp_methods 10000 100 180 "full" | |||
|
|||
# mpool is still considerably faster than malloc in this range. | |||
cmp_methods 1000 1000 200 "partial" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we change this one too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'm just confused by the word "partial". I assumed that meant that we would see less of a benefit, but it seems like it's more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait, my previous comment was garbage. I need to investigate this some more.
Hmm. Does the FreeBSD stdlib have any mpool of its own? Look at this funky graph! (I included "clang" in the gnuplot title, but a later test with gcc shows the same thing.) Huge jump in timing between Same pattern on FreeBSD 13.2 on arm64. I'll test on other versions of FreeBSD, and other OSes, tomorrow. Here's the code; it's a simplified version of our mpool test. Namely, I removed all mpool stuff, and all libcperciva code.
|
Looks like malloc is allocating a slab of pointers at a time; the jumps are when it needs to reserve a kB for the next bunch of pointers. This is probably just a small-allocation optimization, so if you changed from allocating |
Ok, for general interest, here's some comparisons of different malloc sizes. I split them up:
|
More pertinently: what does this mean for our mpool test? One of the assumptions is that doing 100 allocations (of 4 bytes) would be the ideal case for benefiting from mpool instead of malloc. But on FreeBSD 13 and 14 (and possibly earlier versions), that's still in the range of the slab of pre-allocated pointers. I could increase the |
Another option would be to change mpool to start off with a size of 1000, then check 1000 for the "full" and 10000 for the "partial". But my sense is that we tend to use mpool for allocating dozens of items with many bytes, rather than thousands of items with few bytes. So increasing the size of |
This is needed for FreeBSD 14.0 with clang; their malloc is allocating a slab of pointers at a time, which benefits small allocations. Our mpool test is not intended as a serious benchmark of memory allocation speeds; rather, it's a quick check that nothing unusual is happening with the platform's kernel and libc. For a serious comparison, we would need to check the actual scenarios: for example, are we allocating 4096 records of 16 bytes, or 16 records of 52 bytes?
e77d02f
to
08df7ca
Compare
Ok, revised patch: change the allocation from (64 bytes isn't enough to avoid the ratio becoming too low) |
Looks good. For reference, I think the places where I'm using mpool are generally for allocations in the range of 40-100 bytes, although sometimes it's as low as 16 bytes (two pointers). |
Yeah, in libcperciva we're doing:
No non-libcperciva uses in tarsnap, scrypt, and spiped. kivaloo does a bunch of 4096 records (and even 32768 records!), but I didn't dig in to see exactly how large those were. |
No description provided.