Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2034354rdb; Thu, 7 Dec 2023 16:43:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IF8S2/INAZSO55BTI/JK/eBybf1wLfg4DqdaUCX4DZlCAM8rvG5+HR0LcyYPXpBComd7mIV X-Received: by 2002:a05:6358:3102:b0:16e:271d:1db7 with SMTP id c2-20020a056358310200b0016e271d1db7mr4201587rwe.2.1701996222963; Thu, 07 Dec 2023 16:43:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701996222; cv=none; d=google.com; s=arc-20160816; b=apzbqyiEIycIatz95su0SPmIPKTBcN3+dZQw2fi0NC4w76HD9YrwqwDmY4q7KHTEw/ C7l85WppLc1mMgN0jCnvFk0y9+ptzFCzZl6vRh63JRc29XUNpWAGwGmLXio/Y/+7wVB1 eJp8j+dqAS3wHbGMqwLIxLTeu0Pexi3DphZ1UmNCIwKl5cvl+tMuRPWPEYQsi6VmxLyO 17m9g+5gcWqsnJSZH47Majf59zb79QAbVsOpxiO0hz+9L+ZaMuTWVKT2bWZwzfAaLKWY nz0uf/9XymqhFeQXqOg+j2QRCrMWyJwjFdNWucxNVNWJEuS2aL12rDWwfhsjuGB5sCiH KKYw== 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=FWYFuM4aF1DscIfJp1qCXBW0v49EJ4SCp/Ip43Zbk+I=; fh=+IZ/4LgMTYLH70EIjl8jMCQVbP6gCR6+M86/YGwPlHk=; b=OiTWQqnt1d5whjzWwhf7M3vdJU99HFt8EbMDuD98bwXagKsiUu+Ai1aTlCX/NtyrLH TG+okTbXd+T1vESfvifl8k8oVPnA6oV59XG6UfjJys0zyUMafMNbj13ZOpPG8Oztq0fs T/lT4N56JdQxhxAGA1CyfQPrx8fmqOkFsLCQ2D468weT26IfVPK5P/Lv0a69MFofsnWd pnyVp5UAkvnx6oM9z3ucT2JX7s23MGd5VMhAx2yiJgC74ziLER/dag9LhdAdDq8g0Hl1 dZ1r6xQq3hc9A1sxOFn2WNwX3Okb/kWRxYhvtbVm0/06LXalgc9UYKbB/2q83/xHyH8g vDqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oARRA2vC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id f24-20020a17090ac29800b0028555ec82easi1972988pjt.57.2023.12.07.16.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 16:43:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oARRA2vC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 4BCEB80EB855; Thu, 7 Dec 2023 16:43:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235442AbjLHAn0 (ORCPT + 99 others); Thu, 7 Dec 2023 19:43:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232667AbjLHAnY (ORCPT ); Thu, 7 Dec 2023 19:43:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 527BD10DD for ; Thu, 7 Dec 2023 16:43:31 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E03D2C4339A for ; Fri, 8 Dec 2023 00:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701996210; bh=HYlD+5N1fSdWbXan4+yka11Es1jGO6Ei+XatWP7GuHM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=oARRA2vCGIszR1H8XkHNX1QA0rlV1IEbVB6F79fTLj/4HheOIsWWoVhOZbG7il1A+ rrcLQNpoT3g+/xPbDLGRatT50pm6Ncq8frjHY/o9L2CqViHrvmBjCZer0EdPeA/2iy xdIVULFff9kTTbPFUa2AofVidv4gxFjGcqZWcOX408h+Lzl7d45VNrvBJbMjmFGKXJ yeQaTkma3gKGDdiVcYX2IZNphOc3kRy37waOcvG14FuNTEikSm1Vakh0EbFW3wkKc5 DA0uTVuhCrwRHc4KOkaX589U6CO4Rtp38sNhVdVmGlGBjOvD4PWp2nbWfDCrbecpUr RYpxFlw4rTOQg== Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2886576cf18so1283468a91.1 for ; Thu, 07 Dec 2023 16:43:30 -0800 (PST) X-Gm-Message-State: AOJu0Yxk9tiLeaAN71QJwZehTfZhk5p6xkMnwiDstznvBFecMhpPCdMR npkibm6FbYCvyPnKmQ3ZdMOxTMliBRMLcCtEvKIaOQ== X-Received: by 2002:a17:90a:7c46:b0:286:6cc1:278 with SMTP id e6-20020a17090a7c4600b002866cc10278mr3164336pjl.67.1701996210098; Thu, 07 Dec 2023 16:43:30 -0800 (PST) MIME-Version: 1.0 References: <20231130194023.4102148-1-nphamcs@gmail.com> <20231130194023.4102148-6-nphamcs@gmail.com> In-Reply-To: <20231130194023.4102148-6-nphamcs@gmail.com> From: Chris Li Date: Thu, 7 Dec 2023 16:43:18 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v8 5/6] selftests: cgroup: update per-memcg zswap writeback selftest To: Nhat Pham Cc: akpm@linux-foundation.org, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 07 Dec 2023 16:43:40 -0800 (PST) Hi Nhat, Thanks for the self test. Acked-by: Chris Li (Google) Chris On Thu, Nov 30, 2023 at 11:40=E2=80=AFAM Nhat Pham wrot= e: > > From: Domenico Cerasuolo > > The memcg-zswap self test is updated to adjust to the behavior change > implemented by commit 87730b165089 ("zswap: make shrinking memcg-aware"), > where zswap performs writeback for specific memcg. > > Signed-off-by: Domenico Cerasuolo > Signed-off-by: Nhat Pham > --- > tools/testing/selftests/cgroup/test_zswap.c | 74 ++++++++++++++------- > 1 file changed, 50 insertions(+), 24 deletions(-) > > diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/= selftests/cgroup/test_zswap.c > index c99d2adaca3f..47fdaa146443 100644 > --- a/tools/testing/selftests/cgroup/test_zswap.c > +++ b/tools/testing/selftests/cgroup/test_zswap.c > @@ -50,9 +50,9 @@ static int get_zswap_stored_pages(size_t *value) > return read_int("/sys/kernel/debug/zswap/stored_pages", value); > } > > -static int get_zswap_written_back_pages(size_t *value) > +static int get_cg_wb_count(const char *cg) > { > - return read_int("/sys/kernel/debug/zswap/written_back_pages", val= ue); > + return cg_read_key_long(cg, "memory.stat", "zswp_wb"); > } > > static long get_zswpout(const char *cgroup) > @@ -73,6 +73,24 @@ static int allocate_bytes(const char *cgroup, void *ar= g) > return 0; > } > > +static char *setup_test_group_1M(const char *root, const char *name) > +{ > + char *group_name =3D cg_name(root, name); > + > + if (!group_name) > + return NULL; > + if (cg_create(group_name)) > + goto fail; > + if (cg_write(group_name, "memory.max", "1M")) { > + cg_destroy(group_name); > + goto fail; > + } > + return group_name; > +fail: > + free(group_name); > + return NULL; > +} > + > /* > * Sanity test to check that pages are written into zswap. > */ > @@ -117,43 +135,51 @@ static int test_zswap_usage(const char *root) > > /* > * When trying to store a memcg page in zswap, if the memcg hits its mem= ory > - * limit in zswap, writeback should not be triggered. > - * > - * This was fixed with commit 0bdf0efa180a("zswap: do not shrink if cgro= up may > - * not zswap"). Needs to be revised when a per memcg writeback mechanism= is > - * implemented. > + * limit in zswap, writeback should affect only the zswapped pages of th= at > + * memcg. > */ > static int test_no_invasive_cgroup_shrink(const char *root) > { > - size_t written_back_before, written_back_after; > int ret =3D KSFT_FAIL; > - char *test_group; > + size_t control_allocation_size =3D MB(10); > + char *control_allocation, *wb_group =3D NULL, *control_group =3D = NULL; > > /* Set up */ > - test_group =3D cg_name(root, "no_shrink_test"); > - if (!test_group) > - goto out; > - if (cg_create(test_group)) > + wb_group =3D setup_test_group_1M(root, "per_memcg_wb_test1"); > + if (!wb_group) > + return KSFT_FAIL; > + if (cg_write(wb_group, "memory.zswap.max", "10K")) > goto out; > - if (cg_write(test_group, "memory.max", "1M")) > + control_group =3D setup_test_group_1M(root, "per_memcg_wb_test2")= ; > + if (!control_group) > goto out; > - if (cg_write(test_group, "memory.zswap.max", "10K")) > + > + /* Push some test_group2 memory into zswap */ > + if (cg_enter_current(control_group)) > goto out; > - if (get_zswap_written_back_pages(&written_back_before)) > + control_allocation =3D malloc(control_allocation_size); > + for (int i =3D 0; i < control_allocation_size; i +=3D 4095) > + control_allocation[i] =3D 'a'; > + if (cg_read_key_long(control_group, "memory.stat", "zswapped") < = 1) > goto out; > > - /* Allocate 10x memory.max to push memory into zswap */ > - if (cg_run(test_group, allocate_bytes, (void *)MB(10))) > + /* Allocate 10x memory.max to push wb_group memory into zswap and= trigger wb */ > + if (cg_run(wb_group, allocate_bytes, (void *)MB(10))) > goto out; > > - /* Verify that no writeback happened because of the memcg allocat= ion */ > - if (get_zswap_written_back_pages(&written_back_after)) > - goto out; > - if (written_back_after =3D=3D written_back_before) > + /* Verify that only zswapped memory from gwb_group has been writt= en back */ > + if (get_cg_wb_count(wb_group) > 0 && get_cg_wb_count(control_grou= p) =3D=3D 0) > ret =3D KSFT_PASS; > out: > - cg_destroy(test_group); > - free(test_group); > + cg_enter_current(root); > + if (control_group) { > + cg_destroy(control_group); > + free(control_group); > + } > + cg_destroy(wb_group); > + free(wb_group); > + if (control_allocation) > + free(control_allocation); > return ret; > } > > -- > 2.34.1 >