SlackwareThis Forum is for the discussion of Slackware Linux.
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.
Looking at atop I see 'PAG' is flashing red often which indicates accessing the swap file more than 10 times per second, from what I've read. Kinfocenter has been showing various values, but is showing a large amount of memory used for disk cache, 30 - 50%, some free physical memory and also 30-40% of swap used. Swap is on a SSD.
The fact that there is some free physical memory makes me think more RAM would have no benefit, but the frequent PAG file access reported by atop seems to indicate I am low on memory. I thought that disk cache was only used when the kernel had no other use for memory, so used otherwise free memory as a disk cache. But I'm now wondering if the kernel is somewhat more intelligent and it is carefully balancing disk cache and swap to get the best performance it can?
The use case is that I'd doing some calculations based on data in a mariadb database and putting the calcs back in the database. So the NVME drive supporting the database is often maxed on IO.
Heavy swapping means always that for your usage politics of this particular box, certainly will be need more memory.
Thank you, appreciated. Wanted to check before throwing money at it.
Still seems odd that it is swapping right now despite having 32% memory free. It has just stopped, but I switched users so that may have been a long transient effect. A large chunk of swap, 39% of the swap space is in use, which was not the case a while back. I don't think I've got any weird kernel tuning in place.
When you see free physical memory and swap being used, it means that some process is using memory and freeing it later. Sometimes it's so fast you cannot see it using tools like atop.
When you see free physical memory and swap being used, it means that some process is using memory and freeing it later. Sometimes it's so fast you cannot see it using tools like atop.
Yup! And I will give a practical example:
Imagine that you have a 16GB memory on your box, and you use Plasma5 (around 1GB consumption) to do a light browsing with Firefox (around 3GB consumption) while compiling the latest Firefox (1GB as medium memory usage). Looking at the memory usage, you are at a total of around 5GB consumption of it. Nice, right?
BUT, surprise! While compiling Firefox, there are moments with a hit a 14GB memory usage, and your glorious 16GB box hits the swap.
When you inspect later the system, you will find the swap being seriously used, while the memory is almost empty.
Like I said, it's all about your "usage politics" of the box...
Last edited by LuckyCyborg; 10-04-2021 at 07:32 AM.
Run sar -B 10 and watch its output for a while. Unless you're seeing lots of page steals you're probably fine, though majflt is one to keep an eye on too.
swap space is there to be used. It's not a problem if inactive pages are shoved into it, only when thrashing starts occurring (and when that happens you'll know about it because your system will get very sluggish).
Also bear in mind, any tmpfs is also backed by swap.
I thought that disk cache was only used when the kernel had no other use for memory, so used otherwise free memory as a disk cache. But I'm now wondering if the kernel is somewhat more intelligent and it is carefully balancing disk cache and swap to get the best performance it can?
The kernel tries to make the best possible use of physical RAM. This means that during heavy I/O, the kernel will periodically swap out pages from running processes just to see whether the processes are really using them. If not, the memory could better be used for disk caching. The rate at which this testing is done is controlled by /proc/sys/vm/swappiness.
Since you are experiencing swapping during heavy I/O, first try reducing the swappiness parameter to as little as 1. If the machine still swaps, then it is truly short on memory.
Ed
Thanks. My main recollection of swap was from the NT4 / w95 days where and serious hit of swap slowed the machine to a unresponsive crawl. The linux experience was about the same. So the short summery of the article is that the kernel is doing clever stuff and swap is a good idea.
Desktop, 16GB ram. Running various LXC containers including a fairly heavily hit mariadb in one.
Quote:
Originally Posted by Didier Spaier
in my laptop (8G RAM) and 4 VM running in it:
Windows10 4G
openSUSE 4G
Fedora 4G
Slint 1G
Code:
dance[/]# export LANG=C
dance[/]# free -th
total used free shared buff/cache available
Mem: 7.7Gi 6.7Gi 125Mi 146Mi 841Mi 541Mi
Swap: 14Gi 5.9Gi 8.8Gi
Total: 22Gi 12Gi 9.0Gi
dance[/]# swapon
NAME TYPE SIZE USED PRIO
/swapfile file 1024M 0B 10
/dev/zram1 partition 13.8G 6G 32567
dance[/]# zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram1 zstd 13.8G 5.9G 2G 2.1G 4 [SWAP]
Please note that the swap file is not even used in this case.
I've switched consoles so the heavyweight processes have stopped running, so this is likely not a fair representation:
free -th
total used free shared buff/cache available
Mem: 15Gi 5.8Gi 2.7Gi 650Mi 7.0Gi 8.8Gi
Swap: 15Gi 6.8Gi 9.2Gi
Total: 31Gi 12Gi 11Gi
Quote:
Didn't I say that swap in zram can help?
Yes, I need to look at that. Is this compressed swap, or compressed ram in swap? My swap SSD and database NVME are different and my use case is not multi-threaded so perhaps the cpu hit (I assume) won't notice.
Run sar -B 10 and watch its output for a while. Unless you're seeing lots of page steals you're probably fine, though majflt is one to keep an eye on too.
swap space is there to be used. It's not a problem if inactive pages are shoved into it, only when thrashing starts occurring (and when that happens you'll know about it because your system will get very sluggish).
I'm not sure what a lot of page steals looks like, nor what majflt value is good or bad. From sar -B 10:
When I ran this swappiness was 80. I'd tried making it 0 and 80 and a few other numbers. If it had any effect it was not large enough to notice without testing.
Quote:
Also bear in mind, any tmpfs is also backed by swap.
Yes, its amazing how many tmpfs seem to be configured by various things. Only /dev/shm is included in fstab.
When you see free physical memory and swap being used, it means that some process is using memory and freeing it later. Sometimes it's so fast you cannot see it using tools like atop.
Well, looking at kinfocenter, which I left running, this was a fairly permament state, free memory and swap being used.
Is this compressed swap, or compressed ram in swap? My swap SSD and database NVME are different and my use case is not multi-threaded so perhaps the cpu hit (I assume) won't notice.
It is zram, not zswap: this swap space is a block device in RAM. You preferred search engine will tell you more. The default setting mentioned in this config file would add 27G to your 31G. Of course this doen't really add up, but if we assume a compression ratio of 2 (I get more with the zstd compressor) you will get actually at least 13.5 additional G.
Keep you swap partition (or a swap file). This way, you will hopefully realize that the machine is slowing down, so be able to act before the OOM killer does.
Last edited by Didier Spaier; 10-04-2021 at 02:38 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.