# cached memory

## pakjebakmeel

When you see the title you probably go "O boy, another user asking why linux used all the RAM" but actually the opposite is the case. I would like to know how I can get gentoo to use more memory for cache, I have 8GB RAM and after a full boot gentoo uses only 250MB or so.

After starting every imaginable application on the machine a "free -m" shows:

```

             total       used       free     shared    buffers     cached

Mem:          7940       1745       6195          0        119       1110

-/+ buffers/cache:        516       7424

Swap:          511          0        511

```

I cannot get the system to cache more then 1110MB and have plenty left. Does this mean that the system doesn't have anything to cache anymore? I cannot image as starting firefox is not lightning fast. I have had a look around but I couldn't find anything regarding this.

I have however installed preload and added it to the default runlevel but when I check the logfile in /var/log/preload it is completely empty. I cannot get my system to use the excess memory for what it is intended..

heeeelp, gentoo doesn't use enough resources! (bit of a weird complaint.)

----------

## Jaglover

Excess (superabundance) is the correct word probably. You think your car will drive faster if you add four (eight, sixteen ...) more wheels? There were times when adding more powerful CPU and more RAM always made sense. These times are over, for good.

----------

## pakjebakmeel

 *Jaglover wrote:*   

> Excess (superabundance) is the correct word probably. You think your car will drive faster if you add four (eight, sixteen ...) more wheels? There were times when adding more powerful CPU and more RAM always made sense. These times are over, for good.

 

Thanks for your anwser, I understand what you are saying but I don't agree. If I start firefox it loads into memory, but when I close it apparently it doesn't leave it there as it has to load it from disk yet AGAIN when I start it after closing it. As I have plenty of memory left, why doesn't it just leave it in memory for the next time I need it?   :Question: 

The point I'm making is that it could cache more then it's currently doing. Of course if my RAM would be bigger then my HDD ofcourse it would be overkill as I wouldn't have enough data to fill my memory. But if my RAM is smaller then my HDD why can't it fill it with cache? I've got data, cache it!

----------

## roarinelk

try this:

echo 0 > /proc/sys/vm/swappiness

echo 0 > /proc/sys/vm/vfs_cache_pressure

and cat every file in /usr/{bin,lib}  :)

----------

## pigeon768

 *Jaglover wrote:*   

> Excess (superabundance) is the correct word probably. You think your car will drive faster if you add four (eight, sixteen ...) more wheels? There were times when adding more powerful CPU and more RAM always made sense. These times are over, for good.

  He's not wondering why his car doesn't go faster when he adds more wheels, he's wondering why those wheels don't touch the ground when he adds them.

Why shouldn't linux cache every single thing it reads off the disk?

This questions actually gets asked kind of a lot. I don't think I've ever seen a satisfactory answer to it.

----------

## pakjebakmeel

 *pigeon768 wrote:*   

>  *Jaglover wrote:*   Excess (superabundance) is the correct word probably. You think your car will drive faster if you add four (eight, sixteen ...) more wheels? There were times when adding more powerful CPU and more RAM always made sense. These times are over, for good.  He's not wondering why his car doesn't go faster when he adds more wheels, he's wondering why those wheels don't touch the ground when he adds them.
> 
> Why shouldn't linux cache every single thing it reads off the disk?
> 
> This questions actually gets asked kind of a lot. I don't think I've ever seen a satisfactory answer to it.

 

Well yes, I think Jaglover got a point, just adding more power doesn't get always get you better results. But this is not a very state of the art i7 machine or anything, it just has 8GB of RAM. But regardless of how fast a machine is, doing things more efficient should speed stuff up.

I've seen some nice car equations so let's follow along:

"Why stop along the route to check the map if I could have had a look at it at the last time we stopped for fuel"

This would; regardless of drive a Ferrari 599 GTO or a Reliant Robin make the process more efficient and thus the whole takes less time. In my gentoo case, why does it load a whole bunch of stuff off the disk when I start firefox if I've already started it before during that session!? I've got, as you said an abundance of memory. Just leave the darn files in memory so you don't have to load them again.

I'm not saying that linux should cache every single file we ever touch until the memory is full but I think it would definitely make sense to cache a program such as firefox as it:

a) takes roughly 3 to 5 seconds to start

b) gets started multiple times almost every session

c) i have loads of memory (that fits this very purpose) left.

----------

## pigeon768

The reason firefox takes forever to start up isn't because it's not cached or because it has to read the executable from /usr. The reason firefox takes forever to start up because it does a tremendous amount of work when it starts up. Among other things, it checks whether there are updates to your plugins and whether there are updates to firefox itself via the internet.

----------

## pakjebakmeel

 *pigeon768 wrote:*   

> The reason firefox takes forever to start up isn't because it's not cached or because it has to read the executable from /usr. The reason firefox takes forever to start up because it does a tremendous amount of work when it starts up. Among other things, it checks whether there are updates to your plugins and whether there are updates to firefox itself via the internet.

 

So what you are sayin is that I don't have enough apps or gentoo is too memory efficient to use a large portion of my memory?

I mean, if I look at the memory stats on my windows 7 machine it says:

total: 3976

cached: 1802

available: 1998

free:250

So this caches a lot more and firefox (for instance seems to start a lot faster. This is what I would expect linux to do too, that machines caches nearly 2GB with a couple of progs running. OSX does the same..

Ofcourse gentoo is very light-weight etc but I'm not sure whether it is using the memory as efficient as it could..

----------

## pigeon768

 *pakjebakmeel wrote:*   

> So this caches a lot more and firefox (for instance seems to start a lot faster.

  firefox is a 47kB executable, with about 30MB of libraries. It is cached, but it does not use a significant amount of RAM.

The 'problem' is that linux, gentoo especially, doesn't have shitloads of bloat. Windows 7 has gigabytes of crap in its cache because Windows 7 is gigabytes of crap. If you want to, you can do 'find /usr/bin/ /usr/lib/ -xdev -type f -exec cat '{}' \; > /dev/null' and it will load every file in /usr/bin/ and /usr/lib/ and keep it in cache until you run out of RAM.

----------

## Hu

Even if Firefox starts faster on Windows than on Gentoo, that does not necessarily mean there is a problem with the Linux kernel on your system.  Although Windows Firefox and Linux Firefox look similar and are branded the same, they may be different versions and they are definitely built differently.

----------

