From 8021da8ba679047ac8d2bdf1a19cd094563df558 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Wed, 23 May 2018 08:48:46 -0700 Subject: [PATCH] setup.sh: do not unload/reload contigmem.ko on FreeBSD When running "setup.sh config" (or setup.sh without specify a mode - which defaults to config), do not unload the contigmem driver and then reload it. Over time, memory can get fragmented and contigmem will fail, crashing the system. But still check if the requested HUGEMEM matches what was previously specified. If a different amount was requested, unload contigmem as before and then reload with the new amount. This patch brings FreeBSD behavior in line with Linux. On Linux, we do not release all of the hugepages and then reallocate them. Signed-off-by: Jim Harris Change-Id: I18cb6fd4bdc1e1da0382423455ebce58c13bee7a Reviewed-on: https://review.gerrithub.io/412238 Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker Tested-by: SPDK Automated Test System --- scripts/setup.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index 39aa13a55..6aedbd9ea 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -466,10 +466,18 @@ function configure_freebsd_pci { function configure_freebsd { configure_freebsd_pci - kldunload contigmem.ko || true - kenv hw.contigmem.num_buffers=$((HUGEMEM / 256)) - kenv hw.contigmem.buffer_size=$((256 * 1024 * 1024)) - kldload contigmem.ko + # If contigmem is already loaded but the HUGEMEM specified doesn't match the + # previous value, unload contigmem so that we can reload with the new value. + if kldstat -q -m contigmem; then + if [ `kenv hw.contigmem.num_buffers` -ne "$((HUGEMEM / 256))" ]; then + kldunload contigmem.ko + fi + fi + if ! kldstat -q -m contigmem; then + kenv hw.contigmem.num_buffers=$((HUGEMEM / 256)) + kenv hw.contigmem.buffer_size=$((256 * 1024 * 1024)) + kldload contigmem.ko + fi } function reset_freebsd {