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:
Augustin Cavalier
2025-01-27 12:51:12 -05:00
parent 84fb1209cd
commit 1be0d390db
16 changed files with 40 additions and 53 deletions
+1 -2
View File
@@ -43,8 +43,7 @@ extern "C" {
#endif
object_cache* create_object_cache(const char* name, size_t objectSize,
size_t alignment, void* cookie, object_cache_constructor constructor,
object_cache_destructor destructor);
uint32 flags);
object_cache* create_object_cache_etc(const char* name, size_t objectSize,
size_t alignment, size_t maxByteUsage, size_t magazineCapacity,
size_t maxMagazineCount, uint32 flags, void* cookie,
+1 -1
View File
@@ -71,7 +71,7 @@ scsi_free_ccb(scsi_ccb *ccb)
status_t
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)
return B_NO_MEMORY;
@@ -163,8 +163,7 @@ int
init_temp_sg(void)
{
sTempScatterGatherPool = create_object_cache("scsi temp s/g",
MAX_TEMP_SG_FRAGMENTS * sizeof(physical_entry), 0,
NULL, NULL, NULL);
MAX_TEMP_SG_FRAGMENTS * sizeof(physical_entry), 0);
if (sTempScatterGatherPool == NULL)
return B_NO_MEMORY;
@@ -1152,13 +1152,12 @@ packagefs_std_ops(int32 op, ...)
PackageFileHeapAccessorBase::sQuadChunkCache = quadChunkCache =
create_object_cache("pkgfs heap buffers",
PackageFileHeapAccessorBase::kChunkSize * 4,
0, NULL, NULL, NULL);
0);
object_cache_set_minimum_reserve(quadChunkCache, 1);
TwoKeyAVLTreeNode<void*>::sNodeCache =
create_object_cache_etc("pkgfs TKAVLTreeNodes",
sizeof(TwoKeyAVLTreeNode<void*>), 8,
0, 0, 0, CACHE_NO_DEPOT, NULL, NULL, NULL, NULL);
create_object_cache("pkgfs TKAVLTreeNodes",
sizeof(TwoKeyAVLTreeNode<void*>), CACHE_NO_DEPOT);
error = PackageFSRoot::GlobalInit();
if (error != B_OK) {
@@ -18,8 +18,8 @@
if (size != sizeof(CLASS)) \
panic("unexpected size passed to operator new!"); \
if (s##CLASS##Cache == NULL) { \
s##CLASS##Cache = create_object_cache_etc("pkgfs " #CLASS "s", \
sizeof(CLASS), 8, 0, 0, 0, CACHE_NO_DEPOT, NULL, NULL, NULL, NULL); \
s##CLASS##Cache = create_object_cache("pkgfs " #CLASS "s", \
sizeof(CLASS), CACHE_NO_DEPOT); \
} \
\
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
sNetBufferCache = create_object_cache("net buffer cache",
sizeof(net_buffer_private), 8, NULL, NULL, NULL);
sizeof(net_buffer_private), 0);
if (sNetBufferCache == NULL)
return B_NO_MEMORY;
sDataNodeCache = create_object_cache("data node cache", BUFFER_SIZE,
0, NULL, NULL, NULL);
sDataNodeCache = create_object_cache("data node cache",
BUFFER_SIZE, 0);
if (sDataNodeCache == NULL) {
delete_object_cache(sNetBufferCache);
return B_NO_MEMORY;
+4 -7
View File
@@ -317,19 +317,16 @@ init_mbufs()
if (status != B_OK)
goto clean;
sMBufCache = create_object_cache("mbufs", MSIZE, 8, NULL, NULL, NULL);
sMBufCache = create_object_cache("mbufs", MSIZE, 0);
if (sMBufCache == NULL)
goto clean;
sChunkCache = create_object_cache("mbuf chunks", MCLBYTES, 0, NULL, NULL,
NULL);
sChunkCache = create_object_cache("mbuf chunks", MCLBYTES, 0);
if (sChunkCache == NULL)
goto clean;
sJumbo9ChunkCache = create_object_cache("mbuf jumbo9 chunks", MJUM9BYTES, 0,
NULL, NULL, NULL);
sJumbo9ChunkCache = create_object_cache("mbuf jumbo9 chunks", MJUM9BYTES, 0);
if (sJumbo9ChunkCache == NULL)
goto clean;
sJumboPageSizeCache = create_object_cache("mbuf page size chunks",
MJUMPAGESIZE, 0, NULL, NULL, NULL);
sJumboPageSizeCache = create_object_cache("mbuf page chunks", MJUMPAGESIZE, 0);
if (sJumboPageSizeCache == NULL)
goto clean;
return B_OK;
+3 -3
View File
@@ -2971,13 +2971,13 @@ wait_for_notifications(block_cache* cache)
status_t
block_cache_init(void)
{
sBlockCache = create_object_cache_etc("cached blocks", sizeof(cached_block),
8, 0, 0, 0, CACHE_LARGE_SLAB, NULL, NULL, NULL, NULL);
sBlockCache = create_object_cache("cached blocks", sizeof(cached_block),
CACHE_LARGE_SLAB);
if (sBlockCache == NULL)
return B_NO_MEMORY;
sCacheNotificationCache = create_object_cache("cache notifications",
sizeof(cache_listener), 8, NULL, NULL, NULL);
sizeof(cache_listener), 0);
if (sCacheNotificationCache == NULL)
return B_NO_MEMORY;
+2 -3
View File
@@ -1332,9 +1332,8 @@ create_fifo_vnode(fs_volume* superVolume, fs_vnode* vnode)
void
fifo_init()
{
sRingBufferCache = create_object_cache_etc("fifo ring buffers",
kRingBufferCacheObjectSize, 0, 0, 0, 0, CACHE_NO_DEPOT,
NULL, NULL, NULL, NULL);
sRingBufferCache = create_object_cache("fifo ring buffers",
kRingBufferCacheObjectSize, CACHE_NO_DEPOT);
add_debugger_command_etc("fifo", &Inode::Dump,
"Print info about the specified FIFO node",
+3 -3
View File
@@ -5278,18 +5278,18 @@ vfs_init(kernel_args* args)
panic("vfs_init: error creating mounts hash table\n");
sPathNameCache = create_object_cache("vfs path names",
B_PATH_NAME_LENGTH, 8, NULL, NULL, NULL);
B_PATH_NAME_LENGTH, 0);
if (sPathNameCache == NULL)
panic("vfs_init: error creating path name object_cache\n");
object_cache_set_minimum_reserve(sPathNameCache, 1);
sVnodeCache = create_object_cache("vfs vnodes",
sizeof(struct vnode), 8, NULL, NULL, NULL);
sizeof(struct vnode), 0);
if (sVnodeCache == NULL)
panic("vfs_init: error creating vnode object_cache\n");
sFileDescriptorCache = create_object_cache("vfs fds",
sizeof(file_descriptor), 8, NULL, NULL, NULL);
sizeof(file_descriptor), 0);
if (sFileDescriptorCache == NULL)
panic("vfs_init: error creating file descriptor object_cache\n");
+3 -5
View File
@@ -1151,12 +1151,10 @@ object_cache_maintainer(void*)
object_cache*
create_object_cache(const char* name, size_t object_size, size_t alignment,
void* cookie, object_cache_constructor constructor,
object_cache_destructor destructor)
create_object_cache(const char* name, size_t object_size, uint32 flags)
{
return create_object_cache_etc(name, object_size, alignment, 0, 0, 0, 0,
cookie, constructor, destructor, NULL);
return create_object_cache_etc(name, object_size, 0, 0, 0, 0, flags,
NULL, NULL, NULL, NULL);
}
+2 -2
View File
@@ -2743,8 +2743,8 @@ thread_init(kernel_args *args)
panic("thread_init(): failed to init thread hash table!");
// create the thread structure object cache
sThreadCache = create_object_cache("threads", sizeof(Thread), 64, NULL,
NULL, NULL);
sThreadCache = create_object_cache_etc("threads", sizeof(Thread), 64,
0, 0, 0, 0, NULL, NULL, NULL, NULL);
// Note: The x86 port requires 64 byte alignment of thread structures.
if (sThreadCache == NULL)
panic("thread_init(): failed to allocate thread object cache!");
+1 -2
View File
@@ -1551,8 +1551,7 @@ void
swap_init(void)
{
// create swap block cache
sSwapBlockCache = create_object_cache("swapblock", sizeof(swap_block),
sizeof(void*), NULL, NULL, NULL);
sSwapBlockCache = create_object_cache("swapblock", sizeof(swap_block), 0);
if (sSwapBlockCache == NULL)
panic("swap_init(): can't create object cache for swap blocks\n");
+6 -7
View File
@@ -507,20 +507,19 @@ vm_cache_init(kernel_args* args)
{
// Create object caches for the structures we allocate here.
gCacheRefObjectCache = create_object_cache("cache refs", sizeof(VMCacheRef),
0, NULL, NULL, NULL);
0);
#if ENABLE_SWAP_SUPPORT
gAnonymousCacheObjectCache = create_object_cache("anon caches",
sizeof(VMAnonymousCache), 0, NULL, NULL, NULL);
sizeof(VMAnonymousCache), 0);
#endif
gAnonymousNoSwapCacheObjectCache = create_object_cache(
"anon no-swap caches", sizeof(VMAnonymousNoSwapCache), 0, NULL, NULL,
NULL);
"anon no-swap caches", sizeof(VMAnonymousNoSwapCache), 0);
gVnodeCacheObjectCache = create_object_cache("vnode caches",
sizeof(VMVnodeCache), 0, NULL, NULL, NULL);
sizeof(VMVnodeCache), 0);
gDeviceCacheObjectCache = create_object_cache("device caches",
sizeof(VMDeviceCache), 0, NULL, NULL, NULL);
sizeof(VMDeviceCache), 0);
gNullCacheObjectCache = create_object_cache("null caches",
sizeof(VMNullCache), 0, NULL, NULL, NULL);
sizeof(VMNullCache), 0);
if (gCacheRefObjectCache == NULL
#if ENABLE_SWAP_SUPPORT
@@ -87,12 +87,12 @@ status_t
VMKernelAddressSpace::InitObject()
{
fAreaObjectCache = create_object_cache("kernel areas",
sizeof(VMKernelArea), 0, NULL, NULL, NULL);
sizeof(VMKernelArea), 0);
if (fAreaObjectCache == NULL)
return B_NO_MEMORY;
fRangesObjectCache = create_object_cache("kernel address ranges",
sizeof(Range), 0, NULL, NULL, NULL);
sizeof(Range), 0);
if (fRangesObjectCache == NULL)
return B_NO_MEMORY;
@@ -31,12 +31,10 @@ struct ObjectCache {
object_cache *
create_object_cache(const char *name, size_t objectSize,
size_t alignment, void *cookie, object_cache_constructor constructor,
object_cache_destructor destructor)
create_object_cache(const char *name, size_t object_size, uint32 flags)
{
return new(std::nothrow) ObjectCache(name, objectSize, alignment,
0, 0, cookie, constructor, destructor, NULL);
return create_object_cache_etc(name, object_size, 0, 0, 0, 0, flags,
NULL, NULL, NULL, NULL);
}