From patchwork Wed May 1 10:04:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13650441 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 D6272C4345F for ; Wed, 1 May 2024 10:04:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CD316B00B9; Wed, 1 May 2024 06:04:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 156156B00BB; Wed, 1 May 2024 06:04:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F10F36B00BD; Wed, 1 May 2024 06:04:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D04C16B00B9 for ; Wed, 1 May 2024 06:04:56 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 199F040A81 for ; Wed, 1 May 2024 10:04:56 +0000 (UTC) X-FDA: 82069393392.29.BE6D5B3 Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) by imf02.hostedemail.com (Postfix) with ESMTP id 595B680003 for ; Wed, 1 May 2024 10:04:54 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AGPnLLj7; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.166.51 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714557894; 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=nIvbfNHhj5TbvnpekKD4EoyOfeqRMhJTxUZik2O2/6Q=; b=kuI+d/hSrm5CKpF3ZWKLUloU/L5/DwiqYKudfVScSF5qjSGqxjanhS0eEgA8PdLfIcPFLm qSC3NK4rnv0Sey08v1u7TRMG8t0FMnWNjDbCJRCKf7Cy1VSLDoIOWBbqrnGnQkzMKILiun fU1jDBpPiSeI5rBcTHh04nfpjMZN+oo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714557894; a=rsa-sha256; cv=none; b=ZQhnqjxhDtt7WtnSgEkj7vNJUK8BWuUFR/EOa1gKXZyO/ZAyRfwTOPHNrkaDZMFH7Nw/SA ePULpdDsxLmi2x4wKbdYKmD39EHOqHAPqxOpr4qxRW6IBVqgOMEyOgYztmkwJ9syyFaqQO cgK83WEHBEM22MPIUGevWdVuxpI5S3w= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AGPnLLj7; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.166.51 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com Received: by mail-io1-f51.google.com with SMTP id ca18e2360f4ac-7deb424da41so218712739f.1 for ; Wed, 01 May 2024 03:04:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714557893; x=1715162693; 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=nIvbfNHhj5TbvnpekKD4EoyOfeqRMhJTxUZik2O2/6Q=; b=AGPnLLj7FNn/AhWixRTHg5acWa+wfUqcbfJI1+ByD+VJ+qFVoy6pgy3bVyKUv+Cu57 VYcc+7JCAqoqD6yMooFbl4I51bQXQQMR6e3fH8a5xGZBiNo9cbrxkdahVdB6IaH079ZK Yy54raERb+m6+AEZfGfOktpgt4esDgjsuzGhGYreZT5x5rigYkSRWU2p8kK4Z/rECWyK BTgHywF2buBZsSJyKyPOe0++CAVexYj0JMu70+OWmgtVfdjFmTpwNFkGLyZ8QRXOrntA sQt3/blVrzjFDPZUJoZEKnoR1N5N0nHk5PJzgLzA/0Wt7nAUIFyT/u9vMciKzq1funn6 53ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714557893; x=1715162693; 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=nIvbfNHhj5TbvnpekKD4EoyOfeqRMhJTxUZik2O2/6Q=; b=aXkvVMo0AXDquRfygUGf4v5Iem9MgLn5L6k2KXV9aHrTOlg6cZPppFTA2Vc4xezrzu 4BlB1oAUAc7malLEcwjR6aXtEZkZoqyzjIEUpha6nMf4Cf+sK/ysI+AUOcRd11ZhCZfJ OCC8KUofezJt8qSZaY6/01q7tam7Jpv3JWq3eXPAfu6XGJPculefTH4A+d+cWexKOS7S 7gszxCAtSLYvmD8DCO0giXWiw5qH04Hzj2fzDGCE90Qf8cGxrWqqp8bayKHxcMGpKzHn fR5Utj2Cz+w93w/fwVvm22GBxdVl0yDJmqs6onLB1/By932GdtRhcrit67IN7Gmzkn48 iu9A== X-Forwarded-Encrypted: i=1; AJvYcCXIuNWrkMLAwZ2uUzN5cNGCauUFQd5EKB4fllmt+Xfqyj2guYXIo0aGSbJLfpXc/NPSIWXQP4TqbpwVoQ5+OpX6k9g= X-Gm-Message-State: AOJu0YxbzQFG3SwK/rwk7/rLPQMdt+y3AnjMOG7t5i36Xwsi6F99aqTZ rfLpdwrUppUAsedYEFJKXp9kYya+0W6QuqNtyG3UdC9Moi+AeRKk X-Google-Smtp-Source: AGHT+IEvG+BcSl6mnlsCumJF6Aok/QMB9i3YxeuOAZtciS2FbJ0A7xIM8mpR0R+q6Rbs38MWydF0cw== X-Received: by 2002:a05:6602:2554:b0:7de:d55f:c1d3 with SMTP id cg20-20020a056602255400b007ded55fc1d3mr2206254iob.17.1714557893424; Wed, 01 May 2024 03:04:53 -0700 (PDT) Received: from localhost (fwdproxy-nao-119.fbsv.net. [2a03:2880:23ff:77::face:b00c]) by smtp.gmail.com with ESMTPSA id ft3-20020a05660260c300b007dee6a8b524sm369559iob.21.2024.05.01.03.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 03:04:53 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Usama Arif Subject: [PATCH] selftests: cgroup: add tests to verify the zswap writeback path Date: Wed, 1 May 2024 11:04:46 +0100 Message-ID: <20240501100446.1454264-1-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 595B680003 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: m6yuxha6z8ufmax1wmcmdggp51ycz81c X-HE-Tag: 1714557894-981327 X-HE-Meta: U2FsdGVkX1/je8AMArGmzpam2FQwOpdyIteAgab/5NxcfTw6lurdLQJbj6/pX1OZ0549ayocFD9MzFgMuns9W3lqvppzVacOMVULuu7/FH3Y1NoU52l6hecoLdR3/jhRhjHqj9Hw7XePHGgeRdCmmfjLhJicp7w4ftJAFf70cy4kKmIgjMLThHQKBhC3Zjj9pT7eUqx63YpEHZfNRKFDSKitOsbz4SE5i6TjAw7BMcaNIaRMBarLwdR7N9bd7zu3hYh2yHRkV5Z4R5UxxKcXFjrn1+gOQiO4v6P9tDGp2ehhBW/ZV+wTGnO8GJ1jA8E5ggVEfJxWQbcbAgaIRot/RaJJe4ndlR9+5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FUvS/tR9Lvw5quS5T734NrwXoBsYWGOJi0pBIkf0+POirE6wxzM9mdImHm43A= X-Bogosity: Ham, tests=bogofilter, spamicity=0.325298, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The condition for writeback can be triggered by allocating random memory more than memory.high to push memory into zswap, more than zswap.max to trigger writeback if enabled, but less than memory.max so that OOM is not triggered. Both values of memory.zswap.writeback are tested. Signed-off-by: Usama Arif --- tools/testing/selftests/cgroup/test_zswap.c | 83 +++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c index f0e488ed90d8..fe0e7221525c 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -94,6 +94,19 @@ static int allocate_bytes(const char *cgroup, void *arg) return 0; } +static int allocate_random_bytes(const char *cgroup, void *arg) +{ + size_t size = (size_t)arg; + char *mem = (char *)malloc(size); + + if (!mem) + return -1; + for (int i = 0; i < size; i++) + mem[i] = rand() % 128; + free(mem); + return 0; +} + static char *setup_test_group_1M(const char *root, const char *name) { char *group_name = cg_name(root, name); @@ -248,6 +261,74 @@ static int test_zswapin(const char *root) return ret; } +/* Test to verify the zswap writeback path */ +static int test_zswap_writeback(const char *root, bool wb) +{ + int ret = KSFT_FAIL; + char *test_group; + long zswpwb_before, zswpwb_after; + + test_group = cg_name(root, + wb ? "zswap_writeback_enabled_test" : "zswap_writeback_disabled_test"); + if (!test_group) + goto out; + if (cg_create(test_group)) + goto out; + if (cg_write(test_group, "memory.max", "8M")) + goto out; + if (cg_write(test_group, "memory.high", "2M")) + goto out; + if (cg_write(test_group, "memory.zswap.max", "2M")) + goto out; + if (cg_write(test_group, "memory.zswap.writeback", wb ? "1" : "0")) + goto out; + + zswpwb_before = cg_read_key_long(test_group, "memory.stat", "zswpwb "); + if (zswpwb_before < 0) { + ksft_print_msg("failed to get zswpwb_before\n"); + goto out; + } + + /* + * Allocate more than memory.high to push memory into zswap, + * more than zswap.max to trigger writeback if enabled, + * but less than memory.max so that OOM is not triggered + */ + if (cg_run(test_group, allocate_random_bytes, (void *)MB(3))) + goto out; + + /* Verify that zswap writeback occurred only if writeback was enabled */ + zswpwb_after = cg_read_key_long(test_group, "memory.stat", "zswpwb "); + if (wb) { + if (zswpwb_after <= zswpwb_before) { + ksft_print_msg("writeback enabled and zswpwb_after <= zswpwb_before\n"); + goto out; + } + } else { + if (zswpwb_after != zswpwb_before) { + ksft_print_msg("writeback disabled and zswpwb_after != zswpwb_before\n"); + goto out; + } + } + + ret = KSFT_PASS; + +out: + cg_destroy(test_group); + free(test_group); + return ret; +} + +static int test_zswap_writeback_enabled(const char *root) +{ + return test_zswap_writeback(root, true); +} + +static int test_zswap_writeback_disabled(const char *root) +{ + return test_zswap_writeback(root, false); +} + /* * When trying to store a memcg page in zswap, if the memcg hits its memory * limit in zswap, writeback should affect only the zswapped pages of that @@ -425,6 +506,8 @@ struct zswap_test { T(test_zswap_usage), T(test_swapin_nozswap), T(test_zswapin), + T(test_zswap_writeback_enabled), + T(test_zswap_writeback_disabled), T(test_no_kmem_bypass), T(test_no_invasive_cgroup_shrink), };