From patchwork Mon Nov 27 19:37:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13470248 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 9CBDDC07D5A for ; Mon, 27 Nov 2023 19:37:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFA5B6B02BF; Mon, 27 Nov 2023 14:37:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BA9D86B02C4; Mon, 27 Nov 2023 14:37:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FD506B02C5; Mon, 27 Nov 2023 14:37:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8CBA96B02BF for ; Mon, 27 Nov 2023 14:37:12 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6A7491A06FA for ; Mon, 27 Nov 2023 19:37:12 +0000 (UTC) X-FDA: 81504742704.13.7F15735 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf24.hostedemail.com (Postfix) with ESMTP id 80676180011 for ; Mon, 27 Nov 2023 19:37:10 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bpn4189H; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.214.172 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=1701113830; 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=qpgmz+lE50DZaA/oBKT5EnJWyAwPJO9gmArvQZM8Xwo=; b=MoOnqmUlSAhK0RJxiXgIF5m39m50PoNEevJ9oidx3Dglv8/hQPCtCQlhjKlq5ZSq87goZI W6aFXE3ngzRo+PQqtWB8eBYQh+tyvH8Y6pofwfD1qPSoFAUiN2PR+vEzgCd3VmmZvi3zod gvuQ3ExSpt3b3GmHdMSxT3LLIAe7izs= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=bpn4189H; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701113830; a=rsa-sha256; cv=none; b=h/xY9mifjyYVoK1+irBd3XH1pncqBjIQFQgPDQymZukyl8NjCaLGVTz/rzCw2YJ+6wbCrF 2g4hdMM6PkHC+hiUVvBtfy1HFClZ9egSWvPi2wrY1p953m1GLraSCGVFuEW/giGlVx6XuX pdZnDDCmFwuAmmgCBkk/2qmFyPu/KPM= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1ce627400f6so36781115ad.2 for ; Mon, 27 Nov 2023 11:37:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701113829; x=1701718629; 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=qpgmz+lE50DZaA/oBKT5EnJWyAwPJO9gmArvQZM8Xwo=; b=bpn4189HhNBTayIkmorKh+Tnn71C593ul/x0y5RK4x9MxLpC1Dzk/ovMAVEA5tzoS7 S/vVKGrXyBatRhl/F1ogJoZYt4q0MDWxaPbGw4FWhuGXvBSOivWyMRUxKpdKQpbDP83z iB0pJePNv8L8uIIi194gPfj2/0rIHo2XwmH1yLaHqrcrWeVI67SnRxuxnl7rE3nGEVNS cLF5fU/9+vkdKOlN9XsV5HBcQNdZSO5kmMYVp0Uzd/R8NTrZlI8HScBuQTnTPzwL4MGX LMP5uhnAlBftEuUM7VRFJ1zVtGH9eoReU0/TRwcomx11q+f+YauzbkW11K2wo3sF0OTT bN0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701113829; x=1701718629; 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=qpgmz+lE50DZaA/oBKT5EnJWyAwPJO9gmArvQZM8Xwo=; b=A7fcYMv2nCuYEMLg0lXTbZuEjXIALKvyjLOkyOr5cqPisqQ5+1QhL6qytF8/BRo+4+ 4LdngRfS4SGMwTHHHf8S6vmEBVcWcFyG7Y8gkjDvZOuvhBQmW0kqlsdIhkNnEMJFQxl0 bnJ2MZ0C9CzSlGc0pwUbEavdxXvJt7OO5sEwvhQhzJgYFdXJ9W2zjd0t0VLKPWHaHnL+ /Qw2on7/+kj8lO7+c08w+HAAMuo+LvUinoq+M0GEKAeBHpT+RtWqUGHILlOjGysJmk6x NSsYKDleZKCD9eWgQnQZy5s8za+mBH4E+7zujvCPFStnQg5RGXlmIfw9RR9sSK5srlXU qPFw== X-Gm-Message-State: AOJu0YyCrdnru1V3nLKRrZLAQYka/6rfmNpI38O4lbZM4oMj93HUIgja HgM3wPY68+48BSDZ96TSC+s= X-Google-Smtp-Source: AGHT+IGGnMiCHJ1sPxrNpRk0g5/gHoSEWXLvzV7mXBDrZMEhN4XMuBH1qpquSCpMs9EvfZ7SF0hM6Q== X-Received: by 2002:a17:903:2281:b0:1cf:ea64:f508 with SMTP id b1-20020a170903228100b001cfea64f508mr1418367plh.2.1701113829283; Mon, 27 Nov 2023 11:37:09 -0800 (PST) Received: from localhost (fwdproxy-prn-015.fbsv.net. [2a03:2880:ff:f::face:b00c]) by smtp.gmail.com with ESMTPSA id o11-20020a170902d4cb00b001cc0e3a29a8sm7207131plg.89.2023.11.27.11.37.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 11:37:08 -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 v6 5/6] selftests: cgroup: update per-memcg zswap writeback selftest Date: Mon, 27 Nov 2023 11:37:02 -0800 Message-Id: <20231127193703.1980089-6-nphamcs@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231127193703.1980089-1-nphamcs@gmail.com> References: <20231127193703.1980089-1-nphamcs@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 80676180011 X-Stat-Signature: fosrmpmwtr1mnked9j9g1wph38d6dw1b X-HE-Tag: 1701113830-464198 X-HE-Meta: U2FsdGVkX18tpOksWObBP/SfxkJjG49GGJVv3PqPLnyiGM0UkPwP1qd/1dtzDO5iCIgqQT+jDEgrFAkoR8h4Xoxcpmp8EylJhBuaSPLubQtcjywLPn+TzoqCehkQhnZu032xFwbsbmw+Vn7UPmJXFSyqaBiBRPourHKD3+Obt8gFtlq5amCP0UzLtp5rupYwLD79+cWZxTsGBpNn0VKX+RA9IkcvmNSWEku7awyQlas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WxUC2GEDC3o3ufM+BTKhqld7XjsD9bgY0/+XeG/KmcjZSAQboInL4oWjJW0z0VBA+EyQEb1uZNFZmNiFCvuv3yHOwy3Gl+e7Lh1sZdA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.201130, 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 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", value); + 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 *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; +} + /* * 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 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; }