From patchwork Fri Oct 20 22:20:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13431241 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 72256C25B41 for ; Fri, 20 Oct 2023 22:20:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2D168D01D8; Fri, 20 Oct 2023 18:20:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADCFC8D0008; Fri, 20 Oct 2023 18:20:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97D5E8D01D8; Fri, 20 Oct 2023 18:20:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8577F8D0008 for ; Fri, 20 Oct 2023 18:20:13 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5ABAE1CB2D4 for ; Fri, 20 Oct 2023 22:20:13 +0000 (UTC) X-FDA: 81367259106.27.6791C1E Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf04.hostedemail.com (Postfix) with ESMTP id A4EA840010 for ; Fri, 20 Oct 2023 22:20:11 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ctu0ZSrK; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.215.174 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=1697840411; 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:references:dkim-signature; bh=1EeBCEVO9LxbVa6WaU7VSYBs+wBD9B64Uc+nZwPxkVM=; b=MgnUCr9BAiZChYjCBEg07mRkXBnqLEP2NwnXb6mFMva00db7iajn2wC6Z9iCpji6i8yB6+ /NyAJL3lFukRG7hEeifYmzjhMMHOHrEO73dQSm2psK8avCuhg70wPreSl6KBzbs5hnVbWn OcMATYQj2VKxRLi1tjaYObfhVfPYwO0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ctu0ZSrK; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697840411; a=rsa-sha256; cv=none; b=J3kpc6W1x9D/edvVUDdq0ZfDIjzvgX2P6beTfmdjVm6iIO+vzRsbVv/7nb6er0EBP7ydNC 7Dwjqjs7/5f6k9hPTAHk42T5ECm0n63drCcvmrt3yIGnaThD4MmeSY9vagjs/9nxU8jNqp PBFF4UR7FUUcxdsgVGcPhM6AfL8p9Es= Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-5ab2cb900fcso908942a12.0 for ; Fri, 20 Oct 2023 15:20:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697840410; x=1698445210; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1EeBCEVO9LxbVa6WaU7VSYBs+wBD9B64Uc+nZwPxkVM=; b=Ctu0ZSrKXTfD3l9gRoQn5npyHVXsRSPMtu5njFiMZ9jcIzuyzec+WibKYm/wZxRplX I3tlo7yzdzABn1VJ5xY/oBc1WYQDDbmh8ylkkCSK9tnHdqsG4Ve7Qfyjun3qvYeB/H3u DH+3C4aSSwR+f2+h+XIcVjI/H0CMrKJdwCYHYyKrpjAtI4877STZR7kBJjZjrGu2nTuM c4o3kaqSzda+uaioA+xr+1QEJps4zLpp/1q0v8Dr7SIMX5rydR+XO6LqN1dsrcpPxP3H /evLEe0DLYggWBtGNVtOyd/o0Zrp/lO/BXmZVLu18SbUw3CS2BueJ6Q/O+ZA8LMryvvN kN4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697840410; x=1698445210; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1EeBCEVO9LxbVa6WaU7VSYBs+wBD9B64Uc+nZwPxkVM=; b=RAw1Cf+6JaOFKjmZMAcp7V2ck3xpZDjr8R+6EuqR30TPg2nMDlYXZQwyhGfapXBcCJ +jwH1bUF/rTxRMtPq9GJK6KV/XGiRyuh7vbHqhUDtXnIEMHjUTna8kZis/85lY/7zRtV iz/pm2wsflIk8OLpFf7okXOW8My+lbBAo6aLRezKm4YWh1azpi8+qUvcqh78xU2zCoDe QpVTrDKJFgmIkchohcMlaFFmZEq/3TwLx3gQkLfPCPe1h/e04nXbnCQ5IjsxaxvDAk51 5bVl9Est/2YDl/5PYNG8r2z/n2RSRqI5WvcigfU0VoD3A2Wjujz29vYF5xIrFbnTJnLe FiLw== X-Gm-Message-State: AOJu0Yw/gLNdzk7TGTjFIntSS50bXmxkc0nlB6NarUm9IQkkBq97810Z 2GD2Gg2HVnYml+nx+8hylNE= X-Google-Smtp-Source: AGHT+IECXhrANA0QgW4lL0jF6pcm/XmBaXcujdog1r7b1mT3+gIIldlT9Fee7TiRI8hSTb0nqBkZTQ== X-Received: by 2002:a05:6a21:3b45:b0:16b:7602:1837 with SMTP id zy5-20020a056a213b4500b0016b76021837mr2842010pzb.29.1697840410254; Fri, 20 Oct 2023 15:20:10 -0700 (PDT) Received: from localhost (fwdproxy-prn-015.fbsv.net. [2a03:2880:ff:f::face:b00c]) by smtp.gmail.com with ESMTPSA id f20-20020a056a001ad400b006b2677d3684sm2028041pfv.206.2023.10.20.15.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 15:20:10 -0700 (PDT) From: Nhat Pham To: shuah@kernel.org Cc: hannes@cmpxchg.org, cerasuolodomenico@gmail.com, tj@kernel.org, lizefan.x@bytedance.com, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH] selftests: add a sanity check for zswap Date: Fri, 20 Oct 2023 15:20:09 -0700 Message-Id: <20231020222009.2358953-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: A4EA840010 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 78ijpz8g1bq94iu39k8rfxc1c1cs6uix X-HE-Tag: 1697840411-993775 X-HE-Meta: U2FsdGVkX1+Rd/ZN93MuZiNa3VCPj2mwGoycrn+htvH3cHTKHqUXa3NcG5Mohn7AWmKlUfg1CphvBSjX8vzCTQ2RWwgvx8xuCAypeMEfNKbYfUTouNdS/A4rdJA6ojCN9TfGki0dsBShVGiMlG2eCz7jJV26aJ9LtvGH/aBA+Nt4C+IzrPFXkWWJgRcEyFrRTdipCiuSXORcdcdJ8p1iZ6RYBeVLR3BGTLjDzMKEs/2nxGnyaSLtlxkrCFJSCwzjfw/ZQTmYm9WA3Mt20ybDZLpt71huviZQPTPHxSc1iLjodbOj8sMm8e/EyVuJfX4Fr9v2JdWGmvYMPD+XtJLqVDSe6R1rX/12cLAI5gxqHkbiMCaQ73h1rlBsSzBHjQqZu8xTlHCNyaEsmVHku6Ol4f/zg9I+pWneg+lcVaHq3Erprui4R5OmGdWn4J65S1eaOo6gcHLMBCEEEucoO6F8mVedVqWUQK8q5k66NYAKnDltP4ppWec4C6G6GA0SW7H5DMg6MRezNHDEyKl9KJu53YrMpzJM15e7B8ct93HxzzcG3UuPZw2zbuPZzC4Qm3brTZtm9D0+p0004S9m9YBufCpYFThdf9Eb0caYIwRYVMrigATwz16PNycbWtEL4jwcQEpAfiSEaswm9syx1PmU+pvxF7ulHB01WjvnALJY1scRrAZ8KyHodHKdubWqCSRcPEK7AGGZb0xlZa42ZVOTUeoBYQhEns42YD3DERyxGqU6Kd+0b5Fh+yx2z4h3M+Fwf9AmqcsdbY6WK8E3GPjzahtRM3glrNORsvkIcRnT7JOeOsHLBvTFyBoqCSS9FUaU6hjJPBHjPYIjfgbR6OIgmvkrsqT2LaCAYZfcstTVsbTF22mLelyiZtxN9W93G2HUB9Zb0k+g97SJCKV4UC7d6F6bqgYucwMej3v7dzfp+MLNz+2SFcsxKC8wRc1JPnH+4KNu6apnKbVdEYh8QtW 7qq/je0w nQtlTqcLg3QIE4Efqd33fEYkojv1W2G2deiSfgTxxyYGbtiZGzoBqUmXXCoSsRMWlg46a00IqSSXiFLIF8aldFze5V/eusS2mYnhHq+PwduwI8u50Bkqx+gAkrlGMy4eiPthuAoljmxI7x9stpYVqMCaZy/oyXoDzx2jOevKufShfswro7D+3+X/+M0kL3EuaQgMfzGAlPez+l/8viJDofs2uBFQl7g/pti6sT6skBPKVho9wrKOrRFBhlPQ2hfNK/rxh6avH2v9KktuiwvZFq+8pkBV1DlK6ucK1sbydZstZvGzbJbhrlEegI4GekyhJAdG4Os798z2VHliHSALoAxTZiJk+pT58nyzokinDQZCxxOArBbx5F1vD9EIKa4O8siCN0pCcc8l/P8ZBSrIzZMe/rN8QBS7n84pszxyNz3l7z1M= X-Bogosity: Ham, tests=bogofilter, spamicity=0.193178, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We recently encountered a bug that makes all zswap store attempt fail. Specifically, after: "141fdeececb3 mm/zswap: delay the initialization of zswap" if we build a kernel with zswap disabled by default, then enabled after the swapfile is set up, the zswap tree will not be initialized. As a result, all zswap store calls will be short-circuited. We have to perform another swapon to get zswap working properly again. Fortunately, this issue has since been fixed by the patch that kills frontswap: "42c06a0e8ebe mm: kill frontswap" which performs zswap_swapon() unconditionally, i.e always initializing the zswap tree. This test add a sanity check that ensure zswap storing works as intended. Signed-off-by: Nhat Pham Acked-by: Rik van Riel --- tools/testing/selftests/cgroup/test_zswap.c | 48 +++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c index 49def87a909b..c99d2adaca3f 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -55,6 +55,11 @@ static int get_zswap_written_back_pages(size_t *value) return read_int("/sys/kernel/debug/zswap/written_back_pages", value); } +static long get_zswpout(const char *cgroup) +{ + return cg_read_key_long(cgroup, "memory.stat", "zswpout "); +} + static int allocate_bytes(const char *cgroup, void *arg) { size_t size = (size_t)arg; @@ -68,6 +73,48 @@ static int allocate_bytes(const char *cgroup, void *arg) return 0; } +/* + * Sanity test to check that pages are written into zswap. + */ +static int test_zswap_usage(const char *root) +{ + long zswpout_before, zswpout_after; + int ret = KSFT_FAIL; + char *test_group; + + /* Set up */ + test_group = cg_name(root, "no_shrink_test"); + if (!test_group) + goto out; + if (cg_create(test_group)) + goto out; + if (cg_write(test_group, "memory.max", "1M")) + goto out; + + zswpout_before = get_zswpout(test_group); + if (zswpout_before < 0) { + ksft_print_msg("Failed to get zswpout\n"); + goto out; + } + + /* Allocate more than memory.max to push memory into zswap */ + if (cg_run(test_group, allocate_bytes, (void *)MB(4))) + goto out; + + /* Verify that pages come into zswap */ + zswpout_after = get_zswpout(test_group); + if (zswpout_after <= zswpout_before) { + ksft_print_msg("zswpout does not increase after test program\n"); + goto out; + } + ret = KSFT_PASS; + +out: + cg_destroy(test_group); + free(test_group); + return ret; +} + /* * When trying to store a memcg page in zswap, if the memcg hits its memory * limit in zswap, writeback should not be triggered. @@ -235,6 +282,7 @@ struct zswap_test { int (*fn)(const char *root); const char *name; } tests[] = { + T(test_zswap_usage), T(test_no_kmem_bypass), T(test_no_invasive_cgroup_shrink), };