From patchwork Mon Jan 29 22:45:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13536469 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7A494F1EC; Mon, 29 Jan 2024 22:45:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706568346; cv=none; b=tmstdAgSRz6SDWs+OWxzchPGcq/wLPm40Ftgw0s5xcM0sSCalfEtLDnQwJwKgC+J2fRmvto1Du4xVFTy9OrqamNmbhzDMrXRNt0VPFk4z4ARGdLA+7IUzRCNzr8N/lfVKlWc59KhMGkcitU881F94oM7yq+PCEsZrs+yskkJK8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706568346; c=relaxed/simple; bh=d9dASAYZVxsCcMrrA/Ez2Y9axsArxUPAk21y1cr8mYc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=B6ke1VSIbz0mGI5vptY3wG6+kNL2bY5Txh7QLqesvGKo8aSaXUOIwKKHACFjbHQoIpfihgSaolONkOplZSD9kOVylvxM7QOyDICblwu4xZfkJZQ490mDpoOshRkeEPRz55mTCJF2eO7PxLkguCciyWa8GQKSXRZtjTJv6i4GXTY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CRmpPfhH; arc=none smtp.client-ip=209.85.219.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CRmpPfhH" Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-6868823be58so24888986d6.0; Mon, 29 Jan 2024 14:45:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706568343; x=1707173143; darn=vger.kernel.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=e3JKWr6vkV83y4YZraciKQHHZz9sGV8OXuuwrIDvmCQ=; b=CRmpPfhHeb2MVT5LgN+Rtf+JVikIrJ1J8ryvIvg1CVSEckk9wZ//NHuqm6uCr6m2d6 KehxIHiLovW0yddXrjZujJ4YnUm7q2idWofzbvBYogmVgVARlLU/bOKqOuvf8uJGD6SK +xwTRqeKg+9vWWimC3vmxvy5oHxV/zHLURdqv0giL5C8dojGUG3d2LvzO4MaNZ2BQdV7 F+tpP5dWhHYYx2ApLxuTWzDsQB75EQwUqNs0PAr/IfK8/r4v8gGTINzQLfeBGyGKGP0D zqnmT+1xkKhhDTAfUMvcmem/kZ90d1T3jBIVTbP79lvkAFQwBEuPdnmNSDQE8Oz5+/U2 58Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706568343; x=1707173143; 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=e3JKWr6vkV83y4YZraciKQHHZz9sGV8OXuuwrIDvmCQ=; b=iwzPSHDmpmZ9HSJ3n7AeiyorL2huI/50AVryRDsPXWzll6QafPkMnhUPkDVT9S/x8g k3gbEo2RwjJnVB6uU2oMfDQpUBMhFHf4/nx3PVxQOIj47MlHxVWANjNwqvyNFOsvZm23 IAlXJJYrkZagOwWFE2QQgVoGmV9f3DuIg0gFIEXkPsCod44K4zYBdXJPVHsVAjvb6tfH uaaf1tSssxyTf6IQKKd4wjicE+l29ZwiJa25y7kelyUdCzv4pR6CZuGt7qGIecY1rlKI mZ9NZtpWGQ87Iwbq49HypYPWyGjvCGVFbG2hvuSugasIVIi7HqgkIdBhioiL1NJOjqyq o+dQ== X-Gm-Message-State: AOJu0YytXIks2aWKY2fpMeAnM7bilYSWIwX/5nh9LVARvTjHKcbqAwgO jOQvy37260hNKyoDXX1EERh3yP4RzI7CwOE5alcNPlEJ5QIvngiaHWTSjumt X-Google-Smtp-Source: AGHT+IHGfpYkQIuBr797vwJUdfDqHN+zox8xp38LBl6covm60K0wtDOMjuoBeTuxSaVV/2VRXP0wFg== X-Received: by 2002:ad4:5dcd:0:b0:68c:4942:b0b0 with SMTP id m13-20020ad45dcd000000b0068c4942b0b0mr2981525qvh.100.1706568343643; Mon, 29 Jan 2024 14:45:43 -0800 (PST) Received: from localhost (fwdproxy-nao-116.fbsv.net. [2a03:2880:23ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id 12-20020ad45b8c000000b0068c501d0766sm1260449qvp.41.2024.01.29.14.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 14:45:43 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: shuah@kernel.org, hannes@cmpxchg.org, yosryahmed@google.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 1/3] selftests: zswap: add zswap selftest file to zswap maintainer entry Date: Mon, 29 Jan 2024 14:45:40 -0800 Message-Id: <20240129224542.162599-2-nphamcs@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240129224542.162599-1-nphamcs@gmail.com> References: <20240129224542.162599-1-nphamcs@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make it easier for contributors to find the zswap maintainers when they update the zswap tests. Signed-off-by: Nhat Pham Acked-by: Yosry Ahmed --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index fecebfc4c0dc..5f60faaefaf2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -24396,6 +24396,7 @@ F: include/linux/zpool.h F: include/linux/zswap.h F: mm/zpool.c F: mm/zswap.c +F: tools/testing/selftests/cgroup/test_zswap.c THE REST M: Linus Torvalds From patchwork Mon Jan 29 22:45:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13536470 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB8E74F5FB; Mon, 29 Jan 2024 22:45:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706568347; cv=none; b=n/GvigrxkfzOi8GICvwZRDSrrZbR+EFyPKhI7fQ7EN4sfSKmdhwkQgIsKy6AAzx+HQMcs8pMAyR0F3ztM5Z4SM8ugcpOtUc3uEbO8pgsJrL0MNbxE5sgetw5g4H6UJZjqqxlbVhzi+aBfpAQXE60XP8tYldzF0b1b9nmgi+ovl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706568347; c=relaxed/simple; bh=BLJeECboVnIswmLAF9bTF1fqabzkh5aBsFYlz8apIzA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IE9DIMwpZ5jltMuL4QTxugratdi4NkbIzmvACC3qMsUNauoZubgZgkOcsOf//4vl3+GXAkVz/wNY+hUEk/xtMqr9UViq/qcTEsnP97KgnFFJWauRlknUkcm+Shsq0yNVJxinqEcoHJCLgM8vhE0+3fbl/+Ujks6s+r9CnKs9/5c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VvTu1toN; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VvTu1toN" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-783eb452e01so186888985a.1; Mon, 29 Jan 2024 14:45:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706568344; x=1707173144; darn=vger.kernel.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=dC8jdsm04mIqNXpi4c3WwQu2utHfwjKvoXOteQVfINI=; b=VvTu1toNciDaS6+KyVUHcjuX5yVJwF3cRbYcqWnGlkf4UT060mqdK1oqzPycj+mUPU DnPpy+J6FjiBsWkBejoeIc7AVyBmuI/wSuaQWwELb2EP8ZO+Wg+zydNs0ZVH8kOeget8 E+GFGbuJ3Dft8v2psA1igP/Jlm8V9OUtKAqjMn4SB9ZnMAYdNtWe2mQ0OIaAaVZ7O0Se JwuBPDC1FIsgQUrMo7iX3l1zTjudJwPR5l5t94lywBMT/1ghcrHBqH6Mq4Iv1CSBLiJE VGnNKDGQHMc5Jz6IDN08C+po0dGcNW6gx2+okXqHwCI/obdtPSsLnb+hcG/xoQQNiGwP wLDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706568344; x=1707173144; 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=dC8jdsm04mIqNXpi4c3WwQu2utHfwjKvoXOteQVfINI=; b=Q+xkE57WTd7eLrHsCTQJtzEwKVIdIL3KKnfq9wplXmTFV7wBsoXHRtnvcbuc0fIMjy hvVp5ZopF6p+gJW+ZZobyecA/gDnWcDlyQpbluHvhZ0yuZ92aaMVqf7GgB+3TxAIRFPj l5zdJ1zN/PQods3mSCqGDUDfYcRN0gd2nwYGOHbEg1NecuqkD8aWVw/uBajbN5H2uxAN Swx2TnSxJEm+9w8OMEEckMIR3TZ9Ae9c4nXKdO21LAQbEYSPNFjPZFVW69tcoCGm6drV V88aSB1VFa/jr7mi4dG4Rx4RupvjHJi5oh1Og0p08hkuWMw3kXRA4vUzrZyNx4weOZio CGig== X-Gm-Message-State: AOJu0YzJ5ADosZiofTROr4IxdhF8Gtcfn/HnkcLYMDANwy5He+0xOSe1 /RrpKUNqfbPjgLCh+W5OBZfvBA2o1XtUPRKzOz6Z+39Ks8rzEbll X-Google-Smtp-Source: AGHT+IFHRDAjwttfHcY6DCVP5F3AhKrbmlzkwgYdhBdCAoj0RflAflHERJSdD2h9gDthZsxod44wkA== X-Received: by 2002:a05:620a:318c:b0:783:3cef:c885 with SMTP id bi12-20020a05620a318c00b007833cefc885mr9677984qkb.57.1706568344471; Mon, 29 Jan 2024 14:45:44 -0800 (PST) Received: from localhost (fwdproxy-nao-005.fbsv.net. [2a03:2880:23ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id c7-20020a05620a134700b00784087c7f21sm269076qkl.84.2024.01.29.14.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 14:45:44 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: shuah@kernel.org, hannes@cmpxchg.org, yosryahmed@google.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 2/3] selftests: fix the zswap invasive shrink test Date: Mon, 29 Jan 2024 14:45:41 -0800 Message-Id: <20240129224542.162599-3-nphamcs@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240129224542.162599-1-nphamcs@gmail.com> References: <20240129224542.162599-1-nphamcs@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The zswap no invasive shrink selftest breaks because we rename the zswap writeback counter (see [1]). Fix the test. [1]: https://patchwork.kernel.org/project/linux-kselftest/patch/20231205193307.2432803-1-nphamcs@gmail.com/ Fixes: a697dc2be925 ("selftests: cgroup: update per-memcg zswap writeback selftest") Signed-off-by: Nhat Pham Acked-by: Yosry Ahmed --- tools/testing/selftests/cgroup/test_zswap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c index 47fdaa146443..32ce975b21d1 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -52,7 +52,7 @@ static int get_zswap_stored_pages(size_t *value) static int get_cg_wb_count(const char *cg) { - return cg_read_key_long(cg, "memory.stat", "zswp_wb"); + return cg_read_key_long(cg, "memory.stat", "zswpwb"); } static long get_zswpout(const char *cgroup) From patchwork Mon Jan 29 22:45:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13536471 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9576751C3B; Mon, 29 Jan 2024 22:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706568349; cv=none; b=YVCPCODn4QrUeEsa/xIieiZ+S+sMxAu63r/vInZIF8+BoimBSq0kuNiIbw0NKF2K8Q6QfrIgdslLMUlZvwOQdW9eo87ZTzyrH885WA13HRZqs+brZaBhIInpS1NEOzgssKP/xfxWOk2iNvsCOdKs8PxRVHGrog/GPM/YC9UM3II= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706568349; c=relaxed/simple; bh=Y5QmW3rtP/uUq0/9W3YpsAMR2J1KrHWGIXa9+1PEYak=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IazbBXitPJaunmz7J0MnKdKWUxmL0gDrVXDC1YAf5htv73iwv71NVt54ruLQ4Res2/xw7fxTnGbCbbkveUgTcKf1rFDQ9WK5EF1lyaiQqnIDjVl96YjXPmgAuQp2jiRm7piX+sqcoP235B67tYx4hOA3X+aVzWN4HsyGCeQn+vY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MYLSlJDo; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MYLSlJDo" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-783d84ecb13so328916085a.0; Mon, 29 Jan 2024 14:45:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706568345; x=1707173145; darn=vger.kernel.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=xef0hVDdHdF2jNfb1sbGTppVQNq89HdiJsXx3j0Z+RA=; b=MYLSlJDouqXOQJZaJTWyIzUrHYLtz/mLrII8tiA0U0lH3Gf9YYXjhl3uCDV7R1J7X/ LOTyvM8QVSLJU6538gQ+fdp8xefEZRHSkyR/28CK4Mu++mR+SjZWTMCP9lG2+7wj44Nw HRxZFfrNCSaLpErAEpg2vLEHGZ7r/UDAyfvAZts5IwDx5jjeuZn73JCB8HEUnL5Y+h5S cVhVHm7g65pf+a3JJxNEOIcryF4DoQqTP65f5cFiJkCgqhL122aIUqu1LsL41sf+9Pb5 jTMIhJg6bsrC98Q2pZR/vjS3BWp5k72QYe8gHZEqFLPf02j+XuSXY8c9DHrN7IXOeP+B 3NQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706568345; x=1707173145; 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=xef0hVDdHdF2jNfb1sbGTppVQNq89HdiJsXx3j0Z+RA=; b=a3OW2r9HEa5eupfot1QFD7836cCWdIoF81sL4CsyEEbsYKklhSq+bmstFIeVOkj/gu +Yy+aTUe6HP6i6k+0XHIH7VIx/V+nrni0qD48eviwRQAsvt37psheZ+FNUkRMsW26AQF Lpwm85cNl3DUO/IDwKQGV4s59lfUlIUxHw2i4HPhC6iIBhMvBNBWwnNpP1ZDcTzOaIqo e1JclKBk26FAzxLuDc1E3fcpbcHBe4swDdZbIQfeUtnI7BPfFkfIq06GgvRZyGiCvJWQ Q8aDEV35iylYjEE9B7VkE1XaD8peQ5vzovF/Orr9bBwz6Ylofds5Qzw2Sk0gXARTzxPq g0IA== X-Gm-Message-State: AOJu0YzNTDURTw+nadBLTHfUNb1q1EGOSH2i8pxbO8scSEWYscnD3Kfr ShFGbomwbG29tJI5F822+NLMY28VrFLQN/BjBYyDAB+AO7EU/KNk X-Google-Smtp-Source: AGHT+IFA4GtOI5DVLY0CR9h66W+OqJ3ySRkcMjVMpPQ4jAh32cn+UJ5P037C4f1Ww4qSMDoHjtOsIA== X-Received: by 2002:a05:620a:4485:b0:783:f862:88a7 with SMTP id x5-20020a05620a448500b00783f86288a7mr4466928qkp.10.1706568345431; Mon, 29 Jan 2024 14:45:45 -0800 (PST) Received: from localhost (fwdproxy-nao-013.fbsv.net. [2a03:2880:23ff:d::face:b00c]) by smtp.gmail.com with ESMTPSA id p15-20020ae9f30f000000b00783f606dcf8sm1926576qkg.73.2024.01.29.14.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 14:45:45 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: shuah@kernel.org, hannes@cmpxchg.org, yosryahmed@google.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 3/3] selftests: add test for zswapin Date: Mon, 29 Jan 2024 14:45:42 -0800 Message-Id: <20240129224542.162599-4-nphamcs@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240129224542.162599-1-nphamcs@gmail.com> References: <20240129224542.162599-1-nphamcs@gmail.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We recently encountered a kernel crash on the zswapin path in our internal kernel, which went undetected because of a lack of test coverage for this path. Add a selftest to cover this code path, allocating more memories than the cgroup limit to trigger swapout/zswapout, then reading the pages back in memories several times. Also add a variant of this test that runs with zswap disabled, to verify swapin correctness as well. Suggested-by: Rik van Riel Signed-off-by: Nhat Pham --- tools/testing/selftests/cgroup/test_zswap.c | 67 ++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c index 32ce975b21d1..86231c86dc89 100644 --- a/tools/testing/selftests/cgroup/test_zswap.c +++ b/tools/testing/selftests/cgroup/test_zswap.c @@ -60,17 +60,39 @@ 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) +static int allocate_bytes_and_read(const char *cgroup, void *arg, bool read) { size_t size = (size_t)arg; char *mem = (char *)malloc(size); + int ret = 0; if (!mem) return -1; for (int i = 0; i < size; i += 4095) mem[i] = 'a'; + + if (read) { + /* cycle through the allocated memory to (z)swap in and out pages */ + for (int t = 0; t < 5; t++) { + for (int i = 0; i < size; i += 4095) { + if (mem[i] != 'a') + ret = -1; + } + } + } + free(mem); - return 0; + return ret; +} + +static int allocate_bytes(const char *cgroup, void *arg) +{ + return allocate_bytes_and_read(cgroup, arg, false); +} + +static int read_bytes(const char *cgroup, void *arg) +{ + return allocate_bytes_and_read(cgroup, arg, true); } static char *setup_test_group_1M(const char *root, const char *name) @@ -133,6 +155,45 @@ static int test_zswap_usage(const char *root) return ret; } +/* Simple test to verify the (z)swapin code paths */ +static int test_zswapin_size(const char *root, char *zswap_size) +{ + int ret = KSFT_FAIL; + char *test_group; + + /* Set up */ + test_group = cg_name(root, "zswapin_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.zswap.max", zswap_size)) + goto out; + + /* Allocate and read more than memory.max to trigger (z)swap in */ + if (cg_run(test_group, read_bytes, (void *)MB(32))) + goto out; + + ret = KSFT_PASS; + +out: + cg_destroy(test_group); + free(test_group); + return ret; +} + +static int test_swapin(const char *root) +{ + return test_zswapin_size(root, "0"); +} + +static int test_zswapin_no_limit(const char *root) +{ + return test_zswapin_size(root, "max"); +} + /* * 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 @@ -309,6 +370,8 @@ struct zswap_test { const char *name; } tests[] = { T(test_zswap_usage), + T(test_swapin), + T(test_zswapin_no_limit), T(test_no_kmem_bypass), T(test_no_invasive_cgroup_shrink), };