3

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.

2
  • 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, 2018 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, 2018 at 22:33

2 Answers 2

3

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.

4
  • 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, 2018 at 20:06
  • @thc Then you should ask the question accordingly, currently your question is "What's going on?".
    – mook765
    Jun 11, 2018 at 4:09
  • Alright, can you explain what is going on? Why does the file not exist?
    – thc
    Jun 11, 2018 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, 2018 at 6:35
1

[ Edited ]

As I promised before, I found a solution.



Install WSL 2

You need to install WSL 2, because WSL 1 does not support features like Systemd, and thus removal of buffer cache at runtime is not possible.



Install Ubuntu preview

Even if WSL2 is installed, the current versions of Ubuntu do not have Systemd support, so as a result Ubuntu preview must be installed.



RESULT

SystemD running

● DESKTOP-E8H5RD4
    State: running
    Units: 308 loaded (incl. loaded aliases)
     Jobs: 0 queued
   Failed: 0 units
    Since: Thu 2022-12-01 14:03:05 GMT; 1h 36min ago
  systemd: 251.4-1ubuntu7
  Tainted: cgroupsv1
   CGroup: /


Clearing chache

c_sharp_man@DESKTOP-E8H5RD4:/mnt/c/Windows/system32$ free
               total        used        free      shared  buff/cache   available
Mem:         7815484      484724     7191488        3352      139272     7128876
Swap:        2097152         268     2096884
c_sharp_man@DESKTOP-E8H5RD4:/mnt/c/Windows/system32$ sudo sh  -c  "echo 3 > /proc/sys/vm/drop_caches"
[sudo] password for c_sharp_man:
c_sharp_man@DESKTOP-E8H5RD4:/mnt/c/Windows/system32$ free
               total        used        free      shared  buff/cache   available
Mem:         7815484      486760     7192304        3352      136420     7128140
Swap:        2097152         268     2096884
c_sharp_man@DESKTOP-E8H5RD4:/mnt/c/Windows/system32$


Extra

If you want to personalize your Windows Terminal with custom startup banners, this post made by me will guide you step by step.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .