Author Topic: How Does One Reduce The System Cache Size?  (Read 9624 times)

Ragnorok

  • Sr. Member
  • ****
  • Posts: 296
    • View Profile
    • http://
How Does One Reduce The System Cache Size?
« on: April 17, 2006, 03:06:50 pm »
- If cache and free memory are counted together, I have about half of my memory "free", yet Cacko's memory applet often nudges into the yellow, and when I check, I see "free" is very low, about a meg, but there is always plenty of "cache".  Right now I have 5MB "free" and 25MB "cache".
- I'd like to tell the system to be more aggressive about reducing the "cache" part, so I'll have more "free" part.  I'd be much happier to see cache limited to about 10MB, just to see how the system responds with that, and have the rest be left as free RAM.  I'm not entirely convinced that it's freeing cache when it's low on memory, and I have a hard time believing it really needs 20MB of cache at all times.

- I'm thinking of trying this same thing on this FC4 desktop system.  It's got a paltry 256MB RAM, and uses RDRAM, so upgrading isn't really an option.  It shows a paltry 48MB free, and I don't like that, when top shows 122MB cached.  Seems to be a Linux trait.  (grin)

- Is cache size reduction possible?  If so, how does one go about it?  Thanks for your time...
| I shed a tear for the passing of Hiroshi; he served me well
| Zaurus zealot since Nov 2002, PDA user since Oct 1991
| Replaced Z with UMID BZ February 2010

JohnX

  • Full Member
  • ***
  • Posts: 126
    • View Profile
    • http://
How Does One Reduce The System Cache Size?
« Reply #1 on: April 18, 2006, 01:46:39 am »
Well, I read your comment and I was all set to come back and say "It's doing what it's supposed to be doing and you can't change it anyways, so don't worry about it," but then I did some reading.

For the Zaurus I can say with relative certainty that it really is freeing cache just fine exactly when it needs to. Linux is much more agressive about disk caching than other operating systems and it can make people used to other operating systems nervous to see so little memory marked as free. So, you really don't need to worry about it. The 2.6 kernel has some nice options for tuning the VM system through /proc/sys/vm/ , but 2.4 doesn't seem to have that kind of stuff exposed. If you're really concerned about it you might be able to do some basic tuning by looking at information on this page.

On your FC4 machine it's an entirely different case for two reasons:
1) The 2.6 kernel has all sorts of neat VM tuning parameters
2) The presence of swap
If you want less cache because you want to reduce how often it swaps out you can tune the "swappiness" value by doing:
Code: [Select]
echo 60 > /proc/sys/vm/swappinessInstead of 60 put different values between 0 and 100. At 0 the kernel will avoid swapping until it's really necessary. At 100 it will swap whenever it seems like a good idea to do so. Experiment however much you want since your settings will get put back to default (probably 60) when you reboot. The swappiness value is really a personal choice on a desktop.  Basically it's a tradeoff between having a nice big disk cache (start open office, close it, open it again and it shows up instantly since it was still in cache) and not having to hit swap too often. If you really just want to see a bigger number next to "free memory" there's another setting to change called min_free_kbytes. It sets how much memory the kernel will keep for itself. This is almost certainly not something you want to change unless you're having problems with things living in kernel space not being able to allocate memory. Like all settings in /proc however it goes away on reboot, so go crazy.
Code: [Select]
echo 8192 > /proc/sys/vm/min_free_kbytes
Anyways, my take on all this is that any memory that's called "free" might as well be called "wasted." Linux takes the same view on this and thus tries to do something useful (cache) with any memory that would otherwise just sit there unused.

-John
Zaurus SL-C1000 - Linux 2.6.22 - Angstrom/Debian dual boot - Ambicom 802.11b - 1GB Corsair SD
Nokia N800 - 2GB PQI SD card
Zaurus SL-5500 - OZ 3.5.3/Hentges T2/Opie - 64MB Lexar SD card

brashley46

  • Sr. Member
  • ****
  • Posts: 277
    • View Profile
    • http://brashley46.no-ip.info
How Does One Reduce The System Cache Size?
« Reply #2 on: April 18, 2006, 05:34:47 pm »
Quote
Well, I read your comment and I was all set to come back and say "It's doing what it's supposed to be doing and you can't change it anyways, so don't worry about it," but then I did some reading.

For the Zaurus I can say with relative certainty that it really is freeing cache just fine exactly when it needs to. Linux is much more agressive about disk caching than other operating systems and it can make people used to other operating systems nervous to see so little memory marked as free. So, you really don't need to worry about it. The 2.6 kernel has some nice options for tuning the VM system through /proc/sys/vm/ , but 2.4 doesn't seem to have that kind of stuff exposed. If you're really concerned about it you might be able to do some basic tuning by looking at information on this page.

On your FC4 machine it's an entirely different case for two reasons:
1) The 2.6 kernel has all sorts of neat VM tuning parameters
2) The presence of swap
If you want less cache because you want to reduce how often it swaps out you can tune the "swappiness" value by doing:
Code: [Select]
echo 60 > /proc/sys/vm/swappinessInstead of 60 put different values between 0 and 100. At 0 the kernel will avoid swapping until it's really necessary. At 100 it will swap whenever it seems like a good idea to do so. Experiment however much you want since your settings will get put back to default (probably 60) when you reboot. The swappiness value is really a personal choice on a desktop.  Basically it's a tradeoff between having a nice big disk cache (start open office, close it, open it again and it shows up instantly since it was still in cache) and not having to hit swap too often. If you really just want to see a bigger number next to "free memory" there's another setting to change called min_free_kbytes. It sets how much memory the kernel will keep for itself. This is almost certainly not something you want to change unless you're having problems with things living in kernel space not being able to allocate memory. Like all settings in /proc however it goes away on reboot, so go crazy.
Code: [Select]
echo 8192 > /proc/sys/vm/min_free_kbytes
Anyways, my take on all this is that any memory that's called "free" might as well be called "wasted." Linux takes the same view on this and thus tries to do something useful (cache) with any memory that would otherwise just sit there unused.

-John
[div align=\"right\"][a href=\"index.php?act=findpost&pid=123593\"][{POST_SNAPBACK}][/a][/div]

I'd have to say the same, there are XandrOS newbies over on their support forum worried about the same sort of thing on our desktops. All Linux systems seem to act this way; they'll show the memory available as in use, until you need it for something specific.
B. Ross Ashley
http://brashley46.livejournal.com
http://brashley46.no-ip.info
Home desktops: Hewlett-Packard Kayak XM600 running Xandros Desktop Home Edition Premium (4.1), on a P3 Coppermine processor w/ 20G harddrive, 256 MB RAM; Abyss X2 server running on a local shop-built special with Intel Celeron 1.8GHz processor, 40G harddrive running Win XP Home SP2; and my wife's eMac running OS X3.9

Handheld: C860 running CACkO 1.23, with a Panasonic Class 2 1G SD card and a GXT 1G CF card; AmbiCom WL1100C-CF wifi card, and a CE-AG06 camera card.

Ragnorok

  • Sr. Member
  • ****
  • Posts: 296
    • View Profile
    • http://
How Does One Reduce The System Cache Size?
« Reply #3 on: April 18, 2006, 05:53:24 pm »
- Here's the thing.  I'm using Hiro to read OESF, so I turn off all fastloading to keep the memory from "going yellow".  I read your post, JonhX, look at memory, under 30MB in use, nearly 27 cached, rest free or buffers.  So I fastload KDEPIM Calendar & Address, the two things I only ever have fastloaded.  Memory pops straight to yellow, yet the memory applet shows that nearly 21MB is cache.  If it's so aggresive about dumping cache, why do I have 21MB and a yellow memory condition?  I can't help but think it should be dumping like mad if it running low on RAM.  And it just sits there, utterly refusing to let go of even on byte of all that cache.

- I don't have a hard drive for swap, and just plain don't like the idea of using SD as swap, so swap is not currently an option, more's the pity.

- Maybe Opera is the culprit?  Even if it is, I'd think the sytem would toss out cache rather than let itself grind to a halt because there's too little memory.  I'd like to be able to indicate my preference.  (shrug)

- Or maybe the memory applet is hitting yellow when it's not really that dire?  I show yellow with over 5MB free, now that I've closed a couple of browser windows, yet it routinely shows green with 1 meg free when cache is larger.  Is 37MB in use really that serious with 20 MB in cache & 5MB free?  Perhaps I'm being paranoid?  I just know I see yellow there very frequently, and I don't like it.  (grin)

- Sounds like cache resizing is not readily doable.  I thought not, but it didn't hurt to ask.  I'll look for a little newer page on /proc and see what that turns up.  Thanks for your time...
| I shed a tear for the passing of Hiroshi; he served me well
| Zaurus zealot since Nov 2002, PDA user since Oct 1991
| Replaced Z with UMID BZ February 2010

lardman

  • Hero Member
  • *****
  • Posts: 4512
    • View Profile
    • http://people.bath.ac.uk/enpsgp/Zaurus/
How Does One Reduce The System Cache Size?
« Reply #4 on: April 19, 2006, 05:12:24 am »
Quote
I have a hard time believing it really needs 20MB of cache at all times

Cache is more useful than free memory in most situations, especially when there's lots of it (and therefore the code you might want is already in memory, so the cache freeing and memory loading overheads are removed.)

Quote
why do I have 21MB and a yellow memory condition?

You attach too much importance to the colour produced by an applet. Just ignore it, or alter the source so that it calculates the 'free' memory using free + cached.

Quote
Or maybe the memory applet is hitting yellow when it's not really that dire? I show yellow with over 5MB free, now that I've closed a couple of browser windows, yet it routinely shows green with 1 meg free when cache is larger. Is 37MB in use really that serious with 20 MB in cache & 5MB free? Perhaps I'm being paranoid? I just know I see yellow there very frequently, and I don't like it. (grin)

Sounds a bit strange. Might be worth looking at the source to see what it's actually measuring.


Si
C750 OZ3.5.4 (GPE, 2.6.x kernel)
SL5500 OZ3.5.4 (Opie)
Nokia 770
Serial GPS, WCF-12, Socket Ethernet & BT, Ratoc USB
WinXP, Mandriva

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
How Does One Reduce The System Cache Size?
« Reply #5 on: April 19, 2006, 06:18:11 am »
Quote
Quote
I have a hard time believing it really needs 20MB of cache at all times

Cache is more useful than free memory in most situations, especially when there's lots of it (and therefore the code you might want is already in memory, so the cache freeing and memory loading overheads are removed.)

Quote
why do I have 21MB and a yellow memory condition?

You attach too much importance to the colour produced by an applet. Just ignore it, or alter the source so that it calculates the 'free' memory using free + cached.

Quote
Or maybe the memory applet is hitting yellow when it's not really that dire? I show yellow with over 5MB free, now that I've closed a couple of browser windows, yet it routinely shows green with 1 meg free when cache is larger. Is 37MB in use really that serious with 20 MB in cache & 5MB free? Perhaps I'm being paranoid? I just know I see yellow there very frequently, and I don't like it. (grin)

Sounds a bit strange. Might be worth looking at the source to see what it's actually measuring.


Si
[div align=\"right\"][a href=\"index.php?act=findpost&pid=123743\"][{POST_SNAPBACK}][/a][/div]
or just enable swap and its always green
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

JohnX

  • Full Member
  • ***
  • Posts: 126
    • View Profile
    • http://
How Does One Reduce The System Cache Size?
« Reply #6 on: April 19, 2006, 01:35:27 pm »
"If it's so aggresive about dumping cache, why do I have 21MB and a yellow memory condition?  I can't help but think it should be dumping like mad if it running low on RAM."  

That's the opposite of what I said. Linux is aggressive about building cache up. Whenever there's even a couple megs of free memory Linux works to fill it up with cache. This cache will get emptied *exactly* when it's needed and not a moment sooner. If you have 1MB free memory and start Opera, Linux will figure out what in cache is least valuable and drop it as Opera requests memory to start up.

"Or maybe the memory applet is hitting yellow when it's not really that dire?  I show yellow with over 5MB free, now that I've closed a couple of browser windows, yet it routinely shows green with 1 meg free when cache is larger.  Is 37MB in use really that serious with 20 MB in cache & 5MB free?  Perhaps I'm being paranoid?  I just know I see yellow there very frequently, and I don't like it.  (grin)"

Bingo! Sounds like you're right on all counts. I'm willing to bet that the memory applet considers "free mem + cached mem" as "available" for determining when it should show as green or yellow. You really are just being paranoid.
Zaurus SL-C1000 - Linux 2.6.22 - Angstrom/Debian dual boot - Ambicom 802.11b - 1GB Corsair SD
Nokia N800 - 2GB PQI SD card
Zaurus SL-5500 - OZ 3.5.3/Hentges T2/Opie - 64MB Lexar SD card

Ragnorok

  • Sr. Member
  • ****
  • Posts: 296
    • View Profile
    • http://
How Does One Reduce The System Cache Size?
« Reply #7 on: April 26, 2006, 08:18:44 pm »
- D'oh!
- Been letting it "go yellow" more often, since this thread, and it doesn't seem to ba ahuge deal.  Even had 62MB in use at one point and Hiro pulled through.  Stellar!
- Thanks JohnX...
| I shed a tear for the passing of Hiroshi; he served me well
| Zaurus zealot since Nov 2002, PDA user since Oct 1991
| Replaced Z with UMID BZ February 2010