4

I have a laptop running ubuntu 16.04 with 4gb ram. I've been using it for about a month now and recently I noticed that the system slows down a lot even with only 3-4 apps running. This is the output of free -m with a terminal and gedit open.

       total        used        free      shared      buff/cache   available
Mem:    3872         797         842        1971            2232         848
Swap:   4015         141        3874

You can see that the available memory is less than cached memory. Shouldn't cached memory be included in available memory? The problem is, when I open some other application, the cached memory size increases instead of giving space to the new app! Here's the output of 'free -m' after opening firefox, document viewer and vscode.

              total        used        free      shared  buff/cache   available
Mem:           3872        1391         145        1923        2335         299
Swap:          4015         250        3765

sudo sync; echo 3>'/proc/sys/vm/drop_cache' doesn't help much.

              total        used        free      shared  buff/cache   available
Mem:           3872        1368         239        1923        2265         324
Swap:          4015         256        3759

It turns out I can't even open 5 applications on Ubuntu simultaneously. It seems like the 2265mb memory has just leaked out. It's more than half of my physical ram! What can I do about it?

  • ok heres the thing, in 16.04 its a bit odd to read, hold on lemme post a answer – patrick Aug 15 '16 at 8:23
  • Possibly relevant: linuxatemyram.com. – edwinksl Aug 15 '16 at 8:25
  • Yes I've read it. – saga Aug 15 '16 at 8:29
1

If you want to calculate your free memory try this

(it will print it in MB's)

make a script in bash add these

mem1=$( free | sed 'N;s/\n/ /;N;s/\n/ /' | awk '{ print $8 }' | awk '{ total = $1 / 1024 ; print total }' | sed 'N;s/\n/ /;N;s/\n/ /' | awk '{ print $1}' )
mem2c=$( free | sed 'N;s/\n/ /;N;s/\n/ /' | awk '{ print $10}' | awk '{ total = $1 / 1024 ; print total }' | sed 'N;s/\n/ /;N;s/\n/ /' | awk '{ print $1}' )
mem3=$( free | sed 'N;s/\n/ /;N;s/\n/ /' | awk '{ print $9}' | awk '{ total = $1 / 1024 ; print total }' | sed 'N;s/\n/ /;N;s/\n/ /' | awk '{ print $1}' )
mem2f=$( free | sed 'N;s/\n/ /;N;s/\n/ /' | awk '{ print $12}' | awk '{ total = $1 / 1024 ; print total }' | sed 'N;s/\n/ /;N;s/\n/ /' | awk '{ print $1}')
mem2=$(awk "BEGIN {print $mem2c+$mem2f; exit}")

then just do this

echo "$mem1 / $mem3 / $mem2"

source: my own code :)

https://github.com/ppigmans/Tool-box

  • It printed two backslashes separated by spaces. – saga Aug 15 '16 at 8:46
  • It printed two backslashes separated by spaces. – saga Aug 15 '16 at 8:46
  • odd it works for me, ok try this in the terminal – patrick Aug 15 '16 at 8:48
  • ok when I manually calculated it you have 798 MB in use, I did this in 16.04 you need to add up the free memory and the buffers/cache memory and retract that from the total memory – patrick Aug 15 '16 at 8:53
  • 3872.89 / 890.988 / 2982.3 – saga Aug 15 '16 at 8:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.