Lines Matching refs:ctx

61 OomdCGroupContext *oomd_cgroup_context_free(OomdCGroupContext *ctx) {  in oomd_cgroup_context_free()  argument
62 if (!ctx) in oomd_cgroup_context_free()
65 free(ctx->path); in oomd_cgroup_context_free()
66 return mfree(ctx); in oomd_cgroup_context_free()
71 OomdCGroupContext *ctx; in oomd_pressure_above() local
82 HASHMAP_FOREACH_KEY(ctx, key, h) { in oomd_pressure_above()
83 if (ctx->memory_pressure.avg10 > ctx->mem_pressure_limit) { in oomd_pressure_above()
86 if (ctx->mem_pressure_limit_hit_start == 0) in oomd_pressure_above()
87 ctx->mem_pressure_limit_hit_start = now(CLOCK_MONOTONIC); in oomd_pressure_above()
89 diff = now(CLOCK_MONOTONIC) - ctx->mem_pressure_limit_hit_start; in oomd_pressure_above()
91 r = set_put(targets, ctx); in oomd_pressure_above()
96 ctx->mem_pressure_limit_hit_start = 0; in oomd_pressure_above()
125 bool oomd_mem_available_below(const OomdSystemContext *ctx, int threshold_permyriad) { in oomd_mem_available_below() argument
128 assert(ctx); in oomd_mem_available_below()
131 mem_threshold = ctx->mem_total * threshold_permyriad / (uint64_t) 10000; in oomd_mem_available_below()
132 return LESS_BY(ctx->mem_total, ctx->mem_used) < mem_threshold; in oomd_mem_available_below()
135 bool oomd_swap_free_below(const OomdSystemContext *ctx, int threshold_permyriad) { in oomd_swap_free_below() argument
138 assert(ctx); in oomd_swap_free_below()
141 swap_threshold = ctx->swap_total * threshold_permyriad / (uint64_t) 10000; in oomd_swap_free_below()
142 return (ctx->swap_total - ctx->swap_used) < swap_threshold; in oomd_swap_free_below()
223 typedef void (*dump_candidate_func)(const OomdCGroupContext *ctx, FILE *f, const char *prefix);
334 _cleanup_(oomd_cgroup_context_freep) OomdCGroupContext *ctx = NULL; in oomd_cgroup_context_acquire()
343 ctx = new0(OomdCGroupContext, 1); in oomd_cgroup_context_acquire()
344 if (!ctx) in oomd_cgroup_context_acquire()
348 ctx->preference = MANAGED_OOM_PREFERENCE_NONE; in oomd_cgroup_context_acquire()
354 r = read_resource_pressure(p, PRESSURE_TYPE_FULL, &ctx->memory_pressure); in oomd_cgroup_context_acquire()
367 ctx->preference = r == 1 ? MANAGED_OOM_PREFERENCE_AVOID : ctx->preference; in oomd_cgroup_context_acquire()
372 ctx->preference = r == 1 ? MANAGED_OOM_PREFERENCE_OMIT : ctx->preference; in oomd_cgroup_context_acquire()
376 r = procfs_memory_get_used(&ctx->current_memory_usage); in oomd_cgroup_context_acquire()
380 …et_attribute_as_uint64(SYSTEMD_CGROUP_CONTROLLER, path, "memory.current", &ctx->current_memory_usa… in oomd_cgroup_context_acquire()
384 … r = cg_get_attribute_as_uint64(SYSTEMD_CGROUP_CONTROLLER, path, "memory.min", &ctx->memory_min); in oomd_cgroup_context_acquire()
388 … r = cg_get_attribute_as_uint64(SYSTEMD_CGROUP_CONTROLLER, path, "memory.low", &ctx->memory_low); in oomd_cgroup_context_acquire()
392 …_get_attribute_as_uint64(SYSTEMD_CGROUP_CONTROLLER, path, "memory.swap.current", &ctx->swap_usage); in oomd_cgroup_context_acquire()
404 r = safe_atou64(val, &ctx->pgscan); in oomd_cgroup_context_acquire()
409 ctx->path = strdup(empty_to_root(path)); in oomd_cgroup_context_acquire()
410 if (!ctx->path) in oomd_cgroup_context_acquire()
413 *ret = TAKE_PTR(ctx); in oomd_cgroup_context_acquire()
420 OomdSystemContext ctx = {}; in oomd_system_context_acquire() local
451 r = convert_meminfo_value_to_uint64_bytes(word, &ctx.mem_total); in oomd_system_context_acquire()
457 r = convert_meminfo_value_to_uint64_bytes(word, &ctx.swap_total); in oomd_system_context_acquire()
474 if (mem_available > ctx.mem_total) in oomd_system_context_acquire()
478 ctx.mem_total); in oomd_system_context_acquire()
480 if (swap_free > ctx.swap_total) in oomd_system_context_acquire()
484 ctx.swap_total); in oomd_system_context_acquire()
486 ctx.mem_used = ctx.mem_total - mem_available; in oomd_system_context_acquire()
487 ctx.swap_used = ctx.swap_total - swap_free; in oomd_system_context_acquire()
489 *ret = ctx; in oomd_system_context_acquire()
529 OomdCGroupContext *ctx; in oomd_update_cgroup_contexts_between_hashmaps() local
534 HASHMAP_FOREACH(ctx, curr_h) { in oomd_update_cgroup_contexts_between_hashmaps()
537 old_ctx = hashmap_get(old_h, ctx->path); in oomd_update_cgroup_contexts_between_hashmaps()
541 ctx->last_pgscan = old_ctx->pgscan; in oomd_update_cgroup_contexts_between_hashmaps()
542 ctx->mem_pressure_limit = old_ctx->mem_pressure_limit; in oomd_update_cgroup_contexts_between_hashmaps()
543 ctx->mem_pressure_limit_hit_start = old_ctx->mem_pressure_limit_hit_start; in oomd_update_cgroup_contexts_between_hashmaps()
544 ctx->last_had_mem_reclaim = old_ctx->last_had_mem_reclaim; in oomd_update_cgroup_contexts_between_hashmaps()
546 if (oomd_pgscan_rate(ctx) > 0) in oomd_update_cgroup_contexts_between_hashmaps()
547 ctx->last_had_mem_reclaim = now(CLOCK_MONOTONIC); in oomd_update_cgroup_contexts_between_hashmaps()
551 void oomd_dump_swap_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const char *prefix) { in oomd_dump_swap_cgroup_context() argument
552 assert(ctx); in oomd_dump_swap_cgroup_context()
555 if (!empty_or_root(ctx->path)) in oomd_dump_swap_cgroup_context()
559 strempty(prefix), ctx->path, in oomd_dump_swap_cgroup_context()
560 strempty(prefix), FORMAT_BYTES(ctx->swap_usage)); in oomd_dump_swap_cgroup_context()
565 strempty(prefix), ctx->path, in oomd_dump_swap_cgroup_context()
569 void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE *f, const char *pr… in oomd_dump_memory_pressure_cgroup_context() argument
570 assert(ctx); in oomd_dump_memory_pressure_cgroup_context()
578 strempty(prefix), ctx->path, in oomd_dump_memory_pressure_cgroup_context()
579 …strempty(prefix), LOADAVG_INT_SIDE(ctx->mem_pressure_limit), LOADAVG_DECIMAL_SIDE(ctx->mem_pressur… in oomd_dump_memory_pressure_cgroup_context()
581 … LOADAVG_INT_SIDE(ctx->memory_pressure.avg10), LOADAVG_DECIMAL_SIDE(ctx->memory_pressure.avg10), in oomd_dump_memory_pressure_cgroup_context()
582 … LOADAVG_INT_SIDE(ctx->memory_pressure.avg60), LOADAVG_DECIMAL_SIDE(ctx->memory_pressure.avg60), in oomd_dump_memory_pressure_cgroup_context()
583 … LOADAVG_INT_SIDE(ctx->memory_pressure.avg300), LOADAVG_DECIMAL_SIDE(ctx->memory_pressure.avg300), in oomd_dump_memory_pressure_cgroup_context()
584 FORMAT_TIMESPAN(ctx->memory_pressure.total, USEC_PER_SEC), in oomd_dump_memory_pressure_cgroup_context()
585 strempty(prefix), FORMAT_BYTES(ctx->current_memory_usage)); in oomd_dump_memory_pressure_cgroup_context()
587 if (!empty_or_root(ctx->path)) in oomd_dump_memory_pressure_cgroup_context()
593 strempty(prefix), FORMAT_BYTES_CGROUP_PROTECTION(ctx->memory_min), in oomd_dump_memory_pressure_cgroup_context()
594 strempty(prefix), FORMAT_BYTES_CGROUP_PROTECTION(ctx->memory_low), in oomd_dump_memory_pressure_cgroup_context()
595 strempty(prefix), ctx->pgscan, in oomd_dump_memory_pressure_cgroup_context()
596 strempty(prefix), ctx->last_pgscan); in oomd_dump_memory_pressure_cgroup_context()
599 void oomd_dump_system_context(const OomdSystemContext *ctx, FILE *f, const char *prefix) { in oomd_dump_system_context() argument
600 assert(ctx); in oomd_dump_system_context()
607 FORMAT_BYTES(ctx->mem_used), in oomd_dump_system_context()
608 FORMAT_BYTES(ctx->mem_total), in oomd_dump_system_context()
610 FORMAT_BYTES(ctx->swap_used), in oomd_dump_system_context()
611 FORMAT_BYTES(ctx->swap_total)); in oomd_dump_system_context()