]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - linux/shrinker.c
Update bcachefs sources to dbee44d5ab bcachefs: add bcachefs xxhash support
[bcachefs-tools-debian] / linux / shrinker.c
index b8fc2464e20f55781349ca769fe73082beea5556..f6c979aa6ae1bf751139ad604c3e56ead7cc777f 100644 (file)
@@ -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:")))
@@ -69,12 +68,27 @@ static struct meminfo read_meminfo(void)
 void run_shrinkers(void)
 {
        struct shrinker *shrinker;
-       struct meminfo info = read_meminfo();
-       s64 want_shrink = (info.total >> 2) - info.available;
+       struct meminfo info;
+       s64 want_shrink;
 
-       if (want_shrink <= 0)
+       /* Fast out if there are no shrinkers to run. */
+       if (list_empty(&shrinker_list))
                return;
 
+       info = read_meminfo();
+
+       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) {
                struct shrink_control sc = {