2

I'm running the following command to clear the cache:

$ sync; sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"
sh: 1: cannot create /proc/sys/vm/drop_caches: Operation not permitted

$ free
              total        used        free      shared  buff/cache   available
Mem:           7.9G        5.7G        2.0G         17M        230M        2.1G
Swap:           13G        445M         13G

So it is clearly not working as there is 230M in the cache. When I go to /proc/sys/vm/ there is no file called "drop_caches".

What is going on?

I'm using Ubuntu 16.04 through Windows Linux Subsystem.

| improve this question | | | | |
  • I deleted my answer as you say it doesn't work either. – muclux Jun 10 '18 at 8:36
  • The command you have posted should work as expected and the file /proc/sys/vm/drop_caches just does not exists. I guess this is more connected to being Windows Linux Subsystem . Explore your /proc/sys/vm directory to see which files exist. – Thomas Jun 10 '18 at 8:37
  • @Thomas here are the files in the folder: min_free_kbytes, overcommit_memory, swappiness. I think you are right that it's due to WSL -- I noticed also that the kernel is non-standard. Clearing the cache might have to be done on the windows side. – thc Jun 10 '18 at 22:33
2

You can't create a file even as root in /proc/sys/vm due to its permissions:

dr-xr-xr-x 1 root root 0 Jun  9 21:46 /proc/sys/vm

You can see that even root doesn't have write permissions which means that even root can't delete, rename or create files in this directory.

Existing files in /proc/sys/vm might be editable though if the file permissions itself are sufficient.

Files under /proc are provided by the kernel. Using WSL you don't use a Linux kernel but an emulation (lxss.sys, lxcore.sys). If a file under /proc does not exist it means it is not provided by the kernel or, in your case, the emulation.

| improve this answer | | | | |
  • I understand that the folder is special, but if you google "clear cache linux" this is the command that is explained over and over again. So I'm looking for an answer on how to clear the cache, fundamentally. – thc Jun 10 '18 at 20:06
  • @thc Then you should ask the question accordingly, currently your question is "What's going on?". – mook765 Jun 11 '18 at 4:09
  • Alright, can you explain what is going on? Why does the file not exist? – thc Jun 11 '18 at 5:53
  • The kernel emulation used by WSL doesn't support this feature so the file drop_caches is not created by the system in /proc/sys/vm/, see my edit in the answer. Seems you rely completely on the memory management provided by the Windows kernel and you have to manage memory using Windows tools. – mook765 Jun 11 '18 at 6:35

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.