Created
December 17, 2020 23:23
-
-
Save ringosham/b6d5083a38dabd7ada3891b68a91acec to your computer and use it in GitHub Desktop.
Manually clear WSL memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
// Must be run as root | |
// To build: | |
// cc lxgc.c -o lxgc | |
int write(const char *path) { | |
FILE *fp; | |
fp = fopen(path, "w"); | |
int response = fputs("1", fp); | |
fclose(fp); | |
return response; | |
} | |
int main() { | |
printf("Compressing memory...\n"); | |
if (write("/proc/sys/vm/compact_memory") < 0) { | |
printf("Memory compression failed\n"); | |
return 1; | |
} | |
printf("Freeing memory by dropping cache...\n"); | |
if (write("/proc/sys/vm/drop_caches") < 0) { | |
printf("Cache dropping failed\n"); | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment