Index: external/cddl/osnet/dist/uts/common/fs/zfs/arc.c =================================================================== RCS file: /cvsroot/src/external/cddl/osnet/dist/uts/common/fs/zfs/arc.c,v retrieving revision 1.22 diff -u -r1.22 arc.c --- external/cddl/osnet/dist/uts/common/fs/zfs/arc.c 3 Aug 2022 01:53:06 -0000 1.22 +++ external/cddl/osnet/dist/uts/common/fs/zfs/arc.c 12 Dec 2025 10:57:52 -0000 @@ -6094,12 +6094,23 @@ #endif /* illumos */ /* set min cache to 1/32 of all memory, or arc_abs_min, whichever is more */ arc_c_min = MAX(arc_c / 4, arc_abs_min); + +#if defined(__NetBSD__) && defined(_KERNEL) + /* + * Due to concerns about NetBSD/zfs and mechanisms for general + * memory pressure to reduce ARC usage, limit arc_c_max to the + * value computed for 1/8. Additionally, limit it to 1/8 of + * VM, similar to illumos above, to address the i386 case. + */ + arc_c_max = MIN(arc_c, vmem_size(heap_arena, VMEM_ALLOC | VMEM_FREE) / 8); +#else /* set max to 1/2 of all memory, or all but 1GB, whichever is more */ if (arc_c * 8 >= 1 << 30) arc_c_max = (arc_c * 8) - (1 << 30); else arc_c_max = arc_c_min; arc_c_max = MAX(arc_c * 5, arc_c_max); +#endif /* * In userland, there's only the memory pressure that we artificially @@ -6135,8 +6146,16 @@ if (zfs_arc_meta_limit > 0 && zfs_arc_meta_limit <= arc_c_max) arc_meta_limit = zfs_arc_meta_limit; +#if defined(__NetBSD__) + /* + * XXX Explain why this is reasonable; it appears to protect + * the cache from going below half the max allowed amount of + * metadata, and that is not obviously sensible. + */ +#else if (arc_c_min < arc_meta_limit / 2 && zfs_arc_min == 0) arc_c_min = arc_meta_limit / 2; +#endif if (zfs_arc_meta_min > 0) { arc_meta_min = zfs_arc_meta_min; @@ -6218,6 +6237,13 @@ zfs_dirty_data_max = MIN(zfs_dirty_data_max, zfs_dirty_data_max_max); } +#if defined(__NetBSD__) + /* + * XXX Disable prefetch if RAM is low. + */ + printf("zfs: disabling prefetch\n"); + zfs_prefetch_disable = 1; +#endif #ifdef _KERNEL #ifdef __FreeBSD__