Rework node obj pool to use objpool

This commit is contained in:
Antonio SJ Musumeci 2026-02-17 19:09:01 -06:00
parent 4aac5af89f
commit 385a1476c3
4 changed files with 44 additions and 68 deletions

View file

@ -3583,10 +3583,6 @@ metrics_log_nodes_info(FILE *file_)
struct tm tm;
struct timeval tv;
uint64_t sizeof_node;
float node_usage_ratio;
uint64_t node_slab_count;
uint64_t node_avail_objs;
uint64_t node_total_alloc_mem;
gettimeofday(&tv,NULL);
localtime_r(&tv.tv_sec,&tm);
@ -3594,15 +3590,6 @@ metrics_log_nodes_info(FILE *file_)
sizeof_node = sizeof(node_t);
lfmp_t *lfmp;
lfmp = node_lfmp();
lfmp_lock(lfmp);
node_slab_count = fmp_slab_count(&lfmp->fmp);
node_usage_ratio = fmp_slab_usage_ratio(&lfmp->fmp);
node_avail_objs = fmp_avail_objs(&lfmp->fmp);
node_total_alloc_mem = fmp_total_allocated_memory(&lfmp->fmp);
lfmp_unlock(lfmp);
snprintf(buf,sizeof(buf),
"time: %s\n"
"sizeof(node): %" PRIu64 "\n"
@ -3612,10 +3599,6 @@ metrics_log_nodes_info(FILE *file_)
"node name_table size: %" PRIu64 "\n"
"node name_table usage: %" PRIu64 "\n"
"node name_table total allocated memory: %" PRIu64 "\n"
"node memory pool slab count: %" PRIu64 "\n"
"node memory pool usage ratio: %f\n"
"node memory pool avail objs: %" PRIu64 "\n"
"node memory pool total allocated memory: %" PRIu64 "\n"
"msgbuf bufsize: %" PRIu64 "\n"
"msgbuf allocation count: %" PRIu64 "\n"
"msgbuf available count: %" PRIu64 "\n"
@ -3630,10 +3613,6 @@ metrics_log_nodes_info(FILE *file_)
(uint64_t)f.name_table.size,
(uint64_t)f.name_table.use,
(uint64_t)(f.name_table.size * sizeof(node_t*)),
node_slab_count,
node_usage_ratio,
node_avail_objs,
node_total_alloc_mem,
msgbuf_get_bufsize(),
msgbuf_alloc_count(),
msgbuf_avail_count(),
@ -3719,7 +3698,7 @@ void
fuse_gc()
{
SysLog::info("running thorough garbage collection");
node_gc();
node_clear();
msgbuf_gc();
fuse_malloc_trim();
}
@ -3728,7 +3707,7 @@ void
fuse_gc1()
{
SysLog::info("running basic garbage collection");
node_gc1();
node_gc();
msgbuf_gc_10percent();
fuse_malloc_trim();
}

View file

@ -1,60 +1,29 @@
#include "node.hpp"
#include "lfmp.h"
#include "objpool.hpp"
static lfmp_t g_NODE_FMP;
static
__attribute__((constructor))
void
node_constructor()
{
lfmp_init(&g_NODE_FMP,sizeof(node_t),256);
}
static
__attribute__((destructor))
void
node_destructor()
{
lfmp_destroy(&g_NODE_FMP);
}
static ObjPool<node_t> g_NODE_POOL;
node_t*
node_alloc()
{
return (node_t*)lfmp_calloc(&g_NODE_FMP);
return g_NODE_POOL.alloc();
}
void
node_free(node_t *node_)
{
lfmp_free(&g_NODE_FMP,node_);
}
int
node_gc1()
{
return lfmp_gc(&g_NODE_FMP);
g_NODE_POOL.free(node_);
}
void
node_gc()
{
int rv;
int fails;
fails = 0;
do
{
rv = node_gc1();
if(rv == 0)
fails++;
} while(rv || (fails < 3));
g_NODE_POOL.gc();
}
lfmp_t*
node_lfmp()
void
node_clear()
{
return &g_NODE_FMP;
g_NODE_POOL.clear();
}

View file

@ -1,10 +1,10 @@
#pragma once
#include "lock.h"
#include "lfmp.h"
typedef struct node_s node_t;
struct node_s
#include <cstdint>
struct node_t
{
node_t *name_next;
node_t *id_next;
@ -26,6 +26,5 @@ struct node_s
node_t *node_alloc();
void node_free(node_t*);
int node_gc1();
void node_gc();
lfmp_t *node_lfmp();
void node_clear();