From a886bddb9b3e5d8e1a9257fd6ce9bdf4bc75e7c9 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 31 Mar 2018 22:02:22 -0700 Subject: [PATCH] hammer2 - Increase bulkfree buffer size request and cap * Increase the kernel buffer size cap for hammer2 cleanups (aka bulkfree's) from 64MB to 1/16 physical memory. Systems with more memory can accomodate larger in-memory bulkfree bitmap buffers. Systems with less memory simply do multiple scan passes as per usual. * Increase the buffer size requested by the hammer2 utility from 8MB to 1/16 physical memory. The actual amount of memory allocated by the kernel will be 32MB per 1TB of filesystem, up to the cap. * This will generally reduce the number of scans required for a 4TB filesystem from 16 to 1, meaning that bulkfree will take 1/16 the time as it did before for a filesystem of that size. For example, a system with 128GB of ram would be able to request up to 8GB of buffer which can accomodate a bulkfree operation on a 256TB filesystem in a single pass. --- sbin/hammer2/cmd_bulkfree.c | 10 +++++++++- sys/vfs/hammer2/hammer2_bulkfree.c | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sbin/hammer2/cmd_bulkfree.c b/sbin/hammer2/cmd_bulkfree.c index cdd3614a40..702962793f 100644 --- a/sbin/hammer2/cmd_bulkfree.c +++ b/sbin/hammer2/cmd_bulkfree.c @@ -41,9 +41,17 @@ cmd_bulkfree(const char *sel_path) int ecode; int fd; int res; + size_t usermem; + size_t usermem_size = sizeof(usermem); bzero(&bfi, sizeof(bfi)); - bfi.size = 8192 * 1024; + usermem = 0; + if (sysctlbyname("hw.usermem", &usermem, &usermem_size, NULL, 0) == 0) + bfi.size = usermem / 16; + else + bfi.size = 0; + if (bfi.size < 8192 * 1024) + bfi.size = 8192 * 1024; if ((fd = hammer2_ioctl_handle(sel_path)) < 0) return 1; diff --git a/sys/vfs/hammer2/hammer2_bulkfree.c b/sys/vfs/hammer2/hammer2_bulkfree.c index 07f5ce6bc4..e6bbb957c5 100644 --- a/sys/vfs/hammer2/hammer2_bulkfree.c +++ b/sys/vfs/hammer2/hammer2_bulkfree.c @@ -390,8 +390,8 @@ hammer2_bulkfree_pass(hammer2_dev_t *hmp, hammer2_chain_t *vchain, ~(size_t)(HAMMER2_FREEMAP_LEVELN_PSIZE - 1); if (size < 1024 * 1024) size = 1024 * 1024; - if (size > 64 * 1024 * 1024) - size = 64 * 1024 * 1024; + if (size > kmem_lim_size() * 1024 * 1024 / 16) + size = kmem_lim_size() * 1024 * 1024 / 16; cbinfo.hmp = hmp; cbinfo.bmap = kmem_alloc_swapbacked(&cbinfo.kp, size, VM_SUBSYS_HAMMER); -- 2.41.0