Add option to log node memory usage metrics

This commit is contained in:
Antonio SJ Musumeci 2021-10-10 18:37:14 -04:00
parent 50ede1ba97
commit 5f737cb7bf
5 changed files with 136 additions and 7 deletions

View file

@ -694,6 +694,8 @@ int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, siz
int fuse_start_maintenance_thread(struct fuse *fuse);
void fuse_stop_maintenance_thread(struct fuse *fuse);
void fuse_log_metrics(int enabled);
/**
* Iterate over cache removing stale entries
* use in conjunction with "-oremember"

View file

@ -354,3 +354,11 @@ fmp_slab_usage_ratio(fmp_t *fmp_)
return rv;
}
static
inline
uint64_t
fmp_total_allocated_memory(fmp_t *fmp_)
{
return (fmp_->slab_size * kv_size(fmp_->slabs));
}

View file

@ -53,6 +53,8 @@
#define NODE_TABLE_MIN_SIZE 8192
static int g_LOG_METRICS = 0;
struct fuse_config
{
unsigned int uid;
@ -4006,6 +4008,64 @@ node_table_init(struct node_table *t)
return 0;
}
static
void
metrics_log_nodes_info(struct fuse *f_,
FILE *file_)
{
pthread_mutex_lock(&f_->lock);
fprintf(file_,
"time: %zu\n"
"sizeof(node): %zu\n"
"node id_table size: %zu\n"
"node id_table usage: %zu\n"
"node id_table total allocated memory: %zu\n"
"node name_table size: %zu\n"
"node name_table usage: %zu\n"
"node name_table total allocated memory: %zu\n"
"node memory pool slab count: %zu\n"
"node memory pool usage ratio: %f\n"
"node memory pool avail objs: %zu\n"
"node memory pool total allocated memory: %zu\n"
"\n"
,
time(NULL),
sizeof(struct node),
f_->id_table.size,
f_->id_table.use,
(f_->id_table.size * sizeof(struct node*)),
f_->name_table.size,
f_->name_table.use,
(f_->name_table.size * sizeof(struct node*)),
lfmp_slab_count(&f_->node_fmp),
lfmp_slab_usage_ratio(&f_->node_fmp),
lfmp_avail_objs(&f_->node_fmp),
lfmp_total_allocated_memory(&f_->node_fmp)
);
pthread_mutex_unlock(&f_->lock);
}
static
void
metrics_log_nodes_info_to_tmp_dir(struct fuse *f_)
{
FILE *file;
char filepath[256];
sprintf(filepath,"/tmp/mergerfs.%d.info",getpid());
file = fopen(filepath,"w");
if(file == NULL)
return;
metrics_log_nodes_info(f_,file);
fclose(file);
}
static
void
fuse_malloc_trim(void)
@ -4038,6 +4098,9 @@ fuse_maintenance_loop(void *fuse_)
if(loops % 15)
fuse_malloc_trim();
if(g_LOG_METRICS)
metrics_log_nodes_info_to_tmp_dir(f);
loops++;
sleep(sleep_time);
}
@ -4097,6 +4160,8 @@ fuse_new_common(struct fuse_chan *ch,
if(fuse_opt_parse(args,&f->conf,fuse_lib_opts,fuse_lib_opt_proc) == -1)
goto out_free_fs;
g_LOG_METRICS = f->conf.debug;
f->se = fuse_lowlevel_new_common(args,&llop,sizeof(llop),f);
if(f->se == NULL)
goto out_free_fs;
@ -4215,3 +4280,9 @@ fuse_config_num_threads(const struct fuse *fuse_)
{
return fuse_->conf.threads;
}
void
fuse_log_metrics(int log_)
{
g_LOG_METRICS = log_;
}

View file

@ -211,3 +211,17 @@ lfmp_slab_usage_ratio(lfmp_t *lfmp_)
return rv;
}
static
inline
uint64_t
lfmp_total_allocated_memory(lfmp_t *lfmp_)
{
uint64_t rv;
pthread_mutex_lock(&lfmp_->lock);
rv = fmp_total_allocated_memory(&lfmp_->fmp);
pthread_mutex_unlock(&lfmp_->lock);
return rv;
}