Skip to content

Instantly share code, notes, and snippets.

@ringosham
Created December 17, 2020 23:23
Show Gist options
  • Save ringosham/b6d5083a38dabd7ada3891b68a91acec to your computer and use it in GitHub Desktop.
Save ringosham/b6d5083a38dabd7ada3891b68a91acec to your computer and use it in GitHub Desktop.
Manually clear WSL memory
#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