I’m using XFCE latest.
I discovered swappiness.
However, I realized that the cmd:
sudo sysctl vm.swappiness=10
changes the swappiness, but only temporaly, until shutdown.
I also found, that one ought to:
edit the sysctl configuration file:
sudo nano /etc/sysctl.conf
Add or modify the line:
vm.swappiness = MyChosenValue
Save and close the file
For most desktop computers the recommended value is 10: Theoretically, this means to only start swapping when RAM usage reaches around 90 percent.
It will start swapping before 90%, because:
First, it’s important to understand what vm.swappiness does. vm.swappiness is a sysctl that biases memory reclaim either towards reclamation of anonymous pages, or towards file pages. It does this using two different attributes: file_prio (our willingness to reclaim file pages) and anon_prio (our willingness to reclaim anonymous pages). vm.swappiness plays into this, as it becomes the default value for anon_prio, and it also is subtracted from the default value of 200 for file_prio, which means for a value of vm.swappiness = 50, the outcome is that anon_prio is 50, and file_prio is 150 (the exact numbers don’t matter as much as their relative weight compared to the other).
This means that, in general, vm.swappiness is simply a ratio of how costly reclaiming and refaulting anonymous memory is compared to file memory for your hardware and workload. The lower the value, the more you tell the kernel that infrequently accessed anonymous pages are expensive to swap out and in on your hardware. The higher the value, the more you tell the kernel that the cost of swapping anonymous pages and file pages is similar on your hardware. The memory management subsystem will still try to mostly decide whether it swaps file or anonymous pages based on how hot the memory is, but swappiness tips the cost calculation either more towards swapping or more towards dropping filesystem caches when it could go either way. On SSDs these are basically as expensive as each other, so setting vm.swappiness = 100 (full equality) may work well. On spinning disks, swapping may be significantly more expensive since swapping in general requires random reads, so you may want to bias more towards a lower value.
Both ways are correct.
You can create a file under /etc/sysctl.d/filename.conf
and put your value in
or you can change the main config file /etc/sysctl.conf
directly
The effect is the same, the changes you made are easier to keep track of when you use the first method.
Reducing swappiness (aka swap frequency, set to 60 by default) to e.g. 10 will make the system wait much longer before trying to swap to disk. This can be done on the fly with sysctl vm.swappiness=10 or setup permanently, using a configuration file such as:
Seems strange to me to have a std way to invoke it, namely:
vm.swappiness=10
but many ways to store it, for me seems confusing, apparently not for all the others.
Additionnaly, I didn’t know the swappiness param until today, I wish I had first encountered that when I created the swap partition, namely that I’m asked for the value.
I haven’t gotten that information.
Must be a relatively recent change.
man sysctl still mentions /etc/sysctl.conf as one of the configuration files.
I also noticed, that man sysctl
(not: man sysctl.conf)
says, in the last line of the NOTES:
NOTES
System file precedence
When using the --system option, sysctl will read files from directories in the following list in given order from top to bottom. Once a file of a given filename is
loaded, any file of the same name in subsequent directories is ignored.
/etc/sysctl.d/*.conf
/run/sysctl.d/*.conf
/usr/local/lib/sysctl.d/*.conf
/usr/lib/sysctl.d/*.conf
/lib/sysctl.d/*.conf
All configuration files are sorted in lexicographic order, regardless of the directory they reside in. Configuration files can either be completely replaced (by having a
new configuration file with the same name in a directory of higher priority) or partially replaced (by having a configuration file that is ordered later).
The file /etc/sysctl.conf is read last which means it can replace/override any parameters previously set in files in the listed directories.
But, upon trying to use that file to effect changes to vm.swappiness
it indeed does not get used.
on Arch/Manjaro, that is,
the file is still present and used in Mint/Ubuntu, for instance
They also have a file/symlink 99-sysctl.conf in /etc/sysctl.d/ which links back to /etc/sysctl.conf
Well, yes.
The file /etc/sysctl.conf is not even present (by default) in Manjaro/Arch.
And it is not getting parsed when you create it.
… while the manual pages don’t reflect this fact …
That is different than it is in Ubuntu/Mint,
where the file is still present and getting parsed.
I didn’t check Debian.
That is the way many tools work - there can be one configuration file
and then a directory, the files in which also get parsed.
That way you can neatly separate and keep track of your configuration changes,
as you can give your own names to these files, so you know what they are there for, what they contain.
They get parsed in a certain order - which is explained in the manual pages mentioned.
You can just as well put everything in just one file - which may get cumbersome and error prone when you have not just one change like the change to vm.swappiness here.
That I do agree, but then that the directory can differ and filename also, seems prone to error.
How will you remember where you store it and under what name?
And what about multi-users on same machine?
As novice, a bit of std would be beneficial.
Quick question, your example has 10-swappiness.conf and the file I have is 99-swappiness.conf, I cannot remember what the number means or what it does at the beginning of those files, does it matter much if I use 99 or 10 or whatever?
I have 3 conf files in /etc/sysctl.d/ and all of them have 99- at the beginning.
It’s the order of being read. Higher numbers overwrite settings from previous, lower, files. The order is alphabetical, so all the 99-* are interpreted by the first character after 99-…
Typically, you set your own settings in the 99-files, so that they take precedence and will be set definitely. (Or some weird packager also configures a 99-file; cachyos does this for example.)
If you change a registry entry in the Windows registry database. How do you remember the path and what you have changed? That’s exactly what you’re doing here under Linux, just with files instead.
System configurations are always global, not user-specific.
The directory name is easily recognizable by it’s virtual identity with the name of the configuration file: /etc/sysctl.conf is the file
(bad example, actually, because this one, for whatever reason, is no longer recognized in Manjaro - but that is unusual and was very much a surprise to me)
/etc/sysctl.d/ is the directory where supplementary files go
and you can choose your own name, a name that “speaks to you” - as long as the file name ends in .conf
It’s the same naming convention for everything in /etc.
And if you are in doubt or not sure and can’t figure it out by the similarity in name - there is always the man (manual) pages.
These very much system related things have no place inside a users $HOME directory.
The few thing which do follow the same logic
→ dotfiles and directories, sometimes called “hidden” files and directories, because graphical file managers by default don’t show them
These are all user specific configuration files.
That is the standard and has been since the beginnings of Unix - you just didn’t or don’t know about it and thus perhaps want to learn.
The numbers are used to ensure some order - without a number the order would be alphabetical.
It’s just easier to spot which comes first and which comes later, regardless of the name one chooses.
Should two files have the same setting in them, the first, the one with the lower number is taken and the other ignored.
But:
that is why one should use “talking names” - names that tell about the purpose of the file and the settings in there,
to prevent this scenario from occurring in the first place, so two files don’t have the same setting in them.
The content of the file is more important than the filename
The name does not really matter but it must have a .conf suffix
My system has /etc/ sysctl.d/swappiness.conf to reduce swappiness level
Changes in /etc/ system folder would affect all user accounts
You seem to have missed the comments that answered my question, that yes those numbers as part of the file name do matter in this instance (and I’ll remind you that I knew they mattered, I just forgot how they work).
That quote you attribute to me about multi-users - where did you get it? I didn’t ask that question. I don’t know if you did it by accident or not but please correct your comment by removing it please.