Score:0

Limit linux cache memory

ru flag

I know that it is ok to have free memory close to 0 and all memory in cached

But it cause problem with an application

I need the server no to cache so much and release memory back to free

I tried doing it with sudo sysctl -w vm.vfs_cache_pressure=200

But it had no effect

I have centos 7.9 Linux 3.10.0-1160.49.1.el7.x86_64

              total        used        free        shared  buff/cache   available
Mem:           125G         77G         300M         21M         47G         47G
Swap:          8.0G          0B        8.0G
ng flag
I'm curious what *exact literal* problem you're trying to solve? Linux' is kind of dumb in that reading one/couple low priority big things will flush the important things out of cache, but that is cache vs cache. The cache that is in use should impact your applications.
Score:1
cn flag

Linux cannot be made to not cache. That memory is easy to reclaim, it is counted in available.

That host is not under severe memory pressure. If it were, there would be less available and it might start using swap.

Try measuring pressure stall information. This shows time processes actually spent waiting for memory (or cpu or io). If you are really under memory pressure, time spent faulting in or direct reclaim would increase the counter. Requires a later kernel than that unfortunately, maybe try out a newer kernel or a newer distro on a test system.

If you still feel like you need to do something, change the application to call posix_fadvise with advice of POSIX_FADV_DONTNEED on the file descriptors. Free files that will not be accessed again, because cache is hundreds to thousands of times faster than the underlying storage.

ru flag
I don't want not to cache at all but to return to the free after 30 min, my application is always writting files to disk and most of the time no one read it. I don't need this information to stay in the cache if no one use it.
John Mahowald avatar
cn flag
See my edit regarding posix_fadvise
ru flag
I used your advise, thank you !!!! But i still want to return memory to free after period time it hasn't been used
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.