/*
* Misc constants. Note that allocations that are exact multiples of
* PAGE_SIZE, or exceed the zone limit, fall through to the kmem module.
- * IN_SAME_PAGE_MASK is used to sanity-check the per-page free lists.
*/
-#define MIN_CHUNK_SIZE 8 /* in bytes */
-#define MIN_CHUNK_MASK (MIN_CHUNK_SIZE - 1)
#define ZONE_RELS_THRESH 32 /* threshold number of zones */
-#define IN_SAME_PAGE_MASK (~(intptr_t)PAGE_MASK | MIN_CHUNK_MASK)
/*
* The WEIRD_ADDR is used as known text to copy into free objects to
* allocation request size to that particular zone's chunk size.
*/
static __inline int
-zoneindex(unsigned long *bytes)
+zoneindex(unsigned long *bytes, unsigned long *align)
{
unsigned int n = (unsigned int)*bytes; /* unsigned for shift opt */
if (n < 128) {
*bytes = n = (n + 7) & ~7;
+ *align = 8;
return(n / 8 - 1); /* 8 byte chunks, 16 zones */
}
if (n < 256) {
*bytes = n = (n + 15) & ~15;
+ *align = 16;
return(n / 16 + 7);
}
if (n < 8192) {
if (n < 512) {
*bytes = n = (n + 31) & ~31;
+ *align = 32;
return(n / 32 + 15);
}
if (n < 1024) {
*bytes = n = (n + 63) & ~63;
+ *align = 64;
return(n / 64 + 23);
}
if (n < 2048) {
*bytes = n = (n + 127) & ~127;
+ *align = 128;
return(n / 128 + 31);
}
if (n < 4096) {
*bytes = n = (n + 255) & ~255;
+ *align = 256;
return(n / 256 + 39);
}
*bytes = n = (n + 511) & ~511;
+ *align = 512;
return(n / 512 + 47);
}
#if ZALLOC_ZONE_LIMIT > 8192
if (n < 16384) {
*bytes = n = (n + 1023) & ~1023;
+ *align = 1024;
return(n / 1024 + 55);
}
#endif
#if ZALLOC_ZONE_LIMIT > 16384
if (n < 32768) {
*bytes = n = (n + 2047) & ~2047;
+ *align = 2048;
return(n / 2048 + 63);
}
#endif
#endif
SLGlobalData *slgd;
struct globaldata *gd;
+ unsigned long align;
int zi;
#ifdef INVARIANTS
int i;
*
* Note: zoneindex() will panic of size is too large.
*/
- zi = zoneindex(&size);
+ zi = zoneindex(&size, &align);
KKASSERT(zi < NZONES);
crit_enter();
if ((size | (size - 1)) + 1 == (size << 1))
off = (off + size - 1) & ~(size - 1);
else
- off = (off + MIN_CHUNK_MASK) & ~MIN_CHUNK_MASK;
+ off = (off + align - 1) & ~(align - 1);
z->z_Magic = ZALLOC_SLAB_MAGIC;
z->z_ZoneIndex = zi;
z->z_NMax = (ZoneSize - off) / size;
#endif
{
unsigned long osize;
+ unsigned long align;
SLZone *z;
void *nptr;
int *kup;
* size is not too large.
*/
if (size < ZoneLimit) {
- zoneindex(&size);
+ zoneindex(&size, &align);
if (z->z_ChunkSize == size)
return(ptr);
}