From patchwork Tue Oct 17 23:21:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 154592 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4454731vqb; Tue, 17 Oct 2023 16:22:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5B+ulnzRpwBfmBdlc0cuxOVUN4yRE2LXgluizX06YVN85uLxMtpeDHyPzdUL8oTzQ1UBA X-Received: by 2002:a05:6a20:d80d:b0:163:ab09:193e with SMTP id iv13-20020a056a20d80d00b00163ab09193emr3613295pzb.1.1697584940632; Tue, 17 Oct 2023 16:22:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697584940; cv=none; d=google.com; s=arc-20160816; b=0+Oq1WVBZFz7l/u3tpD3l3WYfCFZumyanf/gtsZLD6Cq9B8e/VkqtwR8xGbzyBH/HL sNZrHpMTHLxlWT7gR0cmQuz9gQ6dhnP0hJGFmWngTLIW5P17Zkt4DIWjnHKIkM+RZKv2 /5SYusaC8HesmHSKQEeTsvbEZnOnn8F6lYJpq85pezbWJdjM2qlAWN+3FTkbiv8WuiYY oZyyYMRZVqytEFwcAMl6EYGj7AyifA4kyCaSSTftotGbDBzlsDqpgiz2hWOVMSnemPl/ 3T2PZ69+VR9qMnMNVDYjxcefkBH4893PIKfvK6+di2JT0zu7EWT+rEW3wKHIt+OdevGp Z/2A== 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=l1cHnelUz7JpCw4ya3vv+qgP9pRjbzsLh3QaMob4Kno=; fh=ujhzRoGvNYK+acFkUTmqZhWNw+cNDLTLaE+W0yhRAuE=; b=GmNGqDdXjJDVnDtx+gfEmfTixN1MHx20BAqG9GDTMa25Wo0lyW60bagKCcrIX0kHnH xegBJ/8LcC5QZf0xG2Abw5DdfBQR+oaXYvsPv9VRGMFZAn9biiIDVBeaY8p+JKhSMQ2m YGJjfyHKa27WEAerLesGnH2rKhK4luvISoCR90U+9Bo4xhAa+eDTtfF0ZCceai0V8aPx ibWZDt0uoxp8tl8gk/2/EA8ysdkkUWYpmLrzbBJfvO1LtlIGB23FwSz3RbjfY/8wRvgG fXZfzR5GZfHqlBDtgGfhGjZ4wNAgvcnhHlTxI7CVQ04PM171C7gpyVLuLStFQugIxUWk pH0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bc2Xv+yC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id j184-20020a638bc1000000b0054fbd904b6dsi815375pge.500.2023.10.17.16.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 16:22:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bc2Xv+yC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id A237A8106802; Tue, 17 Oct 2023 16:22:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344368AbjJQXWH (ORCPT + 22 others); Tue, 17 Oct 2023 19:22:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344300AbjJQXV6 (ORCPT ); Tue, 17 Oct 2023 19:21:58 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29FD492; Tue, 17 Oct 2023 16:21:57 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-577e62e2adfso4026563a12.2; Tue, 17 Oct 2023 16:21:57 -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=l1cHnelUz7JpCw4ya3vv+qgP9pRjbzsLh3QaMob4Kno=; b=bc2Xv+yC6w8vZfRQxkt5/aUH2uyTB32/sDUnY/grhMoJx5YGkQmWQYB23Z7u0IJDZa DPZ/lkY+m2bv0LglAXM1J0oQrfWuAKn5/T+OvBtR62UwGy9fS/fznUWDicQGKtlm/dno XeLJExaFHd/Ha+DVn+lW+vVLly5RRxqjw6uXnKLOk6Z/05trKJLwTqyKVqNvH0T7BAy/ 52Uplxa3q7UxWjsromTdoG32K0EzjpZJRJ3E4/9Bk5xZFNvLN9UFBXlHX6WL/m/o5rQY gLNL9b1Pagk+n2kLu52X86eLCD/wqEfDzkuv7brfcZFv0HSoMl4wJi/4CDCvt1p1xxFl V/gA== 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=l1cHnelUz7JpCw4ya3vv+qgP9pRjbzsLh3QaMob4Kno=; b=BzT748mXMUsS5UX2HXR08KPS3NME2nxPJ6FbKkkTS6vV+PeoE8JPRRGDHzr8C8qi6c 8yY8RyDiKHpOenMa76NlT40MUoFYKTuE7DAnGPDQBehWzvkQ1GiIhlkUm9uiQ40CprnZ 0ayH1GaSUK4KsfBOTc9xradpxIbQCOHLm1VUvZ3fCgyTPddDW2kAUdt9IlNFIXIXwJ+p s1O6D69zPeH/oBD/UlOzZsL4NIpDOehpPlYq6/efL5UMaCBDSx1MZJPoRZx23d6zlePF WooTcmE8pcAEMxcNbzIWSuMjDJ2t+PRGXI6Pl0r53GQlaRrl+eBM3MdZG14KQRf+zayE TPzw== X-Gm-Message-State: AOJu0YzfLEEr2ixQPW2Gk69qkGoRIi81JLxFLcVYN83CUkK3nk1T8J4s H4Scnv8UX+9CZW2wEINs0tQ= X-Received: by 2002:a05:6a21:4886:b0:14c:d494:77c3 with SMTP id av6-20020a056a21488600b0014cd49477c3mr3906280pzc.33.1697584916491; Tue, 17 Oct 2023 16:21:56 -0700 (PDT) Received: from localhost (fwdproxy-prn-019.fbsv.net. [2a03:2880:ff:13::face:b00c]) by smtp.gmail.com with ESMTPSA id u12-20020a170902b28c00b001c9bc811d4dsm2111635plr.295.2023.10.17.16.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 16:21:56 -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 4/5] selftests: cgroup: update per-memcg zswap writeback selftest Date: Tue, 17 Oct 2023 16:21:51 -0700 Message-Id: <20231017232152.2605440-5-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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 17 Oct 2023 16:22:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780046827112996633 X-GMAIL-MSGID: 1780046827112996633 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 Acked-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 49def87a909b..11271fabeffc 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", value); + return cg_read_key_long(cg, "memory.stat", "zswap_wb"); } static int allocate_bytes(const char *cgroup, void *arg) @@ -68,45 +68,71 @@ static int allocate_bytes(const char *cgroup, void *arg) return 0; } +static char *setup_test_group_1M(const char *root, const char *name) +{ + char *group_name = 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; +} + /* * When trying to store a memcg page in zswap, if the memcg hits its memory - * limit in zswap, writeback should not be triggered. - * - * This was fixed with commit 0bdf0efa180a("zswap: do not shrink if cgroup 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 that + * memcg. */ static int test_no_invasive_cgroup_shrink(const char *root) { - size_t written_back_before, written_back_after; int ret = KSFT_FAIL; - char *test_group; + size_t control_allocation_size = MB(10); + char *control_allocation, *wb_group = NULL, *control_group = NULL; /* Set up */ - test_group = cg_name(root, "no_shrink_test"); - if (!test_group) - goto out; - if (cg_create(test_group)) + wb_group = 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 = 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 = malloc(control_allocation_size); + for (int i = 0; i < control_allocation_size; i += 4095) + control_allocation[i] = '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 allocation */ - if (get_zswap_written_back_pages(&written_back_after)) - goto out; - if (written_back_after == written_back_before) + /* Verify that only zswapped memory from gwb_group has been written back */ + if (get_cg_wb_count(wb_group) > 0 && get_cg_wb_count(control_group) == 0) ret = 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; }