Replaced the swap_addr_t and SWAP_SLOT_NONE in RadixBitmap.{h,cpp} by
radix_slot_t and RADIX_SLOT_NONE. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36998 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -37,7 +37,7 @@
|
|||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
typedef uint32 swap_addr_t;
|
typedef uint32 radix_slot_t;
|
||||||
typedef uint32 bitmap_t;
|
typedef uint32 bitmap_t;
|
||||||
|
|
||||||
typedef struct radix_node {
|
typedef struct radix_node {
|
||||||
@@ -51,23 +51,23 @@ typedef struct radix_node {
|
|||||||
// Bitmap which uses radix tree for hinting.
|
// Bitmap which uses radix tree for hinting.
|
||||||
// The radix tree is stored in an array.
|
// The radix tree is stored in an array.
|
||||||
typedef struct radix_bitmap {
|
typedef struct radix_bitmap {
|
||||||
swap_addr_t free_slots; // # of free slots
|
radix_slot_t free_slots; // # of free slots
|
||||||
swap_addr_t radix; // coverage radix
|
radix_slot_t radix; // coverage radix
|
||||||
swap_addr_t skip; // starting skip
|
radix_slot_t skip; // starting skip
|
||||||
radix_node *root; // root of radix tree, actually it is an array
|
radix_node *root; // root of radix tree, actually it is an array
|
||||||
swap_addr_t root_size; // size of the array(# of nodes in the tree)
|
radix_slot_t root_size; // size of the array(# of nodes in the tree)
|
||||||
} radix_bitmap;
|
} radix_bitmap;
|
||||||
|
|
||||||
|
|
||||||
#define BITMAP_RADIX (sizeof(swap_addr_t) * 8)
|
#define BITMAP_RADIX (sizeof(radix_slot_t) * 8)
|
||||||
#define NODE_RADIX 16
|
#define NODE_RADIX 16
|
||||||
|
|
||||||
#define SWAP_SLOT_NONE ((swap_addr_t)-1)
|
#define RADIX_SLOT_NONE ((radix_slot_t)-1)
|
||||||
|
|
||||||
|
|
||||||
extern radix_bitmap *radix_bitmap_create(uint32 slots);
|
extern radix_bitmap *radix_bitmap_create(uint32 slots);
|
||||||
extern swap_addr_t radix_bitmap_alloc(radix_bitmap *bmp, uint32 count);
|
extern radix_slot_t radix_bitmap_alloc(radix_bitmap *bmp, uint32 count);
|
||||||
extern void radix_bitmap_dealloc(radix_bitmap *bmp, swap_addr_t slotIndex,
|
extern void radix_bitmap_dealloc(radix_bitmap *bmp, radix_slot_t slotIndex,
|
||||||
uint32 count);
|
uint32 count);
|
||||||
extern void radix_bitmap_destroy(radix_bitmap *bmp);
|
extern void radix_bitmap_destroy(radix_bitmap *bmp);
|
||||||
|
|
||||||
|
|||||||
@@ -39,13 +39,12 @@ _delete_unrhdr_buffer_locked(struct unrhdr* idStore)
|
|||||||
int
|
int
|
||||||
_alloc_unr_locked(struct unrhdr* idStore)
|
_alloc_unr_locked(struct unrhdr* idStore)
|
||||||
{
|
{
|
||||||
swap_addr_t slotIndex;
|
radix_slot_t slotIndex;
|
||||||
int id = ID_STORE_FULL;
|
int id = ID_STORE_FULL;
|
||||||
|
|
||||||
slotIndex = radix_bitmap_alloc(idStore->idBuffer, 1);
|
slotIndex = radix_bitmap_alloc(idStore->idBuffer, 1);
|
||||||
if (slotIndex != SWAP_SLOT_NONE) {
|
if (slotIndex != RADIX_SLOT_NONE)
|
||||||
id = slotIndex + idStore->idBias;
|
id = slotIndex + idStore->idBias;
|
||||||
}
|
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,8 +193,8 @@ radix_bitmap_destroy(radix_bitmap *bmp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static swap_addr_t
|
static radix_slot_t
|
||||||
radix_leaf_alloc(radix_node *leaf, swap_addr_t slotIndex, int32 count)
|
radix_leaf_alloc(radix_node *leaf, radix_slot_t slotIndex, int32 count)
|
||||||
{
|
{
|
||||||
if (count <= (int32)BITMAP_RADIX) {
|
if (count <= (int32)BITMAP_RADIX) {
|
||||||
bitmap_t bitmap = ~leaf->u.bitmap;
|
bitmap_t bitmap = ~leaf->u.bitmap;
|
||||||
@@ -212,12 +212,12 @@ radix_leaf_alloc(radix_node *leaf, swap_addr_t slotIndex, int32 count)
|
|||||||
// we could not allocate count here, update big_hint
|
// we could not allocate count here, update big_hint
|
||||||
if (leaf->big_hint >= count)
|
if (leaf->big_hint >= count)
|
||||||
leaf->big_hint = count - 1;
|
leaf->big_hint = count - 1;
|
||||||
return SWAP_SLOT_NONE;
|
return RADIX_SLOT_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static swap_addr_t
|
static radix_slot_t
|
||||||
radix_node_alloc(radix_node *node, swap_addr_t slotIndex, int32 count,
|
radix_node_alloc(radix_node *node, radix_slot_t slotIndex, int32 count,
|
||||||
uint32 radix, uint32 skip)
|
uint32 radix, uint32 skip)
|
||||||
{
|
{
|
||||||
uint32 next_skip = skip / NODE_RADIX;
|
uint32 next_skip = skip / NODE_RADIX;
|
||||||
@@ -228,13 +228,13 @@ radix_node_alloc(radix_node *node, swap_addr_t slotIndex, int32 count,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if (count <= node[i].big_hint) {
|
if (count <= node[i].big_hint) {
|
||||||
swap_addr_t addr = SWAP_SLOT_NONE;
|
radix_slot_t addr = RADIX_SLOT_NONE;
|
||||||
if (next_skip == 1)
|
if (next_skip == 1)
|
||||||
addr = radix_leaf_alloc(&node[i], slotIndex, count);
|
addr = radix_leaf_alloc(&node[i], slotIndex, count);
|
||||||
else
|
else
|
||||||
addr = radix_node_alloc(&node[i], slotIndex, count, radix,
|
addr = radix_node_alloc(&node[i], slotIndex, count, radix,
|
||||||
next_skip - 1);
|
next_skip - 1);
|
||||||
if (addr != SWAP_SLOT_NONE) {
|
if (addr != RADIX_SLOT_NONE) {
|
||||||
node->u.available -= count;
|
node->u.available -= count;
|
||||||
if (node->big_hint > node->u.available)
|
if (node->big_hint > node->u.available)
|
||||||
node->big_hint = node->u.available;
|
node->big_hint = node->u.available;
|
||||||
@@ -248,21 +248,21 @@ radix_node_alloc(radix_node *node, swap_addr_t slotIndex, int32 count,
|
|||||||
// we could not allocate count in the subtree, update big_hint
|
// we could not allocate count in the subtree, update big_hint
|
||||||
if (node->big_hint >= count)
|
if (node->big_hint >= count)
|
||||||
node->big_hint = count - 1;
|
node->big_hint = count - 1;
|
||||||
return SWAP_SLOT_NONE;
|
return RADIX_SLOT_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
swap_addr_t
|
radix_slot_t
|
||||||
radix_bitmap_alloc(radix_bitmap *bmp, uint32 count)
|
radix_bitmap_alloc(radix_bitmap *bmp, uint32 count)
|
||||||
{
|
{
|
||||||
swap_addr_t addr = SWAP_SLOT_NONE;
|
radix_slot_t addr = RADIX_SLOT_NONE;
|
||||||
|
|
||||||
if (bmp->radix == BITMAP_RADIX)
|
if (bmp->radix == BITMAP_RADIX)
|
||||||
addr = radix_leaf_alloc(bmp->root, 0, count);
|
addr = radix_leaf_alloc(bmp->root, 0, count);
|
||||||
else
|
else
|
||||||
addr = radix_node_alloc(bmp->root, 0, count, bmp->radix, bmp->skip);
|
addr = radix_node_alloc(bmp->root, 0, count, bmp->radix, bmp->skip);
|
||||||
|
|
||||||
if (addr != SWAP_SLOT_NONE)
|
if (addr != RADIX_SLOT_NONE)
|
||||||
bmp->free_slots -= count;
|
bmp->free_slots -= count;
|
||||||
|
|
||||||
return addr;
|
return addr;
|
||||||
@@ -270,7 +270,7 @@ radix_bitmap_alloc(radix_bitmap *bmp, uint32 count)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
radix_leaf_dealloc(radix_node *leaf, swap_addr_t slotIndex, uint32 count)
|
radix_leaf_dealloc(radix_node *leaf, radix_slot_t slotIndex, uint32 count)
|
||||||
{
|
{
|
||||||
uint32 n = slotIndex & (BITMAP_RADIX - 1);
|
uint32 n = slotIndex & (BITMAP_RADIX - 1);
|
||||||
bitmap_t mask = ((bitmap_t)-1 >> (BITMAP_RADIX - count - n))
|
bitmap_t mask = ((bitmap_t)-1 >> (BITMAP_RADIX - count - n))
|
||||||
@@ -282,8 +282,8 @@ radix_leaf_dealloc(radix_node *leaf, swap_addr_t slotIndex, uint32 count)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
radix_node_dealloc(radix_node *node, swap_addr_t slotIndex, uint32 count,
|
radix_node_dealloc(radix_node *node, radix_slot_t slotIndex, uint32 count,
|
||||||
uint32 radix, uint32 skip, swap_addr_t index)
|
uint32 radix, uint32 skip, radix_slot_t index)
|
||||||
{
|
{
|
||||||
node->u.available += count;
|
node->u.available += count;
|
||||||
|
|
||||||
@@ -317,7 +317,7 @@ radix_node_dealloc(radix_node *node, swap_addr_t slotIndex, uint32 count,
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
radix_bitmap_dealloc(radix_bitmap *bmp, swap_addr_t slotIndex, uint32 count)
|
radix_bitmap_dealloc(radix_bitmap *bmp, radix_slot_t slotIndex, uint32 count)
|
||||||
{
|
{
|
||||||
if (bmp->radix == BITMAP_RADIX)
|
if (bmp->radix == BITMAP_RADIX)
|
||||||
radix_leaf_dealloc(bmp->root, slotIndex, count);
|
radix_leaf_dealloc(bmp->root, slotIndex, count);
|
||||||
|
|||||||
@@ -62,6 +62,8 @@
|
|||||||
|
|
||||||
#define INITIAL_SWAP_HASH_SIZE 1024
|
#define INITIAL_SWAP_HASH_SIZE 1024
|
||||||
|
|
||||||
|
#define SWAP_SLOT_NONE RADIX_SLOT_NONE
|
||||||
|
|
||||||
#define SWAP_BLOCK_PAGES 32
|
#define SWAP_BLOCK_PAGES 32
|
||||||
#define SWAP_BLOCK_SHIFT 5 /* 1 << SWAP_BLOCK_SHIFT == SWAP_BLOCK_PAGES */
|
#define SWAP_BLOCK_SHIFT 5 /* 1 << SWAP_BLOCK_SHIFT == SWAP_BLOCK_PAGES */
|
||||||
#define SWAP_BLOCK_MASK (SWAP_BLOCK_PAGES - 1)
|
#define SWAP_BLOCK_MASK (SWAP_BLOCK_PAGES - 1)
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
#if ENABLE_SWAP_SUPPORT
|
#if ENABLE_SWAP_SUPPORT
|
||||||
|
|
||||||
typedef page_num_t swap_addr_t;
|
typedef uint32 swap_addr_t;
|
||||||
|
// TODO: Should be wider, but RadixBitmap supports only a 32 bit type ATM!
|
||||||
struct swap_block;
|
struct swap_block;
|
||||||
struct system_memory_info;
|
struct system_memory_info;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user