Use bitmaps to track small regions.
The previous free list implementation, which embedded singly linked
lists in available regions, had the unfortunate side effect of causing
many cache misses during thread cache fills. Fix this in two places:
- arena_run_t: Use a new bitmap implementation to track which regions
are available. Furthermore, revert to preferring the
lowest available region (as jemalloc did with its old
bitmap-based approach).
- tcache_t: Move read-only tcache_bin_t metadata into
tcache_bin_info_t, and add a contiguous array of pointers
to tcache_t in order to track cached objects. This
substantially increases the size of tcache_t, but results
in much higher data locality for common tcache operations.
As a side benefit, it is again possible to efficiently
flush the least recently used cached objects, so this
change changes flushing from MRU to LRU.
The new bitmap implementation uses a multi-level summary approach to
make finding the lowest available region very fast. In practice,
bitmaps only have one or two levels, though the implementation is
general enough to handle extremely large bitmaps, mainly so that large
page sizes can still be entertained.
Fix tcache_bin_flush_large() to always flush statistics, in the same way
that tcache_bin_flush_small() was recently fixed.
Use JEMALLOC_DEBUG rather than NDEBUG.
Add dassert(), and use it for debug-only asserts.
2011-03-17 01:30:13 +08:00
|
|
|
#define JEMALLOC_MANGLE
|
|
|
|
#include "jemalloc_test.h"
|
|
|
|
|
2011-03-23 00:00:56 +08:00
|
|
|
#if (LG_BITMAP_MAXBITS > 12)
|
|
|
|
# define MAXBITS 4500
|
|
|
|
#else
|
|
|
|
# define MAXBITS (1U << LG_BITMAP_MAXBITS)
|
|
|
|
#endif
|
Use bitmaps to track small regions.
The previous free list implementation, which embedded singly linked
lists in available regions, had the unfortunate side effect of causing
many cache misses during thread cache fills. Fix this in two places:
- arena_run_t: Use a new bitmap implementation to track which regions
are available. Furthermore, revert to preferring the
lowest available region (as jemalloc did with its old
bitmap-based approach).
- tcache_t: Move read-only tcache_bin_t metadata into
tcache_bin_info_t, and add a contiguous array of pointers
to tcache_t in order to track cached objects. This
substantially increases the size of tcache_t, but results
in much higher data locality for common tcache operations.
As a side benefit, it is again possible to efficiently
flush the least recently used cached objects, so this
change changes flushing from MRU to LRU.
The new bitmap implementation uses a multi-level summary approach to
make finding the lowest available region very fast. In practice,
bitmaps only have one or two levels, though the implementation is
general enough to handle extremely large bitmaps, mainly so that large
page sizes can still be entertained.
Fix tcache_bin_flush_large() to always flush statistics, in the same way
that tcache_bin_flush_small() was recently fixed.
Use JEMALLOC_DEBUG rather than NDEBUG.
Add dassert(), and use it for debug-only asserts.
2011-03-17 01:30:13 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
test_bitmap_size(void)
|
|
|
|
{
|
|
|
|
size_t i, prev_size;
|
|
|
|
|
|
|
|
prev_size = 0;
|
|
|
|
for (i = 1; i <= MAXBITS; i++) {
|
|
|
|
size_t size = bitmap_size(i);
|
|
|
|
assert(size >= prev_size);
|
|
|
|
prev_size = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_bitmap_init(void)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 1; i <= MAXBITS; i++) {
|
|
|
|
bitmap_info_t binfo;
|
|
|
|
bitmap_info_init(&binfo, i);
|
|
|
|
{
|
|
|
|
size_t j;
|
|
|
|
bitmap_t bitmap[bitmap_info_ngroups(&binfo)];
|
|
|
|
bitmap_init(bitmap, &binfo);
|
|
|
|
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
assert(bitmap_get(bitmap, &binfo, j) == false);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_bitmap_set(void)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 1; i <= MAXBITS; i++) {
|
|
|
|
bitmap_info_t binfo;
|
|
|
|
bitmap_info_init(&binfo, i);
|
|
|
|
{
|
|
|
|
size_t j;
|
|
|
|
bitmap_t bitmap[bitmap_info_ngroups(&binfo)];
|
|
|
|
bitmap_init(bitmap, &binfo);
|
|
|
|
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
bitmap_set(bitmap, &binfo, j);
|
|
|
|
assert(bitmap_full(bitmap, &binfo));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_bitmap_unset(void)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 1; i <= MAXBITS; i++) {
|
|
|
|
bitmap_info_t binfo;
|
|
|
|
bitmap_info_init(&binfo, i);
|
|
|
|
{
|
|
|
|
size_t j;
|
|
|
|
bitmap_t bitmap[bitmap_info_ngroups(&binfo)];
|
|
|
|
bitmap_init(bitmap, &binfo);
|
|
|
|
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
bitmap_set(bitmap, &binfo, j);
|
|
|
|
assert(bitmap_full(bitmap, &binfo));
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
bitmap_unset(bitmap, &binfo, j);
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
bitmap_set(bitmap, &binfo, j);
|
|
|
|
assert(bitmap_full(bitmap, &binfo));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_bitmap_sfu(void)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (i = 1; i <= MAXBITS; i++) {
|
|
|
|
bitmap_info_t binfo;
|
|
|
|
bitmap_info_init(&binfo, i);
|
|
|
|
{
|
|
|
|
ssize_t j;
|
|
|
|
bitmap_t bitmap[bitmap_info_ngroups(&binfo)];
|
|
|
|
bitmap_init(bitmap, &binfo);
|
|
|
|
|
|
|
|
/* Iteratively set bits starting at the beginning. */
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
assert(bitmap_sfu(bitmap, &binfo) == j);
|
|
|
|
assert(bitmap_full(bitmap, &binfo));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iteratively unset bits starting at the end, and
|
|
|
|
* verify that bitmap_sfu() reaches the unset bits.
|
|
|
|
*/
|
|
|
|
for (j = i - 1; j >= 0; j--) {
|
|
|
|
bitmap_unset(bitmap, &binfo, j);
|
|
|
|
assert(bitmap_sfu(bitmap, &binfo) == j);
|
|
|
|
bitmap_unset(bitmap, &binfo, j);
|
|
|
|
}
|
|
|
|
assert(bitmap_get(bitmap, &binfo, 0) == false);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iteratively set bits starting at the beginning, and
|
|
|
|
* verify that bitmap_sfu() looks past them.
|
|
|
|
*/
|
|
|
|
for (j = 1; j < i; j++) {
|
|
|
|
bitmap_set(bitmap, &binfo, j - 1);
|
|
|
|
assert(bitmap_sfu(bitmap, &binfo) == j);
|
|
|
|
bitmap_unset(bitmap, &binfo, j);
|
|
|
|
}
|
|
|
|
assert(bitmap_sfu(bitmap, &binfo) == i - 1);
|
|
|
|
assert(bitmap_full(bitmap, &binfo));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2012-04-16 22:30:26 +08:00
|
|
|
malloc_printf("Test begin\n");
|
Use bitmaps to track small regions.
The previous free list implementation, which embedded singly linked
lists in available regions, had the unfortunate side effect of causing
many cache misses during thread cache fills. Fix this in two places:
- arena_run_t: Use a new bitmap implementation to track which regions
are available. Furthermore, revert to preferring the
lowest available region (as jemalloc did with its old
bitmap-based approach).
- tcache_t: Move read-only tcache_bin_t metadata into
tcache_bin_info_t, and add a contiguous array of pointers
to tcache_t in order to track cached objects. This
substantially increases the size of tcache_t, but results
in much higher data locality for common tcache operations.
As a side benefit, it is again possible to efficiently
flush the least recently used cached objects, so this
change changes flushing from MRU to LRU.
The new bitmap implementation uses a multi-level summary approach to
make finding the lowest available region very fast. In practice,
bitmaps only have one or two levels, though the implementation is
general enough to handle extremely large bitmaps, mainly so that large
page sizes can still be entertained.
Fix tcache_bin_flush_large() to always flush statistics, in the same way
that tcache_bin_flush_small() was recently fixed.
Use JEMALLOC_DEBUG rather than NDEBUG.
Add dassert(), and use it for debug-only asserts.
2011-03-17 01:30:13 +08:00
|
|
|
|
|
|
|
test_bitmap_size();
|
|
|
|
test_bitmap_init();
|
|
|
|
test_bitmap_set();
|
|
|
|
test_bitmap_unset();
|
|
|
|
test_bitmap_sfu();
|
|
|
|
|
2012-04-16 22:30:26 +08:00
|
|
|
malloc_printf("Test end\n");
|
Use bitmaps to track small regions.
The previous free list implementation, which embedded singly linked
lists in available regions, had the unfortunate side effect of causing
many cache misses during thread cache fills. Fix this in two places:
- arena_run_t: Use a new bitmap implementation to track which regions
are available. Furthermore, revert to preferring the
lowest available region (as jemalloc did with its old
bitmap-based approach).
- tcache_t: Move read-only tcache_bin_t metadata into
tcache_bin_info_t, and add a contiguous array of pointers
to tcache_t in order to track cached objects. This
substantially increases the size of tcache_t, but results
in much higher data locality for common tcache operations.
As a side benefit, it is again possible to efficiently
flush the least recently used cached objects, so this
change changes flushing from MRU to LRU.
The new bitmap implementation uses a multi-level summary approach to
make finding the lowest available region very fast. In practice,
bitmaps only have one or two levels, though the implementation is
general enough to handle extremely large bitmaps, mainly so that large
page sizes can still be entertained.
Fix tcache_bin_flush_large() to always flush statistics, in the same way
that tcache_bin_flush_small() was recently fixed.
Use JEMALLOC_DEBUG rather than NDEBUG.
Add dassert(), and use it for debug-only asserts.
2011-03-17 01:30:13 +08:00
|
|
|
return (0);
|
|
|
|
}
|