You are not logged in.

#1 2009-12-29 13:03:57

Anril
Member
Registered: 2009-12-29
Posts: 11

High cache usage of free memory

I dont know if this is normal but my fresh archlinux x86_64 install with Xfce uses round 300Mb of 4Gb ram space after boot but then after i start and close some programs i get to 3 Gb used of 3.87 Gb free memory when all applycation are closed. Now i understand that kernel caches some data in memory but i cant clear it all with commands:

sync
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches

After i do that system reports 540 Mb used compared to 300Mb from boot. Is there a way to limit the ammount of cache usage so i dont end up having all free memory used by cache?

Last edited by Anril (2009-12-29 13:19:52)

Offline

#2 2009-12-29 13:33:32

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: High cache usage of free memory

That's what memory is for!
Why would you want 'unused' memory?

Offline

#3 2009-12-29 14:22:47

Anril
Member
Registered: 2009-12-29
Posts: 11

Re: High cache usage of free memory

Iam reading about it and normal behavor is when that cached memory is getting replaced if applicaton needs it. But i think that with some applycations its not getting replaced and then system starts to use swap memory. I need to do more testing to be sure...

What i found not normal is to get round 2.5 Gb of cached memory total. After i use command to clear up cached memory i started to load all applycations there is on my system and see how memory rises from 540mb to 1.3Gb. So at the moment iam trying to reproduce 3.5Gb of memory used with all applycations closed and i cant... I top out on 2.5Gb with certain game runing but that game does not stay in cache if i exit.

Thats why i think something might be wrong with the way system is handilng cache.

Last edited by Anril (2009-12-29 14:38:25)

Offline

#4 2009-12-29 15:16:34

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: High cache usage of free memory

Ram that is unused is wasted ram, the linux kernel manages it very well so no worries there.

If you have swap usage it's because most probably you have things stored in the ram that are not being used often but cannot be discarded too so things being used more often take precedence.

If you think you have enough ram for all your needs then why not disable swap? I've read that there might be a speed penalty for running without swap but I've been running my system without swap (arch64 4G ram) and I've never had any bad surprises.

There are a few things that might prompt swap usage (don't quote me on that though, it just seems to me to be the case), if you copy many files from one place to the other the kernel will use all the ram available to try to cache them, if you copy many GB then all the ram will get filled (and maybe other things will get evicted to swap).

It's not a bug, free ram is there to be used, things that have been used/needed recently get to stay in the ram, other things can go to the swap, if you can cache a file that has been recently used and need to use it again shortly after then it's much faster if it is in the ram instead of having to read it again from the hard disk. The logic behind it is good, it's just that some corner cases may make behave badly.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#5 2009-12-29 15:17:47

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: High cache usage of free memory

It's much more likely to be an application fault (memory leak anyone?) than a 'system' fault.

@rookie
ahhh - beat me too it

Last edited by perbh (2009-12-29 15:19:43)

Offline

#6 2009-12-29 16:40:10

Anril
Member
Registered: 2009-12-29
Posts: 11

Re: High cache usage of free memory

Problem is:

I see 3.2gb of ram used from full 3.87Gb reported by system. Since i got no applycation running i concluded it must be cache. That would mean that if i start any applycation that will take another 1gb of Ram (for example) then some cache should be dropped to make enough room for applycation but that didnt happen, what happend is i saw swap space instantly got used and it should not.

Now iam trying to reproduce same thing and it seams kinda hard since i cant get system to use and cache 3.2Gb from 3.87Gb of total memory with no applycation running. Best i can get is 1.3 Gb atm.

I suspect it might be some applycation but its gona take a while before i find wich one is it, so i was wondering if there is a option to tune how much cache system should use or some rules on how to use it.

Offline

#7 2009-12-29 16:57:29

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: High cache usage of free memory

Just a thought but trying to tune how your system uses the cache is not such a good idea, you may be loosing in terms of responsiveness just to try to find out which application is not working properly, this is actually something that has been discussed a lot among the kernel developers I think.

If you have an app that is not working fine now, it may as well be updated in a few days and the update will solve the problem (you can try to downgrade some packages after you narrow down the possible culprits too).

You can try to fiddle with the swappiness value to try to keep as much as possible in the ram but I guess it's not the best solution.

All I can say is that it's normal for all ram to be used after a period of heavy usage, can't say much about swap usage because like I said before I don't have swap enabled, even with virtual machines running I usually have enough ram to keep the system running.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#8 2009-12-29 19:49:42

Anril
Member
Registered: 2009-12-29
Posts: 11

Re: High cache usage of free memory

Ok thx for help, ill will try to see witch applycation is making this. From what i see now i cant reproduce problem i had and my swap is not beeing used, so i guess it works fine smile. I will post if smething changes or i discover something new...

Last edited by Anril (2009-12-29 19:49:57)

Offline

#9 2009-12-30 12:00:51

Anril
Member
Registered: 2009-12-29
Posts: 11

Re: High cache usage of free memory

I just found out that deluge (torrent client) is the cause of this, it gradualy increases memory used over time untill it hits round 95% of total memory... Will try to see if it causes swap memory beeing used to in combination with other software, cause it does not consume swap memory on its own, witch means that caching works fine.

Offline

#10 2009-12-30 16:41:15

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: High cache usage of free memory

Deluge may not be to blame for that (if there is no nasty memory leak bug), it just reads and writes many files, therefore the kernel tries to keep the most used files in the ram for fast access (this means the ones deluge keeps reading and writing).

If deluge accesses a file 10 times in a minute while some other file is accessed only once every few minutes then the least used file may be evicted to the swap (this considering that it must be kept in the ram and can't be discarded and read back later).

The kernel is just trying to make good use of the ram you have, but like I've said before some corner cases may show some problems with the default scheme.


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#11 2009-12-31 01:46:59

Ranguvar
Member
Registered: 2008-08-12
Posts: 2,544

Re: High cache usage of free memory

If your swap is being used prematurely, you can control it with the /proc/sys/vm/swapiness knob.

40 is the default IIRC.  I have mine set to 1, because I way annoyed with it eating swap even when I have 6GiB of RAM available.  It probably shouldn't be set so low, but whatever tongue

/etc/sysctl.conf can set this permanently, with the line 'vm.swapiness = 1', but if you previously didn't know about that file, Google and learn about sysctl first.

Offline

Board footer

Powered by FluxBB