From patchwork Mon Nov 6 18:31:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13447296 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 BBDD1C4167B for ; Mon, 6 Nov 2023 18:32:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E5CD6B0278; Mon, 6 Nov 2023 13:32:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 26F156B027A; Mon, 6 Nov 2023 13:32:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09C256B0279; Mon, 6 Nov 2023 13:32:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DA06C6B0277 for ; Mon, 6 Nov 2023 13:32:08 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B29371CACA7 for ; Mon, 6 Nov 2023 18:32:08 +0000 (UTC) X-FDA: 81428373936.09.F32C11D Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf01.hostedemail.com (Postfix) with ESMTP id CB43A40023 for ; Mon, 6 Nov 2023 18:32:06 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VxREms7B; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.215.176 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=1699295526; 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=fQKZ6uKAgGpieDKxwUlilWEMw/a+RaeqsurH8iiKhxA=; b=fjrcE2//0TT43Kg99E3yhxiKxv0oDZrRcDKdeNIpYFJUi79p6jAOpW34++SLBwqA0eh3jF /F3/sQsCWgjyxQ1bIB3HTvPAyRQLGRO3HMpF0OVz00+aP0F1vEnPe2IxTdcOSXdul4q5YN rdIBMuwVi5Pd6qRcK/kF7z1/nGWd4hU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VxREms7B; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699295526; a=rsa-sha256; cv=none; b=GBJ8EM//3uJFUwZ+JC9Rqf8EZjRW35o6z8XcW4VuxLEt9YLfokOTVwzz9zF3TuMJoxtprs xGOUGnJIN6zT1WI4WyJ8IL8RJiyiGSpsvdfzFJuZmm4Nvm6N1qSDL1C4OwH+7T+OLGMhuv ZkSFuoAEdoiMRcggHixXmBA8Yug4abE= Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5bd306f86a8so2764380a12.0 for ; Mon, 06 Nov 2023 10:32:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699295525; x=1699900325; 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=fQKZ6uKAgGpieDKxwUlilWEMw/a+RaeqsurH8iiKhxA=; b=VxREms7BEXZ7lhuvWGuq/VxJGwCY2iYHj/AvXMqSRGb9Auc5y4jR70082BzRxtjWCZ uf7J3KuNpYQ2c+03j1Qdvas+DRhbD6PfSGF/PxBzJglQurwjWt+o+Ywy/YHZbIEsFbY/ dl9CT1qsNEmcwBU6ZiZOzAvwC0ev3CB2+bqwLaWbj4mrgS1uQkAnyKWr09o1hOcCXyTN 99Kvwng1b8eNNZ6yMnmkelaytQtmqR3rwp8rj34BTtJ3Z0A168Z8MGnGvF/xz27m8TIU csFmZ65eCqMJNck2Gv5Ko4VzW1uiX+/y4IxAa7rO6lZz8ERheo9Iiu7Vz4Emb3hs2LiI tvFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699295525; x=1699900325; 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=fQKZ6uKAgGpieDKxwUlilWEMw/a+RaeqsurH8iiKhxA=; b=SnlBnJj7kiAw3XlaZ6Q7mapYgbY40UEe+BEnoRhyNuyl9SwsxNTiwtYSJOTmt7gAJk W2byszluQXNLs62GZSD7BDv/w3DKOuMYbhuNBdfnsp/8KZuW6/W7xQDbsKv0HLFOSk16 p5FM4YdG4khCN5zcQcpt5wryg5kLETRL7OwMrHqUuTlSoZuR9VDx785DQQpwfmtGcUej QiuVcN3Y/5+Wnky08zwgIyaPnj18QyswGTICuDF/AGX0XCGaJQ5qL086eJF5WvYwFmUc mHJw5hiv8JyGATWVKi8I6Dy0pLxxh99pJTq2aDhtHxT9J8w59c9ZdY+NqQkWUMf9Qi6K X9ng== X-Gm-Message-State: AOJu0YxnqEe8i6WtyhPkbR8k+esgdZtbJhDG+3iLr/V64a9zT+fQAp7i 3MfyitdU54uQRiK7NJDiQJs= X-Google-Smtp-Source: AGHT+IE3472nXfqmh8O2FIqo+TXEJJPgsaUljC9xCLaQyRQ4pk9qek0sRUdOVNhr8wM4dIBARewIvQ== X-Received: by 2002:a05:6a20:7487:b0:15e:b8a1:57b0 with SMTP id p7-20020a056a20748700b0015eb8a157b0mr25302832pzd.39.1699295525583; Mon, 06 Nov 2023 10:32:05 -0800 (PST) Received: from localhost (fwdproxy-prn-007.fbsv.net. [2a03:2880:ff:7::face:b00c]) by smtp.gmail.com with ESMTPSA id r17-20020a62e411000000b006bc189378a7sm5859887pfh.196.2023.11.06.10.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 10:32:05 -0800 (PST) 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, chrisl@kernel.org, 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 v5 5/6] selftests: cgroup: update per-memcg zswap writeback selftest Date: Mon, 6 Nov 2023 10:31:58 -0800 Message-Id: <20231106183159.3562879-6-nphamcs@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106183159.3562879-1-nphamcs@gmail.com> References: <20231106183159.3562879-1-nphamcs@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: CB43A40023 X-Stat-Signature: 3oytx1mabwif1r4e6q76zo1j3j9pic5i X-Rspam-User: X-HE-Tag: 1699295526-976287 X-HE-Meta: U2FsdGVkX19AsdcC8El717bv9fvxEx1+L80N3+GcsjzCP+AG2xV6ibda80ZLSs5V6c6v3oqyNE/3/x5GIv04j8Op9nv5D79P/AJ79KTNPhS+D3wwXRa+cYul5dH3Lm5qL+HwbEmHm5Co7/tMoPaU1rCff+nwo99UgX8Y2S+qHJidjjeoKgG0w0wnKs1NHTShiw7N89nhOmqjq/td3KDY494Rvp64ZoishyWEpa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fhm5qtyhrosAe4HQVImZratjd56vpvhqITFrN4jur3+vZnYa1VveTvT6P6eSWkqCKu0gMhFNAB/qFkOPIb+MDdJSyFQtHaBf7kG2blYULnDjkTzRxumpfw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.203550, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 49def87a909b..753a3b9de1ad 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", "zswp_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; }