kernel/slab: Simplify arguments of create_object_cache().
* alignment, cookie, constructor, destructor are rarely used (in fact constructors/destructors are never used at present.) * Add flags argument, this is more commonly used. This allows a lot of the invocations of create_object_cache_etc to be changed to invocations of just create_object_cache, simplifying the code significantly.
This commit is contained in:
@@ -43,8 +43,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
object_cache* create_object_cache(const char* name, size_t objectSize,
|
object_cache* create_object_cache(const char* name, size_t objectSize,
|
||||||
size_t alignment, void* cookie, object_cache_constructor constructor,
|
uint32 flags);
|
||||||
object_cache_destructor destructor);
|
|
||||||
object_cache* create_object_cache_etc(const char* name, size_t objectSize,
|
object_cache* create_object_cache_etc(const char* name, size_t objectSize,
|
||||||
size_t alignment, size_t maxByteUsage, size_t magazineCapacity,
|
size_t alignment, size_t maxByteUsage, size_t magazineCapacity,
|
||||||
size_t maxMagazineCount, uint32 flags, void* cookie,
|
size_t maxMagazineCount, uint32 flags, void* cookie,
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ scsi_free_ccb(scsi_ccb *ccb)
|
|||||||
status_t
|
status_t
|
||||||
init_ccb_alloc()
|
init_ccb_alloc()
|
||||||
{
|
{
|
||||||
sCcbPool = create_object_cache("scsi ccb", sizeof(scsi_ccb), 0, NULL, NULL, NULL);
|
sCcbPool = create_object_cache("scsi ccb", sizeof(scsi_ccb), 0);
|
||||||
if (sCcbPool == NULL)
|
if (sCcbPool == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
|||||||
@@ -163,8 +163,7 @@ int
|
|||||||
init_temp_sg(void)
|
init_temp_sg(void)
|
||||||
{
|
{
|
||||||
sTempScatterGatherPool = create_object_cache("scsi temp s/g",
|
sTempScatterGatherPool = create_object_cache("scsi temp s/g",
|
||||||
MAX_TEMP_SG_FRAGMENTS * sizeof(physical_entry), 0,
|
MAX_TEMP_SG_FRAGMENTS * sizeof(physical_entry), 0);
|
||||||
NULL, NULL, NULL);
|
|
||||||
if (sTempScatterGatherPool == NULL)
|
if (sTempScatterGatherPool == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
|||||||
@@ -1152,13 +1152,12 @@ packagefs_std_ops(int32 op, ...)
|
|||||||
PackageFileHeapAccessorBase::sQuadChunkCache = quadChunkCache =
|
PackageFileHeapAccessorBase::sQuadChunkCache = quadChunkCache =
|
||||||
create_object_cache("pkgfs heap buffers",
|
create_object_cache("pkgfs heap buffers",
|
||||||
PackageFileHeapAccessorBase::kChunkSize * 4,
|
PackageFileHeapAccessorBase::kChunkSize * 4,
|
||||||
0, NULL, NULL, NULL);
|
0);
|
||||||
object_cache_set_minimum_reserve(quadChunkCache, 1);
|
object_cache_set_minimum_reserve(quadChunkCache, 1);
|
||||||
|
|
||||||
TwoKeyAVLTreeNode<void*>::sNodeCache =
|
TwoKeyAVLTreeNode<void*>::sNodeCache =
|
||||||
create_object_cache_etc("pkgfs TKAVLTreeNodes",
|
create_object_cache("pkgfs TKAVLTreeNodes",
|
||||||
sizeof(TwoKeyAVLTreeNode<void*>), 8,
|
sizeof(TwoKeyAVLTreeNode<void*>), CACHE_NO_DEPOT);
|
||||||
0, 0, 0, CACHE_NO_DEPOT, NULL, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
error = PackageFSRoot::GlobalInit();
|
error = PackageFSRoot::GlobalInit();
|
||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
if (size != sizeof(CLASS)) \
|
if (size != sizeof(CLASS)) \
|
||||||
panic("unexpected size passed to operator new!"); \
|
panic("unexpected size passed to operator new!"); \
|
||||||
if (s##CLASS##Cache == NULL) { \
|
if (s##CLASS##Cache == NULL) { \
|
||||||
s##CLASS##Cache = create_object_cache_etc("pkgfs " #CLASS "s", \
|
s##CLASS##Cache = create_object_cache("pkgfs " #CLASS "s", \
|
||||||
sizeof(CLASS), 8, 0, 0, 0, CACHE_NO_DEPOT, NULL, NULL, NULL, NULL); \
|
sizeof(CLASS), CACHE_NO_DEPOT); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return object_cache_alloc(s##CLASS##Cache, 0); \
|
return object_cache_alloc(s##CLASS##Cache, 0); \
|
||||||
|
|||||||
@@ -2316,12 +2316,12 @@ std_ops(int32 op, ...)
|
|||||||
// and keep around half-constructed buffers in the slab
|
// and keep around half-constructed buffers in the slab
|
||||||
|
|
||||||
sNetBufferCache = create_object_cache("net buffer cache",
|
sNetBufferCache = create_object_cache("net buffer cache",
|
||||||
sizeof(net_buffer_private), 8, NULL, NULL, NULL);
|
sizeof(net_buffer_private), 0);
|
||||||
if (sNetBufferCache == NULL)
|
if (sNetBufferCache == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
sDataNodeCache = create_object_cache("data node cache", BUFFER_SIZE,
|
sDataNodeCache = create_object_cache("data node cache",
|
||||||
0, NULL, NULL, NULL);
|
BUFFER_SIZE, 0);
|
||||||
if (sDataNodeCache == NULL) {
|
if (sDataNodeCache == NULL) {
|
||||||
delete_object_cache(sNetBufferCache);
|
delete_object_cache(sNetBufferCache);
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|||||||
@@ -317,19 +317,16 @@ init_mbufs()
|
|||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
goto clean;
|
goto clean;
|
||||||
|
|
||||||
sMBufCache = create_object_cache("mbufs", MSIZE, 8, NULL, NULL, NULL);
|
sMBufCache = create_object_cache("mbufs", MSIZE, 0);
|
||||||
if (sMBufCache == NULL)
|
if (sMBufCache == NULL)
|
||||||
goto clean;
|
goto clean;
|
||||||
sChunkCache = create_object_cache("mbuf chunks", MCLBYTES, 0, NULL, NULL,
|
sChunkCache = create_object_cache("mbuf chunks", MCLBYTES, 0);
|
||||||
NULL);
|
|
||||||
if (sChunkCache == NULL)
|
if (sChunkCache == NULL)
|
||||||
goto clean;
|
goto clean;
|
||||||
sJumbo9ChunkCache = create_object_cache("mbuf jumbo9 chunks", MJUM9BYTES, 0,
|
sJumbo9ChunkCache = create_object_cache("mbuf jumbo9 chunks", MJUM9BYTES, 0);
|
||||||
NULL, NULL, NULL);
|
|
||||||
if (sJumbo9ChunkCache == NULL)
|
if (sJumbo9ChunkCache == NULL)
|
||||||
goto clean;
|
goto clean;
|
||||||
sJumboPageSizeCache = create_object_cache("mbuf page size chunks",
|
sJumboPageSizeCache = create_object_cache("mbuf page chunks", MJUMPAGESIZE, 0);
|
||||||
MJUMPAGESIZE, 0, NULL, NULL, NULL);
|
|
||||||
if (sJumboPageSizeCache == NULL)
|
if (sJumboPageSizeCache == NULL)
|
||||||
goto clean;
|
goto clean;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|||||||
+3
-3
@@ -2971,13 +2971,13 @@ wait_for_notifications(block_cache* cache)
|
|||||||
status_t
|
status_t
|
||||||
block_cache_init(void)
|
block_cache_init(void)
|
||||||
{
|
{
|
||||||
sBlockCache = create_object_cache_etc("cached blocks", sizeof(cached_block),
|
sBlockCache = create_object_cache("cached blocks", sizeof(cached_block),
|
||||||
8, 0, 0, 0, CACHE_LARGE_SLAB, NULL, NULL, NULL, NULL);
|
CACHE_LARGE_SLAB);
|
||||||
if (sBlockCache == NULL)
|
if (sBlockCache == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
sCacheNotificationCache = create_object_cache("cache notifications",
|
sCacheNotificationCache = create_object_cache("cache notifications",
|
||||||
sizeof(cache_listener), 8, NULL, NULL, NULL);
|
sizeof(cache_listener), 0);
|
||||||
if (sCacheNotificationCache == NULL)
|
if (sCacheNotificationCache == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
|||||||
@@ -1332,9 +1332,8 @@ create_fifo_vnode(fs_volume* superVolume, fs_vnode* vnode)
|
|||||||
void
|
void
|
||||||
fifo_init()
|
fifo_init()
|
||||||
{
|
{
|
||||||
sRingBufferCache = create_object_cache_etc("fifo ring buffers",
|
sRingBufferCache = create_object_cache("fifo ring buffers",
|
||||||
kRingBufferCacheObjectSize, 0, 0, 0, 0, CACHE_NO_DEPOT,
|
kRingBufferCacheObjectSize, CACHE_NO_DEPOT);
|
||||||
NULL, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
add_debugger_command_etc("fifo", &Inode::Dump,
|
add_debugger_command_etc("fifo", &Inode::Dump,
|
||||||
"Print info about the specified FIFO node",
|
"Print info about the specified FIFO node",
|
||||||
|
|||||||
@@ -5278,18 +5278,18 @@ vfs_init(kernel_args* args)
|
|||||||
panic("vfs_init: error creating mounts hash table\n");
|
panic("vfs_init: error creating mounts hash table\n");
|
||||||
|
|
||||||
sPathNameCache = create_object_cache("vfs path names",
|
sPathNameCache = create_object_cache("vfs path names",
|
||||||
B_PATH_NAME_LENGTH, 8, NULL, NULL, NULL);
|
B_PATH_NAME_LENGTH, 0);
|
||||||
if (sPathNameCache == NULL)
|
if (sPathNameCache == NULL)
|
||||||
panic("vfs_init: error creating path name object_cache\n");
|
panic("vfs_init: error creating path name object_cache\n");
|
||||||
object_cache_set_minimum_reserve(sPathNameCache, 1);
|
object_cache_set_minimum_reserve(sPathNameCache, 1);
|
||||||
|
|
||||||
sVnodeCache = create_object_cache("vfs vnodes",
|
sVnodeCache = create_object_cache("vfs vnodes",
|
||||||
sizeof(struct vnode), 8, NULL, NULL, NULL);
|
sizeof(struct vnode), 0);
|
||||||
if (sVnodeCache == NULL)
|
if (sVnodeCache == NULL)
|
||||||
panic("vfs_init: error creating vnode object_cache\n");
|
panic("vfs_init: error creating vnode object_cache\n");
|
||||||
|
|
||||||
sFileDescriptorCache = create_object_cache("vfs fds",
|
sFileDescriptorCache = create_object_cache("vfs fds",
|
||||||
sizeof(file_descriptor), 8, NULL, NULL, NULL);
|
sizeof(file_descriptor), 0);
|
||||||
if (sFileDescriptorCache == NULL)
|
if (sFileDescriptorCache == NULL)
|
||||||
panic("vfs_init: error creating file descriptor object_cache\n");
|
panic("vfs_init: error creating file descriptor object_cache\n");
|
||||||
|
|
||||||
|
|||||||
@@ -1151,12 +1151,10 @@ object_cache_maintainer(void*)
|
|||||||
|
|
||||||
|
|
||||||
object_cache*
|
object_cache*
|
||||||
create_object_cache(const char* name, size_t object_size, size_t alignment,
|
create_object_cache(const char* name, size_t object_size, uint32 flags)
|
||||||
void* cookie, object_cache_constructor constructor,
|
|
||||||
object_cache_destructor destructor)
|
|
||||||
{
|
{
|
||||||
return create_object_cache_etc(name, object_size, alignment, 0, 0, 0, 0,
|
return create_object_cache_etc(name, object_size, 0, 0, 0, 0, flags,
|
||||||
cookie, constructor, destructor, NULL);
|
NULL, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2743,8 +2743,8 @@ thread_init(kernel_args *args)
|
|||||||
panic("thread_init(): failed to init thread hash table!");
|
panic("thread_init(): failed to init thread hash table!");
|
||||||
|
|
||||||
// create the thread structure object cache
|
// create the thread structure object cache
|
||||||
sThreadCache = create_object_cache("threads", sizeof(Thread), 64, NULL,
|
sThreadCache = create_object_cache_etc("threads", sizeof(Thread), 64,
|
||||||
NULL, NULL);
|
0, 0, 0, 0, NULL, NULL, NULL, NULL);
|
||||||
// Note: The x86 port requires 64 byte alignment of thread structures.
|
// Note: The x86 port requires 64 byte alignment of thread structures.
|
||||||
if (sThreadCache == NULL)
|
if (sThreadCache == NULL)
|
||||||
panic("thread_init(): failed to allocate thread object cache!");
|
panic("thread_init(): failed to allocate thread object cache!");
|
||||||
|
|||||||
@@ -1551,8 +1551,7 @@ void
|
|||||||
swap_init(void)
|
swap_init(void)
|
||||||
{
|
{
|
||||||
// create swap block cache
|
// create swap block cache
|
||||||
sSwapBlockCache = create_object_cache("swapblock", sizeof(swap_block),
|
sSwapBlockCache = create_object_cache("swapblock", sizeof(swap_block), 0);
|
||||||
sizeof(void*), NULL, NULL, NULL);
|
|
||||||
if (sSwapBlockCache == NULL)
|
if (sSwapBlockCache == NULL)
|
||||||
panic("swap_init(): can't create object cache for swap blocks\n");
|
panic("swap_init(): can't create object cache for swap blocks\n");
|
||||||
|
|
||||||
|
|||||||
@@ -507,20 +507,19 @@ vm_cache_init(kernel_args* args)
|
|||||||
{
|
{
|
||||||
// Create object caches for the structures we allocate here.
|
// Create object caches for the structures we allocate here.
|
||||||
gCacheRefObjectCache = create_object_cache("cache refs", sizeof(VMCacheRef),
|
gCacheRefObjectCache = create_object_cache("cache refs", sizeof(VMCacheRef),
|
||||||
0, NULL, NULL, NULL);
|
0);
|
||||||
#if ENABLE_SWAP_SUPPORT
|
#if ENABLE_SWAP_SUPPORT
|
||||||
gAnonymousCacheObjectCache = create_object_cache("anon caches",
|
gAnonymousCacheObjectCache = create_object_cache("anon caches",
|
||||||
sizeof(VMAnonymousCache), 0, NULL, NULL, NULL);
|
sizeof(VMAnonymousCache), 0);
|
||||||
#endif
|
#endif
|
||||||
gAnonymousNoSwapCacheObjectCache = create_object_cache(
|
gAnonymousNoSwapCacheObjectCache = create_object_cache(
|
||||||
"anon no-swap caches", sizeof(VMAnonymousNoSwapCache), 0, NULL, NULL,
|
"anon no-swap caches", sizeof(VMAnonymousNoSwapCache), 0);
|
||||||
NULL);
|
|
||||||
gVnodeCacheObjectCache = create_object_cache("vnode caches",
|
gVnodeCacheObjectCache = create_object_cache("vnode caches",
|
||||||
sizeof(VMVnodeCache), 0, NULL, NULL, NULL);
|
sizeof(VMVnodeCache), 0);
|
||||||
gDeviceCacheObjectCache = create_object_cache("device caches",
|
gDeviceCacheObjectCache = create_object_cache("device caches",
|
||||||
sizeof(VMDeviceCache), 0, NULL, NULL, NULL);
|
sizeof(VMDeviceCache), 0);
|
||||||
gNullCacheObjectCache = create_object_cache("null caches",
|
gNullCacheObjectCache = create_object_cache("null caches",
|
||||||
sizeof(VMNullCache), 0, NULL, NULL, NULL);
|
sizeof(VMNullCache), 0);
|
||||||
|
|
||||||
if (gCacheRefObjectCache == NULL
|
if (gCacheRefObjectCache == NULL
|
||||||
#if ENABLE_SWAP_SUPPORT
|
#if ENABLE_SWAP_SUPPORT
|
||||||
|
|||||||
@@ -87,12 +87,12 @@ status_t
|
|||||||
VMKernelAddressSpace::InitObject()
|
VMKernelAddressSpace::InitObject()
|
||||||
{
|
{
|
||||||
fAreaObjectCache = create_object_cache("kernel areas",
|
fAreaObjectCache = create_object_cache("kernel areas",
|
||||||
sizeof(VMKernelArea), 0, NULL, NULL, NULL);
|
sizeof(VMKernelArea), 0);
|
||||||
if (fAreaObjectCache == NULL)
|
if (fAreaObjectCache == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
fRangesObjectCache = create_object_cache("kernel address ranges",
|
fRangesObjectCache = create_object_cache("kernel address ranges",
|
||||||
sizeof(Range), 0, NULL, NULL, NULL);
|
sizeof(Range), 0);
|
||||||
if (fRangesObjectCache == NULL)
|
if (fRangesObjectCache == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
|
|||||||
@@ -31,12 +31,10 @@ struct ObjectCache {
|
|||||||
|
|
||||||
|
|
||||||
object_cache *
|
object_cache *
|
||||||
create_object_cache(const char *name, size_t objectSize,
|
create_object_cache(const char *name, size_t object_size, uint32 flags)
|
||||||
size_t alignment, void *cookie, object_cache_constructor constructor,
|
|
||||||
object_cache_destructor destructor)
|
|
||||||
{
|
{
|
||||||
return new(std::nothrow) ObjectCache(name, objectSize, alignment,
|
return create_object_cache_etc(name, object_size, 0, 0, 0, 0, flags,
|
||||||
0, 0, cookie, constructor, destructor, NULL);
|
NULL, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user