FreeBSD Swap: Why Are Massive Swap Files Ignored And How To Fix It In Seconds.
Автор: COBS: Sharpening Your FPS Skills
Загружено: 2025-12-17
Просмотров: 32
Is your massive swap file being ignored in your FreeBSD machine? I'll tell you how to fix it and down below, I'll even help you understand what's involved when planning to set up a machine. But swap itself is a simple setting. A single setting in /boot/loader.conf called kern.maxswzone can convince your machine to use all of that swap file. I'll show you how to do this in this video.
As an example, in my new 15.0 Release workstation, I only have 16 gigs of ram, but I want to have 256 gigs of swap on a dedicated swap disk partition. On boot, I notice that I only have 128 gigs of swap (123 reported). That means almost 50% of my swap partition is being ignored. After creating an entry in /boot/loader.conf for this setting and then making its value to kern.maxswzone="600000000" when i boot the machine, I have a full reported value of 256 gigs of swap.
Like I mentioned in the video, clearly swap isn't ideal and if we all had the choice, we'd have a bazillion gigglebits of ram, a kerjillion cpu cores that run at a great many gigglehurts, but we don't so we make do with what we have. Some extra useful tidbits about the topic of swap and disks:
A dedicated swap disk is ideal if possible. If you wear it out, you can simply replace that one single disk and it means that you can be reading files from your main disk while the OS is chewing away at your swap disk, all at the same time. It also means that you can improve the performance of your swap purely by how you're setting the machine up. Most people know already that having an SSD completely full is about as bad for the disk as you can get. If your disk is nearly full, it will be very very slow and it will wear out very quickly. Let's look at a made up example:
Let's say I have the choice of two places for my swap drive on my machine with only a tiny 16 gig ram setup. I have 130 gigs free on my main disk and I have 1 TB free on my second disk. So, what will each one act like if I add a 128 gig swap area?
The 130 gig free space has room for our 128 gig swap area so there's no problem. We have 2 gigs free so it fits nicely. When we first boot, the machine is fine. We start some projects and start hitting swap. We only swap out about 32 gigs of stuff at first and it's fine. After it's done this four times though (Which can happen in a short period), suddenly the machine lurches to a halt. Disk throughput drops to almost nothing and suddenly the entire machine is laggy. We let it sit and do its thing and it eventually gets itself sorted, but every time we hit swap hard, it slows to a crawl. Let's look at the other choice.
This time, we have a 1TB drive to use. We partition our 128 gigs of swap, but we leave the rest of the drive completely empty. At first, it seems ridiculously stupid to do this. All of that room wasted. But then we start hitting swap hard. We do the same workload we did in the scenario up top. We swap out 32 gigs of stuff and we do it four times over the course of a fraction of a minute. But this time, when we go to write more data to swap the next time, instead of slowing to a crawl as it shuffles things around to make room and to level out the wear and tear, it writes at the FULL SPEED OF THE DISK. Why? Because it didn't have 2 gigs of free room, it had 752 gigs of free space! (Pretending 1TB is exactly 1000 gigs). And, just as important, with all that free space, by the time we've used up every single free block for writing, the firmware and OS has already cleaned up and released a whole pile more so no matter how hard we hit this thing, swap is always fast and snappy.
These kinds of reasons are why I put so much thought towards my swap arrays. I like to have at least one dedicated swap device, preferably more. In this laptop (My T440P that I recorded the desktop video on), I actually have three disk devices and two of them are dedicated to swap with nothing else on them. The result has been a machine with swap that's so snappy that the only thing that I legitimately can't tell if the machine is swapping OR how much swap it's using. The ONLY workload that I can feel the swap with is large virtual machines.
Sometimes it's worth the time to think and plan things. :) Sometimes it has huge payoffs. :)
-Fraken
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: