Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp17600rdb; Wed, 18 Oct 2023 16:25:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvJLZSpIbsVn5lDjsrrN31r4u2Xg9KUSN1SBFxaaLhbWYl+YaGo7wt0eSqOAKSNEggsHju X-Received: by 2002:a17:902:fb87:b0:1c6:2655:625d with SMTP id lg7-20020a170902fb8700b001c62655625dmr336131plb.15.1697671550458; Wed, 18 Oct 2023 16:25:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697671550; cv=none; d=google.com; s=arc-20160816; b=uMHp/vdrEIUGn5Ks+B1JhvvDIBrYCSDpQZIndFWl24rfiJYm4wSdRvcCZcyddtYVMK SkA49/YFOLdCwK2iCrqwtXef4g8HqY0y/opIBPjwZ2dbSazxrry/QfNSxTuqQEXxEU5t +h3vveVE2/I4JXNjcydwW8c+DTv7P1gS84qgHx6FUIDLqklpZOF/pGA6tBRAJrO2/PvE f5NHlSadYF/QMrZdUCBNs8sRo2A1dZDIq93jE8y4ggz1iy9KfHMvj5Z5t7P2MwVm7HzQ d7bPjVhEwmSb8wnBT7BBScTFxc6Bi4d2Ge9NImWtUrJGCDWpSq+hhIS/bFLDhhqbK9ey c/1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=l6OMMJzrM/r2QS69Np81LPWdTT/4PTGNitohtEO8snE=; fh=DkjA2sPo1IHhj3dSLT/8nkkbEQExnFRA5si61kyVZaQ=; b=PuCpR2Si2meYqthTHnVzXEUjQIyBkaxBDyrLE0Ipomm5IkZqSgDUa5wZwRCn7/9KhA HGzqK+MxL+liBXLl4jo2qaMCNbJWA5aL6A80fp5T4WF6wPzcANfhiX5jGxo1CMETr/aT 1pn+H0AkbXS/8KvgdhXP4VYoJwMCh3aTf4/iEXjMYaCV1qKxjEURCuzbnstyINN4g6NC O1SdewYJf3WteAfk8KjgV/SzyB2RiFRyoraMgm8/FoiyHR2034ZXsCb8EEO3t8lIOuvV tvvcR2D34MGyZmxToKkhrbaU6m/ovfWhb1tzDVeXqKJGYy3oDabQx40gOjwHChjYwyJ1 5Z+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jwvCiUBS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id f22-20020a633816000000b0055c95e91f67si3147281pga.155.2023.10.18.16.25.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:25:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jwvCiUBS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 65DED80A1375; Wed, 18 Oct 2023 16:25:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbjJRXZT (ORCPT + 99 others); Wed, 18 Oct 2023 19:25:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbjJRXZS (ORCPT ); Wed, 18 Oct 2023 19:25:18 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36B81111 for ; Wed, 18 Oct 2023 16:25:16 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9c2a0725825so658940266b.2 for ; Wed, 18 Oct 2023 16:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697671514; x=1698276314; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=l6OMMJzrM/r2QS69Np81LPWdTT/4PTGNitohtEO8snE=; b=jwvCiUBSCWRNkc8wgOUTYcTlhDf++g0fneizrponvy/EF+KqB3XG9FY0upuwnBzUz7 TQwE6sY40GZropMM6B26pJ9Eg3vWsQEZFXFkM2xOnLK3N7qUJe1MMlqgD6MLga6xHJvR g/UYhi7jofKgFugTP1fPxkESgzn+ec0Uf8kZF/fpay7k7fe5IIJCBMqL/5Xnv18QeGzN dc0AYyh+EXRDtNDYDZ1kYnLoi96xubkKdw4AdlYbX1EYnmBvfFzrAIU5fYLAgQ6mj/Nq WTrFFfgxcJ5O/XcSc/8W+1Fi1F6Usmm6plC7x1bc7OwItVkQbwQeuUZ3b7B91ZEFxblc Jxhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697671514; x=1698276314; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l6OMMJzrM/r2QS69Np81LPWdTT/4PTGNitohtEO8snE=; b=jNEyhPEWaD5n5DI5bKyeifdQaOFr0kd1r1FFhLL8epfbqwPEEM+R9CqGqjO4aRE1nW zpueetfrtQnzGDEKKIuFTjI7vOjU/TvaUpf8a9iAFG8Pfu61G6GhVSdQ2fcLSd8CrzHb pd+FsKuPOnBePrKRDwyvjSl7C9RtT8Yp6ljxrNczK/GGCphtiDurcSXoQ4xjkjyV8gGn NRLdDMW4FKxYLG8VuZ27SzRJ5quRAlcGXoQEt/DnyUClD2eUl57K81LoHycnt75JnCMD SYPuY+NI5ttpjBAVpwNEfB2Uok20zGuDVsk+64rQeJtvWZajgcgC/7juS9RW5sj6PHmV XyMw== X-Gm-Message-State: AOJu0YxcmtxjZfxaPGpXqVmUUc6mi+u1p8/xtsTl0XnbTqDOukWGExQl oHnvqYNsqHDdYU3C839v7A3ScOTtLVlgAejir6dT4A== X-Received: by 2002:a17:906:dc91:b0:9bf:5df1:38d2 with SMTP id cs17-20020a170906dc9100b009bf5df138d2mr445791ejc.3.1697671514379; Wed, 18 Oct 2023 16:25:14 -0700 (PDT) MIME-Version: 1.0 References: <20231017232152.2605440-1-nphamcs@gmail.com> <20231017232152.2605440-4-nphamcs@gmail.com> In-Reply-To: <20231017232152.2605440-4-nphamcs@gmail.com> From: Yosry Ahmed Date: Wed, 18 Oct 2023 16:24:38 -0700 Message-ID: Subject: Re: [PATCH v3 3/5] mm: memcg: add per-memcg zswap writeback stat To: Nhat Pham Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, cerasuolodomenico@gmail.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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Wed, 18 Oct 2023 16:25:32 -0700 (PDT) On Tue, Oct 17, 2023 at 4:21=E2=80=AFPM Nhat Pham wrote= : > > 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_cgr= oup *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[] =3D = { > #if defined(CONFIG_MEMCG_KMEM) && defined(CONFIG_ZSWAP) > { "zswap", MEMCG_ZSWAP_B }= , > { "zswapped", MEMCG_ZSWAPPED }= , > + { "zswap_wb", MEMCG_ZSWAP_WB }= , zswap_writeback would be more consistent with file_writeback below. Taking a step back, this is not really a "state". We increment it by 1 every time and never decrement it. Sounds awfully similar to events :) You can also use count_objcg_event() directly and avoid the need for obj_cgroup_report_zswap_wb() below. > #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 =3D 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_he= ad *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 alrea= dy > -- > 2.34.1