# Where has my memory gone?

## sponge

I noticed that around half of my memory (1024MB total, about 600MB used) was being used. So I aborted X and did a `cat /proc/meminfo` and `ps aux` (attached), and still only had 334MB of RAM free, yet the only processes registering as using any significant amount of RAM were bash with .1% and cups with .2%. This should equal about 3 MB.

Essentially, this all started after I updated world, which included a GCC and mplayer update.

Where has all that memory gone? Am I metering memory the wrong way? And if possible, how do I free that memory?

ps aux:

```
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

root         1  0.0  0.0   1528   532 ?        S    00:19   0:00 init [3]  

root         2  0.0  0.0      0     0 ?        SN   00:19   0:00 [ksoftirqd/0]

root         3  0.0  0.0      0     0 ?        S<   00:19   0:00 [events/0]

root         4  0.0  0.0      0     0 ?        S<   00:19   0:00 [khelper]

root         5  0.0  0.0      0     0 ?        S<   00:19   0:00 [kthread]

root         8  0.0  0.0      0     0 ?        S<   00:19   0:00 [kacpid]

root         7  0.0  0.0      0     0 ?        S<   00:19   0:01 [vesafb]

root        80  0.0  0.0      0     0 ?        S<   00:19   0:00 [kblockd/0]

root       135  0.0  0.0      0     0 ?        S    00:19   0:00 [pdflush]

root        83  0.0  0.0      0     0 ?        S    00:19   0:00 [khubd]

root       136  0.0  0.0      0     0 ?        S    00:19   0:00 [kswapd0]

root       137  0.0  0.0      0     0 ?        S<   00:19   0:00 [aio/0]

root       733  0.0  0.0      0     0 ?        S    00:19   0:00 [kseriod]

root       816  0.0  0.0      0     0 ?        S<   00:20   0:00 [reiserfs/0]

root       874  0.0  0.0   1532   508 ?        S<s  00:20   0:00 udevd

root      7156  0.0  0.0   1544   516 ?        Ss   00:20   0:00 /sbin/dhcpcd -h billdesk -N -o -m 0 -c /lib/rcscripts/net.modules.d/helpers.d/dhcpcd-wrapper -e /var/lib/net-scripts/state/eth0 eth0

root      7330  0.0  0.0   2092   644 ?        Ss   00:20   0:00 metalog [MASTER]                                            

root      7331  0.0  0.0   1708   556 ?        S    00:20   0:00 metalog [KERNEL]                                            

root      7452  0.0  0.2   5856  2764 ?        Ss   00:20   0:00 /usr/sbin/cupsd

root      7927  0.0  0.0   1752   712 ?        Ss   00:20   0:00 /usr/sbin/cron

bill      8150  0.0  0.1   2716  1480 tty1     Ss   00:20   0:00 -bash

root      8153  0.0  0.0   1672   720 tty2     Ss+  00:20   0:00 /sbin/agetty 38400 tty2 linux

root      8154  0.0  0.0   1668   716 tty3     Ss+  00:20   0:00 /sbin/agetty 38400 tty3 linux

root      8155  0.0  0.0   1672   720 tty4     Ss+  00:20   0:00 /sbin/agetty 38400 tty4 linux

root      8156  0.0  0.0   1668   716 tty5     Ss+  00:20   0:00 /sbin/agetty 38400 tty5 linux

root      8157  0.0  0.0   1672   720 tty6     Ss+  00:20   0:00 /sbin/agetty 38400 tty6 linux

root     32453  0.0  0.0      0     0 ?        S    03:20   0:01 [pdflush]

bill      7169  0.0  0.0   2660   876 tty1     R+   14:19   0:00 ps aux
```

cat /proc/meminfo:

```
MemTotal:      1035012 kB

MemFree:        342932 kB

Buffers:        222336 kB

Cached:         353972 kB

SwapCached:          0 kB

Active:         396264 kB

Inactive:       182836 kB

HighTotal:      131056 kB

HighFree:        52740 kB

LowTotal:       903956 kB

LowFree:        290192 kB

SwapTotal:     2008084 kB

SwapFree:      2007888 kB

Dirty:              12 kB

Writeback:           0 kB

Mapped:           4956 kB

Slab:           102776 kB

CommitLimit:   2525588 kB

Committed_AS:     7528 kB

PageTables:        176 kB

VmallocTotal:   114680 kB

VmallocUsed:     11912 kB

VmallocChunk:    99796 kB
```

----------

## Naib

 *sponge wrote:*   

> 
> 
> cat /proc/meminfo:
> 
> ```
> ...

 

This is a trap that ppl not knowing the guts of Linux fall into.

Basically you still have your memory it is just the Linux kernel is "smart" enough to realise that the most efficient space for it to store infomation is in RAM, thus it will try to use all of your RAM up. 

Every time you load a program it first must be coppied to RAM (CPU's can only execute from RAM->CACHE) now when you finish using that program the Linux kernel will leave all the libary data in RAM. Why?

Lets say you started Firefox, browsed and then quit it. The first time you load FF it takes some seconds as it loads the data to RAM. However, the 2nd time all that data is already in RAM so it loads almost instantly.

in short

MemTotal:      1035012 kB

MemFree:        342932 kB

Buffers:        222336 kB

Cached:         353972 kB

The key here is Cached memory which you have 350MEg's of, plus 340meg of free memory so essentually you have 690Meg of free RAM.

IF you need more RAM then the linux kernel has in its MemFree section it will start to unload stuff from teh Cached mem to enable that memory to be used

so dont worry its still all there

----------

## sponge

Thanks for the informative reply.  :Smile: 

Is there any way to clear the cache?

----------

## lightvhawk0

you could try playing with /proc/sys/vm/swappiness

but personally i think it's better to have all that ram cached so that programs that have already ran are run from ram... and not waiting on the hard disk..

----------

## -NoXy-

hm, the thing is : what do u need that memory for ?

quick way to check the cached mem : 

free -m

anyway that memory is released if needed.

----------

## neuron

free -m is not accurate with newer kernels, - buffers/cache I'm using 279 mb now, but if I launch a memory hungry app, remove it from memory and check again it'll be considerably lower.

----------

## sponge

 *-NoXy- wrote:*   

> hm, the thing is : what do u need that memory for ?
> 
> quick way to check the cached mem : 
> 
> free -m
> ...

 I just annoys me that my SystemMonitor adesklet displays that I'm using ridiculous amounts of memory while web browsing.

I suppose I'll just fix the adesklet to subtract the cached memory from total used.

----------

## arokh

 *sponge wrote:*   

> 
> 
> I just annoys me that my SystemMonitor adesklet displays that I'm using ridiculous amounts of memory while web browsing.
> 
> I suppose I'll just fix the adesklet to subtract the cached memory from total used.

 

A monitor should subtract the cache by default or at least have the option to, showing free memory is useless.

----------

