mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
oomd: new helper oomd_update_cgroup_contexts_between_hashmaps
This commit is contained in:
parent
301e7cd047
commit
b037a6da31
@ -413,6 +413,25 @@ int oomd_insert_cgroup_context(Hashmap *old_h, Hashmap *new_h, const char *path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void oomd_update_cgroup_contexts_between_hashmaps(Hashmap *old_h, Hashmap *curr_h) {
|
||||
OomdCGroupContext *ctx;
|
||||
|
||||
assert(old_h);
|
||||
assert(curr_h);
|
||||
|
||||
HASHMAP_FOREACH(ctx, curr_h) {
|
||||
OomdCGroupContext *old_ctx;
|
||||
|
||||
old_ctx = hashmap_get(old_h, ctx->path);
|
||||
if (!old_ctx)
|
||||
continue;
|
||||
|
||||
ctx->last_pgscan = old_ctx->pgscan;
|
||||
ctx->mem_pressure_limit = old_ctx->mem_pressure_limit;
|
||||
ctx->last_hit_mem_pressure_limit = old_ctx->last_hit_mem_pressure_limit;
|
||||
}
|
||||
}
|
||||
|
||||
void oomd_dump_swap_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const char *prefix) {
|
||||
char swap[FORMAT_BYTES_MAX];
|
||||
|
||||
|
@ -119,6 +119,9 @@ int oomd_system_context_acquire(const char *proc_swaps_path, OomdSystemContext *
|
||||
* was no prior data to reference. */
|
||||
int oomd_insert_cgroup_context(Hashmap *old_h, Hashmap *new_h, const char *path);
|
||||
|
||||
/* Update each OomdCGroupContext in `curr_h` with prior interval information from `old_h`. */
|
||||
void oomd_update_cgroup_contexts_between_hashmaps(Hashmap *old_h, Hashmap *curr_h);
|
||||
|
||||
void oomd_dump_swap_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const char *prefix);
|
||||
void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const char *prefix);
|
||||
void oomd_dump_system_context(const OomdSystemContext *ctx, FILE *f, const char *prefix);
|
||||
|
@ -176,6 +176,53 @@ static void test_oomd_cgroup_context_acquire_and_insert(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_oomd_update_cgroup_contexts_between_hashmaps(void) {
|
||||
_cleanup_hashmap_free_ Hashmap *h_old = NULL, *h_new = NULL;
|
||||
OomdCGroupContext *c_old, *c_new;
|
||||
char **paths = STRV_MAKE("/0.slice",
|
||||
"/1.slice");
|
||||
|
||||
OomdCGroupContext ctx_old[3] = {
|
||||
{ .path = paths[0],
|
||||
.mem_pressure_limit = 5,
|
||||
.last_hit_mem_pressure_limit = 777,
|
||||
.pgscan = 57 },
|
||||
{ .path = paths[1],
|
||||
.mem_pressure_limit = 6,
|
||||
.last_hit_mem_pressure_limit = 888,
|
||||
.pgscan = 42 },
|
||||
};
|
||||
|
||||
OomdCGroupContext ctx_new[3] = {
|
||||
{ .path = paths[0],
|
||||
.pgscan = 100 },
|
||||
{ .path = paths[1],
|
||||
.pgscan = 101 },
|
||||
};
|
||||
|
||||
assert_se(h_old = hashmap_new(&string_hash_ops));
|
||||
assert_se(hashmap_put(h_old, paths[0], &ctx_old[0]) >= 0);
|
||||
assert_se(hashmap_put(h_old, paths[1], &ctx_old[1]) >= 0);
|
||||
|
||||
assert_se(h_new = hashmap_new(&string_hash_ops));
|
||||
assert_se(hashmap_put(h_new, paths[0], &ctx_new[0]) >= 0);
|
||||
assert_se(hashmap_put(h_new, paths[1], &ctx_new[1]) >= 0);
|
||||
|
||||
oomd_update_cgroup_contexts_between_hashmaps(h_old, h_new);
|
||||
|
||||
assert_se(c_old = hashmap_get(h_old, "/0.slice"));
|
||||
assert_se(c_new = hashmap_get(h_new, "/0.slice"));
|
||||
assert_se(c_old->pgscan == c_new->last_pgscan);
|
||||
assert_se(c_old->mem_pressure_limit == c_new->mem_pressure_limit);
|
||||
assert_se(c_old->last_hit_mem_pressure_limit == c_new->last_hit_mem_pressure_limit);
|
||||
|
||||
assert_se(c_old = hashmap_get(h_old, "/1.slice"));
|
||||
assert_se(c_new = hashmap_get(h_new, "/1.slice"));
|
||||
assert_se(c_old->pgscan == c_new->last_pgscan);
|
||||
assert_se(c_old->mem_pressure_limit == c_new->mem_pressure_limit);
|
||||
assert_se(c_old->last_hit_mem_pressure_limit == c_new->last_hit_mem_pressure_limit);
|
||||
}
|
||||
|
||||
static void test_oomd_system_context_acquire(void) {
|
||||
_cleanup_(unlink_tempfilep) char path[] = "/oomdgetsysctxtestXXXXXX";
|
||||
OomdSystemContext ctx;
|
||||
@ -395,6 +442,7 @@ int main(void) {
|
||||
|
||||
test_setup_logging(LOG_DEBUG);
|
||||
|
||||
test_oomd_update_cgroup_contexts_between_hashmaps();
|
||||
test_oomd_system_context_acquire();
|
||||
test_oomd_pressure_above();
|
||||
test_oomd_memory_reclaim();
|
||||
|
Loading…
Reference in New Issue
Block a user