summaryrefslogtreecommitdiff
path: root/linux
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-03-31 12:50:09 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2021-03-31 13:04:34 -0400
commit98844616f65bee09eda791353a09b2d195f71270 (patch)
treea7d66d6b31f006d344b3d0f5f866e88bc74f457a /linux
parent40e14938eeebf74830c870a067cca0e8c73feed7 (diff)
If we failed to read /proc/meminfo, just run the shrinkers.
Diffstat (limited to 'linux')
-rw-r--r--linux/shrinker.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/linux/shrinker.c b/linux/shrinker.c
index 7926be06..f6c979aa 100644
--- a/linux/shrinker.c
+++ b/linux/shrinker.c
@@ -28,7 +28,6 @@ void unregister_shrinker(struct shrinker *shrinker)
struct meminfo {
u64 total;
u64 available;
-
};
static u64 parse_meminfo_line(const char *line)
@@ -50,7 +49,7 @@ static struct meminfo read_meminfo(void)
f = fopen("/proc/meminfo", "r");
if (!f)
- die("error opening /proc/meminfo: %m");
+ return ret;
while ((len = getline(&line, &n, f)) != -1) {
if ((v = strcmp_prefix(line, "MemTotal:")))
@@ -77,10 +76,18 @@ void run_shrinkers(void)
return;
info = read_meminfo();
- want_shrink = (info.total >> 2) - info.available;
- if (want_shrink <= 0)
- return;
+ if (info.total && info.available) {
+ want_shrink = (info.total >> 2) - info.available;
+
+ if (want_shrink <= 0)
+ return;
+ } else {
+ /* If we weren't able to read /proc/meminfo, we must be pretty
+ * low: */
+
+ want_shrink = 8 << 20;
+ }
mutex_lock(&shrinker_lock);
list_for_each_entry(shrinker, &shrinker_list, list) {