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: 13426195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAE13CDB48B for ; Tue, 17 Oct 2023 23:22:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0D7DF8D0002; Tue, 17 Oct 2023 19:22:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0602A8D011E; Tue, 17 Oct 2023 19:21:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD2F88D0002; Tue, 17 Oct 2023 19:21:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CA9488D0002 for ; Tue, 17 Oct 2023 19:21:59 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 94AEC40F3F for ; Tue, 17 Oct 2023 23:21:59 +0000 (UTC) X-FDA: 81356528358.14.CF77C71 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf04.hostedemail.com (Postfix) with ESMTP id B439E40020 for ; Tue, 17 Oct 2023 23:21:57 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iDiaD20f; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697584917; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=l1cHnelUz7JpCw4ya3vv+qgP9pRjbzsLh3QaMob4Kno=; b=g/ALmhR+H0ciBCXkOTi5DZWjPyjg7Les2zyN+RK/x5n7a9MvLTvjWDVi+fH4fGw4aJVhHB kfYVrYSzqJ13yjkSDBqzZis2shxBdEQSuKM0ZlTebTaS5T69t61PXvBJBPM5Yz0OFOudxS 4t+XP/s78HGDzQabakLeth8bMhvwGPU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iDiaD20f; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697584917; a=rsa-sha256; cv=none; b=qofjzf89yj6i+EBjyQYz19+y/zoaGCiL1A6W5oNj7BJ7QNIWk4aCeU4JIPlSe8QDbsCwxK YOYOdfGRhuhoLvE0ObYtROU4AqXpnVsaAMM2Rbp425iZAVISkv2EZx/lbzwlAmE/bNYokq BqD1k5OpRMY5jMHA7aQ4+nN3wBbiNRg= Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-5a9bc2ec556so3252779a12.0 for ; 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=kvack.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=iDiaD20f/RtoIQkT0QQAi0MSbMCfdOul3dtPubY6Nv5Yp73vb6WXq0Y+rdWZAgypT5 c9AEhRELjvmlAXd/NV46LVD8rw4JOE2v6wpsDFGkceGgEcFqbFrQsTFSgfFNHHmTY8HZ DFOIViTkmTmGUCBpYt0mGZNIuFgUn8PKMpbqW1vpe6Uu+R5IRtsr7fa7xM6cqW22/Cmr Fh2GUTMlsJqbePAZ7yJ9Ku/4vcNTfyxLRiHaoU4wJalOSfj0uyJts4Vuq79ki+bpwMHD FZ7elRSKDAf+JFpZf/5STWTkTU43yVgAmSfndMgUvgTnsiPJ9k3R8jKUg2VrSUYfdPmP wFZQ== 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=pkgVJypZUTb5G1zjQ4ybPJ2nU2g/SvnF2FQfMBZ6Z/v/97Np0ynCUhwBeVmyDI66VW +0hmojvLlwdirHTkbh3lJ4TZ+SIMIH82AxGjan2RAhyd01/IEVLETg9FT2jL76hrv022 f0M5n941qKdLkHKAA24kJySHDhhTHt5JrD6Mu435jPUsgjsI7MKQVNJ61hdx2bw9K8tc mg1R0nbuWrTJdJDEs8Hhr1QLDXK90HZPBKMA53HY2ZJ6C4wXswUavgIE+ul5kcVHfbRv OFkiFT5VXuZqDhvmcrGcjRJ741PqHjxrzyc+SjxemZEkoZOQPDO4wUtvohcseg733/9h xqzw== X-Gm-Message-State: AOJu0YxSH5R6ffVMRNJ3svA5Mk307oxqJ9p9nXo5R83q7I8WMknn2pAA DbGJZO1si509jnd6R2EEY9E= X-Google-Smtp-Source: AGHT+IFesVzJtwp9D46Y7uRYTiIL4vlxo4njVbMDGRffV+cNTLXVfoIhh/9vko3/sNz6DemBDx9n+Q== 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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B439E40020 X-Stat-Signature: jgk457nwkrbd3je44ztz591zydqx6bmh X-HE-Tag: 1697584917-92340 X-HE-Meta: U2FsdGVkX1+NO+iJPTapLhfOI61QEp7JVI1VuQG02gRLNcgfK/GZfepQwcQDjtgeuHrXfpSNHhGevKsM3ihnzpU19PUjGHcGh2eyNypI0iloXgKu5k2P6ZaFO7eC315dPxDlEeH5HfQq2lZI2xuxvxGakrpiZ3NYhCpk3UIoWwAS65HinfQ854Gki0TOKAV3aipGIhxD5uKWNKByFy5Kq8ionTTp4bCGrDizRkoREi0aMMLZnL+rT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ZrpRaEfGASbUWGmfxrEFFBf6QM+NlUPPazirFsIfyU73wgYeXRCX1QuG2DwI2+jmFk8G+j9g+QXPO4s= X-Bogosity: Ham, tests=bogofilter, spamicity=0.225619, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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; }