Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3466779rdg; Tue, 17 Oct 2023 16:22:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXcDX7gLvKI66DrdAVUtCzNMPM7/U5AMVImHNSHZ8wUgwXo6oDS9SFRmlXbR7Z0yGKdmdh X-Received: by 2002:a05:6870:6586:b0:1ea:29cc:d2dc with SMTP id fp6-20020a056870658600b001ea29ccd2dcmr4538515oab.11.1697584969300; Tue, 17 Oct 2023 16:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697584969; cv=none; d=google.com; s=arc-20160816; b=ajp1ybukjQI+Etp4UGsCHuIAL6LMseXfGCXfJK1LE0UyTJVuI/TU3OWZmAvzkz84WJ DZ6Ui0MBdBBjhcgFvWbIcQUtSo9fNTdP97Ptn6xm0javFhiwjMMpUqgLGPKd3gqyE2Dl pTEIBEsgFJl58M74Qyq6E2IKhg6bUHIIE40mtgd/vQ73PZF2BJOxrUW5bvUHFYjyYr5J Dgayj9JcgGOoT7OBhion3LTAnO2Sjljsn17uSfZFXCwXa6nyray9mZIAgNx3OwQvH4tz 1aKfi2d6UAN1p+XktLxvZy3dtHkQe8fCrkE3HjmxIdSMxq5exYgFWM7Uhpt2wokc8AJS Wh0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Z7v4RebQyJpdc4sQlri0EPJCRWGhgONmwRgz8BMi8es=; fh=ujhzRoGvNYK+acFkUTmqZhWNw+cNDLTLaE+W0yhRAuE=; b=sUj54vaAryTQnNOa8nwQXVV/MMX7BJmidU/TAzVkVxrNcZ4AwC7S4EM7AzsG/L29NQ 1XgNE6JHTQWMtUhadaKHfIKO8lwG6hTQ9FsnOgGcdaZ49b/ChknV2JbHWZcdBBZT0KQl zb7sE8YTsfxZ5ADubsy4LeGQIw4Ny0ZBknkNYg5biqEwchZVY+fYLtn5yE2Vd3Dd9q9h 54ObzlsBpi3grbVcC125rS+oy5lHd0x6aeioAwHEvS4q7u2fxVoCtxylo3w8//0D36iE 2ZzUFY5om41SJswBXLMvgGXuOGOBidpTD2PX6cMrROnSplnZpYULGPJ9LvrINgO8AyOW SNsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FJjUrDVN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id r11-20020a65498b000000b005ad176a9d2bsi810060pgs.240.2023.10.17.16.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 16:22:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FJjUrDVN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id AAA968027838; Tue, 17 Oct 2023 16:22:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344327AbjJQXWB (ORCPT + 99 others); Tue, 17 Oct 2023 19:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344285AbjJQXV5 (ORCPT ); Tue, 17 Oct 2023 19:21:57 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F3E4F1; Tue, 17 Oct 2023 16:21:56 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-565334377d0so4666227a12.2; Tue, 17 Oct 2023 16:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697584916; x=1698189716; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z7v4RebQyJpdc4sQlri0EPJCRWGhgONmwRgz8BMi8es=; b=FJjUrDVNM245FBw75PZq6BIDq4hDWljDViMTS48XAb4zWxhQ9/EfhBzRsXfegH7Zu9 zaISAdljETrWRwxggYurxfCsd05MpK1PAu/Zw/TgNqr0B1DVHfMeTbF+6mvgQqfIOOvy SXeSOYvTtZPzmlierwpu+LlwWNC2vzBZpU/BYTcpE7bSejjB3TD2IZg4K7bqaj2Og1Go sVqO1xtm1oOC6o5DHv/qaLgIvB+V9Dghs56iW8pggg3uR0nUjA0d6/G4JLzv91X6BtLZ W8XipcmBeFmjJOFpCynkvcbjTKh/1PdFQq61+eJtvYc/g6txSZpSOp8p5Fyhpwj+qA8i 26nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697584916; x=1698189716; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z7v4RebQyJpdc4sQlri0EPJCRWGhgONmwRgz8BMi8es=; b=BE0hdc4f7iCzhJ1gYXxyaFHr7g7p6t9b7dvD+YxoF07hZwd+sjzokoZtRov9T7/T2t KsvchtWC/m0sWN737G3gj0jmFyWqpZAHiLqDatbIC9OOGcVMpy+lJMxfiw1Z1LRUxJBr C/LSBTknq2r/kjq3kCXi0UyUyQS2C3jA4JbwPsmt0YLRuXzrXPINWGqIV4czKiqKzqhC XcCzYJl3b/cDf/FAOWUav87ms6qN7N5TVwz8dMJWnKbtSS8QJdsRryunGcMIrQzU+eQS SZvpX5G6IEQ7ETrAOMIw9khn7BiKDuYTdddsa+ScM1MNPYgcxxfd0hm4jCsLblfJycK4 Fmzg== X-Gm-Message-State: AOJu0YyjDcNUr9x8Mrnoc1JYw6YuOK9muVMcTzyboN4u+CzMh7yXNOW8 TVhwzQG3yT+TYA/gDuQqDeU= X-Received: by 2002:a05:6a20:938b:b0:17a:284:de50 with SMTP id x11-20020a056a20938b00b0017a0284de50mr4589053pzh.6.1697584915727; Tue, 17 Oct 2023 16:21:55 -0700 (PDT) Received: from localhost (fwdproxy-prn-008.fbsv.net. [2a03:2880:ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id e7-20020a170902b78700b001c735421215sm2116251pls.216.2023.10.17.16.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 16:21:55 -0700 (PDT) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, cerasuolodomenico@gmail.com, yosryahmed@google.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org Subject: [PATCH v3 3/5] mm: memcg: add per-memcg zswap writeback stat Date: Tue, 17 Oct 2023 16:21:50 -0700 Message-Id: <20231017232152.2605440-4-nphamcs@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231017232152.2605440-1-nphamcs@gmail.com> References: <20231017232152.2605440-1-nphamcs@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 17 Oct 2023 16:22:46 -0700 (PDT) From: Domenico Cerasuolo Since zswap now writes back pages from memcg-specific LRUs, we now need a new stat to show writebacks count for each memcg. Suggested-by: Nhat Pham Signed-off-by: Domenico Cerasuolo Signed-off-by: Nhat Pham --- include/linux/memcontrol.h | 2 ++ mm/memcontrol.c | 15 +++++++++++++++ mm/zswap.c | 3 +++ 3 files changed, 20 insertions(+) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 3de10fabea0f..7868b1e00bf5 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -38,6 +38,7 @@ enum memcg_stat_item { MEMCG_KMEM, MEMCG_ZSWAP_B, MEMCG_ZSWAPPED, + MEMCG_ZSWAP_WB, MEMCG_NR_STAT, }; @@ -1884,6 +1885,7 @@ static inline void count_objcg_event(struct obj_cgroup *objcg, bool obj_cgroup_may_zswap(struct obj_cgroup *objcg); void obj_cgroup_charge_zswap(struct obj_cgroup *objcg, size_t size); void obj_cgroup_uncharge_zswap(struct obj_cgroup *objcg, size_t size); +void obj_cgroup_report_zswap_wb(struct obj_cgroup *objcg); #else static inline bool obj_cgroup_may_zswap(struct obj_cgroup *objcg) { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1bde67b29287..a9118871e5a6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1505,6 +1505,7 @@ static const struct memory_stat memory_stats[] = { #if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP) { "zswap", MEMCG_ZSWAP_B }, { "zswapped", MEMCG_ZSWAPPED }, + { "zswap_wb", MEMCG_ZSWAP_WB }, #endif { "file_mapped", NR_FILE_MAPPED }, { "file_dirty", NR_FILE_DIRTY }, @@ -1541,6 +1542,7 @@ static int memcg_page_state_unit(int item) switch (item) { case MEMCG_PERCPU_B: case MEMCG_ZSWAP_B: + case MEMCG_ZSWAP_WB: case NR_SLAB_RECLAIMABLE_B: case NR_SLAB_UNRECLAIMABLE_B: case WORKINGSET_REFAULT_ANON: @@ -7861,6 +7863,19 @@ void obj_cgroup_uncharge_zswap(struct obj_cgroup *objcg, size_t size) rcu_read_unlock(); } +void obj_cgroup_report_zswap_wb(struct obj_cgroup *objcg) +{ + struct mem_cgroup *memcg; + + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) + return; + + rcu_read_lock(); + memcg = obj_cgroup_memcg(objcg); + mod_memcg_state(memcg, MEMCG_ZSWAP_WB, 1); + rcu_read_unlock(); +} + static u64 zswap_current_read(struct cgroup_subsys_state *css, struct cftype *cft) { diff --git a/mm/zswap.c b/mm/zswap.c index d2989ad11814..15485427e3fa 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -704,6 +704,9 @@ static enum lru_status shrink_memcg_cb(struct list_head *item, struct list_lru_o } zswap_written_back_pages++; + if (entry->objcg) + obj_cgroup_report_zswap_wb(entry->objcg); + /* * Writeback started successfully, the page now belongs to the * swapcache. Drop the entry from zswap - unless invalidate already -- 2.34.1