From 8c9b84a588efb095b37ea5bc99a60ecfef46f17e Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 2 Jun 2010 20:42:53 +0000 Subject: [PATCH] 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 --- headers/private/kernel/util/RadixBitmap.h | 24 +++++++++--------- src/libs/compat/freebsd_network/Unit.cpp | 5 ++-- src/system/kernel/util/RadixBitmap.cpp | 30 +++++++++++------------ src/system/kernel/vm/VMAnonymousCache.cpp | 2 ++ src/system/kernel/vm/VMAnonymousCache.h | 3 ++- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/headers/private/kernel/util/RadixBitmap.h b/headers/private/kernel/util/RadixBitmap.h index 1265933d29..0f8380be14 100644 --- a/headers/private/kernel/util/RadixBitmap.h +++ b/headers/private/kernel/util/RadixBitmap.h @@ -37,7 +37,7 @@ #include -typedef uint32 swap_addr_t; +typedef uint32 radix_slot_t; typedef uint32 bitmap_t; typedef struct radix_node { @@ -48,26 +48,26 @@ typedef struct radix_node { int32 big_hint; // the biggest continuous slots under us } radix_node; -// Bitmap which uses radix tree for hinting. +// Bitmap which uses radix tree for hinting. // The radix tree is stored in an array. typedef struct radix_bitmap { - swap_addr_t free_slots; // # of free slots - swap_addr_t radix; // coverage radix - swap_addr_t skip; // starting skip - 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 free_slots; // # of free slots + radix_slot_t radix; // coverage radix + radix_slot_t skip; // starting skip + radix_node *root; // root of radix tree, actually it is an array + radix_slot_t root_size; // size of the array(# of nodes in the tree) } radix_bitmap; -#define BITMAP_RADIX (sizeof(swap_addr_t) * 8) -#define NODE_RADIX 16 +#define BITMAP_RADIX (sizeof(radix_slot_t) * 8) +#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 swap_addr_t radix_bitmap_alloc(radix_bitmap *bmp, uint32 count); -extern void radix_bitmap_dealloc(radix_bitmap *bmp, swap_addr_t slotIndex, +extern radix_slot_t radix_bitmap_alloc(radix_bitmap *bmp, uint32 count); +extern void radix_bitmap_dealloc(radix_bitmap *bmp, radix_slot_t slotIndex, uint32 count); extern void radix_bitmap_destroy(radix_bitmap *bmp); diff --git a/src/libs/compat/freebsd_network/Unit.cpp b/src/libs/compat/freebsd_network/Unit.cpp index 5e08022487..390878ef14 100644 --- a/src/libs/compat/freebsd_network/Unit.cpp +++ b/src/libs/compat/freebsd_network/Unit.cpp @@ -39,13 +39,12 @@ _delete_unrhdr_buffer_locked(struct unrhdr* idStore) int _alloc_unr_locked(struct unrhdr* idStore) { - swap_addr_t slotIndex; + radix_slot_t slotIndex; int id = ID_STORE_FULL; slotIndex = radix_bitmap_alloc(idStore->idBuffer, 1); - if (slotIndex != SWAP_SLOT_NONE) { + if (slotIndex != RADIX_SLOT_NONE) id = slotIndex + idStore->idBias; - } return id; } diff --git a/src/system/kernel/util/RadixBitmap.cpp b/src/system/kernel/util/RadixBitmap.cpp index 9eca42c6ea..aecfb0af88 100644 --- a/src/system/kernel/util/RadixBitmap.cpp +++ b/src/system/kernel/util/RadixBitmap.cpp @@ -193,8 +193,8 @@ radix_bitmap_destroy(radix_bitmap *bmp) } -static swap_addr_t -radix_leaf_alloc(radix_node *leaf, swap_addr_t slotIndex, int32 count) +static radix_slot_t +radix_leaf_alloc(radix_node *leaf, radix_slot_t slotIndex, int32 count) { if (count <= (int32)BITMAP_RADIX) { 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 if (leaf->big_hint >= count) leaf->big_hint = count - 1; - return SWAP_SLOT_NONE; + return RADIX_SLOT_NONE; } -static swap_addr_t -radix_node_alloc(radix_node *node, swap_addr_t slotIndex, int32 count, +static radix_slot_t +radix_node_alloc(radix_node *node, radix_slot_t slotIndex, int32 count, uint32 radix, uint32 skip) { uint32 next_skip = skip / NODE_RADIX; @@ -228,13 +228,13 @@ radix_node_alloc(radix_node *node, swap_addr_t slotIndex, int32 count, break; if (count <= node[i].big_hint) { - swap_addr_t addr = SWAP_SLOT_NONE; + radix_slot_t addr = RADIX_SLOT_NONE; if (next_skip == 1) addr = radix_leaf_alloc(&node[i], slotIndex, count); else addr = radix_node_alloc(&node[i], slotIndex, count, radix, next_skip - 1); - if (addr != SWAP_SLOT_NONE) { + if (addr != RADIX_SLOT_NONE) { node->u.available -= count; if (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 if (node->big_hint >= count) 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) { - swap_addr_t addr = SWAP_SLOT_NONE; + radix_slot_t addr = RADIX_SLOT_NONE; if (bmp->radix == BITMAP_RADIX) addr = radix_leaf_alloc(bmp->root, 0, count); else 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; return addr; @@ -270,7 +270,7 @@ radix_bitmap_alloc(radix_bitmap *bmp, uint32 count) 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); 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 -radix_node_dealloc(radix_node *node, swap_addr_t slotIndex, uint32 count, - uint32 radix, uint32 skip, swap_addr_t index) +radix_node_dealloc(radix_node *node, radix_slot_t slotIndex, uint32 count, + uint32 radix, uint32 skip, radix_slot_t index) { node->u.available += count; @@ -317,7 +317,7 @@ radix_node_dealloc(radix_node *node, swap_addr_t slotIndex, uint32 count, 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) radix_leaf_dealloc(bmp->root, slotIndex, count); diff --git a/src/system/kernel/vm/VMAnonymousCache.cpp b/src/system/kernel/vm/VMAnonymousCache.cpp index ccefe6b298..802f77e745 100644 --- a/src/system/kernel/vm/VMAnonymousCache.cpp +++ b/src/system/kernel/vm/VMAnonymousCache.cpp @@ -62,6 +62,8 @@ #define INITIAL_SWAP_HASH_SIZE 1024 +#define SWAP_SLOT_NONE RADIX_SLOT_NONE + #define SWAP_BLOCK_PAGES 32 #define SWAP_BLOCK_SHIFT 5 /* 1 << SWAP_BLOCK_SHIFT == SWAP_BLOCK_PAGES */ #define SWAP_BLOCK_MASK (SWAP_BLOCK_PAGES - 1) diff --git a/src/system/kernel/vm/VMAnonymousCache.h b/src/system/kernel/vm/VMAnonymousCache.h index 2506d75fc2..934e01eb45 100644 --- a/src/system/kernel/vm/VMAnonymousCache.h +++ b/src/system/kernel/vm/VMAnonymousCache.h @@ -15,7 +15,8 @@ #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 system_memory_info;