From patchwork Tue Aug 13 16:56:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuanchu Xie X-Patchwork-Id: 13762345 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 AFAEEC52D7B for ; Tue, 13 Aug 2024 16:59:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 732D36B0092; Tue, 13 Aug 2024 12:59:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BBA56B0095; Tue, 13 Aug 2024 12:59:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E74D6B009A; Tue, 13 Aug 2024 12:59:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2F42D6B0092 for ; Tue, 13 Aug 2024 12:59:43 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B467B80852 for ; Tue, 13 Aug 2024 16:59:42 +0000 (UTC) X-FDA: 82447833804.07.9F5B9A2 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf14.hostedemail.com (Postfix) with ESMTP id C739410001C for ; Tue, 13 Aug 2024 16:59:40 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=OXvX0Zg4; spf=pass (imf14.hostedemail.com: domain of 3-5C7ZgcKCEg84kxmr4qyyqvo.mywvsx47-wwu5kmu.y1q@flex--yuanchu.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3-5C7ZgcKCEg84kxmr4qyyqvo.mywvsx47-wwu5kmu.y1q@flex--yuanchu.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723568345; a=rsa-sha256; cv=none; b=tGDME7DqI4uuKh/FIZD+4EUuQlWmiZtuy30T8RzrR+IQqzZ8gL6bICCiy8nv2osAwTlmDw 0FpjBL1vYDI7ZlU5LHjo5zfqCQe3CucWnO52bXLkvMXJVTRHEgnGolxNLO8MqpqXzGLqE2 9yRO8nxiU/QJa1ysz3OZB28HIBdHuN0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=OXvX0Zg4; spf=pass (imf14.hostedemail.com: domain of 3-5C7ZgcKCEg84kxmr4qyyqvo.mywvsx47-wwu5kmu.y1q@flex--yuanchu.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3-5C7ZgcKCEg84kxmr4qyyqvo.mywvsx47-wwu5kmu.y1q@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=1723568345; 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=Hqd1jKx+q5wvRHFsKe7RtJaTNM99zPu8YKm8b61Swh4=; b=KXX3/vafDj81f6fY05dWM2G9KWsSou3MtHRLq9oDDEJyvbuyNuf5O5syfdhZToo54HTeiH uIhslM1dA6LJ1b2RuuGUI3uU2cLunVCvuZIKGJD4Ock44VUJDElwWGnwsqFtRG4P8vBanP Y0cvoqWuLCHH62OhoJ+aDwbl9RDzIN4= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-664fc7c4e51so116144817b3.3 for ; Tue, 13 Aug 2024 09:59:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723568380; x=1724173180; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Hqd1jKx+q5wvRHFsKe7RtJaTNM99zPu8YKm8b61Swh4=; b=OXvX0Zg4jf8p3FWqi9U8pm0NHcYzXmPk6WWMAU3p0pfv6NpbDgM2mynPmh56D9Kylk gtFBIDbkN1BWIBu9ZT+phF5H+APJaPUtpK0Z7wrb84KX2POMT7XOx1PNEOWt/mJUUjHM jbOTxjFOvZwefofHPxOkbJ8KYZCBZ3dIPHFVJOH4/feXBP8EyyYtYVJftspBM9dcmtza vPVegRIQpPIpJ3Y28N7VE8YPeOqwVUFGWEGHryQkpiYvsVJF0RRtjsWH5Yh+O6Akl6jl TCVHxw++Nc4M6bR3P9HbdBbSbCiZVDnSn2DKRf1GntsNCqerfGp6EFmAwzbb3se3udbg d80A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723568380; x=1724173180; 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=Hqd1jKx+q5wvRHFsKe7RtJaTNM99zPu8YKm8b61Swh4=; b=BKn4qeeiv0tcy94YYXHYJjz9xTVJ4IE3vC2iE+M6UjrV0IITCAnvPfFZAnZx/ln4q/ UBBE4uek/g2RRmQMcohRiy94oLlJFNXOJE3ZB7gH/RFYTidwdLxPmmRHmFSITwouoYoS RHYD5dHmvzpSVw3PZDOJHrsu7ihEi7VPeSiS/wkb1xxmhcyUNuLhi5Q002h4M+ZIFZ3m mGBVp4G8sDNAJwrnOzvOD1exXNdBosSOXSJPK78mPXueBWVb7dh8FNENnzM+zVagwRNc nikG1rsAtzykQtw9GlVbSfuJTwbj0crffHl9PPPrA3PsWCgfXEkwhkNjluSBWfv6ejvJ D05A== X-Forwarded-Encrypted: i=1; AJvYcCXtU6T2G5A2gBO7bf2mCV6Bs/Q4nNC6QRv+ISRpfNXikqnVEfdGpqq3hiZOTcjE+IY0zEi6X9ziz2UlIO0N6LKXf0Q= X-Gm-Message-State: AOJu0YyJS5isN0GAzuq3DDc7YmqXgCtQDN3O1buSX3sK+ejyD7Lv7/bD MdYq3l4OAh8kvOYbGJTqK0WjqCvicIUDfb8Cb+vDAgaczajxHADNYmiG/Yw79fTgVqdj4TQBzmO EGfo/pg== X-Google-Smtp-Source: AGHT+IHcXqA8D3zvHAIQfVpeQAXseyth/6ohOvX1sAG9G57GDA3x2krpy7DDbUSjGWDUUw5XpHr8rLgkLnqj X-Received: from yuanchu-desktop.svl.corp.google.com ([2620:15c:2a3:200:b50c:66e8:6532:a371]) (user=yuanchu job=sendgmr) by 2002:a0d:ce43:0:b0:62f:f535:f41 with SMTP id 00721157ae682-6ac9bd76ef6mr1297b3.9.1723568379605; Tue, 13 Aug 2024 09:59:39 -0700 (PDT) Date: Tue, 13 Aug 2024 09:56:13 -0700 In-Reply-To: <20240813165619.748102-1-yuanchu@google.com> Mime-Version: 1.0 References: <20240813165619.748102-1-yuanchu@google.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog Message-ID: <20240813165619.748102-3-yuanchu@google.com> Subject: [PATCH v3 2/7] mm: use refresh interval to rate-limit workingset report aggregation From: Yuanchu Xie To: David Hildenbrand , "Aneesh Kumar K.V" , Khalid Aziz , Henry Huang , Yu Zhao , Dan Williams , Gregory Price , Huang Ying , Andrew Morton , Lance Yang , Randy Dunlap , Muhammad Usama Anjum Cc: Kalesh Singh , Wei Xu , David Rientjes , Greg Kroah-Hartman , "Rafael J. Wysocki" , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Shuah Khan , Yosry Ahmed , Matthew Wilcox , Sudarshan Rajagopalan , Kairui Song , "Michael S. Tsirkin" , Vasily Averin , Nhat Pham , Miaohe Lin , Qi Zheng , Abel Wu , "Vishal Moola (Oracle)" , Kefeng Wang , Yuanchu Xie , linux-kernel@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org X-Stat-Signature: joh6xqyysc1sz9zhs5hfy97qch3rok5z X-Rspamd-Queue-Id: C739410001C X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1723568380-228505 X-HE-Meta: U2FsdGVkX18uTmZlhUFo9UXdvIftE/i7nAX+U2Zy/1BU31ivmPPNj5BQgm99oW5ZFVesC1gL1vLM14NaDM38M0yIOHjHmMXnsa1jIO/VeyIWZLiCZoSZOtElGk+k/9pzvJ86mXZqX5/5NEK+lFyGiTFHQ6ZcBJhOH8/L1VGerHw8fr+nm/yp3kWzQQ7tu1s7LpS9X0njgVPdv3NUzKf5pphveCfGCN3gUUfs/tUsScVK6/a2u98xoUeuOBykF8yLeJQajX6oXFFdhEF0JQaXv/Yc5CTDo6p2dERR2FRntJ3Op7GsJYPKINPPmR5o4Th5PQZ6rPwmrMjoyzayTxgAD8itJOXHbzX5KgmnFWUfpu1PEHlFs2ubbqtYZda2SfZ5dXsL2SDFMwKn/b8T+p2n5Yh9GyfT7vM3kIPc36rwIVSsfqrpKa3FVViml1AQS5A+oAfszq4uj2TXnQ9niZTWEWfp3ylQ4a5Rg7uIKamN0+apwaAv1DowKL3DRSgZ2Nba19WS3As6KxU0+HUgNRbPt05C6qFn2zNCNw67WmKiP1sLxDODlpSnG0ubLsEYDLuYn9t2HTXjSKH40YwKjCGYusB/7GuqtOSm+Z07ri9tD1HlDWqvJDXktQ8wIBE1Sr+wpi5eEZIXjsWGXmDaN06QAu6ku3Sd48irvVtRhRr3rwqmYPHZ2L7QRBSseWONNKt3I2/45xcGQhrLt16qDDHaTnIPqDRi+n0JosEWo8Jq1PAQKpLtnQXp7Iz8l4Layk0pIUWra0RFK3pIkwo2r18ZkYQRepfp7ropLTCKJljDU+P50/B7fll5r/vRIR8xmLHtsv8Zfgc1OGXW2ISXCwxArV5d4K4ZrOzSZj3uHtaD8UzjC8KY2grgssGvGDI57ybtG80mbGsiaXCFCVb3BPafI05Q95lcupcrWbun0mO1PTHujXp/JAjMLDC1E6ApQpsuhm8CfGaTNzy+sm27nvh W3hlFUWt +owMdddSV1w/duTSPC9T7mhMFFwSILDcjG28YqV+daJemU/Bk+ZTDaiYyF0Fp8km1J0L9nbCldZ3Mlr2WEms7WUSobS8ByLmrjPuaA1j23qd4JS9JlrRhegicCo7kfBNF5ATVGJSvcyDcgE+HKuRKEEgD/og4prIHA0JzmadR9L3trY8Yu3uLB0txlG9Ed3FQX4nfRRN/qQgR508xbaFPJ2IIN+uxKpDsgE28xpKqrAwu1N9L1sfCFbc3tvmU9T+Uf9/baMDGl0Bh0mJuPHg+G6nHr7lBxgvM4i5mPHFo2AMTWmxKlRUCRKnJu0cbWM7w/bWhDoTmYwcScZKIu2hJjjqoC0EzCm1yrYg9SnR2/waBioGXeuGWOpUUoHbY2N0B4KkJpdYhs4vHlBeDflHUXDr7MlgD3rzsIth7vuTJaLvuhmuxyUma1lzOOdc68v5F2O7SLcvOuASG+rau42wfAfaF8cJUwA1kUtKLyXXQH3ex1DFrdPffnwxXJkHtI4DEY36EyIaQNBbc9MI/YvGYw6UMFKXvjj2pCv8O0vvP2WuLkXQCQXAlMNMsoNPT5qUpZQF66JNo2r5UEkM5/hq5XMWFhh7O4kFhs9ZJ 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: The refresh interval is a rate limiting factor to workingset page age histogram reads. When a workingset report is generated, a timestamp is noted, and the same report will be read until it expires beyond the refresh interval, at which point a new report is generated. Sysfs interface /sys/devices/system/node/nodeX/workingset_report/refresh_interval time in milliseconds specifying how long the report is valid for Signed-off-by: Yuanchu Xie Change-Id: Iabacec2845a7fac7280ffc5f4faed55186cfa7a2 --- include/linux/workingset_report.h | 1 + mm/workingset_report.c | 84 +++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 15 deletions(-) diff --git a/include/linux/workingset_report.h b/include/linux/workingset_report.h index d7c2ee14ec87..8bae6a600410 100644 --- a/include/linux/workingset_report.h +++ b/include/linux/workingset_report.h @@ -37,6 +37,7 @@ struct wsr_page_age_histo { }; struct wsr_state { + unsigned long refresh_interval; /* breakdown of workingset by page age */ struct mutex page_age_lock; struct wsr_page_age_histo *page_age; diff --git a/mm/workingset_report.c b/mm/workingset_report.c index a4dcf62fcd96..fe553c0a653e 100644 --- a/mm/workingset_report.c +++ b/mm/workingset_report.c @@ -195,7 +195,8 @@ static void collect_page_age(struct wsr_page_age_histo *page_age, /* First step: hierarchically scan child memcgs. */ static void refresh_scan(struct wsr_state *wsr, struct mem_cgroup *root, - struct pglist_data *pgdat) + struct pglist_data *pgdat, + unsigned long refresh_interval) { struct mem_cgroup *memcg; unsigned int flags; @@ -208,12 +209,15 @@ static void refresh_scan(struct wsr_state *wsr, struct mem_cgroup *root, do { struct lruvec *lruvec = mem_cgroup_lruvec(memcg, pgdat); unsigned long max_seq = READ_ONCE((lruvec)->lrugen.max_seq); + int gen = lru_gen_from_seq(max_seq); + unsigned long birth = READ_ONCE(lruvec->lrugen.timestamps[gen]); /* * setting can_swap=true and force_scan=true ensures * proper workingset stats when the system cannot swap. */ - try_to_inc_max_seq(lruvec, max_seq, true, true); + if (time_is_before_jiffies(birth + refresh_interval)) + try_to_inc_max_seq(lruvec, max_seq, true, true); cond_resched(); } while ((memcg = mem_cgroup_iter(root, memcg, NULL))); @@ -270,17 +274,25 @@ bool wsr_refresh_report(struct wsr_state *wsr, struct mem_cgroup *root, struct pglist_data *pgdat) { struct wsr_page_age_histo *page_age; + unsigned long refresh_interval = READ_ONCE(wsr->refresh_interval); if (!READ_ONCE(wsr->page_age)) return false; - refresh_scan(wsr, root, pgdat); + if (!refresh_interval) + return false; + mutex_lock(&wsr->page_age_lock); page_age = READ_ONCE(wsr->page_age); - if (page_age) { - copy_node_bins(pgdat, page_age); - refresh_aggregate(page_age, root, pgdat); - } + if (!page_age) + goto unlock; + if (page_age->timestamp && + time_is_after_jiffies(page_age->timestamp + refresh_interval)) + goto unlock; + refresh_scan(wsr, root, pgdat, refresh_interval); + copy_node_bins(pgdat, page_age); + refresh_aggregate(page_age, root, pgdat); +unlock: mutex_unlock(&wsr->page_age_lock); return !!page_age; } @@ -299,6 +311,52 @@ static struct wsr_state *kobj_to_wsr(struct kobject *kobj) return &mem_cgroup_lruvec(NULL, kobj_to_pgdat(kobj))->wsr; } +static ssize_t refresh_interval_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct wsr_state *wsr = kobj_to_wsr(kobj); + unsigned int interval = READ_ONCE(wsr->refresh_interval); + + return sysfs_emit(buf, "%u\n", jiffies_to_msecs(interval)); +} + +static ssize_t refresh_interval_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t len) +{ + unsigned int interval; + int err; + struct wsr_state *wsr = kobj_to_wsr(kobj); + + err = kstrtouint(buf, 0, &interval); + if (err) + return err; + + mutex_lock(&wsr->page_age_lock); + if (interval && !wsr->page_age) { + struct wsr_page_age_histo *page_age = + kzalloc(sizeof(struct wsr_page_age_histo), GFP_KERNEL); + + if (!page_age) { + err = -ENOMEM; + goto unlock; + } + wsr->page_age = page_age; + } + if (!interval && wsr->page_age) { + kfree(wsr->page_age); + wsr->page_age = NULL; + } + + WRITE_ONCE(wsr->refresh_interval, msecs_to_jiffies(interval)); +unlock: + mutex_unlock(&wsr->page_age_lock); + return err ?: len; +} + +static struct kobj_attribute refresh_interval_attr = + __ATTR_RW(refresh_interval); + static ssize_t page_age_intervals_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -382,13 +440,6 @@ static ssize_t page_age_show(struct kobject *kobj, struct kobj_attribute *attr, int ret = 0; struct wsr_state *wsr = kobj_to_wsr(kobj); - - mutex_lock(&wsr->page_age_lock); - if (!wsr->page_age) - wsr->page_age = - kzalloc(sizeof(struct wsr_page_age_histo), GFP_KERNEL); - mutex_unlock(&wsr->page_age_lock); - wsr_refresh_report(wsr, NULL, kobj_to_pgdat(kobj)); mutex_lock(&wsr->page_age_lock); @@ -414,7 +465,10 @@ static ssize_t page_age_show(struct kobject *kobj, struct kobj_attribute *attr, static struct kobj_attribute page_age_attr = __ATTR_RO(page_age); static struct attribute *workingset_report_attrs[] = { - &page_age_intervals_attr.attr, &page_age_attr.attr, NULL + &refresh_interval_attr.attr, + &page_age_intervals_attr.attr, + &page_age_attr.attr, + NULL }; static const struct attribute_group workingset_report_attr_group = {