summaryrefslogtreecommitdiff
path: root/linux/shrinker.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-10-09 23:27:41 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2022-10-10 00:10:45 -0400
commit72add8822c47e5801d4ac6d42af8c5d9d7b4d3c9 (patch)
tree9e4c08aa14105b9d3c88116291b326352aec6065 /linux/shrinker.c
parent8d6138baac3b4fcd715c34cf325ae11b01a4ca67 (diff)
Update bcachefs sources to 47ffed9fad bcachefs: bch2_btree_delete_range_trans() now uses peek_upto()
Diffstat (limited to 'linux/shrinker.c')
-rw-r--r--linux/shrinker.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/linux/shrinker.c b/linux/shrinker.c
index 13f0c4b..25cdfbb 100644
--- a/linux/shrinker.c
+++ b/linux/shrinker.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <linux/list.h>
+#include <linux/mm.h>
#include <linux/mutex.h>
#include <linux/shrinker.h>
@@ -39,30 +40,29 @@ static u64 parse_meminfo_line(const char *line)
return v << 10;
}
-static struct meminfo read_meminfo(void)
+void si_meminfo(struct sysinfo *val)
{
- struct meminfo ret = { 0 };
size_t len, n = 0;
char *line = NULL;
const char *v;
FILE *f;
+ memset(val, 0, sizeof(*val));
+
f = fopen("/proc/meminfo", "r");
if (!f)
- return ret;
+ return;
while ((len = getline(&line, &n, f)) != -1) {
if ((v = strcmp_prefix(line, "MemTotal:")))
- ret.total = parse_meminfo_line(v);
+ val->totalram = parse_meminfo_line(v);
if ((v = strcmp_prefix(line, "MemAvailable:")))
- ret.available = parse_meminfo_line(v);
+ val->freeram = parse_meminfo_line(v);
}
fclose(f);
free(line);
-
- return ret;
}
static void run_shrinkers_allocation_failed(gfp_t gfp_mask)
@@ -85,7 +85,7 @@ static void run_shrinkers_allocation_failed(gfp_t gfp_mask)
void run_shrinkers(gfp_t gfp_mask, bool allocation_failed)
{
struct shrinker *shrinker;
- struct meminfo info;
+ struct sysinfo info;
s64 want_shrink;
/* Fast out if there are no shrinkers to run. */
@@ -97,10 +97,10 @@ void run_shrinkers(gfp_t gfp_mask, bool allocation_failed)
return;
}
- info = read_meminfo();
+ si_meminfo(&info);
- if (info.total && info.available) {
- want_shrink = (info.total >> 2) - info.available;
+ if (info.totalram && info.freeram) {
+ want_shrink = (info.totalram >> 2) - info.freeram;
if (want_shrink <= 0)
return;