You are not logged in.

#1 2019-11-12 17:03:41

Akrai
Member
Registered: 2014-06-20
Posts: 8

Swap being used with half the RAM free and swappiness set to 1

I have a 4 Gb RAM laptop, with intel hd integrated graphics, so like 3.7 Gb of actual ram for the OS.
I noticed that this started happening to me since a few months ago, before that i could use like 3.5 Gb before swap started being used, but now if i start surpassing the 2Gb barrier swap beggings to get used, and it is very annoying since it freezes the system while there is writing in the swap (even when i have an SSD), at least with the normal official linux kernel. Is it happening to any of you, and what can i do to diagnose this?

Last edited by Akrai (2019-11-12 17:04:24)

Offline

#2 2019-11-12 17:29:12

seth
Member
Registered: 2012-09-03
Posts: 51,056

Re: Swap being used with half the RAM free and swappiness set to 1

it freezes the system while there is writing in the swap

lvm?

Optimistic swap outs could happen if some process has anon pages lingering around and doesn't touch them. Or your assumption about the actual memory pressure is wrong.
Check what processes get memory swapped out, https://stackoverflow.com/questions/304 … using-swap or https://blog.sleeplessbeastie.eu/2016/1 … wap-space/ and also dump /proc/meminfo when this happens.

Offline

#3 2019-11-12 17:58:00

Akrai
Member
Registered: 2014-06-20
Posts: 8

Re: Swap being used with half the RAM free and swappiness set to 1

seth wrote:

it freezes the system while there is writing in the swap

lvm?

Optimistic swap outs could happen if some process has anon pages lingering around and doesn't touch them. Or your assumption about the actual memory pressure is wrong.
Check what processes get memory swapped out, https://stackoverflow.com/questions/304 … using-swap or https://blog.sleeplessbeastie.eu/2016/1 … wap-space/ and also dump /proc/meminfo when this happens.

i don't get what has lvm to do with it, with freezing i mean that the whole screen is frozen, i suppose because the whole bandwidth of the bus of I/O is being used, as i know it can be fixed by changing priorities in the kernel or something like that so that writes doesn't take the whole bandwidth and so there is always enough bus for the mouse to move for example, and as i know it is easily achiveable by using a custom kernel like zen, but i don't know, i prefer to not touch the system that much right now, i dont have much free time


im gonna give the reports a try: right now i'm like this, swap barely used, 1.5Gb used

akrai ~ $ cat /proc/meminfo 

MemTotal:        3912956 kB
MemFree:          824944 kB
MemAvailable:    1350804 kB
Buffers:           81692 kB
Cached:          1298312 kB
SwapCached:         4884 kB
Active:          1926480 kB
Inactive:         836216 kB
Active(anon):    1387860 kB
Inactive(anon):   673244 kB
Active(file):     538620 kB
Inactive(file):   162972 kB
Unevictable:       79896 kB
Mlocked:               0 kB
SwapTotal:       4194300 kB
SwapFree:        4179756 kB
Dirty:               356 kB
Writeback:             0 kB
AnonPages:       1457788 kB
Mapped:           421492 kB
Shmem:            678412 kB
KReclaimable:      63876 kB
Slab:             133660 kB
SReclaimable:      63876 kB
SUnreclaim:        69784 kB
KernelStack:        8672 kB
PageTables:        19248 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     6150776 kB
Committed_AS:    4689188 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       28596 kB
VmallocChunk:          0 kB
Percpu:             2064 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      171508 kB
DirectMap2M:     3903488 kB
DirectMap1G:           0 kB
free -h

total        used        free      shared  buff/cache   available
Mem:          3,7Gi       1,6Gi       782Mi       683Mi       1,4Gi       1,3Gi
Swap:         4,0Gi        14Mi       4,0Gi

and i exec this command to list the processes using swap:

find /proc -maxdepth 2 -path "/proc/[0-9]*/status" -readable -exec awk -v FS=":" '{process[$1]=$2;sub(/^[ \t]+/,"",process[$1]);} END {if(process["VmSwap"] && process["VmSwap"] != "0 kB") printf "%10s %-30s %20s\n",process["Pid"],process["Name"],process["VmSwap"]}' '{}' \; | awk '{print $(NF-1),$0}' | sort -h | cut -d " " -f2-

which outputs  PID | Command | swap usage

       554 avahi-daemon                                   4 kB
       589 avahi-daemon                                  16 kB
       787 bluetoothd                                    16 kB
       283 lvmetad                                       20 kB
      1026 udisksd                                       44 kB
      1248 rtkit-daemon                                  52 kB
       813 wpa_supplicant                                56 kB
      1040 upowerd                                       88 kB
       601 cupsd                                        108 kB
       724 systemd-logind                               140 kB
      1078 systemd                                      152 kB
       556 dbus-daemon                                  188 kB
       623 polkitd                                      284 kB
       559 NetworkManager                               340 kB
       637 colord                                       436 kB
       552 accounts-daemon                              456 kB
      1079 (sd-pam)                                     580 kB
       594 gpuStatsServer.                              936 kB

now i force the swap just by opening tabs in the browser and:

      272 systemd-journal                               44 kB
       283 lvmetad                                       68 kB
       813 wpa_supplicant                                96 kB
     17883 ntpd                                         108 kB
      1248 rtkit-daemon                                 128 kB
       787 bluetoothd                                   136 kB
       554 avahi-daemon                                 152 kB
      1099 dbus-daemon                                  196 kB
       589 avahi-daemon                                 208 kB
       306 systemd-udevd                                212 kB
      1026 udisksd                                      240 kB
       556 dbus-daemon                                  296 kB
       724 systemd-logind                               360 kB
      1256 python                                       480 kB
      1040 upowerd                                      504 kB
       623 polkitd                                      592 kB
       601 cupsd                                        640 kB
         1 systemd                                      664 kB
       559 NetworkManager                               960 kB
      1078 systemd                                     1088 kB
      1079 (sd-pam)                                    1236 kB
       552 accounts-daemon                             1476 kB
      1128 kactivitymanage                             1520 kB
       594 gpuStatsServer.                             2232 kB
       637 colord                                      2576 kB
free -h

total        used        free      shared  buff/cache   available
Mem:          3,7Gi       2,6Gi       102Mi       571Mi       1,0Gi       297Mi
Swap:         4,0Gi       284Mi       3,7Gi
cat /proc/meminfo

MemTotal:        3912956 kB
MemFree:          164684 kB
MemAvailable:     343192 kB
Buffers:           24228 kB
Cached:           912088 kB
SwapCached:       124020 kB
Active:          2513864 kB
Inactive:         925452 kB
Active(anon):    2291712 kB
Inactive(anon):   768924 kB
Active(file):     222152 kB
Inactive(file):   156528 kB
Unevictable:       30256 kB
Mlocked:               0 kB
SwapTotal:       4194300 kB
SwapFree:        3866156 kB
Dirty:              1196 kB
Writeback:           132 kB
AnonPages:       2409292 kB
Mapped:           353288 kB
Shmem:            557564 kB
KReclaimable:      55960 kB
Slab:             135452 kB
SReclaimable:      55960 kB
SUnreclaim:        79492 kB
KernelStack:       12480 kB
PageTables:        38592 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     6150776 kB
Committed_AS:    8406364 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       32592 kB
VmallocChunk:          0 kB
Percpu:             2064 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      206324 kB
DirectMap2M:     3868672 kB
DirectMap1G:           0 kB

And in this test, just by opening chromium with youtube+twitch, and firefox with youtube+twitch, didn't used much swap but usually it gets pretty crazy, like 2.5Gb ram usage but 800mb swap usage, which makes the laptop just barely usable
Until that moment that it started behaving like this, i didn't have any issues at using the whole ram, i don't know what could it be, i didn't changed anything and suddenly i can't use my whole RAM properly. I mean, the RAM is okay, i did a memtest, but it is behaving like swappiness is set at like 60 or something, but the swappiness is correctly set to 1

Last edited by Akrai (2019-11-12 20:16:09)

Offline

#4 2019-11-12 20:04:30

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,645

Re: Swap being used with half the RAM free and swappiness set to 1

Please edit your post and use [ code ] tags (not quote tags) when posting output.

https://wiki.archlinux.org/index.php/Co … s_and_code
https://bbs.archlinux.org/help.php#bbcode

Offline

#5 2019-11-12 20:50:04

seth
Member
Registered: 2012-09-03
Posts: 51,056

Re: Swap being used with half the RAM free and swappiness set to 1

There's a known problem w/ lvm going bonkers w/ a swap partition…
https://bbs.archlinux.org/viewtopic.php?id=243554
https://bbs.archlinux.org/viewtopic.php?id=231083
https://bbs.archlinux.org/viewtopic.php … 4#p1758134

usually it gets pretty crazy, like 2.5Gb ram usage but 800mb swap usage

That's unfortunately no usable data, but you could easily have a spike on RAM pressure, provoking swap usage and then the RAM is largely freed by the process (if you're looking at some GUI gauge to know about your memory: they're only good for screenshots)
This is hard to tell unless you can cause the problem at will and monitor the actual behavior, because de/allocation is a matter of nanoseconds.

force the swap just by opening tabs in the browser

Tabs w/ some content or blank?

However, fixing your free indention:

              total        used        free      shared  buff/cache   available
Mem:          3,7Gi       1,6Gi       782Mi       683Mi       1,4Gi       1,3Gi
Swap:         4,0Gi        14Mi       4,0Gi
…
              total        used        free      shared  buff/cache   available
Mem:          3,7Gi       2,6Gi       102Mi       571Mi       1,0Gi       297Mi
Swap:         4,0Gi       284Mi       3,7Gi

The amount of available (non-active) pages dropped significantly - meminfo shows that the active anon memory increased a lot (inactive mildly) while the active file cache dropped (inactive static) what suggests file caches have been dropped for memory pressure (and likewise anon pages have been swapped out)

This seems "legit" behavior, despite a client has maybe a bug or lousy RAM management - the core of your main problem is however very most likely the LVM'd swap partition.

Offline

#6 2019-11-12 21:29:14

Akrai
Member
Registered: 2014-06-20
Posts: 8

Re: Swap being used with half the RAM free and swappiness set to 1

seth wrote:

There's a known problem w/ lvm going bonkers w/ a swap partition…
https://bbs.archlinux.org/viewtopic.php?id=243554
https://bbs.archlinux.org/viewtopic.php?id=231083
https://bbs.archlinux.org/viewtopic.php … 4#p1758134

usually it gets pretty crazy, like 2.5Gb ram usage but 800mb swap usage

That's unfortunately no usable data, but you could easily have a spike on RAM pressure, provoking swap usage and then the RAM is largely freed by the process (if you're looking at some GUI gauge to know about your memory: they're only good for screenshots)
This is hard to tell unless you can cause the problem at will and monitor the actual behavior, because de/allocation is a matter of nanoseconds.

force the swap just by opening tabs in the browser

Tabs w/ some content or blank?

However, fixing your free indention:

              total        used        free      shared  buff/cache   available
Mem:          3,7Gi       1,6Gi       782Mi       683Mi       1,4Gi       1,3Gi
Swap:         4,0Gi        14Mi       4,0Gi
…
              total        used        free      shared  buff/cache   available
Mem:          3,7Gi       2,6Gi       102Mi       571Mi       1,0Gi       297Mi
Swap:         4,0Gi       284Mi       3,7Gi

The amount of available (non-active) pages dropped significantly - meminfo shows that the active anon memory increased a lot (inactive mildly) while the active file cache dropped (inactive static) what suggests file caches have been dropped for memory pressure (and likewise anon pages have been swapped out)

This seems "legit" behavior, despite a client has maybe a bug or lousy RAM management - the core of your main problem is however very most likely the LVM'd swap partition.

yes, i opened tabs with content, specifically both youtube and twitch, just because those are some heavy ones in general

okay, i get that it can be a legit behavior caused by high quick pressure in ram, which is not possible to see in the usual measurements, but  why would it start to happen since some time ago and not before? Using both firefox and chromium causes this issue, so it shouldn't be a program specific issue of bad memory management... i don't know, it's weird, or maybe is that i had those spikes before but i started noticing recently because of the lvm problems

im gonna try to adjust the memory settings of firefox to have a lower limit

Offline

Board footer

Powered by FluxBB