Is it possible to limit cache memory to a process?

Is it possible to limit cache memory to a process?

I am using network capture tool named dumpcap and it is consuming too much cache memory.

So other processes getting no memory to run.

htop command shown cache memory as 29 GB in Meters.

Can anyone help to get a solution for this ?

答案1

There is no problem, so you do not need to do anything.

The question is misunderstanding how system cache works. System cache does not occupy memory thereby preventing it being used by processes. It only occupies available memory. Once that memory is no longer available because a process has allocated it, it will no longer be used by the system cache.

The below is an edited form of an answer I made to a different question:

How Linux uses RAM (very simplified)

Each application can use some of your memory. Linux uses all otherwise unoccupied memory (except for the last few Mb) as "cache". This includes the page cache, inode caches, etc. This is a good thing - it helps speed things up heaps. Both writing to disk and reading from disk can be sped up immensely by cache.

Ideally, you have enough memory for all your applications, and you still have several hundred Mb left for cache. In this situation, as long as your applications don't increase their memory use and the system isn't putting too much pressure on the cache, there is no need for any swap.

Once applications claim more RAM, it simply goes into some of the space that was used by cache, shrinking the cache. De-allocating cache is cheap and easy enough that it is simply done in real time - everything that sits in the cache is either just a second copy of something that's already on disk, so can just be deallocated instantly, or it's something that we would have had to flush to disk within the next few seconds anyway, thus there is zero performance hit in re-allocating cache to applications.

So, when a tool refers to "free" RAM, you need to clarify whether it is including cache as "free" or not. Cache should be thought of as "free", even though tools such as ps and free do not include it in the "free" count.

This is not a situation that is specific to Linux - all modern operating systems work this way. The different operating systems might just report free RAM differently: some include the cache as part of what they consider "free" and some may not.

When you talk about free RAM, it's a lot more meaningful to include cache, because it practically is free - it's available should any application request it. On Linux, the free command reports it both ways - the first line includes cache in the used RAM column, and the second line includes cache (and buffers) in the free column.

相关内容