Explanation for command to drop cache

Good morning, i need your help please

Ina production System, linux server was Reported performance issues, our system admin refers as memory

Here the command:

free -m

This is the output, but id like to know if those values are given in GB, for instance Mem

16047= 16 GB? and 15566=15 GB used? and cahche 8 GB ?

             total       used       free     shared    buffers     cached
Mem:         16047      15566        481          0        621       7970
-/+ buffers/cache:       6974       9073
Swap:        16002          0      16001

If so i dont see any any performance related to memory right?

but after a while they appiled this command, so i would like to know what i does:

sudo sync && sudo sysctl -w vm.drop_caches=3

afterward memory was released and they report the application is normal, so

             total       used       free     shared    buffers     cached
Mem:         16047       6600       9447          0         11        218
-/+ buffers/cache:       6369       9678
Swap:        16002          0      16001

So i came up with these questions:
1 Cache was Released to memory, so if cache had 8 GB is not good for Performance? bcz when aplying drop cache the number was reduced to 218 and they report the application was OK

2 I need a short explanation for the command

sudo sync && sudo sysctl -w vm.drop_caches=3

3 when to decide and why should apply this command? and when no to ?

I appreciate your help in advanced

Hi @alexcol,

  • In the command free -m "m" stands for megabytes, so I think that answers your very first question
  • I do not see any performance issue related to memory either
  1. I do not think it makes a positive difference. Cache would be released immediately when needed by the application. So the command did not free up available memory.
  2. It means commit any outstanding writes to disk and clear caches and buffers
  3. In my opinion never, I think issuing the command did not help. I think whoever issued the command was not fully aware how to interpret the output of the free -m command.

If there are genuine performance problems, then this action will not have solved it. I would have a good look at other factors, which could for example involve maybe tuning the application to use more memory, or make better use of it or optimize disk or network performance. Those are just examples of what might be the matter of course, it is impossible to tell since that information is not available here.

@alexcol

I assume you are talking about a modern Linux operating system?

If so, as @Scrutinizer mentioned, the Linux kernel is very good a memory management and memory allocated to caches will generally be reallocated to the apps by the Linux kernel as required.

Many years ago I used to fiddle around with the Linux system vars about cache memory management; however my experience was that this was a waste of time and effort because the modern Linux kernel is mature and does this task very well and very efficiently.

If your apps need more memory and there is no available "free memory" then the Linux kernel will, generally speaking, reallocate from the "cache and buffers" allocation as required.

Hope this helps.

Thank you both of you for your explanation and suggestions, by the way answering about a modern Linux operating system

there are 2 servers (A cluster) but dont know if they are so much modern Linux operating systems:

[nps@producci01c ~]$ uname -a
Linux producci01c.acme.com 2.6.18-164.15.1.el5 #1 SMP Mon Mar 1 10:56:08 EST 2010 x86_64 x86_64 x86_64 GNU/Linux
[nps@producci02c ~]$ uname -a
Linux producci02c.acme.com 2.6.18-164.15.1.el5 #1 SMP Mon Mar 1 10:56:08 EST 2010 x86_64 x86_64 x86_64 GNU/Linux
[nps@producci02c ~]$

2 According what NEO says:
If your apps need more memory and there is no available "free memory" then the Linux kernel will, generally speaking, reallocate from the "cache and buffers" allocation as required.

How can i evidence it using the free command? or what is the pespective of issuing memory problems with another command? bcz in the perspective of user reports performance issues with enqueued requests, most of processes are java and some of them use weblogic

[nps@producci01c ~]$ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu|head
  PID  PPID CMD                         %MEM %CPU
11959     1 /opt/softw/jdk1.6.0_18/bin/ 15.7  2.9
23229     1 /opt/java/bin/java -server   5.0  2.0
10485     1 /opt/softw/jdk1.6.0_18/bin/  6.3  1.9
15158     1 bpbkar -r 5356800 -dt 0 -to  0.0  1.0
  515     1 /opt/java/bin/java -server   3.8  1.0
10595     1 /opt/softw/jdk1.6.0_18/bin/  2.6  0.7
23244     1 /opt/java/bin/java -server   1.4  0.4
11130 11126 /opt/java/bin/java -Dapp.ho  0.8  0.4
 4543     1 /opt/java/bin/java -server   1.0  0.4

I appreciate your help in advanced

Linux free command is not as intuitive as one could wish if one looks at it for the first time.

Look for example here for an explanation of the different numbers:

The first free output shows that you are using only 7 GB of RAM of a total of 16 GB. So there seems to be no physical memory shortage seen by this output.

As you stated there are Java-Applications on the server in question, know that Java-Applications get fixed RAM-Limits assigned when they are starting up. So if those limits are too low, the java applications get problems. It maybe too that the applications have memory leaks so they end up using all assigned memory and when all that memory is used the application is getting into trouble. To figure out this kind of problem you need some Java Application Server Memory Monitoring. There should be some options to do that, depending on what Application Servers you are using.

You may look for a line like this in an init script of the Java-Application Server, to figure out the configured memory limits:

CATALINA_OPTS="-Xms4096m -Xmx4096m -XX:+UseG1GC ${CATALINA_OPTS}"

See here for an explanation of those values:

I must say that we go the opposite way and try to fill cache. We have a job that reads the most important large files occasionally in case they are seen as too old in memory and dropped automatically. Using memory is good and the OS will drop the oldest pages when it needs to (or swap them if the processes are still live) but generally servers run with memory full so they still just have things hanging about just in case. It is not a memory full problem unless you start using swap

One other thing could be if you have pinned memory. Oracle databases (and probably other things) require some pinned memory and it is easy to get the instance configuration wrong and exhaust your machine. Setting them too high can cripple your server, however still I see no swap, so it's probably not that. I just thought I shoud mention it for completeness.

I hope that this helps,
Robin

Good evening, I want to thank each and everyone for your time,suggestions, explanations and useful links u sent me, they are very useful

i came up with these to finish this thread;

1 It is not a memory full problem unless you start using swap
how do i realize the application is swapping or using swap? the swap number is changing frequently?

2 bcz i have no knowlede and experience it is not clear for me the Java Application Server Memory Monitoring
its a thirthy party software like jconsole or jmeter googling at internet?
it sounds a programatic isuue bcz i found sth related to heap memory,GC and so on

3 In the example;

CATALINA_OPTS="-Xms4096m -Xmx4096m -XX:+UseG1GC ${CATALINA_OPTS}"

If java application reaches 4 GB used memory described in Xmx4096m parameter there will be a memory problem?

Thank for your help in advanced

Application issue, not operating system lacking memory.

Creating enormous arrays filling up JVM memory, by parsing files or doing DB selects.
GC kicks in, stuff pauses for a moment, bad loops still running memory hungry, stuff pauses even more.
Until that (bad) code finishes, services and users notice 'bad performance'.

Solution is to either optimize the code or add more memory to JVM to accomodate requirment.

When did this started happening, any new java code pushed recently ?

Hope that helps
Regards
Peasant.

Good evening, thanks you once again for your help

Answering your question, there was not any new java code pushed recently

The only change management made is both applications servers increased their RAM from 16 GB to 48 GB, how can i tune the Java Application to make use the best of this memory?

which a bunch of java processes running on each server how do i identify the application config file to be to set up?

Thanks for your help in advanced