Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 2693  / 1 Year ago, mon, january 2, 2023, 1:13:02

My situation is pretty simple: I backup-ed some of my documents and put them on a NAS and since I rather transfer one big file instead of million small ones, I created a tar



tar cf backup/2013-07-12-pictures.tar Pictures


My Pictures directory contains about 12GB of data and what happens is, that my cache fills up steadily. If I tar some more files (e.g. my projects, whatever) it doesn't take long and all of my 32GB RAM are used:



sheldor:~$ free -g
total used free shared buffers cached
Mem: 31 31 0 0 0 27
-/+ buffers/cache: 2 28
Swap: 29 0 29


At this point, although the mouse and the system is in general responsible, starting programs (which reads from disk) takes ages. Literally ages: I have an SSD and starting Chrome which usually takes a second needs now about 2 minutes.



Now you find all those posts on the internet about that it is bad to clear the cache and so on. Here, on Ask Ubuntu you find such a post too which saved my life by providing the command



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


If you read through the comments, you find for instance this here:




This is not a problem, this is how the page cache works. It will keep things cached as long as possible, but release items automatically when memory pressure from other applications increases. Clearing it up manually is unnecessary. – Caesium Nov 22 '11 at 16:08




What? My system (Intel Core i7 3.50GHz × 8, 32GB RAM, NVidia Gtx 590) was frozen after a simple tar. I mean, how much pressure do I have to make before my cache is freed automatically?



Question: Is there a way to tweak settings so my cache gets cleared more often? Or is this just something I have to live with?


More From » cache

 Answers
4

I agree that cache handling in Linux is far from optimal. In fact, in many regards Linux still feels more optimized for server/workstation use than desktop use. See this Q&A for a similar problem with CPU/IO-scheduling.



With that said, there are solutions out there that can alleviate the problem. You can manually clear the cache or set up a cronjob, like user197590 pointed out. Another method would be to disable cache generation for specific applications. You can do so with the nocache utility. At the moment it's only available in the 13.10 repos but I was able to install the Saucy package on 12.04 without any problems.



nocache is fairly straightforward to use. You prepend it to any command you want to execute without cache, e.g.:



nocache tar cf backup/2013-07-12-pictures.tar Pictures



It's not a causal solution but it can most definitely cure the symptoms of overzealous caching.


[#30348] Monday, January 2, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
riffnkful

Total Points: 390
Total Questions: 123
Total Answers: 110

Location: Puerto Rico
Member since Sat, Mar 13, 2021
3 Years ago
;