Skip to content

Commit 425e8ee

Browse files
authored
Merge pull request #39 from DataCoreSoftware/zfs-454
Periodically calling 'vmem_update' function to dynamically update the vmem->vm_hash_table size.
2 parents 40d36f8 + 07018f2 commit 425e8ee

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

ZFSin/spl/module/spl/spl-kmem.c

+5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ static const char *KMEM_VA_PREFIX = "kmem_va";
130130
static const char *KMEM_MAGAZINE_PREFIX = "kmem_magazine_";
131131

132132
static char kext_version[64] = SPL_META_VERSION "-" SPL_META_RELEASE SPL_DEBUG_STR;
133+
extern boolean_t hash_rescale_exit;
134+
extern kmutex_t vmem_list_lock;
133135

134136
//struct sysctl_oid_list sysctl__spl_children;
135137
//SYSCTL_DECL(_spl);
@@ -5448,6 +5450,9 @@ spl_kmem_thread_fini(void)
54485450
dprintf("SPL: spl_free_thread stop: destroying cv and mutex\n");
54495451
cv_destroy(&spl_free_thread_cv);
54505452
mutex_destroy(&spl_free_thread_lock);
5453+
mutex_enter(&vmem_list_lock);
5454+
hash_rescale_exit = TRUE;
5455+
mutex_exit(&vmem_list_lock);
54515456

54525457
dprintf("SPL: bsd_untimeout\n");
54535458

ZFSin/spl/module/spl/spl-vmem.c

+26-10
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static uint32_t vmem_id;
320320
static uint32_t vmem_populators;
321321
static vmem_seg_t vmem_seg0[VMEM_SEG_INITIAL];
322322
static vmem_seg_t *vmem_segfree;
323-
static kmutex_t vmem_list_lock;
323+
kmutex_t vmem_list_lock;
324324
static kmutex_t vmem_segfree_lock;
325325
static kmutex_t vmem_sleep_lock;
326326
static kmutex_t vmem_nosleep_lock;
@@ -342,9 +342,10 @@ vmem_t *spl_heap_arena;
342342
static void *spl_heap_arena_initial_alloc;
343343
static uint32_t spl_heap_arena_initial_alloc_size = 0;
344344
#define NUMBER_OF_ARENAS_IN_VMEM_INIT 21
345-
//static struct timespec vmem_update_interval = {15, 0}; /* vmem_update() every 15 seconds */
345+
static struct timespec vmem_update_interval = {60, 0}; /* vmem_update() every 60 seconds */
346346
uint32_t vmem_mtbf; /* mean time between failures [default: off] */
347347
uint32_t vmem_seg_size = sizeof (vmem_seg_t);
348+
volatile boolean_t hash_rescale_exit = FALSE;
348349

349350
// must match with include/sys/vmem_impl.h
350351
static vmem_kstat_t vmem_kstat_template = {
@@ -2127,9 +2128,12 @@ vmem_destroy(vmem_t *vmp)
21272128
vmp->vm_name, leaked, (vmp->vm_cflags & VMC_IDENTIFIER) ?
21282129
"identifiers" : "bytes");
21292130

2130-
if (vmp->vm_hash_table != vmp->vm_hash0)
2131-
vmem_free(vmem_hash_arena, vmp->vm_hash_table,
2132-
(vmp->vm_hash_mask + 1) * sizeof (void *));
2131+
if (vmp->vm_hash_table != vmp->vm_hash0) {
2132+
if(vmem_hash_arena != NULL) {
2133+
vmem_free(vmem_hash_arena, vmp->vm_hash_table,
2134+
(vmp->vm_hash_mask + 1) * sizeof (void *));
2135+
}
2136+
}
21332137

21342138
/*
21352139
* Give back the segment structures for anything that's left in the
@@ -2176,10 +2180,13 @@ vmem_destroy_internal(vmem_t *vmp)
21762180
vmp->vm_name, leaked, (vmp->vm_cflags & VMC_IDENTIFIER) ?
21772181
"identifiers" : "bytes");
21782182

2179-
if (vmp->vm_hash_table != vmp->vm_hash0)
2180-
if(vmem_hash_arena != NULL)
2181-
vmem_free(vmem_hash_arena, vmp->vm_hash_table,
2182-
(vmp->vm_hash_mask + 1) * sizeof (void *));
2183+
if (vmp->vm_hash_table != vmp->vm_hash0) {
2184+
if(vmem_hash_arena != NULL) {
2185+
vmem_free(vmem_hash_arena, vmp->vm_hash_table,
2186+
(vmp->vm_hash_mask + 1) * sizeof (void *));
2187+
}
2188+
}
2189+
21832190

21842191
/*
21852192
* Give back the segment structures for anything that's left in the
@@ -2275,9 +2282,16 @@ void
22752282
vmem_update(void *dummy)
22762283
{
22772284
vmem_t *vmp;
2285+
static struct bsd_timeout_wrapper vmem_update_tm;
2286+
2287+
if (hash_rescale_exit == TRUE)
2288+
return;
22782289

22792290
mutex_enter(&vmem_list_lock);
22802291
for (vmp = vmem_list; vmp != NULL; vmp = vmp->vm_next) {
2292+
if (hash_rescale_exit == TRUE) {
2293+
break;
2294+
}
22812295
/*
22822296
* If threads are waiting for resources, wake them up
22832297
* periodically so they can issue another kmem_reap()
@@ -2292,7 +2306,9 @@ vmem_update(void *dummy)
22922306
}
22932307
mutex_exit(&vmem_list_lock);
22942308

2295-
// (void) bsd_timeout(vmem_update, dummy, &vmem_update_interval);
2309+
2310+
if (hash_rescale_exit == FALSE)
2311+
(void) bsd_timeout(vmem_update, &vmem_update_tm, &vmem_update_interval);
22962312
}
22972313

22982314
void

0 commit comments

Comments
 (0)