From patchwork Thu Nov 16 02:24:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13457528 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 8FBA1C072A2 for ; Thu, 16 Nov 2023 02:24:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 243436B03DA; Wed, 15 Nov 2023 21:24:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 17E326B03DC; Wed, 15 Nov 2023 21:24:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0456C6B03DD; Wed, 15 Nov 2023 21:24:18 -0500 (EST) 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 E861F6B03DA for ; Wed, 15 Nov 2023 21:24:18 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C2668B5BCA for ; Thu, 16 Nov 2023 02:24:18 +0000 (UTC) X-FDA: 81462222996.23.5AEB911 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf04.hostedemail.com (Postfix) with ESMTP id 0C44E40009 for ; Thu, 16 Nov 2023 02:24:16 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Lz4er087; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3UH1VZQoKCNELBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3UH1VZQoKCNELBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700101457; 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=BcE9vJD0hOv2TBpe3ivca8OUmRQ1FOEoUuzJXTFrwQU=; b=V/cQ+HPub3LRc5wRmHRqgmdZDgagO0gT78aM6gqGhcr+q/Iicz8xNvyxhvsIHqqBvekbB8 tLblR3zLDA/OZ89AJTA7eQudhtX5IlhrwnRbKe952q548rpzfOeHG1sTUUsQHNhwrHw+ju 9izIAf/Y7H3AFVH4c1cQPXlJOcwCxNc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Lz4er087; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3UH1VZQoKCNELBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3UH1VZQoKCNELBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700101457; a=rsa-sha256; cv=none; b=rxcPehLDZhoNEReFDQVz/rFUQULYj0pWbrtLfRYh1ZE8DV8dleUIvoTYmMpU2hDb8B8h1p 4WJ3veT5o7Xv86qlj3s0tkaclQBUdywoex0MCSUfUe98XXs8BANyUjOdw7nXgmq4Cuhn1I nNtN3/kkQwXHMM5qoiWkuOMfSx1ZZOs= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-daf35a935fcso401421276.2 for ; Wed, 15 Nov 2023 18:24:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700101456; x=1700706256; 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=BcE9vJD0hOv2TBpe3ivca8OUmRQ1FOEoUuzJXTFrwQU=; b=Lz4er087QG+xQnsOtBopWjKXijaXJhajN/WNLlKJ9XxqxYHbY1XGYV9O5Lmc6eOgLK c3IZLlgNpN7Vugq99WcLerWEU9sABfVjQd7RI7eOhmxWEtdf6aSuFlQGSpLnTqoYJ8v7 rPcdxqxGY+garxk43MiiApl8kO2b4m52DC47PwlfzblXK8U6a+O6nr6Bg18cmkSFv577 5ZOzk2RbqdDSAIEfSWjHRh8MKsB9njhoBEnjNpWkA2SCsx1wg5hArNluVDQOW8I6y9rN tGq0qfC9KjbdUNc7ZgwN1PxeC6rTWPB9054UEHxAL/tYv9AUKlKcVkhNMS/T8gqDYYI5 Tfcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700101456; x=1700706256; 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=BcE9vJD0hOv2TBpe3ivca8OUmRQ1FOEoUuzJXTFrwQU=; b=xK0IMHQcSWFZLHSWQpfpHYwS0yBJ4VYi7GjKFsZ8URJVBdNIIh/r78BvKTIq9Ybzch rbF6cSyVRh6fAfjL+AWfaNKD6uh1SSndBhqYji/md4/EACPf/9NhyAAmHKIeg5HuOSfh PMqdYzIAABwifF9+pdRnov2IJOhjl64yJsA5PtL9zwNVHppAvkn4PI90ysLSAH1uPc+X vhOoctiHI3xZ5yciVkDQIWPWzYiICbp4JpAHbSFl8R10OenAV3GNKOajJN3aivGS+OlG DSQcHDxOGGwqya98vx3VVme2fg6E6c6XabLLCSd3aYtoF1SVhgbMn23jXYFDV1CjKE8C fj1A== X-Gm-Message-State: AOJu0YyujsDANLm639fEGKwExHTJr85uDpASyjD9+jWVdsStvO4otTX8 GySgee6QxcVBSVDlB77SEU3JCpX7oBDDMRyM X-Google-Smtp-Source: AGHT+IFy97x2nQDJgIiWGH9dEF3svZisBvzaosL7zloYt6xMQ4EjhERYd/7GmdSfHzW6U7mYn8R6aavP5vLCYx6D X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:285:b0:d9a:d272:ee58 with SMTP id v5-20020a056902028500b00d9ad272ee58mr402081ybh.9.1700101456166; Wed, 15 Nov 2023 18:24:16 -0800 (PST) Date: Thu, 16 Nov 2023 02:24:06 +0000 In-Reply-To: <20231116022411.2250072-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20231116022411.2250072-1-yosryahmed@google.com> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Message-ID: <20231116022411.2250072-2-yosryahmed@google.com> Subject: [PATCH v3 1/5] mm: memcg: change flush_next_time to flush_last_time From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Ivan Babrou , Tejun Heo , " =?utf-8?q?Michal_Koutn=C3=BD?= " , Waiman Long , kernel-team@cloudflare.com, Wei Xu , Greg Thelen , Domenico Cerasuolo , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: 0C44E40009 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: cs3x7ky9eypdoqywfxk95xotgzr7tszh X-HE-Tag: 1700101456-83682 X-HE-Meta: U2FsdGVkX1+gC8AobI580H4v9OnNKLDllmfOs4iZoxMEOsHWpwZ1hihqrjxlfFM9XkmzEU8QunXX6PVBQ0CItwEX2VEfjZ9H4QQvYNnlmT5jFGzxs9448yMYC08gZtIpBxm2H5LxPwZOjjY7+WugatEiJPEd54bqBu72b+FWHn6HA57t48nvfMMAFI4lfm9FtPAKdV+/eBI3TfGgKPxiaiv88vKO71eRnMbdLf5yXY0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v5HAv2dlrNBEuujp4Mp/vuCxDVk/bzQIYa1TdNDYmMz6As7Quwv5MzVLtSrC3ghJpPufTK6sbLoU5ZVJkmd9C1BZOuh941fBtt9D68QmcCFhsfR8mVH9TOe6Y8BMcpwPv9ttPkpI9uL3Zd67h0PQbOp928Jtuxy6+s+X5EyCs9fgfnx5CvKGfcSszrAS2eOwPMVT5amBH6cxQdqIzaMCRM/iDVzgHxbF0nKiZeSLdn2WX2a4UdftiwMsigsi0NmDEFkXBz1c3bcb7o4r2ZGA54muULVXaFHWKMiUEPxfeHkTfE5M5Y4MI+KV/yoiCOdiAlKsS+w1eICx3HTKrv9ILHM9MNod+7NPgQ5TXASbVyjeIg6YdxKaZ7LR/q+K7Yy8= 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: flush_next_time is an inaccurate name. It's not the next time that periodic flushing will happen, it's rather the next time that ratelimited flushing can happen if the periodic flusher is late. Simplify its semantics by just storing the timestamp of the last flush instead, flush_last_time. Move the 2*FLUSH_TIME addition to mem_cgroup_flush_stats_ratelimited(), and add a comment explaining it. This way, all the ratelimiting semantics live in one place. No functional change intended. Signed-off-by: Yosry Ahmed Tested-by: Domenico Cerasuolo Acked-by: Shakeel Butt Acked-by: Chris Li (Google) --- mm/memcontrol.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 774bd6e21e278..18931d82f108f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -593,7 +593,7 @@ static DECLARE_DEFERRABLE_WORK(stats_flush_dwork, flush_memcg_stats_dwork); static DEFINE_PER_CPU(unsigned int, stats_updates); static atomic_t stats_flush_ongoing = ATOMIC_INIT(0); static atomic_t stats_flush_threshold = ATOMIC_INIT(0); -static u64 flush_next_time; +static u64 flush_last_time; #define FLUSH_TIME (2UL*HZ) @@ -653,7 +653,7 @@ static void do_flush_stats(void) atomic_xchg(&stats_flush_ongoing, 1)) return; - WRITE_ONCE(flush_next_time, jiffies_64 + 2*FLUSH_TIME); + WRITE_ONCE(flush_last_time, jiffies_64); cgroup_rstat_flush(root_mem_cgroup->css.cgroup); @@ -669,7 +669,8 @@ void mem_cgroup_flush_stats(void) void mem_cgroup_flush_stats_ratelimited(void) { - if (time_after64(jiffies_64, READ_ONCE(flush_next_time))) + /* Only flush if the periodic flusher is one full cycle late */ + if (time_after64(jiffies_64, READ_ONCE(flush_last_time) + 2*FLUSH_TIME)) mem_cgroup_flush_stats(); }