From bac2eda43e322e8081770ddb95464c65606c3969 Mon Sep 17 00:00:00 2001 From: Jorgen Lundman Date: Thu, 2 Nov 2023 09:52:55 +0900 Subject: [PATCH] Set abd cache based on vm size This mops up all the differences to macOS versions of the source files. Signed-off-by: Jorgen Lundman --- module/os/windows/spl/spl-kmem.c | 8 +++--- module/os/windows/spl/spl-seg_kmem.c | 40 +++++++++++++++++++--------- module/os/windows/spl/spl-windows.c | 12 +-------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/module/os/windows/spl/spl-kmem.c b/module/os/windows/spl/spl-kmem.c index 88dd75832633..7f3dfb05f836 100644 --- a/module/os/windows/spl/spl-kmem.c +++ b/module/os/windows/spl/spl-kmem.c @@ -2467,7 +2467,8 @@ kmem_cache_free(kmem_cache_t *cp, const void *buf) return; } if (ccp->cc_flags & KMF_BUFTAG) { - if (kmem_cache_free_debug(cp, buf, caller()) == -1) + if (kmem_cache_free_debug(cp, __DECONST(void *, buf), + caller()) == -1) return; } } @@ -2918,7 +2919,7 @@ kmem_reap_common(void *flag_arg) */ /* - * It may not be safe to do memory allocation when a reap is called + * It may not be safe to do memory allocation when a reap * is called (for example, if vmem_populate() is in the call chain). * So we start the reap going with a TQ_NOALLOC dispatch. If the * dispatch fails, we reset the flag, and the next reap will try again. @@ -4458,9 +4459,6 @@ spl_reduce_dynamic_cap(void) int64_t spl_free_wrapper(void) { -// MEMORYSTATUSEX memInfo; -// memInfo.dwLength = sizeof(MEMORYSTATUSEX); - if (spl_enforce_memory_caps != 0 && spl_free > 0) { if (segkmem_total_mem_allocated >= spl_dynamic_memory_cap) { diff --git a/module/os/windows/spl/spl-seg_kmem.c b/module/os/windows/spl/spl-seg_kmem.c index 44ad83133eb7..1afdfa2872f7 100644 --- a/module/os/windows/spl/spl-seg_kmem.c +++ b/module/os/windows/spl/spl-seg_kmem.c @@ -149,11 +149,6 @@ osif_malloc(uint64_t size) dprintf("%s:%d: ExAllocatePoolWithTag failed (memusage: %llu)" "\n", __func__, __LINE__, segkmem_total_mem_allocated); - extern volatile unsigned int vm_page_free_wanted; - extern volatile unsigned int vm_page_free_min; - spl_free_set_emergency_pressure(vm_page_free_min); - vm_page_free_wanted = vm_page_free_min; - atomic_inc_64(&stat_osif_malloc_fail); return (NULL); } @@ -240,9 +235,24 @@ segkmem_abd_init() extern vmem_t *spl_heap_arena; - abd_arena = vmem_create("abd_cache", NULL, 0, - PAGESIZE, vmem_alloc_impl, vmem_free_impl, spl_heap_arena, - 131072, VM_SLEEP | VMC_NO_QCACHE | VM_FIRSTFIT); +#define BIG_SLAB 131072 +#ifdef __arm64__ +#define BIG_BIG_SLAB (BIG_SLAB * 2) +#else +#define BIG_BIG_SLAB BIG_SLAB +#endif + +#define SMALL_RAM_MACHINE (4ULL * 1024ULL * 1024ULL * 1024ULL) + + if (total_memory >= SMALL_RAM_MACHINE) { + abd_arena = vmem_create("abd_cache", NULL, 0, + PAGESIZE, vmem_alloc_impl, vmem_free_impl, spl_heap_arena, + BIG_BIG_SLAB, VM_SLEEP | VMC_NO_QCACHE); + } else { + abd_arena = vmem_create("abd_cache", NULL, 0, + PAGESIZE, vmem_alloc_impl, vmem_free_impl, spl_heap_arena, + 131072, VM_SLEEP | VMC_NO_QCACHE); + } VERIFY3P(abd_arena, !=, NULL); @@ -256,12 +266,18 @@ segkmem_abd_init() * This will be _Static_assert-ed in abd_os.c. */ - abd_subpage_arena = vmem_create("abd_subpage_cache", NULL, 0, - 512, vmem_alloc_impl, vmem_free_impl, abd_arena, - 131072, VM_SLEEP | VMC_NO_QCACHE | VM_FIRSTFIT); + if (total_memory >= SMALL_RAM_MACHINE) { + abd_subpage_arena = vmem_create("abd_subpage_cache", NULL, 0, + sizeof (void *), vmem_alloc_impl, vmem_free_impl, + spl_heap_arena, + BIG_SLAB, VM_SLEEP | VMC_NO_QCACHE); + } else { + abd_subpage_arena = vmem_create("abd_subpage_cache", NULL, 0, + 512, vmem_alloc_impl, vmem_free_impl, abd_arena, + 131072, VM_SLEEP | VMC_NO_QCACHE); + } VERIFY3P(abd_subpage_arena, !=, NULL); - } void diff --git a/module/os/windows/spl/spl-windows.c b/module/os/windows/spl/spl-windows.c index 2e7f74a7ca4c..453067dbe3bf 100644 --- a/module/os/windows/spl/spl-windows.c +++ b/module/os/windows/spl/spl-windows.c @@ -48,11 +48,6 @@ unsigned int max_ncpus = 0; uint64_t total_memory = 0; uint64_t real_total_memory = 0; -volatile unsigned int vm_page_free_wanted = 0; -volatile unsigned int vm_page_free_min = 512; -volatile unsigned int vm_page_free_count = 5000; -volatile unsigned int vm_page_speculative_count = 5500; - uint64_t spl_GetPhysMem(void); uint64_t spl_GetZfsTotalMemory(PUNICODE_STRING RegistryPath); @@ -64,7 +59,7 @@ extern uint64_t segkmem_total_mem_allocated; #define MAXHOSTNAMELEN 64 extern char hostname[MAXHOSTNAMELEN]; -#define ZFS_MIN_MEMORY_LIMIT 2ULL * 1024ULL * 1024ULL * 1024ULL +#define ZFS_MIN_MEMORY_LIMIT 2ULL * 1024ULL * 1024ULL * 1024ULL /* * Windows internal tunables, we use the RAW method when @@ -525,11 +520,6 @@ spl_start(PUNICODE_STRING RegistryPath) zfs_total_memory_limit, total_memory); physmem = total_memory / PAGE_SIZE; - // We need to set these to some non-zero values - // so we don't think there is permanent memory - // pressure. - vm_page_free_count = (unsigned int)(physmem / 2ULL); - vm_page_speculative_count = vm_page_free_count; // Set hostid here, it will be overwritten if it is in registry if (spl_hostid == 0)