Add support for sized deallocation.

This adds a new `sdallocx` function to the external API, allowing the
size to be passed by the caller.  It avoids some extra reads in the
thread cache fast path.  In the case where stats are enabled, this
avoids the work of calculating the size from the pointer.

An assertion validates the size that's passed in, so enabling debugging
will allow users of the API to debug cases where an incorrect size is
passed in.

The performance win for a contrived microbenchmark doing an allocation
and immediately freeing it is ~10%.  It may have a different impact on a
real workload.

Closes #28
This commit is contained in:
Daniel Micay
2014-08-28 15:41:48 -04:00
committed by Jason Evans
parent c3f8650749
commit 4cfe55166e
10 changed files with 201 additions and 5 deletions

View File

@@ -72,6 +72,17 @@ malloc_dallocx(void)
dallocx(p, 0);
}
static void
malloc_sdallocx(void)
{
void *p = malloc(1);
if (p == NULL) {
test_fail("Unexpected malloc() failure");
return;
}
sdallocx(p, 1, 0);
}
TEST_BEGIN(test_free_vs_dallocx)
{
@@ -80,6 +91,14 @@ TEST_BEGIN(test_free_vs_dallocx)
}
TEST_END
TEST_BEGIN(test_dallocx_vs_sdallocx)
{
compare_funcs(10*1000*1000, 100*1000*1000, "dallocx", malloc_dallocx,
"sdallocx", malloc_sdallocx);
}
TEST_END
static void
malloc_mus_free(void)
{
@@ -135,6 +154,7 @@ main(void)
return (test(
test_malloc_vs_mallocx,
test_free_vs_dallocx,
test_dallocx_vs_sdallocx,
test_mus_vs_sallocx,
test_sallocx_vs_nallocx));
}