LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-04-2021, 06:11 AM   #1
petejc
Member
 
Registered: Apr 2019
Distribution: Slackware
Posts: 134

Rep: Reputation: Disabled
More RAM needed? - swapping


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.

Does it seem like I'm low on RAM?
 
Old 10-04-2021, 06:19 AM   #2
LuckyCyborg
Senior Member
 
Registered: Mar 2010
Posts: 3,508

Rep: Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329
Quote:
Originally Posted by petejc View Post
Does it seem like I'm low on RAM?
Yes.

Heavy swapping means always that for your usage politics of this particular box, certainly will be need more memory.

Last edited by LuckyCyborg; 10-04-2021 at 06:24 AM.
 
1 members found this post helpful.
Old 10-04-2021, 07:01 AM   #3
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,060

Rep: Reputation: Disabled
Use swap in zram

Try this.
Its md5sum.
Source directory.
README.

This should al least delay the need for more RAM.

PS Enabled by default in Slint, should work the same in Slackware, no user complaint so far.

Last edited by Didier Spaier; 10-04-2021 at 07:06 AM. Reason: PS added.
 
2 members found this post helpful.
Old 10-04-2021, 07:02 AM   #4
petejc
Member
 
Registered: Apr 2019
Distribution: Slackware
Posts: 134

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by LuckyCyborg View Post
Yes.

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.
 
Old 10-04-2021, 07:03 AM   #5
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
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.
 
Old 10-04-2021, 07:14 AM   #6
LuckyCyborg
Senior Member
 
Registered: Mar 2010
Posts: 3,508

Rep: Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329Reputation: 3329
Quote:
Originally Posted by Guttorm View Post
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.
 
1 members found this post helpful.
Old 10-04-2021, 08:13 AM   #7
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
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.
 
Old 10-04-2021, 11:17 AM   #8
EdGr
Member
 
Registered: Dec 2010
Location: California, USA
Distribution: I run my own OS
Posts: 998

Rep: Reputation: 471Reputation: 471Reputation: 471Reputation: 471Reputation: 471
Quote:
Originally Posted by petejc View Post
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
 
2 members found this post helpful.
Old 10-04-2021, 11:33 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,897

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
some background info, if interested: https://chrisdown.name/2018/01/02/in...e-of-swap.html
 
Old 10-04-2021, 12:31 PM   #10
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,060

Rep: Reputation: Disabled
With swap in zram

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.

Didn't I say that swap in zram can help?
 
Old 10-04-2021, 01:26 PM   #11
petejc
Member
 
Registered: Apr 2019
Distribution: Slackware
Posts: 134

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
some background info, if interested: https://chrisdown.name/2018/01/02/in...e-of-swap.html
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.
 
Old 10-04-2021, 01:32 PM   #12
petejc
Member
 
Registered: Apr 2019
Distribution: Slackware
Posts: 134

Original Poster
Rep: Reputation: Disabled
Desktop, 16GB ram. Running various LXC containers including a fairly heavily hit mariadb in one.

Quote:
Originally Posted by Didier Spaier View Post
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.
 
Old 10-04-2021, 01:39 PM   #13
petejc
Member
 
Registered: Apr 2019
Distribution: Slackware
Posts: 134

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by GazL View Post
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:
Code:
Linux 5.13.19 (phoenix.exfire)  04/10/21        _x86_64_        (16 CPU)

19:14:19     pgpgin/s pgpgout/s   fault/s  majflt/s  pgfree/s pgscank/s pgscand/s pgsteal/s    %vmeff
19:14:29     48962.80   1609.30    895.00      7.90  16805.40  14321.30      0.00  27444.80    191.64
19:14:39     66600.00    136.80   1067.10      2.90  18643.20  15682.00      0.00  30842.60    196.68
19:14:49     62822.00    192.80   1602.00      0.10  19334.80  15775.80      0.00  31325.80    198.57
19:14:59     77203.60    997.20   5203.30      0.00  23808.50  19946.30    117.80  39942.60    199.07
19:15:09     74848.40    106.40   1369.80      0.80  22194.70  18672.80     20.90  37259.80    199.32
19:15:19     75805.20    309.20   1147.00      0.20  24582.30  21342.70      0.00  42524.00    199.24
19:15:29     96469.60    898.40    944.30      0.00  27958.20  24107.70      0.00  48122.20    199.61
19:15:39    106618.80     98.80   1022.20      0.60  31037.90  27487.30      0.00  54909.40    199.76
19:15:49    102068.80    621.20   1359.10      6.30  29957.50  26932.40      0.00  53456.60    198.48
19:15:59     79390.80   2704.00   5534.60      2.10  24073.60  20133.20      0.00  39329.80    195.35
19:16:09     27296.40   3694.40   1441.80      3.30  17668.30   6088.00    579.20  12415.60    186.22
19:16:19     38044.00   3665.20   2026.60      6.80  16314.60  10013.50      0.00  18719.00    186.94
19:16:29     27412.40   4168.70    928.30      1.20  15141.80   8304.40    137.40  15459.80    183.13
19:16:39     23158.80   3302.40   1952.70      0.30  16586.20   8274.70    190.60  15456.20    182.58
19:16:49     18936.80   3175.40   1180.80      0.20  11969.70   4683.00    148.70   8390.40    173.65
19:16:59     13374.80   3713.60   5069.10      0.10   8601.60   1694.00      0.00   3151.00    186.01
19:17:09     11649.60   3537.00   1706.90     14.00   9536.10   4521.70      0.00   9017.40    199.42
19:17:19     18523.20   3542.40   1174.50      0.80  11696.10   6546.90      0.00  11665.20    178.18
19:17:29      2719.20   5813.40    938.10      1.00   8276.60   1928.10     25.40   3458.20    177.03
19:17:39     14812.00   5808.40   1317.70      2.10  16811.90   4391.80    384.20   9094.80    190.43
19:17:49     50631.20   6970.80   1413.20      0.20  16828.30   9377.50     87.30  18266.20    192.99
19:17:59     23503.20   6438.70   5010.80      0.10  12449.00   6047.40      0.00  11024.40    182.30
19:18:09      8903.20   4946.20    992.30      1.90   9203.30   3162.90      0.00   6012.60    190.10
19:18:19      7169.60   3739.00   1312.70     19.20  10046.30   2403.80      0.00   4785.20    199.07
19:18:29     21421.60   5998.00    540.90      0.20  11973.90   4970.20     72.50   9964.40    197.60
19:18:39     36856.80   5093.80   1633.50      0.30  16728.70   9942.10      0.00  19618.80    197.33
19:18:49     23948.00   3076.00    940.00      0.00  11397.60   5356.00      0.00  10449.00    195.09
19:18:59     13496.80   3666.30   5050.00      0.30  10376.50   3738.30      0.00   6937.00    185.57
19:19:09     14378.40   4329.80   1397.00      0.20  11380.60   4830.90      0.00   9288.20    192.27
19:19:19     11761.20   3461.00   1011.50      0.50  11981.20   5431.50    114.70  10829.00    195.25
19:19:29     40255.20   4153.20    883.30      2.40  13778.40   7097.40      0.00  13651.40    192.34
19:19:39     42791.20   4297.60   1074.50      0.00  17634.50  11240.20      0.00  21942.40    195.21
19:19:49     11951.60   6660.20   2007.80    156.20  14851.70   6547.80     59.30  12551.40    189.97
19:19:59      6066.80   5993.00   5404.50     25.30   8486.70   1105.30      0.00   1983.20    179.43
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.

Last edited by petejc; 10-04-2021 at 01:40 PM.
 
Old 10-04-2021, 01:42 PM   #14
petejc
Member
 
Registered: Apr 2019
Distribution: Slackware
Posts: 134

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Guttorm View Post
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.
 
Old 10-04-2021, 02:36 PM   #15
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,060

Rep: Reputation: Disabled
Quote:
Originally Posted by petejc View Post
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.

Caveats:
  • Use a recent kernel. Those shipped in -current are OK, if on 14.2 you can just rebuild one using the source files provided in https://slackware.uk/slackware/slack...rent/source/k/ as I do for Slint.
  • 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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Low RAM condition makes SSD run like crazy, even when swapping is switched off? browny_amiga Linux - General 18 09-15-2020 07:39 AM
Finding out what RAM chip needed to upgrade from 2GB to 4GB RAM. farmerluk Linux - Hardware 4 11-17-2011 12:02 PM
Why size of swap space is 2x of RAM??? Why not 1.5x of RAM or 2.5x of RAM??? Saurav Ghosh Linux - Newbie 7 11-01-2011 03:49 AM
Needed: Byte-Swapping Program tonyfreeman Linux - Software 2 06-20-2007 06:16 PM
Adding More Ram...More Swap Needed? Crashed_Again Linux - Hardware 4 03-12-2004 10:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 11:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration