From patchwork Wed Dec 14 22:51:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuanchu Xie X-Patchwork-Id: 13073645 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 6D93FC4167B for ; Wed, 14 Dec 2022 22:51:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F30538E0006; Wed, 14 Dec 2022 17:51:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EDFC48E0002; Wed, 14 Dec 2022 17:51:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D81638E0006; Wed, 14 Dec 2022 17:51:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C89AE8E0002 for ; Wed, 14 Dec 2022 17:51:53 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9ED14AB5BC for ; Wed, 14 Dec 2022 22:51:53 +0000 (UTC) X-FDA: 80242410906.14.1E7ED87 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf24.hostedemail.com (Postfix) with ESMTP id 1632F18000D for ; Wed, 14 Dec 2022 22:51:51 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=T1vg6Npx; spf=pass (imf24.hostedemail.com: domain of 3h1OaYwcKCLo3zfshmzlttlqj.htrqnsz2-rrp0fhp.twl@flex--yuanchu.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3h1OaYwcKCLo3zfshmzlttlqj.htrqnsz2-rrp0fhp.twl@flex--yuanchu.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671058312; a=rsa-sha256; cv=none; b=zPakUm65WrXimBLje115cJ85bzIJ8XChB+49yg/mkYImEuBRSPu1b8QOJLGyDWyzlmsjow oYYuW9GzcqEl5VQqgGu3aWq7cyKpXASfNRG6Yck3cobnSau0H7GXDzRCojl2pMYwcJhOzW 0lDf5hbRc3vcqmrnRRtQqCLl5WOuFPA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=T1vg6Npx; spf=pass (imf24.hostedemail.com: domain of 3h1OaYwcKCLo3zfshmzlttlqj.htrqnsz2-rrp0fhp.twl@flex--yuanchu.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3h1OaYwcKCLo3zfshmzlttlqj.htrqnsz2-rrp0fhp.twl@flex--yuanchu.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671058312; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pP1HscS3NBizlWxdjalcxiOCxdTFFXWst9Um78lFYew=; b=Mwp79IJEFxjsZmRqobKBBhZ0fafMngPPf/3rfZP4uK2iVnEBtO9cVbotaJ7HUzm8U1ARjT BDeyvIhDJQUeyjiVo8e/1OwHx2Y1IxKKmygBPy9ryx1XONUqFTRqJwXawhY5QEXY5k/uBZ CEDnHEUCt4ouSE67psE2C1xYXuvLtyk= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-3dfb9d11141so15218527b3.3 for ; Wed, 14 Dec 2022 14:51:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pP1HscS3NBizlWxdjalcxiOCxdTFFXWst9Um78lFYew=; b=T1vg6NpxLo6/eIwoy3Qed3mwYZrRcOaXUysYifLHaPi+vYhazUnDs6UDkTZlfRIw7V Y5hy6nvWH1kyT8kmze9eEa6nJSZiNVpW3N3UXMgfEqMuN0e25TVhuhO9D7VqOL/r6JiD 44j5nrRtBPJjeCrY/eBcV76Ko9qHQL7Uf12YDUe97/+MP0nkOYsl4soDy9ktZnmEK6x+ JG4eyDx3Gz2L0H7brEud6mnsIZbHYNBVEQ+rFXpJSg7KtZwCH9Hw29QGY6vvNpzSWtha wOUPLTllmlPcjgFW+I/5/U+W1WIJ6SDoiC88ehNVmoHhh1WhKqr8mBzhsap235RbUrOI kVPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pP1HscS3NBizlWxdjalcxiOCxdTFFXWst9Um78lFYew=; b=q6cUBij3Z+BI1K0wuqPkL0f8j59NknKBBwM3tFYtZC1HqSBSMDGJf5zrrkRNLhAGN6 CP5ZxchoCyQBk048K1sukthJGCAbn18/+Km3ZzNdfkoXIUDZrStR6bQBUvBI+5zT9rMA Aq71Cmf+KxLVTpxfMy0Wm7BV3kM4ChUismyfJ3dt9QGMYgHzMtfWh4gv9WaFXEDo+HXu sHOXQAtLMJelGYRWpk6076+FGRhr1QHly40JIctSSG1RVmudsVHwmAZgpIWwIMMtiEp+ wJxVk/h9GgfBDkBBgTkbJ81Wemq+9VdJQEYjhjEtIbY1Sh80tsafzvEuf2qMYrOZgX87 bJsw== X-Gm-Message-State: ANoB5pmbVjKlp40ZlsojLGnwiXM2nrRhGRW7UhGvrziWuJlLZzsXHQ1o vbbMJRo7AjYR5jPRnNKZs4SzvHCdr7Gi X-Google-Smtp-Source: AA0mqf7P1hKr2kxnLCk/QZ1080xuaZc9TM+496Hb5ZsvxrM7pi3Lu6mK+r3cvFJ2NP34V6PpPdiHlgQapjM1 X-Received: from yuanchu.svl.corp.google.com ([2620:15c:2d4:203:1311:60bc:9e2a:ab1]) (user=yuanchu job=sendgmr) by 2002:a25:dfc3:0:b0:6f3:2748:7469 with SMTP id w186-20020a25dfc3000000b006f327487469mr55315847ybg.564.1671058311228; Wed, 14 Dec 2022 14:51:51 -0800 (PST) Date: Wed, 14 Dec 2022 14:51:23 -0800 In-Reply-To: <20221214225123.2770216-1-yuanchu@google.com> Mime-Version: 1.0 References: <20221214225123.2770216-1-yuanchu@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221214225123.2770216-3-yuanchu@google.com> Subject: [RFC PATCH 2/2] mm: multi-gen LRU: cgroup working set stats From: Yuanchu Xie To: Johannes Weiner , Michal Hocko , Roman Gushchin , Yu Zhao Cc: Andrew Morton , Shakeel Butt , Muchun Song , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, Yuanchu Xie X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 1632F18000D X-Stat-Signature: 84e7owcdxijnk897u4ziga76h9y7aom7 X-HE-Tag: 1671058311-151979 X-HE-Meta: U2FsdGVkX1+SQatFgMSebaPaAc4pf1sbi3VwDtqIZPpU6ldFVFwLmDIRuFZtpBK/Y9rMF6/dW8wvXZ1sutNyQkcoYZBv+WfrB8LbRo7F7BnrMMS27ay5gjFvSswml27WUIu4U8rZ2WMpQU97HNcJ5gWWE4iuafNS/wnf643a6/wwOlVDfOPZQM+vaeM4wOpEDOkrgM8mzrcVWxitjlp6vo8Mhk+7CIFzDYqDRquKqXk1781HQZzBqSkGKCTDiCVdfxgp2xAAS+RSVqDOMrZkfD/GQn93MxfAePfEKatDZcgHLKjJbI0WdXUUyQrfvC7o2JeqwBQfSBJmatmOLwy6DYW7n7PSWXVoqNpx7sQRNEGAzO/f+ozuEsOLrZy1kHQY6VBhVrAuQa9Wp+XHWZKiH1D6SltGGNyufLTqUcDgxj7DSwMIhD0n8YKZLBADlp6ggQNNJx3F2kf6hlYyV0BDuGf3AyT4COXJmBzyP13/AhZCi4D6/3/ZmJIsjimNKBzeMXX306WedLPKEzJt89GnkkluTl4jVi+xfOwt0mCFFdZ2cqLHJo2Z8aGrQ1ZBELMg3KVv0pLBlvwnun1BDExZdodgUC/VH4YmolhT/NOZ+RekW2+03ea7Jo82sUKDizxfzt2Jffbxinm+VbF9/b7MD+HKTtDl31isoBB3p46xGmUEQvRYHeJITXl1sR+P0H9O+/mj7G+J1fkfqlV97UdX9AnprOueZCLJg0KPlDgd91ndVKYx3q6b/RJpgubzDNWE1u8tAyNrAkaQgbbFyc3h3htCUvGzk/WzEKCZjz7slgLAEbN/0oGR078eZxcn+SicgatC39nLs83fzSOZRileSQZwVOWGGfki2Q2DoAeftN42Ay+wnPQN4sl7t6+nqCYprITS4MrM3LeXBZnkqoOMOjJ6pv5VbRbvVBXwYjOe1BipoGP12LL3izP8BxJFYkethUJpu8Rp4Ry0SiN12x2 GetuJEHe /iRiONgr0A+cegQoIjVAv/3vJYTlTAjNqCCOJaXbrRXy5OD8UPaRVh0rlpjRW7tz2NIKjDWm05NyiB7jqcUgz7/yRdrI7g7GCgaTEN8JtC3W1deA6hQRWZ43YB+MZ0TbUkx2jFevIQ+beWRcx0rxSy66oC2Y1wN7F36E9wWptsBKgz8bkLn57sWipJNceKixVNx0woe2mznO/CttlS+7/RPiSTCbvqW/lOfQwapvuLuNaN3aN7el1uao4Oaz86HCgNPy/T803oImHY1upIGhuu6P6esaDaZZXjngP6Uw4A9KKgzEOQnJH7PWIvj1lOcyPmTU4z41w1QszTe5AmsszodI2+HTQYissGGBvusvZXCE57bWZ3yNtf2xLGQ== 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: Expose MGLRU generations as working set stats in cgroupfs as memory.page_idle_age, where we group pages into idle age ranges, and present the number of pages per node per pagetype in each range. This aggregates the time information from MGLRU generations hierarchically. Signed-off-by: Yuanchu Xie --- mm/memcontrol.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7d2fb3fc4580..86554e17be58 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1655,6 +1655,130 @@ void mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) pr_info("%s", buf); } +#ifdef CONFIG_LRU_GEN +static const unsigned long page_idle_age_ranges[] = { + 1, 2, 5, 10, 20, 30, 45, 60, 90, 120, 180, + 240, 360, 480, 720, 960, 1440, 1920, 2880, 3840, -1 +}; + +#define PAGE_IDLE_AGE_NR_RANGES ARRAY_SIZE(page_idle_age_ranges) + +static unsigned int lru_gen_time_to_page_idle_age_range(unsigned long timestamp) +{ + unsigned int i; + unsigned long gen_age = jiffies_to_msecs(jiffies - timestamp) / MSEC_PER_SEC; + + for (i = 0; i < PAGE_IDLE_AGE_NR_RANGES - 1; ++i) + if (gen_age <= page_idle_age_ranges[i]) + return i; + + return PAGE_IDLE_AGE_NR_RANGES - 1; +} + +static void lru_gen_fill_page_idle_age_table(unsigned long *table, + struct lru_gen_struct *lrugen, + int nid) +{ + unsigned long max_seq = READ_ONCE(lrugen->max_seq); + unsigned long min_seq[ANON_AND_FILE] = { + READ_ONCE(lrugen->min_seq[LRU_GEN_ANON]), + READ_ONCE(lrugen->min_seq[LRU_GEN_FILE]), + }; + unsigned long seq; + unsigned int pagetype; + + /* + * what do we want to do here? + * iterate over all the generations, for each anon and file + */ + + for (pagetype = LRU_GEN_ANON; pagetype < ANON_AND_FILE; ++pagetype) { + for (seq = min_seq[pagetype]; seq <= max_seq; ++seq) { + unsigned int zone; + unsigned int gen = lru_gen_from_seq(seq); + unsigned int idle_age = lru_gen_time_to_page_idle_age_range( + READ_ONCE(lrugen->timestamps[gen])); + unsigned long page_count = 0; + + for (zone = 0; zone < MAX_NR_ZONES; ++zone) { + page_count += READ_ONCE( + lrugen->nr_pages[gen][pagetype][zone]); + } + table[pagetype * PAGE_IDLE_AGE_NR_RANGES * + nr_node_ids + + PAGE_IDLE_AGE_NR_RANGES * nid + idle_age] += + page_count; + } + } +} + +static void memory_page_idle_age_print(struct seq_file *m, unsigned long *table) +{ + static const char *type_str[ANON_AND_FILE] = { "anon", "file" }; + unsigned int i, nid, pagetype; + unsigned int lower = 0; + + for (i = 0; i < PAGE_IDLE_AGE_NR_RANGES; ++i) { + unsigned int upper = page_idle_age_ranges[i]; + + for (pagetype = LRU_GEN_ANON; pagetype < ANON_AND_FILE; + ++pagetype) { + if (upper == -1) + seq_printf(m, "%u-inf %s", lower, + type_str[pagetype]); + else + seq_printf(m, "%u-%u %s", lower, upper, + type_str[pagetype]); + for_each_node_state(nid, N_MEMORY) { + unsigned long page_count = table + [pagetype * + PAGE_IDLE_AGE_NR_RANGES * + nr_node_ids + + PAGE_IDLE_AGE_NR_RANGES * nid + + i]; + seq_printf(m, " N%u=%lu", nid, page_count); + } + seq_puts(m, "\n"); + } + + lower = upper; + } +} + +static int memory_page_idle_age_format(struct mem_cgroup *root, + struct seq_file *m) +{ + struct mem_cgroup *memcg; + unsigned long *table; + + /* + * table contains PAGE_IDLE_AGE_NR_RANGES entries + * per node per pagetype + */ + table = kmalloc_array(PAGE_IDLE_AGE_NR_RANGES * nr_node_ids * + ANON_AND_FILE, + sizeof(*table), __GFP_ZERO | GFP_KERNEL); + + if (!table) + return -ENOMEM; + + memcg = mem_cgroup_iter(root, NULL, NULL); + do { + int nid; + + for_each_node_state(nid, N_MEMORY) { + struct lru_gen_struct *lrugen = + &memcg->nodeinfo[nid]->lruvec.lrugen; + + lru_gen_fill_page_idle_age_table(table, lrugen, nid); + } + } while ((memcg = mem_cgroup_iter(root, memcg, NULL))); + + memory_page_idle_age_print(m, table); + return 0; +} +#endif /* CONFIG_LRU_GEN */ + /* * Return the memory (and swap, if configured) limit for a memcg. */ @@ -6571,6 +6695,13 @@ static ssize_t memory_oom_group_write(struct kernfs_open_file *of, } #ifdef CONFIG_LRU_GEN +static int memory_page_idle_age_show(struct seq_file *m, void *v) +{ + struct mem_cgroup *memcg = mem_cgroup_from_seq(m); + + return memory_page_idle_age_format(memcg, m); +} + static int memory_periodic_aging_show(struct seq_file *m, void *v) { unsigned int interval = kold_get_interval(); @@ -6724,6 +6855,11 @@ static struct cftype memory_files[] = { .write = memory_reclaim, }, #ifdef CONFIG_LRU_GEN + { + .name = "page_idle_age", + .flags = CFTYPE_NS_DELEGATABLE, + .seq_show = memory_page_idle_age_show, + }, { .name = "periodic_aging", .flags = CFTYPE_ONLY_ON_ROOT,