Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
limit swap caching
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
timblech
Tux's lil' helper
Tux's lil' helper


Joined: 28 Oct 2003
Posts: 89

PostPosted: Sat Jan 21, 2006 3:10 pm    Post subject: limit swap caching Reply with quote

hi all,

on my system, most of my memory is used by caching the swap space in physical memory:
Code:

laptop tim # free
             total       used       free     shared    buffers     cached
Mem:        904372     891480      12892          0          8     503848
-/+ buffers/cache:     387624     516748
Swap:       506036     181900     324136


this is ok for most application, but i use some applications that have to allocate from the free physical memory, so i'd like to reduce the swap caching (maybe from unlimited to 200mb) ...

is there any way to tweak the swap caching?

thanks ... t
Back to top
View user's profile Send private message
chunderbunny
Veteran
Veteran


Joined: 31 May 2004
Posts: 1281
Location: 51°24'27" N, 0°57'15" W

PostPosted: Sat Jan 21, 2006 6:39 pm    Post subject: Reply with quote

I'm not sure exactly what you mean, but are you saying you want your system to use swap space less often? Swap is never cached in physical memory, the whole point of swap space is to cache the physical memeory, not the other way around. What is cached in physical memory is stuff that is on your hard disk, applications, libraries etc. The kernel can free this up instantly if it needs to, so it is not considered part of the used RAM. If an application suddenly needs an extra 100MB of RAM then the kernel will just dump 100MB of disk cache to make room.

Having said that, if you do want to alter the amount of swap space the kernel uses you can alter the /proc/sys/vm/swappiness file. It contains a number between 0 and 100, 0 means "never use swap ever" and 100 means "use swap as much as possible". The default value is 60. This file is recreated on reboot, so you will need to stick a command in /etc/conf.d/local.start or in your crontab if you want it to be set all the time.
Back to top
View user's profile Send private message
timblech
Tux's lil' helper
Tux's lil' helper


Joined: 28 Oct 2003
Posts: 89

PostPosted: Sat Jan 21, 2006 7:23 pm    Post subject: Reply with quote

yes, i'm familiar with the swappiness, but i'm concerned about the "cached 503848" of the free output ...

it has nothing to do with swapping, but with the caching of the swapping ...

cheers ... tim
Back to top
View user's profile Send private message
SinoTech
Advocate
Advocate


Joined: 20 Mar 2004
Posts: 2579
Location: Neunkirchen / Saarland / Germany

PostPosted: Sat Jan 21, 2006 7:43 pm    Post subject: Reply with quote

timblech wrote:
yes, i'm familiar with the swappiness, but i'm concerned about the "cached 503848" of the free output ...

it has nothing to do with swapping, but with the caching of the swapping ...

cheers ... tim

As chunderbunny said, you can't cache swap.
Linux first tries to use your memory as good as it can, and at a last step it starts swapping (Moving not needed data from memory to your harddrive). You can change that behaviour a little bit using swappiness (See post above). But what's the advantage if linux starts swapping earlier? In both situations you've got the same data loaded. In case of swapping, alot of data must be stored and reloaded on your hard drive, which is slower as your ram. If your system doesn't swap (or as less as possible) it has all the data in memory and doesn't need to reload data from your slow hard drive.
Regards,

Sino
Back to top
View user's profile Send private message
timblech
Tux's lil' helper
Tux's lil' helper


Joined: 28 Oct 2003
Posts: 89

PostPosted: Sat Jan 21, 2006 8:00 pm    Post subject: Reply with quote

Quote:
Linux first tries to use your memory as good as it can, and at a last step it starts swapping (Moving not needed data from memory to your harddrive). You can change that behaviour a little bit using swappiness (See post above). But what's the advantage if linux starts swapping earlier? In both situations you've got the same data loaded. In case of swapping, alot of data must be stored and reloaded on your hard drive, which is slower as your ram. If your system doesn't swap (or as less as possible) it has all the data in memory and doesn't need to reload data from your slow hard drive.


well, then it might be another problem ... as you seem to be familiar with linux-mm, can you explain me the following:

free has the following output:
Code:
             total       used       free     shared    buffers     cached
Mem:        904372     878380      25992          0          0     216096


what's the meaning of "cached"? from my understanding the vm caches the swap pages in physical memory before writing them to disk (which is basically fine) ... but my free memory is "free" + "cached" ...
now, when i allocate several hundred mb of ram, and force it to the physical ram with mlock, i have a problem, because the "cached" memory can't be allocated fast enough ...

how do i limit the size of the "cached" memory?

thanks ... tim
Back to top
View user's profile Send private message
SinoTech
Advocate
Advocate


Joined: 20 Mar 2004
Posts: 2579
Location: Neunkirchen / Saarland / Germany

PostPosted: Sat Jan 21, 2006 9:01 pm    Post subject: Reply with quote

Never used "free" and never tries to understand it. But think "cached" means the size of data currently stored in memory which is NOT used by an running process (Data which could also be swapped), but since you've got enough memory it is still kept in memory (For linux there's no reason to write that data to swap). Now when allocating hundred megabytes of ram, linux recognize it must swap unnneded data to your hard drive and then starts to do that. Sure, if swapping from the beginning you could allocate memory alot faster, but linux doesn't know that you will run an application which needs hundred memgabytes of ram at once, and so it starts swapping only if needed. If you want to tell inux to start swapping earlier, use the swappiness method mentioned above.
So here's my summary:
Swapping early
- Kept your memory free and so you can allocate much memory very fast
- Can slow down applications since linux needs often to reload data from swap

Don't swapping (or less as possible)
- Don't decrease the speed of your applications since reloading of data from swap isn't needed
- Slow down applications if they allocate a huge amount of memory which isn't currently available (So linux must write alot of data to swap first)

Anyway, it could also be possible that I am wrong with all my statements here (Not sure if they are all correct), so tell me if I am wrong.
Regards,

Sino
Back to top
View user's profile Send private message
Gentoo_freak
n00b
n00b


Joined: 07 Oct 2005
Posts: 10

PostPosted: Tue Feb 07, 2006 4:49 pm    Post subject: Reply with quote

[quote="timblech"]
Quote:


how do i limit the size of the "cached" memory?

thanks ... tim


the same problem/ question
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum