Miscellaneous bitmap refactoring.
This commit is contained in:
parent
4c4ee292e4
commit
01ecdf32d6
@ -93,9 +93,8 @@ struct bitmap_info_s {
|
|||||||
#ifdef JEMALLOC_H_EXTERNS
|
#ifdef JEMALLOC_H_EXTERNS
|
||||||
|
|
||||||
void bitmap_info_init(bitmap_info_t *binfo, size_t nbits);
|
void bitmap_info_init(bitmap_info_t *binfo, size_t nbits);
|
||||||
size_t bitmap_info_ngroups(const bitmap_info_t *binfo);
|
|
||||||
size_t bitmap_size(size_t nbits);
|
|
||||||
void bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo);
|
void bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo);
|
||||||
|
size_t bitmap_size(const bitmap_info_t *binfo);
|
||||||
|
|
||||||
#endif /* JEMALLOC_H_EXTERNS */
|
#endif /* JEMALLOC_H_EXTERNS */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -128,7 +127,7 @@ bitmap_get(bitmap_t *bitmap, const bitmap_info_t *binfo, size_t bit)
|
|||||||
assert(bit < binfo->nbits);
|
assert(bit < binfo->nbits);
|
||||||
goff = bit >> LG_BITMAP_GROUP_NBITS;
|
goff = bit >> LG_BITMAP_GROUP_NBITS;
|
||||||
g = bitmap[goff];
|
g = bitmap[goff];
|
||||||
return (!(g & (1LU << (bit & BITMAP_GROUP_NBITS_MASK))));
|
return (!(g & (ZU(1) << (bit & BITMAP_GROUP_NBITS_MASK))));
|
||||||
}
|
}
|
||||||
|
|
||||||
JEMALLOC_INLINE void
|
JEMALLOC_INLINE void
|
||||||
@ -143,8 +142,8 @@ bitmap_set(bitmap_t *bitmap, const bitmap_info_t *binfo, size_t bit)
|
|||||||
goff = bit >> LG_BITMAP_GROUP_NBITS;
|
goff = bit >> LG_BITMAP_GROUP_NBITS;
|
||||||
gp = &bitmap[goff];
|
gp = &bitmap[goff];
|
||||||
g = *gp;
|
g = *gp;
|
||||||
assert(g & (1LU << (bit & BITMAP_GROUP_NBITS_MASK)));
|
assert(g & (ZU(1) << (bit & BITMAP_GROUP_NBITS_MASK)));
|
||||||
g ^= 1LU << (bit & BITMAP_GROUP_NBITS_MASK);
|
g ^= ZU(1) << (bit & BITMAP_GROUP_NBITS_MASK);
|
||||||
*gp = g;
|
*gp = g;
|
||||||
assert(bitmap_get(bitmap, binfo, bit));
|
assert(bitmap_get(bitmap, binfo, bit));
|
||||||
/* Propagate group state transitions up the tree. */
|
/* Propagate group state transitions up the tree. */
|
||||||
@ -155,8 +154,8 @@ bitmap_set(bitmap_t *bitmap, const bitmap_info_t *binfo, size_t bit)
|
|||||||
goff = bit >> LG_BITMAP_GROUP_NBITS;
|
goff = bit >> LG_BITMAP_GROUP_NBITS;
|
||||||
gp = &bitmap[binfo->levels[i].group_offset + goff];
|
gp = &bitmap[binfo->levels[i].group_offset + goff];
|
||||||
g = *gp;
|
g = *gp;
|
||||||
assert(g & (1LU << (bit & BITMAP_GROUP_NBITS_MASK)));
|
assert(g & (ZU(1) << (bit & BITMAP_GROUP_NBITS_MASK)));
|
||||||
g ^= 1LU << (bit & BITMAP_GROUP_NBITS_MASK);
|
g ^= ZU(1) << (bit & BITMAP_GROUP_NBITS_MASK);
|
||||||
*gp = g;
|
*gp = g;
|
||||||
if (g != 0)
|
if (g != 0)
|
||||||
break;
|
break;
|
||||||
@ -201,8 +200,8 @@ bitmap_unset(bitmap_t *bitmap, const bitmap_info_t *binfo, size_t bit)
|
|||||||
gp = &bitmap[goff];
|
gp = &bitmap[goff];
|
||||||
g = *gp;
|
g = *gp;
|
||||||
propagate = (g == 0);
|
propagate = (g == 0);
|
||||||
assert((g & (1LU << (bit & BITMAP_GROUP_NBITS_MASK))) == 0);
|
assert((g & (ZU(1) << (bit & BITMAP_GROUP_NBITS_MASK))) == 0);
|
||||||
g ^= 1LU << (bit & BITMAP_GROUP_NBITS_MASK);
|
g ^= ZU(1) << (bit & BITMAP_GROUP_NBITS_MASK);
|
||||||
*gp = g;
|
*gp = g;
|
||||||
assert(!bitmap_get(bitmap, binfo, bit));
|
assert(!bitmap_get(bitmap, binfo, bit));
|
||||||
/* Propagate group state transitions up the tree. */
|
/* Propagate group state transitions up the tree. */
|
||||||
@ -214,9 +213,9 @@ bitmap_unset(bitmap_t *bitmap, const bitmap_info_t *binfo, size_t bit)
|
|||||||
gp = &bitmap[binfo->levels[i].group_offset + goff];
|
gp = &bitmap[binfo->levels[i].group_offset + goff];
|
||||||
g = *gp;
|
g = *gp;
|
||||||
propagate = (g == 0);
|
propagate = (g == 0);
|
||||||
assert((g & (1LU << (bit & BITMAP_GROUP_NBITS_MASK)))
|
assert((g & (ZU(1) << (bit & BITMAP_GROUP_NBITS_MASK)))
|
||||||
== 0);
|
== 0);
|
||||||
g ^= 1LU << (bit & BITMAP_GROUP_NBITS_MASK);
|
g ^= ZU(1) << (bit & BITMAP_GROUP_NBITS_MASK);
|
||||||
*gp = g;
|
*gp = g;
|
||||||
if (!propagate)
|
if (!propagate)
|
||||||
break;
|
break;
|
||||||
|
@ -131,7 +131,6 @@ base_stats_get
|
|||||||
bitmap_full
|
bitmap_full
|
||||||
bitmap_get
|
bitmap_get
|
||||||
bitmap_info_init
|
bitmap_info_init
|
||||||
bitmap_info_ngroups
|
|
||||||
bitmap_init
|
bitmap_init
|
||||||
bitmap_set
|
bitmap_set
|
||||||
bitmap_sfu
|
bitmap_sfu
|
||||||
|
33
src/bitmap.c
33
src/bitmap.c
@ -32,22 +32,6 @@ bitmap_info_init(bitmap_info_t *binfo, size_t nbits)
|
|||||||
binfo->nbits = nbits;
|
binfo->nbits = nbits;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
|
||||||
bitmap_info_ngroups(const bitmap_info_t *binfo)
|
|
||||||
{
|
|
||||||
|
|
||||||
return (binfo->levels[binfo->nlevels].group_offset << LG_SIZEOF_BITMAP);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
|
||||||
bitmap_size(size_t nbits)
|
|
||||||
{
|
|
||||||
bitmap_info_t binfo;
|
|
||||||
|
|
||||||
bitmap_info_init(&binfo, nbits);
|
|
||||||
return (bitmap_info_ngroups(&binfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo)
|
bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo)
|
||||||
{
|
{
|
||||||
@ -61,8 +45,7 @@ bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo)
|
|||||||
* correspond to the first logical bit in the group, so extra bits
|
* correspond to the first logical bit in the group, so extra bits
|
||||||
* are the most significant bits of the last group.
|
* are the most significant bits of the last group.
|
||||||
*/
|
*/
|
||||||
memset(bitmap, 0xffU, binfo->levels[binfo->nlevels].group_offset <<
|
memset(bitmap, 0xffU, bitmap_size(binfo));
|
||||||
LG_SIZEOF_BITMAP);
|
|
||||||
extra = (BITMAP_GROUP_NBITS - (binfo->nbits & BITMAP_GROUP_NBITS_MASK))
|
extra = (BITMAP_GROUP_NBITS - (binfo->nbits & BITMAP_GROUP_NBITS_MASK))
|
||||||
& BITMAP_GROUP_NBITS_MASK;
|
& BITMAP_GROUP_NBITS_MASK;
|
||||||
if (extra != 0)
|
if (extra != 0)
|
||||||
@ -76,3 +59,17 @@ bitmap_init(bitmap_t *bitmap, const bitmap_info_t *binfo)
|
|||||||
bitmap[binfo->levels[i+1].group_offset - 1] >>= extra;
|
bitmap[binfo->levels[i+1].group_offset - 1] >>= extra;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
bitmap_info_ngroups(const bitmap_info_t *binfo)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (binfo->levels[binfo->nlevels].group_offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
bitmap_size(const bitmap_info_t *binfo)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (bitmap_info_ngroups(binfo) << LG_SIZEOF_BITMAP);
|
||||||
|
}
|
||||||
|
@ -6,7 +6,11 @@ TEST_BEGIN(test_bitmap_size)
|
|||||||
|
|
||||||
prev_size = 0;
|
prev_size = 0;
|
||||||
for (i = 1; i <= BITMAP_MAXBITS; i++) {
|
for (i = 1; i <= BITMAP_MAXBITS; i++) {
|
||||||
size_t size = bitmap_size(i);
|
bitmap_info_t binfo;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
bitmap_info_init(&binfo, i);
|
||||||
|
size = bitmap_size(&binfo);
|
||||||
assert_true(size >= prev_size,
|
assert_true(size >= prev_size,
|
||||||
"Bitmap size is smaller than expected");
|
"Bitmap size is smaller than expected");
|
||||||
prev_size = size;
|
prev_size = size;
|
||||||
@ -23,8 +27,8 @@ TEST_BEGIN(test_bitmap_init)
|
|||||||
bitmap_info_init(&binfo, i);
|
bitmap_info_init(&binfo, i);
|
||||||
{
|
{
|
||||||
size_t j;
|
size_t j;
|
||||||
bitmap_t *bitmap = (bitmap_t *)malloc(sizeof(bitmap_t) *
|
bitmap_t *bitmap = (bitmap_t *)malloc(
|
||||||
bitmap_info_ngroups(&binfo));
|
bitmap_size(&binfo));
|
||||||
bitmap_init(bitmap, &binfo);
|
bitmap_init(bitmap, &binfo);
|
||||||
|
|
||||||
for (j = 0; j < i; j++) {
|
for (j = 0; j < i; j++) {
|
||||||
@ -46,8 +50,8 @@ TEST_BEGIN(test_bitmap_set)
|
|||||||
bitmap_info_init(&binfo, i);
|
bitmap_info_init(&binfo, i);
|
||||||
{
|
{
|
||||||
size_t j;
|
size_t j;
|
||||||
bitmap_t *bitmap = (bitmap_t *)malloc(sizeof(bitmap_t) *
|
bitmap_t *bitmap = (bitmap_t *)malloc(
|
||||||
bitmap_info_ngroups(&binfo));
|
bitmap_size(&binfo));
|
||||||
bitmap_init(bitmap, &binfo);
|
bitmap_init(bitmap, &binfo);
|
||||||
|
|
||||||
for (j = 0; j < i; j++)
|
for (j = 0; j < i; j++)
|
||||||
@ -69,8 +73,8 @@ TEST_BEGIN(test_bitmap_unset)
|
|||||||
bitmap_info_init(&binfo, i);
|
bitmap_info_init(&binfo, i);
|
||||||
{
|
{
|
||||||
size_t j;
|
size_t j;
|
||||||
bitmap_t *bitmap = (bitmap_t *)malloc(sizeof(bitmap_t) *
|
bitmap_t *bitmap = (bitmap_t *)malloc(
|
||||||
bitmap_info_ngroups(&binfo));
|
bitmap_size(&binfo));
|
||||||
bitmap_init(bitmap, &binfo);
|
bitmap_init(bitmap, &binfo);
|
||||||
|
|
||||||
for (j = 0; j < i; j++)
|
for (j = 0; j < i; j++)
|
||||||
@ -98,8 +102,8 @@ TEST_BEGIN(test_bitmap_sfu)
|
|||||||
bitmap_info_init(&binfo, i);
|
bitmap_info_init(&binfo, i);
|
||||||
{
|
{
|
||||||
ssize_t j;
|
ssize_t j;
|
||||||
bitmap_t *bitmap = (bitmap_t *)malloc(sizeof(bitmap_t) *
|
bitmap_t *bitmap = (bitmap_t *)malloc(
|
||||||
bitmap_info_ngroups(&binfo));
|
bitmap_size(&binfo));
|
||||||
bitmap_init(bitmap, &binfo);
|
bitmap_init(bitmap, &binfo);
|
||||||
|
|
||||||
/* Iteratively set bits starting at the beginning. */
|
/* Iteratively set bits starting at the beginning. */
|
||||||
|
Loading…
Reference in New Issue
Block a user