Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp26276rdb; Wed, 18 Oct 2023 16:51:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLXSFvdDfhvjbwr+hzBjtrk6v6oAyLDlUi0n8XmcYo/DSX7sOwg+kBmlzzSqw/3bckcQlA X-Received: by 2002:a05:6870:cb8a:b0:1d0:d78b:982e with SMTP id ov10-20020a056870cb8a00b001d0d78b982emr1109677oab.35.1697673102664; Wed, 18 Oct 2023 16:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697673102; cv=none; d=google.com; s=arc-20160816; b=kFlTsnZuS3OMc2bQtvX50QeyVUiPbRNwW4RNJ67IbdwJs0pyewV3Iu3sk6xXkDU+Xr ko9rnDGLtytnw/0GLuBpH//e1ZeQgjZawIt8eMUc6p3Ijzgl2uyT2GFuUA90K7u3rwir s/UJD777rQ9GJnquCm0hoN3E1TmdI+yUWGTD/ZJeJc4sK8yBWSzv7pxxmmsGiaK8NNL9 8bS14Cpk78LGhSx8z6LWFhAXTzxyYcAvqwZhNPkE2isRjVRx3vmvoLLEVBCOnBcI61Q0 nBBtvTdXXmsdN296w4aI092CkwwJ6g0P5SbWLyDk9t+Vp3SSYah5eAqZW2IwIb2GwuZo V02w== 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=f1fdvR+TCyCaeZPp3VqktkqpHwhabkS/n0H1eh7TjWE=; fh=Ha6Yyi747j2OVGLpdshCP7pZJv95ZhOfXyqiD6nnQ+Y=; b=fBv4aEM50l+aoa2YoKKQMnIxUlDrFqr2W5j585bVBLaG6PK6R8KnCbcG4z7CXrdwv7 BimNbg/ewH8nmmdNVsnlzSwPJiRQhblrow9Y75Me4pBEYYXYGl27oLSpj1wANNlXpqk4 GmSCquFMAfUw9d7cSXReBBgZW2f6h0Aesv2U3mwyIqxxyQ6eRjsucuQeCvCbnvqXAcpL 5bHH7rmthzhAbI0ZdreWPvdUEWq2vVSN1PZxM4NRiq72sZ2Kzp0hBxTVgLhVpI+n0ZUt kokT2F/2HDi5M2zyBu/7dtjq99F5VyhzUa1l7e4NVym8CCvOoOTTEkdNrWJ+zfaYpq54 8zgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mvmi0VVs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id h4-20020a636c04000000b00578eafd0826si2026213pgc.398.2023.10.18.16.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 16:51:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mvmi0VVs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 949DA80F9319; Wed, 18 Oct 2023 16:51:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231886AbjJRXvO (ORCPT + 99 others); Wed, 18 Oct 2023 19:51:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229694AbjJRXvM (ORCPT ); Wed, 18 Oct 2023 19:51:12 -0400 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 807B8FA; Wed, 18 Oct 2023 16:51:10 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-7a66a321e62so64655639f.2; Wed, 18 Oct 2023 16:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697673070; x=1698277870; 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=f1fdvR+TCyCaeZPp3VqktkqpHwhabkS/n0H1eh7TjWE=; b=mvmi0VVsvUX3jCpfN2o7B8SwDXi01NlKK4aJwmgPNzZL54iof1Iv+R90Zc1uMiG+9B Pt3Q+7KnAEIIMp2f10wTwe9XAg8fdcAo5xkxqfE1N0Yes/T21HLj64L/hkjaRTpwI6qz Il1O/RvMFQsQ7q2mUz6vSb+KHUR5kG9oPeqP+aE5KevD7lOUcFYSB4z/kBcvIiiBELTY Gf6XcGRH6fpKY7dV+c06V85s+UAymFrBCf0wx9DvnPfvhywigX9EJ4js01UPV0IYaY6Z wAwvhaD/DIU0xtVtwUpXrzR2Ws6drwVof+Ldph+3YaEmW2Z4kUCMW0pwefF8YT9AFScb /XNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697673070; x=1698277870; 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=f1fdvR+TCyCaeZPp3VqktkqpHwhabkS/n0H1eh7TjWE=; b=HuykW/bSAzi4Yr97/toqaT7ygpHioooS7RtvrjgyUn5ypy1Jn8DKFGaAcga/BZRAEm uDJu3rX2pYUOvLZhJ2WmqEGsvnVU0D1HpTQDNgV6up0A6Ck5UfCMN6cUmH2q//eZWE9g kG+e9J18pGlLikKI/j/Gt4XxwbyMjAyx9tIai5aEYs6w5s6B1B2/uUezE5a/tCYqw9++ T0NxJKMuVHdbZLLgV6hA6br7e0jFtXuyKPegLQ+HfUuNP9EMMLlrd1A5XXCPcz1zkMdg TPW7FbTYPMzwALz5+iNQBZ8/gp8VoqF0Ucn/qL0aMjuRqFElUCtZYEQQEozZy1kMd4RE s9jA== X-Gm-Message-State: AOJu0YyKxWZsqMcG+tMi8HMT3Twegzlk8n/uK/cPoSpcQOOrttq59wXF mlAmqsLNe9nhLGQm1pb2m8jX3KEYnBfUyMSaHEc= X-Received: by 2002:a05:6602:2e10:b0:792:8d16:91ef with SMTP id o16-20020a0566022e1000b007928d1691efmr756328iow.18.1697673069754; Wed, 18 Oct 2023 16:51:09 -0700 (PDT) MIME-Version: 1.0 References: <20231017232152.2605440-1-nphamcs@gmail.com> <20231017232152.2605440-4-nphamcs@gmail.com> In-Reply-To: From: Nhat Pham Date: Wed, 18 Oct 2023 16:50:58 -0700 Message-ID: Subject: Re: [PATCH v3 3/5] mm: memcg: add per-memcg zswap writeback stat To: Yosry Ahmed 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=-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 howler.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 (howler.vger.email [0.0.0.0]); Wed, 18 Oct 2023 16:51:35 -0700 (PDT) On Wed, Oct 18, 2023 at 4:25=E2=80=AFPM Yosry Ahmed = wrote: > > On Tue, Oct 17, 2023 at 4:21=E2=80=AFPM Nhat Pham wro= te: > > > > 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_c= group *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 :) Ah yeah, this is probably closer to zswpin/zswpout counters :) We can probably re-use that piece of logic. > > 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_= 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 alr= eady > > -- > > 2.34.1