From patchwork Mon Jul 22 23:55:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Finkel X-Patchwork-Id: 13739230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00F20C3DA5D for ; Mon, 22 Jul 2024 23:56:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 507AC6B0083; Mon, 22 Jul 2024 19:56:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B44E6B0088; Mon, 22 Jul 2024 19:56:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B8D66B0089; Mon, 22 Jul 2024 19:56:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 094A26B0083 for ; Mon, 22 Jul 2024 19:56:05 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9E235A61F8 for ; Mon, 22 Jul 2024 23:56:04 +0000 (UTC) X-FDA: 82369049448.07.9BE8214 Received: from m47-110.mailgun.net (m47-110.mailgun.net [69.72.47.110]) by imf15.hostedemail.com (Postfix) with ESMTP id B781DA0002 for ; Mon, 22 Jul 2024 23:56:02 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=relay.vimeo.com header.s=mailo header.b="l/fzxvjy"; dmarc=pass (policy=reject) header.from=vimeo.com; spf=pass (imf15.hostedemail.com: domain of "bounce+ea57f2.9d2a1c-linux-mm=kvack.org@relay.vimeo.com" designates 69.72.47.110 as permitted sender) smtp.mailfrom="bounce+ea57f2.9d2a1c-linux-mm=kvack.org@relay.vimeo.com" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721692511; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Pi1c2hEp2R8PWovebVZMYFE85iEPioP8TIooUVBrJtk=; b=TEN49Qam+oI4VvU45Tz/dp1YtRAHBdzFPMPXnwiZSeIYGrFpZa4qLH69Qn0rkhtmqNQOEK eSngk8TCMsTPQynhJKxSmB/Ud9Jk8HLB0ANa5qH2PVS1pyLpDdE5BQz0Z/zv23r/VNq/43 bsSQB0j6sRx+xIWem3Q2ajToj8SDxKM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721692511; a=rsa-sha256; cv=none; b=lAESD0TbnVtnMpywuUYsfByTcZgu6KzgLFcNw1XTZNlMmjxVBHiH2/FAgJ8imY+ykQRYTR MFtLWxB/eNaJorXQCkeL/fS1MV2XZeFs5fVUxYsx94Xe8RNzA1Co0LeWqXiP6HLD1XRDMU 1degaylM0bcBoUEivAaQ8wshtuTFWY0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=relay.vimeo.com header.s=mailo header.b="l/fzxvjy"; dmarc=pass (policy=reject) header.from=vimeo.com; spf=pass (imf15.hostedemail.com: domain of "bounce+ea57f2.9d2a1c-linux-mm=kvack.org@relay.vimeo.com" designates 69.72.47.110 as permitted sender) smtp.mailfrom="bounce+ea57f2.9d2a1c-linux-mm=kvack.org@relay.vimeo.com" DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=relay.vimeo.com; q=dns/txt; s=mailo; t=1721692561; x=1721699761; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-Id: Date: Subject: Subject: Cc: To: To: From: From: Sender: Sender; bh=Pi1c2hEp2R8PWovebVZMYFE85iEPioP8TIooUVBrJtk=; b=l/fzxvjyNtDKVRJU3Ia6XxcPTT9MYkMFNuq05eFZMYBhXbdVj7lZQZk9dJD1UE+hlcn7b4j4448Y5E5gss0PY310pceQBovJZ2UdO3bu0CzklhCSthrBvMzZ6up1+xX9J2BwTUNcHjDRAQwmpLUkI4EZyDV/myRLo4N9w6Eg4q8= X-Mailgun-Sending-Ip: 69.72.47.110 X-Mailgun-Sid: WyI5NTRmYiIsImxpbnV4LW1tQGt2YWNrLm9yZyIsIjlkMmExYyJd Received: from smtp.vimeo.com (215.71.185.35.bc.googleusercontent.com [35.185.71.215]) by 59065f94d682 with SMTP id 669ef1911c3b766f41f09f7d (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Mon, 22 Jul 2024 23:56:01 GMT Received: from nutau (gke-sre-us-east1-main-c45160e0-2rrj.c.vimeo-core.internal [10.56.27.206]) by smtp.vimeo.com (Postfix) with ESMTP id 9950264D5F; Mon, 22 Jul 2024 23:56:00 +0000 (UTC) Received: by nutau (Postfix, from userid 1001) id 68B3EB4117E; Mon, 22 Jul 2024 19:56:00 -0400 (EDT) From: David Finkel To: Muchun Song , Tejun Heo , Roman Gushchin , Andrew Morton Cc: core-services@vimeo.com, Jonathan Corbet , Michal Hocko , Shakeel Butt , Shuah Khan , Johannes Weiner , Zefan Li , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, David Finkel , Waiman Long Subject: [PATCH 1/2] mm, memcg: cg2 memory{.swap,}.peak write handlers Date: Mon, 22 Jul 2024 19:55:53 -0400 Message-Id: <20240722235554.2911971-2-davidf@vimeo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240722235554.2911971-1-davidf@vimeo.com> References: <20240722235554.2911971-1-davidf@vimeo.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B781DA0002 X-Stat-Signature: rmut9fpxi46gfwe7oq99drtyug94hxbo X-Rspam-User: X-HE-Tag: 1721692562-193012 X-HE-Meta: U2FsdGVkX1+ztvlLHojQNkLsyOpriOzPYl2BqPZ9SwgGcZ7KKjHMtzgcgyoaQ+U1Dx5Ahvzbk+cje0BWtSFxIKNhLSXylwJqJ/7gSyhOi36boFMROwIyWFADkRNg864LLIUm63D/MeFvsI9r/JWgPf/tE9/k/6utiknaLR0BrZjrOy6YcKzX1d76HpLplbnUD7AZ5uNTc/BkOMPb7aMttFMx/LZCB+nDFcbwCcs9vrOB/ni8r2qd4Dast7WOBYe9IOeYC+zMiVEI/Brmol0WUQwEPS8DE3qwO2oPUb3PieoLC2FwAOA4fsBfcy4LJ3FKhEoGbpZ6P1/3L6H32Fr132ainkbvyzrcnB5ewept4NvUb9wt0o78gy8J2mVhMAafE5dvcSzmr/bMA7XHjmch65wPslkc3VpM9N9LkG8iw4zlFc7H5GcK+MAKEQHLUqqNAxpankDks+/x1ufqhLJAIzE3l5KuyoZHPk9wFrWx0Es8iJTdsa9Eb5AuYyYgCw2QLM1tFir1B6Xjt2UGbxqcIfWX6R3cWsOi9v7hHBpsHP8X8F5W/bz1N0I56B+4o+30lTK60vIai8aBCw/woWxKVNl/e6edhm9qwRxrRLRJZl+UbgAoC7+br0GMKfw6T/BPeq9RvQ1BxtMfYadbQg9ZhAP1vCmiKG+nNooMvIRi7Lv0hHer1/gvC1W4brE6J2vIL32RISB+uha5u+bbypnf+EKpNGw/cJefVZG01pic88JS11IFFSrhxopMc9H8JtOE0hfqBV6+jmotKONuG7/IbSiNbw0hgDU7J9c/TloQMfFDDwNdoQIpEiL/s6flS0Bu3vW7Qpe3vfnxgen49Bd+OYjCvLpT7YYpGuuK/9G/4NcOWoImZ2elQ/xCveeFVec74/1S7Dxf4OlGCqtPPZze/8TqJnHgppEEVFjmjPUOzIDfBRQDFpv3RduC6kkvk/MfaWw73d37R9mvoRYLr4f fKwKVw8g /AWXaF+GUcNE2a8++QPMESYJumABAaqUVZ8Czkh9rJBKHPgI0j1k26WO/uYsCE3ES1QttrT4KwZozF4TK2moc0IvAz4CAgWw38c5x9HTv62jgyiI+SxFAs+0saSMNWl6J1m9pqNuzwYMtomHL1wnzjJnCyadWzirsukCbYvbT0nWcG64sElcrAF/vNoNrWLHwi7ylJoqWdZnYgsf3Kg4IylFZMtYRW5q7LOhjie1wbKbzh3mPMkcv1xQBCep1jUKqS+A9s95nL3wSNl+Zy4Z5zbZVONh8dYG1SlF1h8800xueC8C2ZrsO4nDgwoaCE2sMa00rjlaxNHrMrC52IANSwpK2LNdnjhX9C0EdCGTqrPOFYPzyflVYvTFqEQFDkRHGW/O8Jdvrjb+64rRnMaGJ/nmNGmsa9Wt7YdRtdawYWewb7p6Xvx1bNM0o5pBlsISJZMwLFsbKL8SrB4EW/cNzu8jPzsD7DGMtwdujKmBaL0fyR+XlwDzkWRqao4CxMFwxjXhqWrmyfIhr4W2NsYViQW3xPeEt9ct/oDxNhjYac4c9gw8hMYEA28Ws0s3GQayDRBko X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Other mechanisms for querying the peak memory usage of either a process or v1 memory cgroup allow for resetting the high watermark. Restore parity with those mechanisms, but with a less racy API. For example: - Any write to memory.max_usage_in_bytes in a cgroup v1 mount resets the high watermark. - writing "5" to the clear_refs pseudo-file in a processes's proc directory resets the peak RSS. This change is an evolution of a previous patch, which mostly copied the cgroup v1 behavior, however, there were concerns about races/ownership issues with a global reset, so instead this change makes the reset filedescriptor-local. Writing a specific string to the memory.peak and memory.swap.peak pseudo-files reset the high watermark to the current usage for subsequent reads through that same fd. Notably, following Johannes's suggestion, this implementation moves the O(fds that have written) behavior onto the fd write(2) path. Instead, on the page-allocation path, we simply add one additional watermark to conditionally bump per-hierarchy level in the page-counter. Additionally, this takes Longman's suggestion of nesting the page-charging-path checks for the two watermarks to reduce the number of common-case comparisons. This behavior is particularly useful for work scheduling systems that need to track memory usage of worker processes/cgroups per-work-item. Since memory can't be squeezed like CPU can (the OOM-killer has opinions), these systems need to track the peak memory usage to compute system/container fullness when binpacking workitems. Most notably, Vimeo's use-case involves a system that's doing global binpacking across many Kubernetes pods/containers, and while we can use PSI for some local decisions about overload, we strive to avoid packing workloads too tightly in the first place. To facilitate this, we track the peak memory usage. However, since we run with long-lived workers (to amortize startup costs) we need a way to track the high watermark while a work-item is executing. Polling runs the risk of missing short spikes that last for timescales below the polling interval, and peak memory tracking at the cgroup level is otherwise perfect for this use-case. As this data is used to ensure that binpacked work ends up with sufficient headroom, this use-case mostly avoids the inaccuracies surrounding reclaimable memory. Suggested-by: Johannes Weiner Suggested-by: Waiman Long Signed-off-by: David Finkel --- Documentation/admin-guide/cgroup-v2.rst | 26 ++-- include/linux/cgroup.h | 8 ++ include/linux/memcontrol.h | 5 + include/linux/page_counter.h | 11 +- kernel/cgroup/cgroup-internal.h | 2 + kernel/cgroup/cgroup.c | 7 + mm/memcontrol.c | 129 +++++++++++++++++-- mm/page_counter.c | 36 +++++- tools/testing/selftests/cgroup/cgroup_util.c | 22 ++++ tools/testing/selftests/cgroup/cgroup_util.h | 2 + 10 files changed, 225 insertions(+), 23 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 8fbb0519d556..8dd68e07d13d 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1322,11 +1322,16 @@ PAGE_SIZE multiple when read back. reclaim induced by memory.reclaim. memory.peak - A read-only single value file which exists on non-root - cgroups. + A read-write single value file which exists on non-root cgroups. + + The max memory usage recorded for the cgroup and its descendants since + either the creation of the cgroup or the most recent reset for that FD. - The max memory usage recorded for the cgroup and its - descendants since the creation of the cgroup. + A write of the string "reset" to this file resets it to the + current memory usage for subsequent reads through the same + file descriptor. + Attempts to write any other non-empty string will return EINVAL + (modulo leading and trailing whitespace). memory.oom.group A read-write single value file which exists on non-root @@ -1652,11 +1657,16 @@ PAGE_SIZE multiple when read back. Healthy workloads are not expected to reach this limit. memory.swap.peak - A read-only single value file which exists on non-root - cgroups. + A read-write single value file which exists on non-root cgroups. + + The max swap usage recorded for the cgroup and its descendants since + the creation of the cgroup or the most recent reset for that FD. - The max swap usage recorded for the cgroup and its - descendants since the creation of the cgroup. + A write of the string "reset" to this file resets it to the + current memory usage for subsequent reads through the same + file descriptor. + Attempts to write any other non-empty string will return EINVAL + (modulo leading and trailing whitespace). memory.swap.max A read-write single value file which exists on non-root diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 2150ca60394b..7001ed74e339 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -855,4 +856,11 @@ static inline void cgroup_bpf_put(struct cgroup *cgrp) {} struct cgroup *task_get_cgroup1(struct task_struct *tsk, int hierarchy_id); +struct memcg_peak_mem_ctx { + long local_watermark; + struct list_head peers; +}; + +struct memcg_peak_mem_ctx *memcg_extract_peak_mem_ctx(struct kernfs_open_file *of); + #endif /* _LINUX_CGROUP_H */ diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 030d34e9d117..cbc390234605 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -198,6 +198,11 @@ struct mem_cgroup { struct page_counter kmem; /* v1 only */ struct page_counter tcpmem; /* v1 only */ + /* lists of memcg peak watching contexts on swap and memory */ + struct list_head peak_memory_local_watermark_watchers; + struct list_head peak_swap_local_watermark_watchers; + spinlock_t swap_memory_peak_watchers_lock; + /* Range enforcement for interrupt charges */ struct work_struct high_work; diff --git a/include/linux/page_counter.h b/include/linux/page_counter.h index 8cd858d912c4..06bb84218960 100644 --- a/include/linux/page_counter.h +++ b/include/linux/page_counter.h @@ -26,6 +26,7 @@ struct page_counter { atomic_long_t children_low_usage; unsigned long watermark; + unsigned long local_watermark; /* track min of fd-local resets */ unsigned long failcnt; /* Keep all the read most fields in a separete cacheline. */ @@ -78,7 +79,15 @@ int page_counter_memparse(const char *buf, const char *max, static inline void page_counter_reset_watermark(struct page_counter *counter) { - counter->watermark = page_counter_read(counter); + unsigned long cur = page_counter_read(counter); + + counter->watermark = cur; + counter->local_watermark = cur; +} + +static inline void page_counter_reset_local_watermark(struct page_counter *counter) +{ + counter->local_watermark = page_counter_read(counter); } #endif /* _LINUX_PAGE_COUNTER_H */ diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h index 520b90dd97ec..5a97ba08e976 100644 --- a/kernel/cgroup/cgroup-internal.h +++ b/kernel/cgroup/cgroup-internal.h @@ -81,6 +81,8 @@ struct cgroup_file_ctx { struct { struct cgroup_pidlist *pidlist; } procs1; + + struct memcg_peak_mem_ctx peak; }; /* diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index e32b6972c478..38b935ffa6cf 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -1964,6 +1964,13 @@ static int cgroup2_parse_param(struct fs_context *fc, struct fs_parameter *param return -EINVAL; } +struct memcg_peak_mem_ctx *memcg_extract_peak_mem_ctx(struct kernfs_open_file *of) +{ + struct cgroup_file_ctx *ctx = of->priv; + + return &ctx->peak; +} + static void apply_cgroup_root_flags(unsigned int root_flags) { if (current->nsproxy->cgroup_ns == &init_cgroup_ns) { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 8f2f1bb18c9c..306698d32828 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -25,6 +25,7 @@ * Copyright (C) 2020 Alibaba, Inc, Alex Shi */ +#include #include #include #include @@ -42,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -5745,6 +5747,9 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent) vmpressure_init(&memcg->vmpressure); INIT_LIST_HEAD(&memcg->event_list); spin_lock_init(&memcg->event_list_lock); + INIT_LIST_HEAD(&memcg->peak_memory_local_watermark_watchers); + INIT_LIST_HEAD(&memcg->peak_swap_local_watermark_watchers); + spin_lock_init(&memcg->swap_memory_peak_watchers_lock); memcg->socket_pressure = jiffies; #ifdef CONFIG_MEMCG_KMEM memcg->kmemcg_id = -1; @@ -6907,12 +6912,109 @@ static u64 memory_current_read(struct cgroup_subsys_state *css, return (u64)page_counter_read(&memcg->memory) * PAGE_SIZE; } -static u64 memory_peak_read(struct cgroup_subsys_state *css, - struct cftype *cft) +inline int swap_memory_peak_show( + struct seq_file *sf, void *v, bool swap_cg) { + struct cgroup_subsys_state *css = seq_css(sf); struct mem_cgroup *memcg = mem_cgroup_from_css(css); + struct page_counter *pc; + struct kernfs_open_file *of = sf->private; + struct memcg_peak_mem_ctx *ctx = memcg_extract_peak_mem_ctx(of); + s64 fd_peak = ctx->local_watermark; - return (u64)memcg->memory.watermark * PAGE_SIZE; + if (swap_cg) + pc = &memcg->swap; + else + pc = &memcg->memory; + + if (fd_peak == -1) { + seq_printf(sf, "%llu\n", (u64)pc->watermark * PAGE_SIZE); + return 0; + } + + s64 pc_peak = pc->local_watermark; + s64 wm = fd_peak > pc_peak ? fd_peak : pc_peak; + + seq_printf(sf, "%lld\n", wm * PAGE_SIZE); + return 0; +} + +static int memory_peak_show(struct seq_file *sf, void *v) +{ + return swap_memory_peak_show(sf, v, false); +} + +static int swap_memory_peak_open(struct kernfs_open_file *of) +{ + struct memcg_peak_mem_ctx *ctx = memcg_extract_peak_mem_ctx(of); + + ctx->local_watermark = -1; + return 0; +} + +inline void swap_memory_peak_release(struct kernfs_open_file *of) +{ + struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); + struct memcg_peak_mem_ctx *ctx = memcg_extract_peak_mem_ctx(of); + + if (ctx->local_watermark == -1) { + /* fast path (no writes on this fd) */ + return; + } + spin_lock(&memcg->swap_memory_peak_watchers_lock); + list_del(&ctx->peers); + spin_unlock(&memcg->swap_memory_peak_watchers_lock); +} + +inline ssize_t swap_memory_peak_write( + struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off, bool swap_cg) +{ + unsigned long cur; + struct memcg_peak_mem_ctx *peer_ctx; + struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); + struct memcg_peak_mem_ctx *ctx = memcg_extract_peak_mem_ctx(of); + struct page_counter *pc; + struct list_head *watchers, *pos; + + buf = strstrip(buf); + /* Only allow "reset" to keep the API clear */ + if (strcmp(buf, "reset")) + return -EINVAL; + + if (swap_cg) { + pc = &memcg->swap; + watchers = &memcg->peak_swap_local_watermark_watchers; + } else { + pc = &memcg->memory; + watchers = &memcg->peak_memory_local_watermark_watchers; + } + + spin_lock(&memcg->swap_memory_peak_watchers_lock); + + page_counter_reset_local_watermark(pc); + cur = pc->local_watermark; + + list_for_each(pos, watchers) { + peer_ctx = list_entry(pos, typeof(*ctx), peers); + if (cur > peer_ctx->local_watermark) + peer_ctx->local_watermark = cur; + } + + if (ctx->local_watermark == -1) + /* only append to the list if we're not already there */ + list_add_tail(&ctx->peers, watchers); + + ctx->local_watermark = cur; + spin_unlock(&memcg->swap_memory_peak_watchers_lock); + + return nbytes; +} + +static ssize_t memory_peak_write(struct kernfs_open_file *of, char *buf, + size_t nbytes, loff_t off) +{ + return swap_memory_peak_write(of, buf, nbytes, off, false); } static int memory_min_show(struct seq_file *m, void *v) @@ -7231,7 +7333,10 @@ static struct cftype memory_files[] = { { .name = "peak", .flags = CFTYPE_NOT_ON_ROOT, - .read_u64 = memory_peak_read, + .open = swap_memory_peak_open, + .release = swap_memory_peak_release, + .seq_show = memory_peak_show, + .write = memory_peak_write, }, { .name = "min", @@ -8193,12 +8298,15 @@ static u64 swap_current_read(struct cgroup_subsys_state *css, return (u64)page_counter_read(&memcg->swap) * PAGE_SIZE; } -static u64 swap_peak_read(struct cgroup_subsys_state *css, - struct cftype *cft) +static int swap_peak_show(struct seq_file *sf, void *v) { - struct mem_cgroup *memcg = mem_cgroup_from_css(css); + return swap_memory_peak_show(sf, v, true); +} - return (u64)memcg->swap.watermark * PAGE_SIZE; +static ssize_t swap_peak_write(struct kernfs_open_file *of, char *buf, + size_t nbytes, loff_t off) +{ + return swap_memory_peak_write(of, buf, nbytes, off, true); } static int swap_high_show(struct seq_file *m, void *v) @@ -8282,7 +8390,10 @@ static struct cftype swap_files[] = { { .name = "swap.peak", .flags = CFTYPE_NOT_ON_ROOT, - .read_u64 = swap_peak_read, + .open = swap_memory_peak_open, + .release = swap_memory_peak_release, + .seq_show = swap_peak_show, + .write = swap_peak_write, }, { .name = "swap.events", diff --git a/mm/page_counter.c b/mm/page_counter.c index db20d6452b71..724d31508664 100644 --- a/mm/page_counter.c +++ b/mm/page_counter.c @@ -79,9 +79,22 @@ void page_counter_charge(struct page_counter *counter, unsigned long nr_pages) /* * This is indeed racy, but we can live with some * inaccuracy in the watermark. + * + * Notably, we have two watermarks to allow for both a globally + * visible peak and one that can be reset at a smaller scope. + * + * Since we reset both watermarks when the global reset occurs, + * we can guarantee that watermark >= local_watermark, so we + * don't need to do both comparisons every time. + * + * On systems with branch predictors, the inner condition should + * be almost free. */ - if (new > READ_ONCE(c->watermark)) - WRITE_ONCE(c->watermark, new); + if (new > READ_ONCE(c->local_watermark)) { + WRITE_ONCE(c->local_watermark, new); + if (new > READ_ONCE(c->watermark)) + WRITE_ONCE(c->watermark, new); + } } } @@ -131,10 +144,23 @@ bool page_counter_try_charge(struct page_counter *counter, propagate_protected_usage(c, new); /* * Just like with failcnt, we can live with some - * inaccuracy in the watermark. + * inaccuracy in the watermarks. + * + * Notably, we have two watermarks to allow for both a globally + * visible peak and one that can be reset at a smaller scope. + * + * Since we reset both watermarks when the global reset occurs, + * we can guarantee that watermark >= local_watermark, so we + * don't need to do both comparisons every time. + * + * On systems with branch predictors, the inner condition should + * be almost free. */ - if (new > READ_ONCE(c->watermark)) - WRITE_ONCE(c->watermark, new); + if (new > READ_ONCE(c->local_watermark)) { + WRITE_ONCE(c->local_watermark, new); + if (new > READ_ONCE(c->watermark)) + WRITE_ONCE(c->watermark, new); + } } return true; diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index 432db923bced..1e2d46636a0c 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -141,6 +141,16 @@ long cg_read_long(const char *cgroup, const char *control) return atol(buf); } +long cg_read_long_fd(int fd) +{ + char buf[128]; + + if (pread(fd, buf, sizeof(buf), 0) <= 0) + return -1; + + return atol(buf); +} + long cg_read_key_long(const char *cgroup, const char *control, const char *key) { char buf[PAGE_SIZE]; @@ -183,6 +193,18 @@ int cg_write(const char *cgroup, const char *control, char *buf) return ret == len ? 0 : ret; } +/* + * Returns fd on success, or -1 on failure. + * (fd should be closed with close() as usual) + */ +int cg_open(const char *cgroup, const char *control, int flags) +{ + char path[PATH_MAX]; + + snprintf(path, sizeof(path), "%s/%s", cgroup, control); + return open(path, flags); +} + int cg_write_numeric(const char *cgroup, const char *control, long value) { char buf[64]; diff --git a/tools/testing/selftests/cgroup/cgroup_util.h b/tools/testing/selftests/cgroup/cgroup_util.h index e8d04ac9e3d2..19b131ee7707 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.h +++ b/tools/testing/selftests/cgroup/cgroup_util.h @@ -34,9 +34,11 @@ extern int cg_read_strcmp(const char *cgroup, const char *control, extern int cg_read_strstr(const char *cgroup, const char *control, const char *needle); extern long cg_read_long(const char *cgroup, const char *control); +extern long cg_read_long_fd(int fd); long cg_read_key_long(const char *cgroup, const char *control, const char *key); extern long cg_read_lc(const char *cgroup, const char *control); extern int cg_write(const char *cgroup, const char *control, char *buf); +extern int cg_open(const char *cgroup, const char *control, int flags); int cg_write_numeric(const char *cgroup, const char *control, long value); extern int cg_run(const char *cgroup, int (*fn)(const char *cgroup, void *arg), From patchwork Mon Jul 22 23:55:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Finkel X-Patchwork-Id: 13739231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4F16C3DA7E for ; Mon, 22 Jul 2024 23:56:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 134196B0089; Mon, 22 Jul 2024 19:56:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E7C36B008A; Mon, 22 Jul 2024 19:56:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8F716B008C; Mon, 22 Jul 2024 19:56:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B8F466B0089 for ; Mon, 22 Jul 2024 19:56:06 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5E993C1A9B for ; Mon, 22 Jul 2024 23:56:06 +0000 (UTC) X-FDA: 82369049532.06.68F0DF0 Received: from m35-116.mailgun.net (m35-116.mailgun.net [69.72.35.116]) by imf18.hostedemail.com (Postfix) with ESMTP id 907801C0025 for ; Mon, 22 Jul 2024 23:56:04 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=relay.vimeo.com header.s=mailo header.b=mW2RcOUT; spf=pass (imf18.hostedemail.com: domain of "bounce+ea57f2.9d2a1c-linux-mm=kvack.org@relay.vimeo.com" designates 69.72.35.116 as permitted sender) smtp.mailfrom="bounce+ea57f2.9d2a1c-linux-mm=kvack.org@relay.vimeo.com"; dmarc=pass (policy=reject) header.from=vimeo.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721692542; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jsjLPBYavQVdLclCa8kvxT1KA4iDIPKvM8j0Os5u/Ok=; b=NDxmamtWYgi3t9eIqNyGWZGdqsnBuaTTEbPCqhY7ZfaMRCIrsFQhJfnYaqUg5EANCGwrD2 uy6b3kWgje4bYZjWFF2lT5/US18KV1k0zL95KBog0W8KfIh1nKGyctsRI1F/K4qnaHxwEH pAzJw6z85grvs20lVwKH/pqmM+Y/YAw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=relay.vimeo.com header.s=mailo header.b=mW2RcOUT; spf=pass (imf18.hostedemail.com: domain of "bounce+ea57f2.9d2a1c-linux-mm=kvack.org@relay.vimeo.com" designates 69.72.35.116 as permitted sender) smtp.mailfrom="bounce+ea57f2.9d2a1c-linux-mm=kvack.org@relay.vimeo.com"; dmarc=pass (policy=reject) header.from=vimeo.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721692542; a=rsa-sha256; cv=none; b=MNFKhV5x4hoTeTu3a+RMVC9sjv20knEnq9LkvIgXZvyZ4S6C6wYp3gb2pGvsZcYedl/Ryi E8HS07Z5hgazO+DcgW8zwZ0raLQi8J/NaTZnbiCb/GFQt9QuluIDNiduZRQ5VXE+ufZq+Q Vcnv0uXDhetJqxad3Xnau4kv/lKIg6Y= DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=relay.vimeo.com; q=dns/txt; s=mailo; t=1721692563; x=1721699763; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-Id: Date: Subject: Subject: Cc: To: To: From: From: Sender: Sender; bh=jsjLPBYavQVdLclCa8kvxT1KA4iDIPKvM8j0Os5u/Ok=; b=mW2RcOUTekC6+zlsQxf5PNpBammJ20zPMXM1CY50whaMgR2iHUaZ5WqCD3LXwju8vzZDT+botemCA7A24sqxle1JE/j4g9DMB4llB4KE22R0onwUmLgy0l8yIvxghYwFoAqsqoY4FHnaXzf1i1Jkn2x5rg3l2rjovP0MKokKGcM= X-Mailgun-Sending-Ip: 69.72.35.116 X-Mailgun-Sid: WyI5NTRmYiIsImxpbnV4LW1tQGt2YWNrLm9yZyIsIjlkMmExYyJd Received: from smtp.vimeo.com (215.71.185.35.bc.googleusercontent.com [35.185.71.215]) by 59065f94d682 with SMTP id 669ef193c143980835d4fbfd (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Mon, 22 Jul 2024 23:56:03 GMT Received: from nutau (gke-sre-us-east1-main-7f6ba6de-fx1q.c.vimeo-core.internal [10.56.27.207]) by smtp.vimeo.com (Postfix) with ESMTP id B860C64D5F; Mon, 22 Jul 2024 23:56:02 +0000 (UTC) Received: by nutau (Postfix, from userid 1001) id 88E78B4117E; Mon, 22 Jul 2024 19:56:02 -0400 (EDT) From: David Finkel To: Muchun Song , Tejun Heo , Roman Gushchin , Andrew Morton Cc: core-services@vimeo.com, Jonathan Corbet , Michal Hocko , Shakeel Butt , Shuah Khan , Johannes Weiner , Zefan Li , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, David Finkel Subject: [PATCH 2/2] mm, memcg: cg2 memory{.swap,}.peak write tests Date: Mon, 22 Jul 2024 19:55:54 -0400 Message-Id: <20240722235554.2911971-3-davidf@vimeo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240722235554.2911971-1-davidf@vimeo.com> References: <20240722235554.2911971-1-davidf@vimeo.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 907801C0025 X-Stat-Signature: gako7bwn7gqofu5wewuaebmepxut9aqi X-HE-Tag: 1721692564-377308 X-HE-Meta: U2FsdGVkX1/CvjVctHy3HhHKYTCnuo+ylotL0Cdk05LkxKxdNWw3WYuTE4LSTtDttTAJDjPMrfKDjIGh7JyJQu/nf3cWVRCUUFQkASvi6P41P5eKWRXq/eDC55xFZhq6zWzLUqxIkKHYPrj5JifrugxxtG/oN8ekwdZfd1BHrfLBa3FZsB6CY27snDcWdUO+Js8xsW3A9Z5bxqMcdxHbrQldrVkIpAk3wZLVKoJSp+QSet1Q3utg/ESR3rIAwbL4/6Bd7TN8XFbirxfJS56E5PetUJf/1C1mNmRHE4i4HzRn5QwE5iiFQS6fNAYX99MoWHasx3ETDVSJjQIarD0V/44QZsYxCqjWNF/S7iFAnaHSwrbLMXX2sonqNZvQSk0AeufHVjYb6644hys28OYyR4F8cZ3zNj5xwJ32L1hvjhRch48x7+FHPjGIQ/8mHPV4x3JNEsAqCpSwZXuBkG4LecSALP5vErnEfvL1kIFkiJ8q9w2VvRXZpsMvQocKKkgHYZkof0DxZCcy8YYtfh/Pju+EZnuNGj1Ok0oap1oKbdJ4uGjU8LdOBudjwNLhmzPryPlqgNT8HqgxmGfZHMxOgn1ts5eyXC/xxDtoPvmdUU6WEfkP77AH0DAvNFusZQeLQtVOEuoQ26f3kNO4pALizALwtYKZQ07n3oJEb/s7U3ldwjeOFkNICZ6RC5E5izYAgrENHP4In2fn9+RWIMmmTeaxaAXQ3y4Pz1p8d2cYznWWWUFAzL+2BhtPpIuu7jZFl9jkU8DEzH7rIIgjjhNKIeBeFVXCUUZUjOelUB+UCjoEuFkkg8L0VCzdNUVwzNB0YxoSdkUbYX26JcUFuljTyKZxWsgXTYzZG8A+ue/Ir3byZtwM+DCEV5lcb6NAZ1ochfgUrzz75zFhIBcJ+q7w2HgV/7hcd7gjV9qIgLZwhft+O40+K5svM2A56OpAEocEjFiXM9QLn7RlKK4BDOU f/fUYWhh a0YdcJYYo59HuHjg0uriytXfRetKwJgh2PdMXU50UazKJVPenkyhBQUEfnJLYPhCM37cGEeyI8FlAz12VIMjv+YoDC1fW00WlEnhfoaeRUY8BPwNcfgjL1DjyMhgJV5PEeJ6H5W+O9f/yQNMvGmmr7022AzH6Yk7n34ztueqrKTCrPDTln+/A0dGaRSGD6gCPBSpaDSqU0WzedubxwPP9+9/FbROidDoXx1kypI3DcqOymTNbzdPqKcEcK8U9EEgXfIOdy5mn5AM+h/N+Tp4fAthw1PvuF0OG4tlAcpjSPtBMIivggL6xOE7gTVh0iyRBSOO9W7s4oWHm/eVgC+kUFkYFY4EnZqlbVEtVcRjrzppNmwDiFfgqUTvtWvr4PC9wAPPHSKp9kvNWx8ayQLarmdVD0Y3owjNaGxj/jY3PpcZu0QigloMaRyH6s93bKVWFuE/ZEm4OZZ55JbZI3Ec6Nyq50TNDzp5gvp3xq6yAPpHFzec= X-Bogosity: Ham, tests=bogofilter, spamicity=0.001682, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Extend two existing tests to cover extracting memory usage through the newly mutable memory.peak and memory.swap.peak handlers. In particular, make sure to exercise adding and removing watchers with overlapping lifetimes so the less-trivial logic gets tested. Signed-off-by: David Finkel --- .../selftests/cgroup/test_memcontrol.c | 227 +++++++++++++++++- 1 file changed, 219 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index 41ae8047b889..768f3e6c21af 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -161,12 +161,12 @@ static int alloc_pagecache_50M_check(const char *cgroup, void *arg) /* * This test create a memory cgroup, allocates * some anonymous memory and some pagecache - * and check memory.current and some memory.stat values. + * and checks memory.current, memory.peak, and some memory.stat values. */ -static int test_memcg_current(const char *root) +static int test_memcg_current_peak(const char *root) { int ret = KSFT_FAIL; - long current; + long current, peak, peak_reset; char *memcg; memcg = cg_name(root, "memcg_test"); @@ -180,15 +180,109 @@ static int test_memcg_current(const char *root) if (current != 0) goto cleanup; + peak = cg_read_long(memcg, "memory.peak"); + if (peak != 0) + goto cleanup; + if (cg_run(memcg, alloc_anon_50M_check, NULL)) goto cleanup; + peak = cg_read_long(memcg, "memory.peak"); + if (peak < MB(50)) + goto cleanup; + + /* + * We'll open a few FDs for the same memory.peak file to exercise the free-path + * We need at least three to be closed in a different order than writes occurred to test + * the linked-list handling. + */ + int peak_fd = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC); + + if (peak_fd == -1) + goto cleanup; + + bool fd2_closed = false, fd3_closed = false, fd4_closed = false; + int peak_fd2 = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC); + + if (peak_fd2 == -1) + goto cleanup; + + int peak_fd3 = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC); + + if (peak_fd3 == -1) + goto cleanup; + + static const char reset_string[] = "reset\n"; + + peak_reset = write(peak_fd, reset_string, sizeof(reset_string)); + if (peak_reset != sizeof(reset_string)) + goto cleanup; + + peak_reset = write(peak_fd2, reset_string, sizeof(reset_string)); + if (peak_reset != sizeof(reset_string)) + goto cleanup; + + peak_reset = write(peak_fd3, reset_string, sizeof(reset_string)); + if (peak_reset != sizeof(reset_string)) + goto cleanup; + + /* Make sure a completely independent read isn't affected by our FD-local reset above*/ + peak = cg_read_long(memcg, "memory.peak"); + if (peak < MB(50)) + goto cleanup; + + fd2_closed = true; + if (close(peak_fd2)) + goto cleanup; + + int peak_fd4 = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC); + + if (peak_fd4 == -1) + goto cleanup; + + peak_reset = write(peak_fd4, reset_string, sizeof(reset_string)); + if (peak_reset != sizeof(reset_string)) + goto cleanup; + + peak = cg_read_long_fd(peak_fd); + if (peak > MB(30) || peak < 0) + goto cleanup; + if (cg_run(memcg, alloc_pagecache_50M_check, NULL)) goto cleanup; + peak = cg_read_long(memcg, "memory.peak"); + if (peak < MB(50)) + goto cleanup; + + /* Make sure everything is back to normal */ + peak = cg_read_long_fd(peak_fd); + if (peak < MB(50)) + goto cleanup; + + peak = cg_read_long_fd(peak_fd4); + if (peak < MB(50)) + goto cleanup; + + fd3_closed = true; + if (close(peak_fd3)) + goto cleanup; + + fd4_closed = true; + if (close(peak_fd4)) + goto cleanup; + + ret = KSFT_PASS; cleanup: + close(peak_fd); + if (!fd2_closed) + close(peak_fd2); + if (!fd3_closed) + close(peak_fd3); + if (!fd4_closed) + close(peak_fd4); cg_destroy(memcg); free(memcg); @@ -817,13 +911,16 @@ static int alloc_anon_50M_check_swap(const char *cgroup, void *arg) /* * This test checks that memory.swap.max limits the amount of - * anonymous memory which can be swapped out. + * anonymous memory which can be swapped out. Additionally, it verifies that + * memory.swap.peak reflects the high watermark and can be reset. */ -static int test_memcg_swap_max(const char *root) +static int test_memcg_swap_max_peak(const char *root) { int ret = KSFT_FAIL; char *memcg; - long max; + long max, peak; + + static const char reset_string[] = "reset\n"; if (!is_swap_enabled()) return KSFT_SKIP; @@ -840,6 +937,45 @@ static int test_memcg_swap_max(const char *root) goto cleanup; } + int swap_peak_fd = cg_open(memcg, "memory.swap.peak", + O_RDWR | O_APPEND | O_CLOEXEC); + + if (swap_peak_fd == -1) + goto cleanup; + + int mem_peak_fd = cg_open(memcg, "memory.peak", O_RDWR | O_APPEND | O_CLOEXEC); + + if (mem_peak_fd == -1) + goto cleanup; + + if (cg_read_long(memcg, "memory.swap.peak")) + goto cleanup; + + if (cg_read_long_fd(swap_peak_fd)) + goto cleanup; + + /* switch the swap and mem fds into local-peak tracking mode*/ + int peak_reset = write(swap_peak_fd, reset_string, sizeof(reset_string)); + + if (peak_reset != sizeof(reset_string)) + goto cleanup; + + if (cg_read_long_fd(swap_peak_fd)) + goto cleanup; + + if (cg_read_long(memcg, "memory.peak")) + goto cleanup; + + if (cg_read_long_fd(mem_peak_fd)) + goto cleanup; + + peak_reset = write(mem_peak_fd, reset_string, sizeof(reset_string)); + if (peak_reset != sizeof(reset_string)) + goto cleanup; + + if (cg_read_long_fd(mem_peak_fd)) + goto cleanup; + if (cg_read_strcmp(memcg, "memory.max", "max\n")) goto cleanup; @@ -862,6 +998,61 @@ static int test_memcg_swap_max(const char *root) if (cg_read_key_long(memcg, "memory.events", "oom_kill ") != 1) goto cleanup; + peak = cg_read_long(memcg, "memory.peak"); + if (peak < MB(29)) + goto cleanup; + + peak = cg_read_long(memcg, "memory.swap.peak"); + if (peak < MB(29)) + goto cleanup; + + peak = cg_read_long_fd(mem_peak_fd); + if (peak < MB(29)) + goto cleanup; + + peak = cg_read_long_fd(swap_peak_fd); + if (peak < MB(29)) + goto cleanup; + + /* + * open, reset and close the peak swap on another FD to make sure + * multiple extant fds don't corrupt the linked-list + */ + peak_reset = cg_write(memcg, "memory.swap.peak", (char *)reset_string); + if (peak_reset) + goto cleanup; + + peak_reset = cg_write(memcg, "memory.peak", (char *)reset_string); + if (peak_reset) + goto cleanup; + + /* actually reset on the fds */ + peak_reset = write(swap_peak_fd, reset_string, sizeof(reset_string)); + if (peak_reset != sizeof(reset_string)) + goto cleanup; + + peak_reset = write(mem_peak_fd, reset_string, sizeof(reset_string)); + if (peak_reset != sizeof(reset_string)) + goto cleanup; + + peak = cg_read_long_fd(swap_peak_fd); + if (peak > MB(10)) + goto cleanup; + + /* + * The cgroup is now empty, but there may be a page or two associated + * with the open FD accounted to it. + */ + peak = cg_read_long_fd(mem_peak_fd); + if (peak > MB(1)) + goto cleanup; + + if (cg_read_long(memcg, "memory.peak") < MB(29)) + goto cleanup; + + if (cg_read_long(memcg, "memory.swap.peak") < MB(29)) + goto cleanup; + if (cg_run(memcg, alloc_anon_50M_check_swap, (void *)MB(30))) goto cleanup; @@ -869,9 +1060,29 @@ static int test_memcg_swap_max(const char *root) if (max <= 0) goto cleanup; + peak = cg_read_long(memcg, "memory.peak"); + if (peak < MB(29)) + goto cleanup; + + peak = cg_read_long(memcg, "memory.swap.peak"); + if (peak < MB(29)) + goto cleanup; + + peak = cg_read_long_fd(mem_peak_fd); + if (peak < MB(29)) + goto cleanup; + + peak = cg_read_long_fd(swap_peak_fd); + if (peak < MB(19)) + goto cleanup; + ret = KSFT_PASS; cleanup: + if (close(mem_peak_fd)) + ret = KSFT_FAIL; + if (close(swap_peak_fd)) + ret = KSFT_FAIL; cg_destroy(memcg); free(memcg); @@ -1295,7 +1506,7 @@ struct memcg_test { const char *name; } tests[] = { T(test_memcg_subtree_control), - T(test_memcg_current), + T(test_memcg_current_peak), T(test_memcg_min), T(test_memcg_low), T(test_memcg_high), @@ -1303,7 +1514,7 @@ struct memcg_test { T(test_memcg_max), T(test_memcg_reclaim), T(test_memcg_oom_events), - T(test_memcg_swap_max), + T(test_memcg_swap_max_peak), T(test_memcg_sock), T(test_memcg_oom_group_leaf_events), T(test_memcg_oom_group_parent_events),