summaryrefslogtreecommitdiff
path: root/src/oom/oomd-util.c
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2021-03-25 23:54:22 -0700
committerAnita Zhang <the.anitazha@gmail.com>2021-04-01 19:45:24 -0700
commit37d8020ccc2f54260b581af416e02294c7591cfc (patch)
tree1dd22af61b8b39fb5664b7e17e1cda1c2e2befc4 /src/oom/oomd-util.c
parent81d66fab342e112aefe8b5f43bc853ef66c92add (diff)
downloadsystemd-37d8020ccc2f54260b581af416e02294c7591cfc.tar.gz
oomd: refactor pgscan_rate calculation into helper
Diffstat (limited to 'src/oom/oomd-util.c')
-rw-r--r--src/oom/oomd-util.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/oom/oomd-util.c b/src/oom/oomd-util.c
index 894d23a83a..5133b1c060 100644
--- a/src/oom/oomd-util.c
+++ b/src/oom/oomd-util.c
@@ -134,6 +134,23 @@ bool oomd_memory_reclaim(Hashmap *h) {
return pgscan_of > last_pgscan_of;
}
+uint64_t oomd_pgscan_rate(const OomdCGroupContext *c) {
+ uint64_t last_pgscan;
+
+ assert(c);
+
+ /* If last_pgscan > pgscan, assume the cgroup was recreated and reset last_pgscan to zero.
+ * pgscan is monotonic and in practice should not decrease (except in the recreation case). */
+ last_pgscan = c->last_pgscan;
+ if (c->last_pgscan > c->pgscan) {
+ log_debug("Last pgscan %"PRIu64" greater than current pgscan %"PRIu64" for %s. Using last pgscan of zero.",
+ c->last_pgscan, c->pgscan, c->path);
+ last_pgscan = 0;
+ }
+
+ return c->pgscan - last_pgscan;
+}
+
bool oomd_swap_free_below(const OomdSystemContext *ctx, int threshold_permyriad) {
uint64_t swap_threshold;