mem: improve pre-allocation

This commit is contained in:
Thomas Schoebel-Theuer 2023-05-08 17:00:55 +02:00
parent 21bb01cfbd
commit 272b9d8e46
4 changed files with 50 additions and 2 deletions

View File

@ -223,6 +223,17 @@ config MARS_MEM_PREALLOC
help
Normally ON. Switch off only for EXPERIMENTS!
config MARS_MEM_MAX_RESERVE
bool "avoid memory fragmentation by preallocation"
depends on MARS_MEM_PREALLOC
default n
help
Higher preallocation reserve, for avoidance of
too frequent higher-order memory allocations on
highly loaded servers with a lot of resources.
May be enabled when encountering suchalike problems
(known as accurring very rare, but may happen).
config MARS_FAST_FULLSYNC
bool "decrease network traffic at initial sync"
depends on MARS

View File

@ -735,6 +735,22 @@ int brick_mem_reserve(void)
#endif
EXPORT_SYMBOL_GPL(brick_mem_reserve);
#ifdef CONFIG_MARS_MEM_MAX_RESERVE
void set_brick_mem_freelist_max(int max, int order)
{
if (max > brick_mem_freelist_max[order]) {
brick_mem_freelist_max[order] = max;
} else if (max < brick_mem_freelist_max[order] / 2 &&
brick_mem_freelist_max[order] > 0) {
brick_mem_freelist_max[order]--;
}
}
#else
void set_brick_mem_freelist_max(int max, int order)
{
}
#endif
void *_brick_block_alloc(loff_t pos, int len, int line)
{
void *data;

View File

@ -244,6 +244,7 @@ extern int brick_mem_alloc_count[BRICK_MAX_ORDER+1];
extern int brick_mem_alloc_max[BRICK_MAX_ORDER+1];
extern int brick_mem_reserve(void);
extern void set_brick_mem_freelist_max(int max, int order);
#endif

View File

@ -247,12 +247,30 @@ void _crashme(int mode, bool do_sync)
emergency_restart();
}
}
#endif
#define MARS_MEMRESERVE_ORDER 5
#define MEMRESERVE_FACTOR_5 32
int nr_affected_resources;
int tmp_nr_affected_resources;
void update_brick_mem_freelist_max(void)
{
#ifdef CONFIG_MARS_MEM_MAX_RESERVE
int order;
for (order = 0; order <= BRICK_MAX_ORDER; order++) {
int max = 0;
if (order == MARS_MEMRESERVE_ORDER) {
max = nr_affected_resources * MEMRESERVE_FACTOR_5;
}
set_brick_mem_freelist_max(max, order);
}
#endif
}
void invalidate_user_cache(void)
{
const char *path;
@ -7903,6 +7921,8 @@ static int _main_thread(void *data)
__make_alivelink("compat-alivelinks", compat_alivelinks, true);
update_brick_mem_freelist_max();
down_read(&rot_sem);
for (tmp = rot_anchor.next; tmp != &rot_anchor; tmp = tmp->next) {
struct mars_rotate *rot = container_of(tmp, struct mars_rotate, rot_head);
@ -8213,7 +8233,7 @@ static int __init init_main(void)
DO_INIT(mars_proc);
#ifdef CONFIG_MARS_MEM_PREALLOC
brick_pre_reserve[5] = 64;
brick_pre_reserve[MARS_MEMRESERVE_ORDER] = 64;
brick_mem_reserve();
#endif