LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Limit Disk Cache Size (https://www.linuxquestions.org/questions/linux-newbie-8/limit-disk-cache-size-4175479195/)

sysbox 10-01-2013 07:40 AM

Limit Disk Cache Size
 
My machine has 24 GB of memory and runs CentOS 6.4 64-bit. I'm having problems using /dev/shm. I think this is because the disk cache is filling up (see previous thread). I don't know how to fix it, but if I limit the disk cache size, then that's might work.

Does anyone know how to limit the size of the disk cache?

camorri 10-01-2013 08:45 AM

You can change the size of /dev/shm on the fly with a command like this :

Quote:

mount -o remount,size=40G /dev/shm
Make the size as you see fit. The default is half of your ram. If you have a swap file, and /dev/shm fills up, the kernel will swap some of it out to swap.

You can display what is in /dev/shm with a 'df' command.

sysbox 10-01-2013 09:09 AM

I don't want to change the size of /dev/shm. I want to change the size of the disk cache. Why? Because the disk cache is getting too large and that is taking space away from /dev/shm. That prevents me from being able to use /dev/shm (and it prevents other apps from using /dev/shm, and those apps are crashing).

How can I decrease the size of the disk cache?

Or, how can I prevent the disk cache taking space away from /dev/shm? I know that the disk cache is not supposed to take space away from other applications. Maybe this is true. But it is certainly taking space away from /dev/shm. So the disk cache is effectively taking memory space away from other applications. Thank you.

camorri 10-01-2013 10:16 AM

Quote:

How can I decrease the size of the disk cache?
Are you asking about memory cache ( ram ) or hard drive cache memory (swap)?

camorri 10-01-2013 10:36 AM

If its the buffers, and cache in memory, you may find this link useful.

-->http://www.unixmen.com/how-to-clear-...linux-servers/

sysbox 10-01-2013 10:45 AM

Quote:

Originally Posted by camorri (Post 5038020)
Are you asking about memory cache ( ram ) or hard drive cache memory (swap)?

I'm not sure (newbie). I'm asking about the cache which is reported in /proc/meminfo on the fourth line which begins with 'Cached:'. As this number grows, the available space I can use in /dev/shm decreases, and this causes my app (which uses /dev/shm for tmp files) to fail.

sysbox 10-01-2013 10:49 AM

Quote:

Originally Posted by camorri (Post 5038035)
If its the buffers, and cache in memory, you may find this link useful.

-->http://www.unixmen.com/how-to-clear-...linux-servers/

Yes, I think that will work for me. I will try it later. However, can you think of a reason why this cache isn't automatically free'ed as I copy files into /dev/shm? For 3 years, on this machine, this worked fine. But for some reason, about a month ago, the memory cache seems to be preventing me from using /dev/shm, and this is causing all sorts of problems. Could I have inadvertently changed something which altered this behavior?

camorri 10-01-2013 11:04 AM

Quote:

I'm asking about the cache which is reported in /proc/meminfo
That is what is in ram, not the hard drive. The sync command as indicated in post #5 can reduce the number of buffers and cache. BTW, you can see the buffers and cache dynamically with the top command.

There are parameters in the kernel config that have an affect on buffers and cache.

Quote:

Could I have inadvertently changed something which altered this behavior?
I believe a kernel upgrade could have had some effect on this. That would take some investigating.

I had a problem recently with /dev/shm in memory. I had problems compiling an application. The work around was to mount temp file space on a real hard drive partition, with adequate space. Once done, the app compiled. This is not an ideal solution for the long term though, since disk access is much slower than memory access.

sysbox 10-01-2013 11:23 AM

Okay, then forget disk cache. I think my issue is with the memory cache. The problem seems to be that when the memory cache gets close to the total size of physical memory, I can no longer use /dev/shm.

I did not upgrade the kernel recently, so that could not have caused this problem.

This problem started about a month ago about the time I configured a software RAID with mdadm. Is it possible I changed something that caused the memory cache to behavior differently? I looked at every file in the
/etc directory tree that changed during the past month. No files changed which had anything to do with the disk (other than possibly the mdadm config file).

Where would be a good place to look for answers to this? I really need to be able to use /dev/shm.

rknichols 10-01-2013 12:22 PM

You might try reducing swappiness to increase the kernel's preference for throwing away cache pages when there are demands for memory.

camorri 10-01-2013 12:23 PM

Quote:

This problem started about a month ago about the time I configured a software RAID with mdadm. Is it possible I changed something that caused the memory cache to behavior differently?
This is beyond my knowledge; unfortunately. However, if the problems started after configuring RAID, it looks like the best bet at this point.


All times are GMT -5. The time now is 09:11 AM.