You are not logged in.

#1 2019-09-02 12:56:14

Radu212
Member
Registered: 2019-08-17
Posts: 29

do i need swap ?

so i have a 10gb swap partition just because i have the space and 8gb of ram my swappiness is set to 10 and sometimes after i don't touch apps for a while (for example discord) when i come back to them they are very laggy so i suppose it is loading it from swap so do i need it that much cuz from what i've read people say that you need it only if you want hibernation and i don't need it

Offline

#2 2019-09-02 13:27:20

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,712
Website

Re: do i need swap ?

The question

do i need swap ?

can only be answered by yourself.
Do you need it? We don't know that.
I don't need SWAP on my 8 GB RAM workstation in the office, because I don't execute that memory-expensive tasks.
Do you?


Inofficial first vice president of the Rust Evangelism Strike Force

Offline

#3 2019-09-02 13:58:30

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,530
Website

Re: do i need swap ?

It's been years (probably over a decade) since I had a swap partition/file.  I was, for most of that time, using a system with 2GB ram, for the past couple years I've had 4GB, but still wouldn't need swap today if I only had 2GB.  But that's me.  Most people have a lot more features in their system than I do.

If I ever do briefly need more space, I can always create a temporary swap file.  I've been saying that for a decade or so, and have never created such a file.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2019-09-02 15:24:45

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,439

Re: do i need swap ?

Well… if, as you indicate by your assumption that applications are "laggy" because they swap out (something you might want to secure by actually looking at the memory/swap usage), you are using the swap, there's a strong indication that you actually need it.

The kernel doesn't  randomly swap pages because it feels like it could bother you by making things slower just for the lulz…

Online

#5 2019-09-02 15:53:43

Radu212
Member
Registered: 2019-08-17
Posts: 29

Re: do i need swap ?

@seth the thing is that my max ram usage without doing something too intesive is at about 2-3 gb (i have a plex server running in the background that is not that ram intesinve becuse it does not have to transcode anything a google calendar that i keep open and discord and the chromium browser that's pretty much all i use about all the time) and it still uses 500 mb of swap sometimes (i do do more ram intesive tasks like producing music but i do that on my windows install so yeah )

Offline

#6 2019-09-02 16:22:48

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,439

Re: do i need swap ?

File cache?
Did you look at the RAM distribution in /proc/meminfo or at least at "free"?
Maybe some indexer (baloo or tracker or something) ran across the system and ate your RAM?

Online

#7 2019-09-03 01:32:02

Radu212
Member
Registered: 2019-08-17
Posts: 29

Re: do i need swap ?

didn't know about these commands

[iulian@iulian-arch ~]$ free
              total        used        free      shared  buff/cache   available
Mem:        8149536     1652748      130408       93056     6366380     6104048
Swap:      10465300      341760    10123540
[iulian@iulian-arch ~]$ cat /proc/meminfo
MemTotal:        8149536 kB
MemFree:          126780 kB
MemAvailable:    6107852 kB
Buffers:         3005700 kB
Cached:          3191456 kB
SwapCached:        12276 kB
Active:          1261448 kB
Inactive:        6275844 kB
Active(anon):     969096 kB
Inactive(anon):   453036 kB
Active(file):     292352 kB
Inactive(file):  5822808 kB
Unevictable:          64 kB
Mlocked:              64 kB
SwapTotal:      10465300 kB
SwapFree:       10114836 kB
Dirty:                64 kB
Writeback:             0 kB
AnonPages:       1330012 kB
Mapped:           402424 kB
Shmem:             85688 kB
KReclaimable:     169808 kB
Slab:             262328 kB
SReclaimable:     169808 kB
SUnreclaim:        92520 kB
KernelStack:       11168 kB
PageTables:        29388 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    14540068 kB
Committed_AS:    7627988 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
Percpu:             3712 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:     1095168 kB
DirectMap2M:     7276544 kB
[iulian@iulian-arch ~]$ 

i think it is caheing because when this started to happen i looked at system monitor and the hdd is doing something like 200 mb reads and 100 mb writes and i checked in htop and plex was analysing files i think but why is it useing the swap for that ?

edit : so i looked into it and it was plex at fault it was analyzeing files for loundess and other things and it was useing A LOT of hdd that was the cause i turned them off and now it is fine but my question still stands how bad is it if i turn swap off ?

Last edited by Radu212 (2019-09-03 01:51:15)

Offline

#8 2019-09-03 07:12:25

Stellarator
Member
Registered: 2019-01-12
Posts: 32

Re: do i need swap ?

It looks like you want a direct answer. Well, because the kernel overcommits memory, you could live without it. But note that in case of running out of memory the kernel will start to kill your memory-hogging processes to free up memory for others. If it's OK for you, you can "safely" turn it off.

But if you don't want to do things blindly, following the advice of others, I highly recommend spending some time understanding the subject. Memory management is one of the toughest disciplines. And have at least a superficial understanding is quite useful.

Start with Linux Swap Space. And because your vm.swappiness value looks questionable for me too, it makes sense to check the following links: Why is swappiness set to 60 by default? and Discussion about vm.swappiness variable.

Last edited by Stellarator (2019-09-03 07:14:03)

Offline

#9 2019-09-03 07:24:37

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,439

Re: do i need swap ?

In his scenario, the kernel would simply have to drop file caches faster. It's hard to say whether swapping is more efficient in this case (when he looked, most of the file cache was inactive cruft).
I guess a solution would be to jail plex in a cgroup that limits the file cache, but I'm not even sure whether that's possible.

Online

#10 2019-09-03 08:33:28

Stellarator
Member
Registered: 2019-01-12
Posts: 32

Re: do i need swap ?

Oh, yes! I just gave a general advice, because

Radu212 wrote:

didn't know about these commands

looked alarming to me. Many of people are trying to solve "I don't wanna swap" problem by blindly modifying vm.swappiness value (not understanding what it is responsible for).

For "this case" it is definitely worth playing with configs / settings of plex. Or with plex ... in general. But this is a question beyond my knowledge (I've never used plex).

Offline

#11 2019-09-03 10:37:11

sabroad
Member
Registered: 2015-05-24
Posts: 242

Re: do i need swap ?

Radu212 wrote:

i looked at system monitor and the hdd is doing something like 200 mb reads and 100 mb writes and i checked in htop and plex was analysing files i think but why is it useing the swap for that ?

edit : so i looked into it and it was plex at fault it was analyzeing files for loundess and other things and it was useing A LOT of hdd that was the cause i turned them off and now it is fine but my question still stands how bad is it if i turn swap off ?

It's likely that the 500MB of swap used here (for idle pages) went towards filecache instead, improving performance. For more information, Linux Performance: Why You Should Almost Always Add Swap Space

If you had latency issues (ie. sluggish) when IO maxed, try an IO scheduler (such as BFQ) that prioritises latency: https://wiki.archlinux.org/index.php/Im … algorithms


--
saint_abroad

Offline

#12 2019-09-03 12:12:14

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,530
Website

Re: do i need swap ?

Files cached because an indexing tool read them is unlikely to benefit performance.  Caching of files is useful when they are likely to be reread, but the indexer just runs through all files regardless of how often they are used.  So it destroys the benefit of file caching.  Ideally an indexer would be run in a manner that none of its file read's result in caching, so that files that are actually read more often can stay in the cache.

Last edited by Trilby (2019-09-03 12:12:40)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB