From patchwork Wed Sep 13 07:38:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13382562 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 54377CA5501 for ; Wed, 13 Sep 2023 07:44:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E41286B0160; Wed, 13 Sep 2023 03:44:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF0AE6B0161; Wed, 13 Sep 2023 03:44:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB8996B0162; Wed, 13 Sep 2023 03:44:57 -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 BA1E06B0160 for ; Wed, 13 Sep 2023 03:44:57 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 87A7D120210 for ; Wed, 13 Sep 2023 07:44:57 +0000 (UTC) X-FDA: 81230787834.21.56C5C78 Received: from mail-ua1-f74.google.com (mail-ua1-f74.google.com [209.85.222.74]) by imf02.hostedemail.com (Postfix) with ESMTP id CFADD8000B for ; Wed, 13 Sep 2023 07:44:55 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Up6KpqOV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3CmcBZQoKCA0B154Bnuzrqt11tyr.p1zyv07A-zzx8npx.14t@flex--yosryahmed.bounces.google.com designates 209.85.222.74 as permitted sender) smtp.mailfrom=3CmcBZQoKCA0B154Bnuzrqt11tyr.p1zyv07A-zzx8npx.14t@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694591095; 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: references:dkim-signature; bh=TER8l9tb6XZzOMFgeFSUUqc1AW9x7/45uI22fSAHiTA=; b=gqhSjf5Iy0DdyceU/6usocmBqjzYJQoa/1ucsJ8L6q47KxyyhQMZxgGszQJ5mb4UP5MAMX AKj8580oFeOCgKrG2LQWBBdtjF/2jg2RyfF+8CdOJdOCDsmT48vIC662NdGjXnfQ9T4Znw 1orELFsUf8eAKivLAZR3kF/VUgcNZPU= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Up6KpqOV; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3CmcBZQoKCA0B154Bnuzrqt11tyr.p1zyv07A-zzx8npx.14t@flex--yosryahmed.bounces.google.com designates 209.85.222.74 as permitted sender) smtp.mailfrom=3CmcBZQoKCA0B154Bnuzrqt11tyr.p1zyv07A-zzx8npx.14t@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694591095; a=rsa-sha256; cv=none; b=v2BTYYo0CWpmXZaOvIMy1fIZ71jChic3H+5scLCMbCQZP15XujksOBO/mLDa40bbh4TQze ZeGLJfrDXHtCAWH+ICjTwHcDG+mOTXadZTvmx1dUlB8q2dzM0W+vwrR7b7lNSY+a5IoEkx iQUxBbItfIwfo1XmGIbyJBLizzm7lE4= Received: by mail-ua1-f74.google.com with SMTP id a1e0cc1a2514c-7a52a27dcc0so590620241.0 for ; Wed, 13 Sep 2023 00:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694591095; x=1695195895; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=TER8l9tb6XZzOMFgeFSUUqc1AW9x7/45uI22fSAHiTA=; b=Up6KpqOVqy3sEc9mSkCLDnZZ5E6XtpoKF9V0CgXQ4vW0TJLuspRVnSnA3v9w1QcARn ag+Oez+4GhmGS0i2yRsRraCe3sY7Z2It7BbD6ik/zsr3sDirBMz/jpHPqSbiSVYtJAIy TIP8SGFSG8wTPRDtHNNUSAphjwBlowi4raubKjKlNNK1UH6dvxAf3FUy4tMnMtdz5stb 0GEY/DaQYpZHq9ZWeLHutGLk2JRn3HLBJkCRHQmhbB9mC/s6n+8ee0iFlWGEgnudjXit ckwHqRj0JoiQPiCuIbKR8KMaFU6sSmf7xAGDUVFOKFjpOrhiK+o/ev+7e1QLqgTa8JZ3 x/pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694591095; x=1695195895; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TER8l9tb6XZzOMFgeFSUUqc1AW9x7/45uI22fSAHiTA=; b=IKF404VhoI8b9qJxzdjZLzEFasQxmELydOdlhA/8UzNbdsaqQiMSoQ24xsLFHpQUBe d9Dcx2yEHGf8Jfz+S6/An8j6C7Rg/SBQnKDIdMQtemboQyDWVPvbZGaZkANn2LihomQf ODYNcCQBCZPKy5Ou1GFKvsBp96i/pgwEk8GSClnIWSl6Pbj9COVFw1GaLKIQQmuAyJCe 5D+QoRZiYCdyvDHLbDzmL1MQRxQURUh2GKqJ4SnPcFBNZu8WVll5K8O3Qz0HRIAsHyAg fKSvRVGXLkWJD0DruSbPZGsnfbAhB3PrMR4T2qHUm5vqRmtF1HfkxPEhzgfOAIUkHTvi WTRw== X-Gm-Message-State: AOJu0YwDPZHrudaForibb+Mrc5O5dzkR9OHj3Op/6s6gk0E3m1QmyRPl Rhfg3dNV6b4SymWFx+CFNPrbmmjcuK9t9CEW X-Google-Smtp-Source: AGHT+IHQp+PFu+njnT1p9w3nSNET2cy8Iap1HxbLqu81ziIGR3gt50Y0BFxbflp2TpmdmnhV8RihdoKxxpXNaGXb X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a25:dad2:0:b0:d81:5c03:df99 with SMTP id n201-20020a25dad2000000b00d815c03df99mr18096ybf.3.1694590730421; Wed, 13 Sep 2023 00:38:50 -0700 (PDT) Date: Wed, 13 Sep 2023 07:38:43 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230913073846.1528938-1-yosryahmed@google.com> Subject: [PATCH 0/3] memcg: more sophisticated stats flushing 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 , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: CFADD8000B X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 7r8iw9559dsihso5mwuafgbzius8mzq6 X-HE-Tag: 1694591095-278654 X-HE-Meta: U2FsdGVkX19DIvJ5zHqEtPGf4JQm2ZUXJJ3YJMpaROkJpa16nbOWoqptYdIBtNUwBesWVSag3xsNTlhAwUUv5gVTiQj/rNGBXJL+v/mjVLzQt0LhUKBK7xJyXYIwgMK+YH6Cb99bJnLuofM/HJVf5gtK2Qukp/cMW9FJNu3jy6z6QlU8n+QQz7ClUHMMWDneDNEtG22isMJWkVrkiyWWAS+Zt2U76cTsD7HmEoxxmxJA8cIHXJMGKWjJ6u9WHRQhU21jgfKcRDvqLOvyzsd2xQ9umBXTpWfDov+lQCORZn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KiOO4yYUuCzrwhefkYYJGddmgQg4V1Q6RpgaMOYhe439zyXJMynl472LES+7+cKF0c7ul4cnhLHJbOoj7mGNnCxu5Jv2HtRWU+2UklV6LXwuxQ8lZj85Ul7B/CoE9s+/lhcDS9zQXg6+QFn7g1E2gwyZHHqcdeHl2X7yj6yFXA9XbMkN1O17QRzjwdEwkjP/4lBS256Jy8Xx7ndyhQEMq7DvjzGq8pi+LnJ52CkgRn0Y9Sm5kIupEYHMC05QtzzhKSQuQFRGyMbLetTgPpYcRM33dMgjVafYUx4eIbS8t61HZjL3TkolPStUC4Z4mocFB X-Bogosity: Ham, tests=bogofilter, spamicity=0.000016, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The current stats flushing approach is very simple. Everyone tries to flush the entire tree, and only a single flusher is allowed. Concurrent flushers just skip the flush completely. This approach has problems that manifest in both flushing latency and stats accuracy (or freshness). This series introduces a more sophisticated approach that aims to find a better trade-off between accuracy and performance. Essentially we try to get the best accuracy with the minimal amount of work done when possible (fast path), and we fallback to more expensive or less accurate flushes only when necessary. Details are in the commit message of patch 3, which is really the core of this series. Patches 1 & 2 are just cleanups with no functional change intended. This series replaces v4 of "memcg: non-unified flushing for userspace stats" series [1]. I did not send this as v5 as it completely deviates from what that patchset is doing (but still trying to solve the same problem). The approach followed in this series attempts to provide a more generic framework for flushing for both userspace readers and in-kernel flushers, to avoid having a lot of different flushing flavors. It also benefits in-kernel flushers as well as userspace readers. This series is a result of the discussions held in [1], and various suggestions by Wei Xu . [1] https://lore.kernel.org/lkml/20230831165611.2610118-1-yosryahmed@google.com/ Yosry Ahmed (3): mm: memcg: change flush_next_time to flush_last_time mm: memcg: rename stats_flush_threshold to stats_updates_order mm: memcg: optimize stats flushing for latency and accuracy include/linux/memcontrol.h | 4 +- mm/memcontrol.c | 125 ++++++++++++++++++++++++++----------- mm/vmscan.c | 2 +- mm/workingset.c | 8 ++- 4 files changed, 98 insertions(+), 41 deletions(-)