From patchwork Tue Jun 4 02:05:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuanchu Xie X-Patchwork-Id: 13684570 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 89520C25B78 for ; Tue, 4 Jun 2024 02:06:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCD546B0092; Mon, 3 Jun 2024 22:06:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B52F56B0093; Mon, 3 Jun 2024 22:06:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 847E16B0095; Mon, 3 Jun 2024 22:06:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5CAB96B0092 for ; Mon, 3 Jun 2024 22:06:15 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1EC27120F68 for ; Tue, 4 Jun 2024 02:06:15 +0000 (UTC) X-FDA: 82191566310.03.A09D528 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf30.hostedemail.com (Postfix) with ESMTP id 52CFE8000A for ; Tue, 4 Jun 2024 02:06:13 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KJleM9QJ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of 3lHZeZgcKCDUplReTYlXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yuanchu.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3lHZeZgcKCDUplReTYlXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yuanchu.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717466773; 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=lTOg/v4agW4t4UIoB+YneZrty+w+zSP5tjy7abHeLhs=; b=C7ckFnox0b0mx0XPKbkikpT/5R2JFdNhJr9etIqd7VCSjkmkOT9knq334TZC63n5rtBO0C 92CxO/fpXZM9f643477SbxdKvHnta6neu/OEatakV4h7JLLMloJk8SoOykxp0kulK76xnm 2LizAjDD/1dlFvF7qRi8Q9JCQNCgsKk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KJleM9QJ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of 3lHZeZgcKCDUplReTYlXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yuanchu.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3lHZeZgcKCDUplReTYlXffXcV.TfdcZelo-ddbmRTb.fiX@flex--yuanchu.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717466773; a=rsa-sha256; cv=none; b=JdnPm02dUfx5arfcf+XSGRZKm5DWU84asbhtp8//u9VFMzRvO17dyrfQ/SSidjIzVb6piH wSoWcvscWx+qFIZCd99AfcCVvv9ha6g1K9eT5sdJIVOn6u4nBPJEUSOO8SV5PMh8o+5I8v G1E5CRXSqcc/xub5n7EUXyl6fxtkg30= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-df78efda253so8012827276.1 for ; Mon, 03 Jun 2024 19:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717466772; x=1718071572; 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=lTOg/v4agW4t4UIoB+YneZrty+w+zSP5tjy7abHeLhs=; b=KJleM9QJnjP2sCAILf3lIGWfdfhktd58+yDPcf9WYZ36AjJo66m+/AhEPtSUXtaMAM TOYOk+uvAMPcXM4DE/NByewZsdFXYJDlMKEGhKbgTpJZVYsKMrSnYUaffnnll4lULDz2 7oSYfLs5koJMQzJp1MdcZnqYo5GNp3QC0kR0NR0WADlFesMQlwrj8YaFhS2K2Y5eZfUn oqqrWYRvoLGXMbNspqYzblp2EqiYWLg+95kfiMB9I7JwCPSV4BiMI0EMSP12w+iLIMvX RD9JRys4W2mR6YjJ1Dyka3QjfBVaF9N+bTO2OopXU5y7X+C23vws9ezgbhGDiLSFqqqn DEPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717466772; x=1718071572; 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=lTOg/v4agW4t4UIoB+YneZrty+w+zSP5tjy7abHeLhs=; b=LZSmytAN7ObFTomAAdsO2ZpsJDdOVKpYXhRC2Zel+AtAoNPOx9d2hAA+Pm1oLexXXs VEJ1tnbeRIPyz3hwCmvnM1jpzBijaVeMXTs7kf4DlWs/YdyY1h3AobNTw/80MEjPJct6 p8hLrlnYNUKHMLtFX0eUaL2DVkMwGYpFleNeA63hv7CnJ0bOzCNP3V6Q8JLHd4gmKg03 wDN3cDzjRde2t/FGozR9Z02JvZpNZfCwTHHbbU+PdR90T3eitKNMRBCu6mW/SgDE3ii6 FLYT91Q7pqWI3pK+aqRlyPoGOCkTY2faOu2ghKuzZHw0puWNlzQ0lRaG11gfTuWRum5i JenQ== X-Forwarded-Encrypted: i=1; AJvYcCVLjQ24ra/uFECiaMVaovjOv5AeGuWVxk5jD1epVQObrU+SnO2xsjTFIq639zGFCEjn0Qwtekhm+M8P0vXBuHH8Lrw= X-Gm-Message-State: AOJu0YyBD99XwnRf9u6NNU5iwcLLls/Y9mXGtFK+HFYQqZ88Kf5E/kQv CZFYQssl4TAl9RhgoNWb51UovGLljiMAZw7EcHKfXJAKP9yguAhYyffG6/rhYw7hGBwjACyF+vv C5bC5qw== X-Google-Smtp-Source: AGHT+IF3oIyaAWYZ8ktE5GFmyMb/f4z4VLJcbawoHVR7E/BZJtA687NFWcmcqqxVcMJp0b3YvGvnhH6eb1O6 X-Received: from yuanchu-desktop.svl.corp.google.com ([2620:15c:2a3:200:367f:7387:3dd2:73f1]) (user=yuanchu job=sendgmr) by 2002:a05:6902:2d42:b0:df7:83fa:2736 with SMTP id 3f1490d57ef6-dfa73dbc831mr913449276.11.1717466772327; Mon, 03 Jun 2024 19:06:12 -0700 (PDT) Date: Mon, 3 Jun 2024 19:05:44 -0700 In-Reply-To: <20240604020549.1017540-1-yuanchu@google.com> Mime-Version: 1.0 References: <20240604020549.1017540-1-yuanchu@google.com> X-Mailer: git-send-email 2.45.1.467.gbab1589fc0-goog Message-ID: <20240604020549.1017540-4-yuanchu@google.com> Subject: [PATCH v2 3/8] 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 , Muhammad Usama Anjum Cc: Kalesh Singh , Wei Xu , David Rientjes , Greg Kroah-Hartman , "Rafael J. Wysocki" , Andrew Morton , 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-Rspamd-Queue-Id: 52CFE8000A X-Stat-Signature: hjrgg67cntwisdssg3rgtw7mx8prrisg X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1717466773-725133 X-HE-Meta: U2FsdGVkX1+6pAkLmzRVYf5qql476P6cNgraerNHUwoY3/3wpyP3ga6SHjJO/9zNVwmkKda089n94MApAxjTkb271NI2isG5YnOhBHp5+AmzKA5SGKELDgP0X2OumsZySJKiMMloLI9NqpC2Y9SCtEqYmTDZAbdMY0bpgjPBvxkL7yPttugTqxNMWYG9YcHx3DxebQjRK1lIQnkuw/gE+D/3Q+xvrR4gCnCjgbU/Qyl+HPn1t3qLKen0nGa5CGkLzO/IJRpNEASAFPxf/bZ+9Bblawa4Nk0g5b6I+xkMBSKkeZMGAALK3biQN+50YYKiXcXVxA1kkuHLQWf3BXMLFxb05NKzSlJVsGTwQIjnj30PYGrhuAZzj3idMQHJf25OLcWCyQV7mH3rEMqlT2nhc0J+CWNSjk+XV3Ym815iP0SBxtul5iiT8TCmVS/sfexgJeBtqxnF7MBfzDv/OBpaVUFCmb/DJLYZ+PFugM8tBcajCWnhVVBDGBef8/Rk0wojBxCwY9Ae7M+euZEhtgO3oofl1KYFq6XaZirZPep6o1Qa7aKGeUCTJuBxglbakvdnyxiyfHBvWi94R05aBB08W8oYLujTHLQEpfxPqWh7KHM8mu6q0htfAMxFwF2A0Cubp+Cjxdppu0RSZuT2Ya/rxJvypmNY86fMGj/0L6PISHAEmcfHAnngHjOTLSJXJ0m5lH38ip4Csik/JFY4CaKhL0rRxHyK143gWeoTlYQUdOg+gKjDMCwbsq76LD9Pl8KrqpE7UQxdNOZq5kIQD0VnJriSv9paRV8aPPmerj+yWC2QLCVhxqnblfl3Gcqw+MXkpc2tY8CU7td09JTtmMlTUZSINFINtY3LEnAD3KkxHk9fjqim9XInkrrIoq3ppibU4lASKPVkiQOE58Qjas99VdEz/na0c79mKjsqAHmTtN3MXD1DlrfY/sQScck+z8PhSTSMOh6y9xbOrIPiv0i xBJ0pcK7 +3zUlYdq3/p4bsDZnYVGA8fp9M5+uqc4EjcD8786h5EgVU92Pagx/S3e7O5NGPspO4Q5bCJ+sZ0uTu0+YxeX5gNXwaNCLIkMQl6zvp7pO4JOD4WcbTs1U1dfWB2sjfNN0f60+Z4M75YSYfZvcLHm1nZ8RpYi9FCNR9a44VbwncAAqad8b8BiqyfgUnnUDhtr+rug8o25LdVDp16LzZiDfuT6TkwUqsioi9Wg2W3XEsv4hZxfwarbuEnqlyy0KMM9ejT2Wuh4aE3rRQam3KrTMQks5Iwk1fifI9Us6Y0BNW0vVMjpuhmhfJ1R0QJWxzUfBIZTAzUc4s9n1+GdeWIRZ43wWSSOLMWYPby+UM7W8pUiNk+Jhvrus93YpQQB8Q2R2MZCHWoNoTkTIJ7sOKVWSju/sflW6QmUw4ACUtfwMuzcpzHkPHoBOKY0AsTpRY4RJ0yxj63EF+3TuxAIUije/COhq7pH0ZHISNciB0FjiZYwkHmbIaM1ais6qkxh+okohfLO3PmZO/FDbJuoeGhKp0CGuu9AMKaTMpV/dye8dUvKKSBGR2OiTHePwV3rWhpozGZhl0y59m+qDbaOp/abaIXyZyNG45+XtCQzyGBGtyVg2v9kFS0oNR8NaQPcvuXYXtKi+n+jutimovn8yk23Mvf4mZ10qqahgMQRdNa1orMUyoPTiT6FFGYrdTA== 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 --- 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 = {