#include <assert.h>
#include <stdlib.h>
#include "alloc.h"
-#include "build_assert/build_assert.h"
-#include "alignof/alignof.h"
+#include <ccan/build_assert/build_assert.h>
+#include <ccan/alignof/alignof.h>
#include "config.h"
/* FIXME: We assume getpagesize() doesnt change. Remapping file with
}
}
+unsigned long alloc_size(void *pool, unsigned long poolsize, void *p)
+{
+ unsigned long len, pagenum;
+ struct metaheader *mh;
+
+ assert(poolsize >= MIN_SIZE);
+
+ mh = first_mheader(pool, poolsize);
+ assert((char *)p >= (char *)(mh + 1));
+ assert((char *)pool + poolsize > (char *)p);
+
+ pagenum = pool_offset(pool, p) / getpagesize();
+
+ if (get_page_state(pool, pagenum) == SPECIAL) {
+ unsigned long off = (unsigned long)p % getpagesize();
+ uint8_t *metadata = get_page_metadata(pool, pagenum);
+ enum sub_metadata_type type = get_bit_pair(metadata, 0);
+
+ assert(off < SUBPAGE_METAOFF);
+
+ switch (type) {
+ case BITMAP:
+ assert(off % BITMAP_GRANULARITY == 0);
+ off /= BITMAP_GRANULARITY;
+
+ /* Offset by one because first bit used for header. */
+ off++;
+ len = BITMAP_GRANULARITY;
+ while (++off < SUBPAGE_METAOFF / BITMAP_GRANULARITY
+ && get_bit_pair(metadata, off) == TAKEN)
+ len += BITMAP_GRANULARITY;
+ break;
+ case UNIFORM:
+ len = decode_usize(metadata);
+ break;
+ default:
+ assert(0);
+ }
+ } else {
+ len = getpagesize();
+ while (get_page_state(pool, ++pagenum) == TAKEN)
+ len += getpagesize();
+ }
+
+ return len;
+}
+
static bool is_metadata_page(void *pool, unsigned long poolsize,
unsigned long page)
{
if (meta[j / 8] & (1 << (j % 8)))
total++;
- printf(" %u: %u/%u (%u%% density)\n",
+ printf(" %u: %u/%zu (%zu%% density)\n",
uc->size[j], total, SUBPAGE_METAOFF / uc->size[i],
(total * 100) / (SUBPAGE_METAOFF / uc->size[i]));
}