2

In our project we have a few tests which run for about 3-4 hours continuously. In due course, the tests fail as they couldn't find enough memory. On googling, I found that running the following command helps me to resume my tests:

sync; echo 3 > /proc/sys/vm/drop_caches

However, these are nightly tests and it would help us a great deal if we can run it without manual intervention.

I am just looking at the options to get this done.

I found a few links 1 and 2 which, from the looks of it could be useful.

I just wanted to know my other options before I could go ahead and update the cron tabs.

Is it ok to clean up cache periodically? Will it cause other issues?

Will increasing the RAM be helpful? What are my alternatives?

  • 1
    Cache are freed automatically when more memory is needed. I doubt that it will help. Try to identify what application is using the more of memory. Maybe some applications are over sized. Do you have swap on your system ? – Emmanuel Apr 28 '14 at 13:58
2

Will increasing the RAM be helpful?

Hard to say without knowing why your tests succeed after running those two commands (sync and drop_caches). TBH I don't think that dropping the filesystem cache is what's enabling your tests to work unless your tests are failing due to latency issues. When the kernel notices things dip below min_free_kbytes it starts evicting the oldest entries from the cache to get actually-free memory back to at least min_free_kbytes. The only exception to that process is for pages marked as "dirty". So the existence of a filesystem cache usually isn't an issue unless your applications are allocating memory faster than the kernel can locate entries to prune (in which case bumping up min_free_kbytes is in order).

The command that's probably doing the most for you is the sync command which is probably freeing memory dedicated to the buffers used for asyncronous disk I/O (as well removing dirty from all entries in the filesystem cache, making them candidates for eviction in low memory conditions).

I put the odds at about 80-90% that adding more RAM would be helpful, but I don't know what tests you're running so I can't say for sure.

Is it ok to clean up cache periodically? Will it cause other issues?

What you're doing here is basically performance tuning (or at least you're playing with tunables made available for that purpose). Tunables are usually made available when knowing the "right" answer in general is considered impossible/impractical. If it were possible to create general rules about how things ought to run, they would just make the software do that thing and would leave the sysadmin out of the question.

All that to say that we can't really say with absolute certainty that it won't cause problems for you. We can say it probably won't cause loss of functionality but we can't be certain. I would say that the filesystem cache is designed to improve performance so forcing applications to waiting on data to come in from disk whenever they read anything probably isn't desirable (though it could sometimes be undesirable but necessary).

EDIT:

Just read @Emmanuel's comment. He brings up a good point. If you have unused swap space, you might try increasing vm.swappiness to increase the kernel's preference to swap out the less-used application memory. If you need more swap space (or don't have any) you can find instructions online for creating swap partitions and swap files.

EDIT #2

I haven't played with this one, but looking at the kernel docs, there's a dirty_ratio sysctl tunable, that controls how much dirty data will be held in memory before the kernel does its own sync, you may try lowering that so that as few pages in the filesystem cache are marked "dirty" and thus can be evicted when the memory is needed.

  • Joel/Emmanuel, Thanks for the detailed explanation. To add a little more detail. We have 7.5G RAM, 4Core CPU VM running Suse Linux 11.2. These are selenium tests which uses a Java process. To understand the root cause, we broke the tests into 2-3 legs and ran them one after the other. The issue occurs frequently when there are a lot of file uploads happening. The rest of the things works just fine. We'll work with the options that you've given us. - Thanks. – Karthick R Apr 28 '14 at 16:40

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.