From patchwork Wed Feb 12 17:44:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13972246 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 192D525D522; Wed, 12 Feb 2025 17:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739382350; cv=none; b=W0rXWQXSrzbAxTa4x71ouyKLsYG6uei4wo3yEKiROLrZBzl29zW93palizm0zZlbCiCpxFm7cD7l1m6K7Yyuk/6zxJY4nQB2HyesZu0H5f2Fo8BhnWopM0367f/l8VBPunsmpkCWO0F5eQXzSqnlNdNJri4T+BI/lzyIb6uYE80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739382350; c=relaxed/simple; bh=i+ImuvsxORMr/sR+be1Pph9bvunPitRZvD6hqlNBEDc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=etvsPHy42jLy/ztsGFgBViw/Hq3rU58QLboUfsVt6O8hECFHoz6eCb7Ju6nuOOxAtPmzg2YOPHkA46z8nhnRNsL29SpZVaNcj0c2is1ryX4sNI3GLoxH5do/4e+Ev3lsa0VGZ4N91vOIrDPOmI5OzXHBhXcNbw+gNpCfgX965k0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AxzR0TVM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AxzR0TVM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2391C4CEE4; Wed, 12 Feb 2025 17:45:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739382349; bh=i+ImuvsxORMr/sR+be1Pph9bvunPitRZvD6hqlNBEDc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AxzR0TVMTWyh7xnme+LP3aCMji8bjWSFBzALs5tg8UnbVBKsq2PQ1Ona5m/IAhNoZ QRhGuk4k1TGgC/0UNnLN5CJh2+StUeUYr3QQyRnIKneHc3HELKpImgcGE9hlp/vUoy MXY1WBustxHpoRrKjgrvzuc8TG7PmlpKNY/9EV7VbJbN777CmuUJ3TQR/De3pZZ+h9 yvASm51NVg1e32ubpwElq98lTnfOKBEqST7g8gW4Pi1jaeV64umfFaVBnoGstZNRg8 z2eXdmw14zdc0mmlvVQ9F632TXqdbpMY6TSFGMYAarNTLsD+Cq6ydEPFE18VmQDO+s imb23PLFpROyA== From: Mark Brown Date: Wed, 12 Feb 2025 17:44:25 +0000 Subject: [PATCH 1/2] selftests/mm: Fix check for running THP tests Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250212-kselftest-mm-no-hugepages-v1-1-44702f538522@kernel.org> References: <20250212-kselftest-mm-no-hugepages-v1-0-44702f538522@kernel.org> In-Reply-To: <20250212-kselftest-mm-no-hugepages-v1-0-44702f538522@kernel.org> To: Andrew Morton , Shuah Khan Cc: Nico Pache , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-1b0d6 X-Developer-Signature: v=1; a=openpgp-sha256; l=1316; i=broonie@kernel.org; h=from:subject:message-id; bh=i+ImuvsxORMr/sR+be1Pph9bvunPitRZvD6hqlNBEDc=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBnrN5IUrvy3XDSqCWlJNoAoldjlOInN9p/4/cpcJIZ Y9o6aq2JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZ6zeSAAKCRAk1otyXVSH0JjuB/ 9DgRF7lxnlHn9mSwi0nb59wQR/eez2gNc3inHbieualr91tybkbV0y8Cpe1SWLVlq/7jK/rgEHpyLR ebFumJRsjPwdmvzTymL46uBAb58j00Gn2w4egP5T2pSEc65iseDUH8WfwjUf9CRLJx6IDUCpOXxx58 AFfbcw8iHN3lpVsaBqYmQ7Uo/i2qefQjvNXJ61hNkSqgt0XL1C+pAQ79L3ddx5A1Ek4uLl2XMvx8Cb ryFKehJBJaIAHkbTXkYfrPKqfTogBCDBQFNCHjXsDIftRSqq45VySEi77k2BJCFqg0THXV9Ah582oC HzdAPRTB+sesizmKW7o7WpPG09Skeo X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB When testing if we should try to compact memory or drop caches before we run the THP or HugeTLB tests we use | as an or operator. This doesn't work since run_vmtests.sh is written in shell where this is used to pipe the output of the first argument into the second. Instead use the shell's -o operator. Fixes: b433ffa8dbac ("selftests: mm: perform some system cleanup before using hugepages") Signed-off-by: Mark Brown Reviewed-by: Nico Pache --- tools/testing/selftests/mm/run_vmtests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index 333c468c26991421cd8f9ce6d995f9b64b0643c7..da7e266681031d2772fb0c4139648904a18e0bf9 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -220,7 +220,7 @@ run_test() { if test_selected ${CATEGORY}; then # On memory constrainted systems some tests can fail to allocate hugepages. # perform some cleanup before the test for a higher success rate. - if [ ${CATEGORY} == "thp" ] | [ ${CATEGORY} == "hugetlb" ]; then + if [ ${CATEGORY} == "thp" -o ${CATEGORY} == "hugetlb" ]; then echo 3 > /proc/sys/vm/drop_caches sleep 2 echo 1 > /proc/sys/vm/compact_memory From patchwork Wed Feb 12 17:44:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 13972247 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C5C325D54D; Wed, 12 Feb 2025 17:45:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739382351; cv=none; b=sYGy69myGObZaJITxDY5Hsn3E1eaD2HlAOdjdHzhlMhbWVqbvLh3Zm6QlT20LjO6fwqQ/TTS8/BLXTxjH9syjxJPzLMoMnuxQ4EsH8qyq6QzwMsXP5FLGfxUNKMRaTjexAUqC+CKS0lrz2IO9K7Cp7LaclplomP2Fjo+7oW8ifo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739382351; c=relaxed/simple; bh=Am3KdYIPQjJJqDySmLeo2AVr33lxdKgLJ8ZrAYJIfwE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Tr91xlNjLQspZ+26E/dSlUA8pS7HHmI50D+iT4Z8E6ljsBX/e9JAn5R6veSv2QvYY8ChvQ3yU4DkPlc1wrKpViRGzNVoKribB/helCkSuoZiZXmjzzDyFsKwnjukYJsPNMctvqfIxkRgE5NztxTPvdkd9xGxNI8PZcnvrw0gSW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Iihh7zap; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Iihh7zap" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E043C4CEE5; Wed, 12 Feb 2025 17:45:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739382351; bh=Am3KdYIPQjJJqDySmLeo2AVr33lxdKgLJ8ZrAYJIfwE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Iihh7zapczT7KxM5Vm3g/yb9+uPSB50XlzAuM/ZoQlE/5EuYk1NrXTxEN8WzE4vEd UypVyXnjfqXbtDsPro2pnKgJ93nwdPDsn8lkP+0Bh/OwBQIULiubjzbSzAV4AYYzsl WXdoYsEhJc52TSKIyoi8bvXruubS9li10FrChCFIa/WmAFblavJnYtwHVZfLKHE6tL fy43htODUYPox4RDzISQzzHxn1rOpNn352ZnGa/A1Lx+Uxrb/pPRfepwTAr07/y2RX j/m+yNQ04DRO+UeOKVJiHqQlAwBA4CSJDeIkyeowpS3ZvcU3LAA5Qsy1x8TyabvKfy FdzFdwFNiQoXg== From: Mark Brown Date: Wed, 12 Feb 2025 17:44:26 +0000 Subject: [PATCH 2/2] selftests/mm: Allow tests to run with no huge pages support Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250212-kselftest-mm-no-hugepages-v1-2-44702f538522@kernel.org> References: <20250212-kselftest-mm-no-hugepages-v1-0-44702f538522@kernel.org> In-Reply-To: <20250212-kselftest-mm-no-hugepages-v1-0-44702f538522@kernel.org> To: Andrew Morton , Shuah Khan Cc: Nico Pache , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-1b0d6 X-Developer-Signature: v=1; a=openpgp-sha256; l=5034; i=broonie@kernel.org; h=from:subject:message-id; bh=Am3KdYIPQjJJqDySmLeo2AVr33lxdKgLJ8ZrAYJIfwE=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBnrN5Il20DD+VhUdR0ubKKm9DDL6E/oyYts5aGN3Za zrQz7T2JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZ6zeSAAKCRAk1otyXVSH0ICeB/ 4w/FgxT9RwtA7DwrjwxGCHSfCWlO/iDd4knXJQInuAxqYW2IveU6Y2bvg280rXvcuN4+hctl0uLwQK fp3zw+bBota+Gl+ftZ9rN9GrTSuGG8XMipvbBAUDfziHGsExY7LkD/OXHe3S7ukFBu23gfzbzvEiAX ty4OiU5xMUOEnC6szMeeiUFUU72RdJaReiAHLcwhhr6Gsxyq0C6CDVXpwEYLHXcaDowJEireF4mGaq GkEP2n938y7ooIcmA08JVDrjKZfEUUzwH1laDNEgVoV7HMuNuAL0hHNUFKjjyseOQWq3OerBry8xHw 2xZq/jwpdRGaasWQYe1dBPPEgUHsJZ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Currently the mm selftests refuse to run if huge pages are not available in the current system but this is an optional feature and not all the tests actually require them. Change the test during startup to be non-fatal and skip or omit tests which actually rely on having huge pages, allowing the other tests to be run. The gup_test does support using madvise() to configure huge pages but it ignores the error code so we just let it run. Signed-off-by: Mark Brown Reviewed-by: Nico Pache --- tools/testing/selftests/mm/run_vmtests.sh | 66 ++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index da7e266681031d2772fb0c4139648904a18e0bf9..d3866b50a6e16a9ba08b6cf33d131edf2a9226be 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -187,9 +187,10 @@ if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then printf "Not enough huge pages available (%d < %d)\n" \ "$freepgs" "$needpgs" fi + HAVE_HUGEPAGES=1 else echo "no hugetlbfs support in kernel?" - exit 1 + HAVE_HUGEPAGES=0 fi # filter 64bit architectures @@ -218,13 +219,20 @@ pretty_name() { # Usage: run_test [test binary] [arbitrary test arguments...] run_test() { if test_selected ${CATEGORY}; then + local skip=0 + # On memory constrainted systems some tests can fail to allocate hugepages. # perform some cleanup before the test for a higher success rate. if [ ${CATEGORY} == "thp" -o ${CATEGORY} == "hugetlb" ]; then - echo 3 > /proc/sys/vm/drop_caches - sleep 2 - echo 1 > /proc/sys/vm/compact_memory - sleep 2 + if [ "${HAVE_HUGEPAGES}" = "1" ]; then + echo 3 > /proc/sys/vm/drop_caches + sleep 2 + echo 1 > /proc/sys/vm/compact_memory + sleep 2 + else + echo "hugepages not supported" | tap_prefix + skip=1 + fi fi local test=$(pretty_name "$*") @@ -232,8 +240,12 @@ run_test() { local sep=$(echo -n "$title" | tr "[:graph:][:space:]" -) printf "%s\n%s\n%s\n" "$sep" "$title" "$sep" | tap_prefix - ("$@" 2>&1) | tap_prefix - local ret=${PIPESTATUS[0]} + if [ "${skip}" != "1" ]; then + ("$@" 2>&1) | tap_prefix + local ret=${PIPESTATUS[0]} + else + local ret=$ksft_skip + fi count_total=$(( count_total + 1 )) if [ $ret -eq 0 ]; then count_pass=$(( count_pass + 1 )) @@ -271,13 +283,15 @@ CATEGORY="hugetlb" run_test ./hugepage-vmemmap CATEGORY="hugetlb" run_test ./hugetlb-madvise CATEGORY="hugetlb" run_test ./hugetlb_dio -nr_hugepages_tmp=$(cat /proc/sys/vm/nr_hugepages) -# For this test, we need one and just one huge page -echo 1 > /proc/sys/vm/nr_hugepages -CATEGORY="hugetlb" run_test ./hugetlb_fault_after_madv -CATEGORY="hugetlb" run_test ./hugetlb_madv_vs_map -# Restore the previous number of huge pages, since further tests rely on it -echo "$nr_hugepages_tmp" > /proc/sys/vm/nr_hugepages +if [ "${HAVE_HUGEPAGES}" = "1" ]; then + nr_hugepages_tmp=$(cat /proc/sys/vm/nr_hugepages) + # For this test, we need one and just one huge page + echo 1 > /proc/sys/vm/nr_hugepages + CATEGORY="hugetlb" run_test ./hugetlb_fault_after_madv + CATEGORY="hugetlb" run_test ./hugetlb_madv_vs_map + # Restore the previous number of huge pages, since further tests rely on it + echo "$nr_hugepages_tmp" > /proc/sys/vm/nr_hugepages +fi if test_selected "hugetlb"; then echo "NOTE: These hugetlb tests provide minimal coverage. Use" | tap_prefix @@ -391,7 +405,9 @@ CATEGORY="memfd_secret" run_test ./memfd_secret fi # KSM KSM_MERGE_TIME_HUGE_PAGES test with size of 100 -CATEGORY="ksm" run_test ./ksm_tests -H -s 100 +if [ "${HAVE_HUGEPAGES}" = "1" ]; then + CATEGORY="ksm" run_test ./ksm_tests -H -s 100 +fi # KSM KSM_MERGE_TIME test with size of 100 CATEGORY="ksm" run_test ./ksm_tests -P -s 100 # KSM MADV_MERGEABLE test with 10 identical pages @@ -440,15 +456,17 @@ CATEGORY="thp" run_test ./transhuge-stress -d 20 # Try to create XFS if not provided if [ -z "${SPLIT_HUGE_PAGE_TEST_XFS_PATH}" ]; then - if test_selected "thp"; then - if grep xfs /proc/filesystems &>/dev/null; then - XFS_IMG=$(mktemp /tmp/xfs_img_XXXXXX) - SPLIT_HUGE_PAGE_TEST_XFS_PATH=$(mktemp -d /tmp/xfs_dir_XXXXXX) - truncate -s 314572800 ${XFS_IMG} - mkfs.xfs -q ${XFS_IMG} - mount -o loop ${XFS_IMG} ${SPLIT_HUGE_PAGE_TEST_XFS_PATH} - MOUNTED_XFS=1 - fi + if [ "${HAVE_HUGEPAGES}" = "1" ]; then + if test_selected "thp"; then + if grep xfs /proc/filesystems &>/dev/null; then + XFS_IMG=$(mktemp /tmp/xfs_img_XXXXXX) + SPLIT_HUGE_PAGE_TEST_XFS_PATH=$(mktemp -d /tmp/xfs_dir_XXXXXX) + truncate -s 314572800 ${XFS_IMG} + mkfs.xfs -q ${XFS_IMG} + mount -o loop ${XFS_IMG} ${SPLIT_HUGE_PAGE_TEST_XFS_PATH} + MOUNTED_XFS=1 + fi + fi fi fi