[SOLVED] Why does buffer cache build up cause unnecessary swapping?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Why does buffer cache build up cause unnecessary swapping?
(I'm using bold words to refer to 'free -h' columns)
I have Arch Linux installed on my laptop with 4GB RAM. When I'm copying a large file (or doing anything involving file operations), I can see the Mem: buff/cache increasing using 'free -h'. Regardless of how much RAM I'm using at the moment, buff/cache grows up until there's only about 100mb of Mem: free memory. Then, when the value of Mem: free goes below 100mb, the system starts swapping. Usually about 35mb of data gets swapped, and it stays around that number. Then, as the file is still being copied, the data amount in Swap: used fluctuates between 1-2 megabytes. If 35mb are swapped, it becomes 36mb after a few seconds, and then after another few seconds it returns to 35mb. This fluctuation affects the performance as it continues swapping in and out until the file is copied. I've experienced this behaviour on Arch, PopOS and Elementary OS. So I thought this was normal for linux until...
I recently installed Linux Mint and noticed that this doesn't happen on it. No matter how large a file I try to copy, Mem: buff/cache grows until Mem: free goes below 100mb, and then it stabilizes. Mem: free value fluctuates slightly by about 10 megabytes. In Mint, swapping doesn't occur while copying files.
How does this happen? Does Mint have special settings that prevent unnecessary swapping? If it does how do I apply them to Arch or any other distro?
PS: Sorry for my bad English and the terrible structure of the question. I tried my best to put this together.
What you need to read is the linux kernel documentation on swapping, if you're going to rebuild the kernel. Usually it's in the Documentation directory of the kernel source. Otherwise do what the rest of us do: use your computer without fixating on figures.
Linux isn't windows. No BSOD in linux! It can run hundreds of processes any of which can want a chunk of ram to avoid crashing, and linux might give them the same chunk of ram. Then when one of them actually starts writing to that ram, it has to juggle things around, and tries to keep blocks contiguous (=together), rather than spread all over. It never wants to use the last byte, and does different things depending on the pressure it's under. Programs may have asked for a buffer, and they fill unpredictably. So if youi can figure what it's up to with free -h, you're smarter than me.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.