Changeset View
Changeset View
Standalone View
Standalone View
sys/contrib/openzfs/module/os/freebsd/zfs/arc_os.c
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
#include <sys/arc_impl.h> | #include <sys/arc_impl.h> | ||||
#include <sys/sdt.h> | #include <sys/sdt.h> | ||||
#include <sys/aggsum.h> | #include <sys/aggsum.h> | ||||
#include <sys/vnode.h> | #include <sys/vnode.h> | ||||
#include <cityhash.h> | #include <cityhash.h> | ||||
#include <machine/vmparam.h> | #include <machine/vmparam.h> | ||||
#include <sys/vm.h> | #include <sys/vm.h> | ||||
#include <sys/vmmeter.h> | #include <sys/vmmeter.h> | ||||
#include <vm/vm_pageout.h> | |||||
extern struct vfsops zfs_vfsops; | extern struct vfsops zfs_vfsops; | ||||
uint_t zfs_arc_free_target = 0; | uint_t zfs_arc_free_target = 0; | ||||
static void | static void | ||||
arc_free_target_init(void *unused __unused) | arc_free_target_init(void *unused __unused) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | |||||
uint64_t | uint64_t | ||||
arc_free_memory(void) | arc_free_memory(void) | ||||
{ | { | ||||
return (ptob(freemem)); | return (ptob(freemem)); | ||||
} | } | ||||
static eventhandler_tag arc_event_lowmem = NULL; | static eventhandler_tag arc_event_lowmem = NULL; | ||||
/* | |||||
* The vm_lowmem event counters. | |||||
*/ | |||||
wmsum_t zfs_arc_vm_lowmem_events; | |||||
wmsum_t zfs_arc_vm_lowmem_kmem; | |||||
wmsum_t zfs_arc_vm_lowmem_pages; | |||||
wmsum_t zfs_arc_vm_lowmem_nofree; | |||||
wmsum_t zfs_arc_vm_lowmem_pagedaemon; | |||||
static void | static void | ||||
arc_lowmem(void *arg __unused, int howto __unused) | arc_lowmem(void *arg __unused, int howto) | ||||
{ | { | ||||
int64_t free_memory, to_free; | int64_t free_memory, to_free; | ||||
wmsum_add(&zfs_arc_vm_lowmem_events, 1); | |||||
switch (howto) { | |||||
case VM_LOW_KMEM: | |||||
wmsum_add(&zfs_arc_vm_lowmem_kmem, 1); | |||||
break; | |||||
case VM_LOW_PAGES: | |||||
wmsum_add(&zfs_arc_vm_lowmem_pages, 1); | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
if (curproc == pageproc) | |||||
wmsum_add(&zfs_arc_vm_lowmem_pagedaemon, 1); | |||||
arc_no_grow = B_TRUE; | arc_no_grow = B_TRUE; | ||||
arc_warm = B_TRUE; | arc_warm = B_TRUE; | ||||
arc_growtime = gethrtime() + SEC2NSEC(arc_grow_retry); | arc_growtime = gethrtime() + SEC2NSEC(arc_grow_retry); | ||||
free_memory = arc_available_memory(); | free_memory = arc_available_memory(); | ||||
int64_t can_free = arc_c - arc_c_min; | int64_t can_free = arc_c - arc_c_min; | ||||
if (can_free <= 0) | if (can_free <= 0) { | ||||
wmsum_add(&zfs_arc_vm_lowmem_nofree, 1); | |||||
return; | return; | ||||
} | |||||
to_free = (can_free >> arc_shrink_shift) - MIN(free_memory, 0); | to_free = (can_free >> arc_shrink_shift) - MIN(free_memory, 0); | ||||
DTRACE_PROBE2(arc__needfree, int64_t, free_memory, int64_t, to_free); | DTRACE_PROBE2(arc__needfree, int64_t, free_memory, int64_t, to_free); | ||||
arc_reduce_target_size(to_free); | arc_reduce_target_size(to_free); | ||||
/* | /* | ||||
* It is unsafe to block here in arbitrary threads, because we can come | * It is unsafe to block here in arbitrary threads, because we can come | ||||
* here from ARC itself and may hold ARC locks and thus risk a deadlock | * here from ARC itself and may hold ARC locks and thus risk a deadlock | ||||
* with ARC reclaim thread. | * with ARC reclaim thread. | ||||
*/ | */ | ||||
if (curproc == pageproc) | if (curproc == pageproc) | ||||
arc_wait_for_eviction(to_free, B_FALSE); | arc_wait_for_eviction(to_free, B_FALSE); | ||||
} | } | ||||
void | void | ||||
arc_lowmem_init(void) | arc_lowmem_init(void) | ||||
{ | { | ||||
wmsum_init(&zfs_arc_vm_lowmem_events, 0); | |||||
wmsum_init(&zfs_arc_vm_lowmem_kmem, 0); | |||||
wmsum_init(&zfs_arc_vm_lowmem_pages, 0); | |||||
wmsum_init(&zfs_arc_vm_lowmem_nofree, 0); | |||||
wmsum_init(&zfs_arc_vm_lowmem_pagedaemon, 0); | |||||
arc_event_lowmem = EVENTHANDLER_REGISTER(vm_lowmem, arc_lowmem, NULL, | arc_event_lowmem = EVENTHANDLER_REGISTER(vm_lowmem, arc_lowmem, NULL, | ||||
EVENTHANDLER_PRI_FIRST); | EVENTHANDLER_PRI_FIRST); | ||||
} | } | ||||
void | void | ||||
arc_lowmem_fini(void) | arc_lowmem_fini(void) | ||||
{ | { | ||||
if (arc_event_lowmem != NULL) | if (arc_event_lowmem != NULL) | ||||
EVENTHANDLER_DEREGISTER(vm_lowmem, arc_event_lowmem); | EVENTHANDLER_DEREGISTER(vm_lowmem, arc_event_lowmem); | ||||
wmsum_fini(&zfs_arc_vm_lowmem_events); | |||||
wmsum_fini(&zfs_arc_vm_lowmem_kmem); | |||||
wmsum_fini(&zfs_arc_vm_lowmem_pages); | |||||
wmsum_fini(&zfs_arc_vm_lowmem_nofree); | |||||
wmsum_fini(&zfs_arc_vm_lowmem_pagedaemon); | |||||
} | } | ||||
void | void | ||||
arc_register_hotplug(void) | arc_register_hotplug(void) | ||||
{ | { | ||||
} | } | ||||
void | void | ||||
arc_unregister_hotplug(void) | arc_unregister_hotplug(void) | ||||
{ | { | ||||
} | } |