Skip to content

Commit

Permalink
Set abd cache based on vm size
Browse files Browse the repository at this point in the history
This mops up all the differences to macOS versions of the source files.

Signed-off-by: Jorgen Lundman <[email protected]>
  • Loading branch information
lundman committed Nov 2, 2023
1 parent 538d466 commit bac2eda
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
8 changes: 3 additions & 5 deletions module/os/windows/spl/spl-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
40 changes: 28 additions & 12 deletions module/os/windows/spl/spl-seg_kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand All @@ -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
Expand Down
12 changes: 1 addition & 11 deletions module/os/windows/spl/spl-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bac2eda

Please sign in to comment.