From nobody Wed Jun 17 01:32:57 2026 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 E93AF1397; Tue, 28 Apr 2026 20:42:57 +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=1777408978; cv=none; b=hKFzCj2KEMbMsLnqCcVyZA8iUG28oWBn1faSZ9tf7PSyyH5F6I+p03uY0cnnQu+elh23RtKJsd/iV0t1skmWctZcSKU5kfpE81dRC6yPpC6ZxXkj+pnasukUQFS7WC5P96fzDQfxecS7Iw589q/GzTb21/6BbfKVbYbzImzAU7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777408978; c=relaxed/simple; bh=9Wa6cmQ8SR+FAIiSEI++oU+tCSCF1FiRlP76nYdhufU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pldcj7upA+rCsrFsw0arNE2hDo81938H6Fm8ScZTH01cZcIxBERHQV9cwD8e3uVWD2a3sA4lqK0lIgFfCTl4WL9UMBUBRcAQIxTd8faLB917FoKKmFZe16ax9in66T17TB8R74zqOP/kvse2lRd7NHaDQfvHy47HXWnoSiEKZYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FlakYzFG; 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="FlakYzFG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4119C2BCAF; Tue, 28 Apr 2026 20:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777408977; bh=9Wa6cmQ8SR+FAIiSEI++oU+tCSCF1FiRlP76nYdhufU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FlakYzFGRiVmn0uV4gIwdSBEOWZkQoAdQSVzm/1V6MlS/ZqTqb5SIDMHqBjY1+40J 8HEnx0nNE4umIeaMl7XnC8OMFE9S07ldbrhokMGfvPLF29zW6dfzzd0ggUKfT/pIHk dKH//u72yXeZhMQ5L7hVKQziZdKfzaKJCD87y7AmeAMnhTunWQ2o/j6FxVtrsW6HKP dnNoVueV/JfBBgSNlrYmJheNe5nRwJN6Qkrx710AbfSMr1zk3oEm1V1ltKnclL+nK7 akJQ9C55LTnO3cN32mS3ww0r5mVaGm18NVren62WP7pKY3v9wTsEkqJj4mZn17rKTC qgYQgPCQXxbWw== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 01/54] selftests/mm: hugetlb-read-hwpoison: add SIGBUS handler Date: Tue, 28 Apr 2026 23:41:47 +0300 Message-ID: <20260428204240.1924129-2-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Access of poisoned memory causes SIGBUS, which terminates the hugetlb-read-hwpoison test prematurely. Add a dummy SIGBUS handler to allow the test to continue regardless of SIGBUS. Tested-by: Sarthak Sharma Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Li Wang Tested-by: Li Wang Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/hugetlb-read-hwpoison.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/mm/hugetlb-read-hwpoison.c b/tools/tes= ting/selftests/mm/hugetlb-read-hwpoison.c index 46230462ad48..6bbf15f78061 100644 --- a/tools/testing/selftests/mm/hugetlb-read-hwpoison.c +++ b/tools/testing/selftests/mm/hugetlb-read-hwpoison.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 #include "kselftest.h" =20 @@ -261,6 +262,11 @@ static int create_hugetlbfs_file(struct statfs *file_s= tat) return -1; } =20 +static void sigbus_handler(int sig) +{ + printf(PREFIX "received SIGBUS\n"); +} + int main(void) { int fd; @@ -273,6 +279,7 @@ int main(void) }; size_t i; =20 + signal(SIGBUS, sigbus_handler); for (i =3D 0; i < ARRAY_SIZE(wr_chunk_sizes); ++i) { printf("Write/read chunk size=3D0x%lx\n", wr_chunk_sizes[i]); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 A81931397; Tue, 28 Apr 2026 20:43:04 +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=1777408984; cv=none; b=N+Tdr4HhOLA9jsbViyGtzLI8zdb4D+FqIGM6m0a4n3N89KkIo3t9PVvTDEAQd6tLBL8eyn4OaCKWrJHOC+37xGmjSDpkkLxIGcfta+Ke8DuDJ1KyWgD9k3zITOENtN33ycgVlN/tjJICaLGBzuiheDOgF6ROcGm6n4YMER3Jr6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777408984; c=relaxed/simple; bh=gbVKoM4MIVVO1d1uh4/TMxtNfLZkzsd0Lj1SU7TW/GE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=owKCFlaowq57o4E1ECvNHmc57ahu9RJ1dLJoYECAzXs/WF46HSglb6K13CL+jE6dAgnJ3MGcdACsAZdfTAM8QxMXx+ZUsTg8Js8pjp4Ra/q8XExlADH71BfhQPytwoyLK4pDvS7R6eoXjIsauA7lVOhofXMwXi2kXfVReDGcX3c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XumDcMVz; 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="XumDcMVz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BE4FC2BCB7; Tue, 28 Apr 2026 20:42:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777408984; bh=gbVKoM4MIVVO1d1uh4/TMxtNfLZkzsd0Lj1SU7TW/GE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XumDcMVzgxhC8x7yeu67yd4mcOlveUMWkL8TW3aonrdHfKYvP5i+qhJ3qZnVImkEV cxnQbpV4KkqEeMYqbl6Ly5shuemW5JZDUVV1koqcVRwDkJbAf6H4acEWIB/PMZzpU/ R/ecz53cklHv4Mv+h3YleugbD5HpHfUzEUIso5OwSmbqc7AVjJ4OczGI34cNVXAHgF FSW2ELRf075BvHbxGOc5KFpsY/gJjBEvQ8KDP6oCCcUBVKgNuDd//1V1zzYu/ovdym d3Lr19hVyOyyX2N/cbWFDJMqldhuerEO901JC5oeA4EYTffEZE3j5gT1Jm9KNQFHoZ OjbP0lgDZpaHQ== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 02/54] selftests/mm: migration: don't assume hupe page is TWOMEG Date: Tue, 28 Apr 2026 23:41:48 +0300 Message-ID: <20260428204240.1924129-3-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" migration tests presume that both THP and HugeTLB huge pages are 2MB. Add dynamic detection of huge page size with read_pmd_pagesize() for THP and with default_huge_page_size() for HugeTLB. Reviewed-by: Donet Tom Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Luiz Capitulino Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/migration.c | 44 +++++++++++++++++++------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftes= ts/mm/migration.c index 60e78bbfc0e3..7e547d945e1a 100644 --- a/tools/testing/selftests/mm/migration.c +++ b/tools/testing/selftests/mm/migration.c @@ -184,22 +184,27 @@ TEST_F_TIMEOUT(migration, shared_anon, 2*RUNTIME) */ TEST_F_TIMEOUT(migration, private_anon_thp, 2*RUNTIME) { + uint64_t pmdsize; uint64_t *ptr; int i; =20 if (!thp_is_enabled()) SKIP(return, "Transparent Hugepages not available"); =20 + pmdsize =3D read_pmd_pagesize(); + if (!pmdsize) + SKIP(return, "Reading PMD pagesize failed"); + if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) SKIP(return, "Not enough threads or NUMA nodes available"); =20 - ptr =3D mmap(NULL, 2*TWOMEG, PROT_READ | PROT_WRITE, + ptr =3D mmap(NULL, 2 * pmdsize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); ASSERT_NE(ptr, MAP_FAILED); =20 - ptr =3D (uint64_t *) ALIGN((uintptr_t) ptr, TWOMEG); - ASSERT_EQ(madvise(ptr, TWOMEG, MADV_HUGEPAGE), 0); - memset(ptr, 0xde, TWOMEG); + ptr =3D (uint64_t *) ALIGN((uintptr_t) ptr, pmdsize); + ASSERT_EQ(madvise(ptr, pmdsize, MADV_HUGEPAGE), 0); + memset(ptr, 0xde, pmdsize); for (i =3D 0; i < self->nthreads - 1; i++) if (pthread_create(&self->threads[i], NULL, access_mem, ptr)) perror("Couldn't create thread"); @@ -215,6 +220,7 @@ TEST_F_TIMEOUT(migration, private_anon_thp, 2*RUNTIME) =20 TEST_F_TIMEOUT(migration, shared_anon_thp, 2*RUNTIME) { + unsigned long pmdsize; pid_t pid; uint64_t *ptr; int i; @@ -222,17 +228,21 @@ TEST_F_TIMEOUT(migration, shared_anon_thp, 2*RUNTIME) if (!thp_is_enabled()) SKIP(return, "Transparent Hugepages not available"); =20 + pmdsize =3D read_pmd_pagesize(); + if (!pmdsize) + SKIP(return, "Reading PMD pagesize failed"); + if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) SKIP(return, "Not enough threads or NUMA nodes available"); =20 - ptr =3D mmap(NULL, 2 * TWOMEG, PROT_READ | PROT_WRITE, + ptr =3D mmap(NULL, 2 * pmdsize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); ASSERT_NE(ptr, MAP_FAILED); =20 - ptr =3D (uint64_t *) ALIGN((uintptr_t) ptr, TWOMEG); - ASSERT_EQ(madvise(ptr, TWOMEG, MADV_HUGEPAGE), 0); + ptr =3D (uint64_t *) ALIGN((uintptr_t) ptr, pmdsize); + ASSERT_EQ(madvise(ptr, pmdsize, MADV_HUGEPAGE), 0); =20 - memset(ptr, 0xde, TWOMEG); + memset(ptr, 0xde, pmdsize); for (i =3D 0; i < self->nthreads - 1; i++) { pid =3D fork(); if (!pid) { @@ -256,17 +266,22 @@ TEST_F_TIMEOUT(migration, shared_anon_thp, 2*RUNTIME) */ TEST_F_TIMEOUT(migration, private_anon_htlb, 2*RUNTIME) { + unsigned long hugepage_size; uint64_t *ptr; int i; =20 if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) SKIP(return, "Not enough threads or NUMA nodes available"); =20 - ptr =3D mmap(NULL, TWOMEG, PROT_READ | PROT_WRITE, + hugepage_size =3D default_huge_page_size(); + if (!hugepage_size) + SKIP(return, "Reading HugeTLB pagesize failed\n"); + + ptr =3D mmap(NULL, hugepage_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); ASSERT_NE(ptr, MAP_FAILED); =20 - memset(ptr, 0xde, TWOMEG); + memset(ptr, 0xde, hugepage_size); for (i =3D 0; i < self->nthreads - 1; i++) if (pthread_create(&self->threads[i], NULL, access_mem, ptr)) perror("Couldn't create thread"); @@ -281,6 +296,7 @@ TEST_F_TIMEOUT(migration, private_anon_htlb, 2*RUNTIME) */ TEST_F_TIMEOUT(migration, shared_anon_htlb, 2*RUNTIME) { + unsigned long hugepage_size; pid_t pid; uint64_t *ptr; int i; @@ -288,11 +304,15 @@ TEST_F_TIMEOUT(migration, shared_anon_htlb, 2*RUNTIME) if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) SKIP(return, "Not enough threads or NUMA nodes available"); =20 - ptr =3D mmap(NULL, TWOMEG, PROT_READ | PROT_WRITE, + hugepage_size =3D default_huge_page_size(); + if (!hugepage_size) + SKIP(return, "Reading HugeTLB pagesize failed\n"); + + ptr =3D mmap(NULL, hugepage_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); ASSERT_NE(ptr, MAP_FAILED); =20 - memset(ptr, 0xde, TWOMEG); + memset(ptr, 0xde, hugepage_size); for (i =3D 0; i < self->nthreads - 1; i++) { pid =3D fork(); if (!pid) { --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 3D7ED311C2D; Tue, 28 Apr 2026 20:43:11 +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=1777408991; cv=none; b=bg+B59m/Z2fCl73aNSWvx4hG5C4FJvfxQG3VXmQ+U7jXfcB/sXJ5vI136VY/oJHEk9KIJJGXpSPczTRu1LvRFTEN5xkqjDIld15aHJ4DqbupHEre340CzAz2N1XEeFYNlBoTbH+z8lyRgv+w4kfrr2+AxmxhNb1zqr037euwYC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777408991; c=relaxed/simple; bh=TjQ0p1EGbgPObHJ7eufAXRVft/JMHNsgzynJsyAX4Ro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M4SaVpWkVmohXApbIi0pXxyxvrETzl/l0STEGCfbZRlK25sIggW4B/UTlMW4bGHsl+cCmWOP6/c3xkwZiclQrpkOBqSuJZtJhTWBbv3LbW/vLjDtq58Gffh5qKK+kOoX+Yd7az4mFaYBpJKTAuLEoAponjacID4h0no4PKKAuUc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H+ZSn5Fk; 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="H+ZSn5Fk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D82F0C2BCAF; Tue, 28 Apr 2026 20:43:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777408990; bh=TjQ0p1EGbgPObHJ7eufAXRVft/JMHNsgzynJsyAX4Ro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H+ZSn5FkeimOUjEC4shA19METCOWCCCNxrqgbHDLaq0t9XqFo0tP262UcFd0MpiW/ OOtplgxA8Bdd+HR+RPORL63i5P3FDdaSETgZvK9XilFcTfMRclX96S4l7d8cacLaGY TA5BQiLwSdqc10NEYKALV245BMw1CwarhoM992en3RBph0krphz2q0bjDdyHIAZQk7 okMnvrClQMv+X+pjQ5i/SqyqpMrNO+pC3YSmfM1LyfvUMNYr2iYEkFIawQx2wD/HMa SNMHLtdo2w4hc+kEI+xEBEUaku6xaWZ+fpdGzMuj0LvecAMANcl07Rx3zrrd94WBqE MmNOcyenwZo5w== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 03/54] selftests/mm: migration: make nthreads represent number of working threads Date: Tue, 28 Apr 2026 23:41:49 +0300 Message-ID: <20260428204240.1924129-4-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Fixture setup sets self->nthreads to number of available CPUs minus 1 and then each test creates 'self->nthreads - 1' threads or processes, so essentially nthreads counts the worker tasks and the main task. Make nthreads represent the number of spawned tasks to simplify thread/process creation and teardown. While on it, make the fixture setup skip the tests if there are not enough CPUs or NUMA nodes instead of checking this in each test. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Luiz Capitulino Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/migration.c | 47 +++++++++----------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftes= ts/mm/migration.c index 7e547d945e1a..3630f2fb0800 100644 --- a/tools/testing/selftests/mm/migration.c +++ b/tools/testing/selftests/mm/migration.c @@ -38,7 +38,7 @@ FIXTURE_SETUP(migration) =20 if (numa_available() < 0) SKIP(return, "NUMA not available"); - self->nthreads =3D numa_num_task_cpus() - 1; + self->nthreads =3D numa_num_task_cpus() - 2; self->n1 =3D -1; self->n2 =3D -1; =20 @@ -52,6 +52,9 @@ FIXTURE_SETUP(migration) } } =20 + if (self->nthreads < 1 || self->n1 < 0 || self->n2 < 0) + SKIP(return, "Not enough threads or NUMA nodes available"); + self->threads =3D malloc(self->nthreads * sizeof(*self->threads)); ASSERT_NE(self->threads, NULL); self->pids =3D malloc(self->nthreads * sizeof(*self->pids)); @@ -127,20 +130,17 @@ TEST_F_TIMEOUT(migration, private_anon, 2*RUNTIME) uint64_t *ptr; int i; =20 - if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) - SKIP(return, "Not enough threads or NUMA nodes available"); - ptr =3D mmap(NULL, TWOMEG, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); ASSERT_NE(ptr, MAP_FAILED); =20 memset(ptr, 0xde, TWOMEG); - for (i =3D 0; i < self->nthreads - 1; i++) + for (i =3D 0; i < self->nthreads; i++) if (pthread_create(&self->threads[i], NULL, access_mem, ptr)) perror("Couldn't create thread"); =20 ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); - for (i =3D 0; i < self->nthreads - 1; i++) + for (i =3D 0; i < self->nthreads; i++) ASSERT_EQ(pthread_cancel(self->threads[i]), 0); } =20 @@ -153,15 +153,12 @@ TEST_F_TIMEOUT(migration, shared_anon, 2*RUNTIME) uint64_t *ptr; int i; =20 - if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) - SKIP(return, "Not enough threads or NUMA nodes available"); - ptr =3D mmap(NULL, TWOMEG, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); ASSERT_NE(ptr, MAP_FAILED); =20 memset(ptr, 0xde, TWOMEG); - for (i =3D 0; i < self->nthreads - 1; i++) { + for (i =3D 0; i < self->nthreads; i++) { pid =3D fork(); if (!pid) { prctl(PR_SET_PDEATHSIG, SIGHUP); @@ -175,7 +172,7 @@ TEST_F_TIMEOUT(migration, shared_anon, 2*RUNTIME) } =20 ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); - for (i =3D 0; i < self->nthreads - 1; i++) + for (i =3D 0; i < self->nthreads; i++) ASSERT_EQ(kill(self->pids[i], SIGTERM), 0); } =20 @@ -195,9 +192,6 @@ TEST_F_TIMEOUT(migration, private_anon_thp, 2*RUNTIME) if (!pmdsize) SKIP(return, "Reading PMD pagesize failed"); =20 - if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) - SKIP(return, "Not enough threads or NUMA nodes available"); - ptr =3D mmap(NULL, 2 * pmdsize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); ASSERT_NE(ptr, MAP_FAILED); @@ -205,12 +199,12 @@ TEST_F_TIMEOUT(migration, private_anon_thp, 2*RUNTIME) ptr =3D (uint64_t *) ALIGN((uintptr_t) ptr, pmdsize); ASSERT_EQ(madvise(ptr, pmdsize, MADV_HUGEPAGE), 0); memset(ptr, 0xde, pmdsize); - for (i =3D 0; i < self->nthreads - 1; i++) + for (i =3D 0; i < self->nthreads; i++) if (pthread_create(&self->threads[i], NULL, access_mem, ptr)) perror("Couldn't create thread"); =20 ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); - for (i =3D 0; i < self->nthreads - 1; i++) + for (i =3D 0; i < self->nthreads; i++) ASSERT_EQ(pthread_cancel(self->threads[i]), 0); } =20 @@ -232,9 +226,6 @@ TEST_F_TIMEOUT(migration, shared_anon_thp, 2*RUNTIME) if (!pmdsize) SKIP(return, "Reading PMD pagesize failed"); =20 - if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) - SKIP(return, "Not enough threads or NUMA nodes available"); - ptr =3D mmap(NULL, 2 * pmdsize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); ASSERT_NE(ptr, MAP_FAILED); @@ -243,7 +234,7 @@ TEST_F_TIMEOUT(migration, shared_anon_thp, 2*RUNTIME) ASSERT_EQ(madvise(ptr, pmdsize, MADV_HUGEPAGE), 0); =20 memset(ptr, 0xde, pmdsize); - for (i =3D 0; i < self->nthreads - 1; i++) { + for (i =3D 0; i < self->nthreads; i++) { pid =3D fork(); if (!pid) { prctl(PR_SET_PDEATHSIG, SIGHUP); @@ -257,7 +248,7 @@ TEST_F_TIMEOUT(migration, shared_anon_thp, 2*RUNTIME) } =20 ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); - for (i =3D 0; i < self->nthreads - 1; i++) + for (i =3D 0; i < self->nthreads; i++) ASSERT_EQ(kill(self->pids[i], SIGTERM), 0); } =20 @@ -270,9 +261,6 @@ TEST_F_TIMEOUT(migration, private_anon_htlb, 2*RUNTIME) uint64_t *ptr; int i; =20 - if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) - SKIP(return, "Not enough threads or NUMA nodes available"); - hugepage_size =3D default_huge_page_size(); if (!hugepage_size) SKIP(return, "Reading HugeTLB pagesize failed\n"); @@ -282,12 +270,12 @@ TEST_F_TIMEOUT(migration, private_anon_htlb, 2*RUNTIM= E) ASSERT_NE(ptr, MAP_FAILED); =20 memset(ptr, 0xde, hugepage_size); - for (i =3D 0; i < self->nthreads - 1; i++) + for (i =3D 0; i < self->nthreads; i++) if (pthread_create(&self->threads[i], NULL, access_mem, ptr)) perror("Couldn't create thread"); =20 ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); - for (i =3D 0; i < self->nthreads - 1; i++) + for (i =3D 0; i < self->nthreads; i++) ASSERT_EQ(pthread_cancel(self->threads[i]), 0); } =20 @@ -301,9 +289,6 @@ TEST_F_TIMEOUT(migration, shared_anon_htlb, 2*RUNTIME) uint64_t *ptr; int i; =20 - if (self->nthreads < 2 || self->n1 < 0 || self->n2 < 0) - SKIP(return, "Not enough threads or NUMA nodes available"); - hugepage_size =3D default_huge_page_size(); if (!hugepage_size) SKIP(return, "Reading HugeTLB pagesize failed\n"); @@ -313,7 +298,7 @@ TEST_F_TIMEOUT(migration, shared_anon_htlb, 2*RUNTIME) ASSERT_NE(ptr, MAP_FAILED); =20 memset(ptr, 0xde, hugepage_size); - for (i =3D 0; i < self->nthreads - 1; i++) { + for (i =3D 0; i < self->nthreads; i++) { pid =3D fork(); if (!pid) { prctl(PR_SET_PDEATHSIG, SIGHUP); @@ -327,7 +312,7 @@ TEST_F_TIMEOUT(migration, shared_anon_htlb, 2*RUNTIME) } =20 ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); - for (i =3D 0; i < self->nthreads - 1; i++) + for (i =3D 0; i < self->nthreads; i++) ASSERT_EQ(kill(self->pids[i], SIGTERM), 0); } =20 --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 D6C9728725A; Tue, 28 Apr 2026 20:43:17 +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=1777408997; cv=none; b=nsEvhw3gsDNZfuorWkWRBRwo3BWTxswl3k+/HcNP0nQO7fn1OSf5qd7T4rdfTwHvqU54wNdeW/F8drOg3pXPyN8BiWR09R10qfhJ6vG/v778n1XnWd3hgV53ZWE08ACO+gYFYBaoE7Ff1XxUyOk0BPH2E2p0SyZNj948ZdTJGFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777408997; c=relaxed/simple; bh=YVLuQpulE4IGKf3/7Seoz5g6EvCitjNNVoS1iFEVWZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WRmBJaKxAmRJcdmje3zAvwb7zDuN3DvYMVUeIoxCUf412R29TfdkrJBnhN8XJC5o6XxXplnfFfhvtKRCKNtNEd3eyd+BhmMlQkpiY6pVNbCp1/YhASB0YJmAQBgdMNHHvyatCoWJzbJJCkmeagelHss1PF6sP8y+CFm6WwM4wBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cAZE/WSS; 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="cAZE/WSS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 704AAC2BCAF; Tue, 28 Apr 2026 20:43:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777408997; bh=YVLuQpulE4IGKf3/7Seoz5g6EvCitjNNVoS1iFEVWZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cAZE/WSSmQVOFRo/+tVPHTO4Sxp02oS/bYllLIpL3lw8OXLIQ0lrkt5dKHdUnkU2K CB5JaWg476OmEVmbtTJJypc7Zh4Zgk7N3cXU6tOpohf6UFC3voeUklGLT/UHIs4OS+ XogWu2BK+VU2RnPNUMPRR7r+wBr7WM6HJIjGFaJKndndNqZJ2GJWoQdVUX4FAsbNg+ qeQjiwJJSLqSjhx9+jWoW7DRC0s+prg3meLM4VELz/UUcnBWYulBwX8GQOmAJzMrFl oKpgMml6UiOmp5QC1W/wIIWZvh5QnAgv0e4TvuAcxmKagy8vYDR/SW4Hwt7whzzd0X 8mzrcXpDGMMPQ== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 04/54] selftests/mm: migration: properly cleanup fork()ed processes Date: Tue, 28 Apr 2026 23:41:50 +0300 Message-ID: <20260428204240.1924129-5-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Several migration test use fork() to create worker processes. These processes are later killed, but nothing collects their exit status and they remain as zombies in the system. Add a helper function that kills the worker processes, waitpid()s for them and verifies the exit status. Replace the loops that call kill() for each process with a call to that helper. The addition of waitpid() calls also makes sure the migrating process never exits before the processes accessing the memory, so it's possible to drop the call to prctl(PR_SET_PDEATHSIG, SIGHUP). Reported-by: Luiz Capitulino Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/migration.c | 54 +++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftes= ts/mm/migration.c index 3630f2fb0800..76e380b74658 100644 --- a/tools/testing/selftests/mm/migration.c +++ b/tools/testing/selftests/mm/migration.c @@ -67,6 +67,24 @@ FIXTURE_TEARDOWN(migration) free(self->pids); } =20 +static bool kill_children(FIXTURE_DATA(migration) * self) +{ + int i, status; + pid_t pid; + + for (i =3D 0; i < self->nthreads; i++) { + pid =3D self->pids[i]; + if (kill(pid, SIGTERM)) + return false; + if (pid !=3D waitpid(pid, &status, 0)) + return false; + if (!WIFSIGNALED(status) || WTERMSIG(status) !=3D SIGTERM) + return false; + } + + return true; +} + int migrate(uint64_t *ptr, int n1, int n2) { int ret, tmp; @@ -160,20 +178,14 @@ TEST_F_TIMEOUT(migration, shared_anon, 2*RUNTIME) memset(ptr, 0xde, TWOMEG); for (i =3D 0; i < self->nthreads; i++) { pid =3D fork(); - if (!pid) { - prctl(PR_SET_PDEATHSIG, SIGHUP); - /* Parent may have died before prctl so check now. */ - if (getppid() =3D=3D 1) - kill(getpid(), SIGHUP); + if (!pid) access_mem(ptr); - } else { + else self->pids[i] =3D pid; - } } =20 ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); - for (i =3D 0; i < self->nthreads; i++) - ASSERT_EQ(kill(self->pids[i], SIGTERM), 0); + ASSERT_EQ(kill_children(self), true); } =20 /* @@ -236,20 +248,14 @@ TEST_F_TIMEOUT(migration, shared_anon_thp, 2*RUNTIME) memset(ptr, 0xde, pmdsize); for (i =3D 0; i < self->nthreads; i++) { pid =3D fork(); - if (!pid) { - prctl(PR_SET_PDEATHSIG, SIGHUP); - /* Parent may have died before prctl so check now. */ - if (getppid() =3D=3D 1) - kill(getpid(), SIGHUP); + if (!pid) access_mem(ptr); - } else { + else self->pids[i] =3D pid; - } } =20 ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); - for (i =3D 0; i < self->nthreads; i++) - ASSERT_EQ(kill(self->pids[i], SIGTERM), 0); + ASSERT_EQ(kill_children(self), true); } =20 /* @@ -300,20 +306,14 @@ TEST_F_TIMEOUT(migration, shared_anon_htlb, 2*RUNTIME) memset(ptr, 0xde, hugepage_size); for (i =3D 0; i < self->nthreads; i++) { pid =3D fork(); - if (!pid) { - prctl(PR_SET_PDEATHSIG, SIGHUP); - /* Parent may have died before prctl so check now. */ - if (getppid() =3D=3D 1) - kill(getpid(), SIGHUP); + if (!pid) access_mem(ptr); - } else { + else self->pids[i] =3D pid; - } } =20 ASSERT_EQ(migrate(ptr, self->n1, self->n2), 0); - for (i =3D 0; i < self->nthreads; i++) - ASSERT_EQ(kill(self->pids[i], SIGTERM), 0); + ASSERT_EQ(kill_children(self), true); } =20 TEST_HARNESS_MAIN --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 6314828725A; Tue, 28 Apr 2026 20:43:24 +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=1777409004; cv=none; b=RoD35rEkl/bOchC6Ala2KTv1j9XIhi012pOAFFYrg2wnnr827lYKCEOptZ9icmx68uREajZUntuXa4F7iUmZE/751DcSY05M6IDV2Myb62rNUdRb5A8L0/CiZoBv8753jZhSlPHPS+BoAO7SEsh+/x7sThLxSxEBQIuvSNptSLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409004; c=relaxed/simple; bh=HP6NlM6bvsHL46OUqlPVamucjfq0ryG8JPKt7QsDS+o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KZYjoRqgewnZcZWmlf4G9BG9fGbty5Bilr58nIf1eZh3NIzf2OwCkYrCaLMjClSnLCvNiN2NbfFcOLwO0Gz1LDcQEgq6cfWJ00hhRfUmzl1jIWkxIGLa5PfVriTu9WCO4vZ0YPn7MvAGyIMGScLFwql7ypPEKFkomNyKS0YqoIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZwvvUuOC; 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="ZwvvUuOC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08BCCC2BCAF; Tue, 28 Apr 2026 20:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409004; bh=HP6NlM6bvsHL46OUqlPVamucjfq0ryG8JPKt7QsDS+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZwvvUuOCRb4mLONa62MF14/EHPDaEgwTSspNatxARqmMq9p7PjYJ4NgH0MV6SJiYq nJ2muU7549az2x13kF0bn39WJjyMhy5G8zKtabFWtSig1otK/YO4pgbWcWuXTcb2aI hNT1OjU+U71QwUqdO4Y2vfcmMjakL2zZoGWBT/QPqzcsDeT7/0aL/Ohlcqh6itR3ly LU33nqCupVcXYRzQGOdBQMdayd9YONVYEA6Wyo9eB5uC39TKD4/oCaqPDjIaBhbFKg Nr/AE0eOnFfq9U7eN9rWYZ5/Q0VxHQ4uVUgWUlZHb8T/m+L2qvWzZRmyk28qTcs2J3 B9s9ySwwUgtFw== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 05/54] selftests/mm: run_vmtests.sh: don't gate THP and KSM tests on HAVE_HUGEPAGES Date: Tue, 28 Apr 2026 23:41:51 +0300 Message-ID: <20260428204240.1924129-6-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" HAVE_HUGEPAGES indicates availability of free HugeTLB pages. It should not be used to gate KSM test that merges transparent huge pages or split_huge_page_test. Remove check for HAVE_HUGEPAGES when running these tests. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Li Wang Tested-by: Li Wang Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/run_vmtests.sh | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/self= tests/mm/run_vmtests.sh index d8468451b3a3..e2dc9ac87bfc 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -436,9 +436,7 @@ CATEGORY=3D"memfd_secret" run_test ./memfd_secret fi =20 # KSM KSM_MERGE_TIME_HUGE_PAGES test with size of 100 -if [ "${HAVE_HUGEPAGES}" =3D "1" ]; then - CATEGORY=3D"ksm" run_test ./ksm_tests -H -s 100 -fi +CATEGORY=3D"ksm" run_test ./ksm_tests -H -s 100 # KSM KSM_MERGE_TIME test with size of 100 CATEGORY=3D"ksm" run_test ./ksm_tests -P -s 100 # KSM MADV_MERGEABLE test with 10 identical pages @@ -493,16 +491,14 @@ CATEGORY=3D"thp" run_test ./transhuge-stress -d 20 =20 # Try to create XFS if not provided if [ -z "${SPLIT_HUGE_PAGE_TEST_XFS_PATH}" ]; then - if [ "${HAVE_HUGEPAGES}" =3D "1" ]; then - if test_selected "thp"; then - if grep xfs /proc/filesystems &>/dev/null; then - XFS_IMG=3D$(mktemp /tmp/xfs_img_XXXXXX) - SPLIT_HUGE_PAGE_TEST_XFS_PATH=3D$(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=3D1 - fi + if test_selected "thp"; then + if grep xfs /proc/filesystems &>/dev/null; then + XFS_IMG=3D$(mktemp /tmp/xfs_img_XXXXXX) + SPLIT_HUGE_PAGE_TEST_XFS_PATH=3D$(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=3D1 fi fi fi --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 C309B28725A; Tue, 28 Apr 2026 20:43:30 +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=1777409010; cv=none; b=U7vh7MHIp54bG7DzRxwV1y3sXL37pF7LsT01eo9gknXVp76LRj8+U3rfVg+58WzrZpUs9VKBL31y80JUbakm5ljrh4v3hjkFGTeXWdNAvSgze5R4iRmfyi5m4NuRhBzwh+qV37QeyA507gNwJfCWxAYXts802q7Mb82vuSskkcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409010; c=relaxed/simple; bh=0Xw45rszAEbFQUh2ZztIRx13l4Zw/sywyZ9vzo8mOnk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RXePnjCU4GY9BNOEY1pkUeveiZXYcGuF6P8RDiX3mIpi3Y5WKG4Lr02trm88RqU5FkMc5Ud6/tVeC9EPUQ6rmZbulL4X4VCpOJzRMda+3NiTDaNJad60lzfmKm7Jfz1AH5cgBxuXarsPWs9NiQgcCqb1Rd4qugX8E8upQ0I4uCc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sNWHpLes; 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="sNWHpLes" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9628DC2BCAF; Tue, 28 Apr 2026 20:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409010; bh=0Xw45rszAEbFQUh2ZztIRx13l4Zw/sywyZ9vzo8mOnk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sNWHpLesWI7IebZX6J51fywpdE+qz+SJaz661LpdtMcgjf/9rrehQBzVdNPn+QGnh uNN+Gno4IE5iveQdXGOPZ2Kadgq6OM4dgBfK1a4qMxk0Ofqxu2SJhEtBzWMBkZ872Q Qy/NF/3GHAX8ymlEXi3998hvb/H0nj2FnnlcsFEx2hl5fDHnOk7HcevRJScVAIW0F+ qGVjTIkjBHxHLkAnSzVLUXHjXtUGA2h9uk06xgOV+7MTBRzHxRGh5RcHz/onqwlfgV 9/WGgYPTmEijd+9u7Yh3DNjJmsIq8Q+LQqL8Q1YuJnAJWC8M1Vnn3twsuyzfoAiRfx MQLzJuqthl7HQ== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 06/54] selftests/mm: merge map_hugetlb into hugepage-mmap Date: Tue, 28 Apr 2026 23:41:52 +0300 Message-ID: <20260428204240.1924129-7-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Both tests create a hugettlb mapping, fill it with data and verify the data, the only difference is that one uses file-backed memory and another one uses anonymous memory. Merge both tests into a single file. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Donet Tom Reviewed-by: Luiz Capitulino Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/Makefile | 1 - tools/testing/selftests/mm/hugepage-mmap.c | 111 ++++++++++++++++----- tools/testing/selftests/mm/map_hugetlb.c | 88 ---------------- tools/testing/selftests/mm/run_vmtests.sh | 1 - 4 files changed, 86 insertions(+), 115 deletions(-) delete mode 100644 tools/testing/selftests/mm/map_hugetlb.c diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/= mm/Makefile index cd24596cdd27..cbda989f6b6a 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -70,7 +70,6 @@ TEST_GEN_FILES +=3D hugepage-vmemmap TEST_GEN_FILES +=3D khugepaged TEST_GEN_FILES +=3D madv_populate TEST_GEN_FILES +=3D map_fixed_noreplace -TEST_GEN_FILES +=3D map_hugetlb TEST_GEN_FILES +=3D map_populate ifneq (,$(filter $(ARCH),arm64 riscv riscv64 x86 x86_64 loongarch32 loonga= rch64)) TEST_GEN_FILES +=3D memfd_secret diff --git a/tools/testing/selftests/mm/hugepage-mmap.c b/tools/testing/sel= ftests/mm/hugepage-mmap.c index d543419de040..fa886ec148c2 100644 --- a/tools/testing/selftests/mm/hugepage-mmap.c +++ b/tools/testing/selftests/mm/hugepage-mmap.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include "vm_util.h" #include "kselftest.h" =20 #define LENGTH (256UL*1024*1024) @@ -25,54 +27,113 @@ static void check_bytes(char *addr) ksft_print_msg("First hex is %x\n", *((unsigned int *)addr)); } =20 -static void write_bytes(char *addr) +static void write_bytes(char *addr, size_t length) { unsigned long i; =20 - for (i =3D 0; i < LENGTH; i++) + for (i =3D 0; i < length; i++) *(addr + i) =3D (char)i; } =20 -static int read_bytes(char *addr) +static bool verify_bytes(char *addr, size_t length) { unsigned long i; =20 check_bytes(addr); - for (i =3D 0; i < LENGTH; i++) + for (i =3D 0; i < length; i++) if (*(addr + i) !=3D (char)i) { - ksft_print_msg("Error: Mismatch at %lu\n", i); - return 1; + ksft_print_msg("Error: Mismatch at %lu(%p)\n", i, addr); + return false; } - return 0; + + return true; } =20 -int main(void) +static bool test_mmap(size_t length, int mmap_flags, int fd, + const char *test_name) { void *addr; - int fd, ret; =20 - ksft_print_header(); - ksft_set_plan(1); + addr =3D mmap(NULL, length, PROTECTION, mmap_flags, fd, 0); + if (addr =3D=3D MAP_FAILED) + ksft_exit_fail_perror("mmap"); + + ksft_print_msg("Returned address is %p\n", addr); + check_bytes(addr); + write_bytes(addr, length); + if (!verify_bytes(addr, length)) + ksft_exit_fail_msg("%s\n", test_name); + + /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */ + if (munmap(addr, length)) + ksft_exit_fail_perror("munmap"); + + return true; +} + +static void test_anon_mmap(size_t length, int shift) +{ + const char *test_name =3D "hugetlb anonymous mmap"; + int mmap_flags =3D MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB; + bool passed; + + if (shift) + mmap_flags |=3D (shift & MAP_HUGE_MASK) << MAP_HUGE_SHIFT; + + passed =3D test_mmap(length, mmap_flags, -1, test_name); + ksft_test_result(passed, "%s\n", test_name); +} + +static void test_file_mmap(size_t length, int shift) +{ + const char *test_name =3D "hugetlb file mmap"; + int mfd_flags =3D MFD_HUGETLB; + bool passed; + int fd; + + if (shift) + mfd_flags |=3D (shift & MFD_HUGE_MASK) << MFD_HUGE_SHIFT; =20 - fd =3D memfd_create("hugepage-mmap", MFD_HUGETLB); + fd =3D memfd_create("hugetlb-mmap", mfd_flags); if (fd < 0) - ksft_exit_fail_msg("memfd_create() failed: %s\n", strerror(errno)); + ksft_exit_fail_perror("memfd_create"); + + passed =3D test_mmap(length, MAP_SHARED, fd, test_name); + + close(fd); + ksft_test_result(passed, "%s\n", test_name); +} + +int main(int argc, char **argv) +{ + size_t hugepage_size; + size_t length =3D LENGTH; + int shift =3D 0; + + ksft_print_header(); + ksft_set_plan(2); + + if (argc > 1) + length =3D atol(argv[1]) << 20; + if (argc > 2) + shift =3D atoi(argv[2]); =20 - addr =3D mmap(NULL, LENGTH, PROTECTION, MAP_SHARED, fd, 0); - if (addr =3D=3D MAP_FAILED) { - close(fd); - ksft_exit_fail_msg("mmap(): %s\n", strerror(errno)); + if (shift) { + hugepage_size =3D (1 << shift); + ksft_print_msg("%u kB hugepages\n", 1 << (shift - 10)); + } else { + hugepage_size =3D default_huge_page_size(); + ksft_print_msg("Default size hugepages (%lu Kb)\n", hugepage_size >> 10); } =20 - ksft_print_msg("Returned address is %p\n", addr); - check_bytes(addr); - write_bytes(addr); - ret =3D read_bytes(addr); + /* munmap with fail if the length is not page aligned */ + if (hugepage_size > length) + length =3D hugepage_size; =20 - munmap(addr, LENGTH); - close(fd); + ksft_print_msg("Mapping %lu Mbytes\n", (unsigned long)length >> 20); =20 - ksft_test_result(!ret, "Read same data\n"); + test_anon_mmap(length, shift); + test_file_mmap(length, shift); =20 - ksft_exit(!ret); + ksft_finished(); } diff --git a/tools/testing/selftests/mm/map_hugetlb.c b/tools/testing/selft= ests/mm/map_hugetlb.c deleted file mode 100644 index aa409107611b..000000000000 --- a/tools/testing/selftests/mm/map_hugetlb.c +++ /dev/null @@ -1,88 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Example of using hugepage memory in a user application using the mmap - * system call with MAP_HUGETLB flag. Before running this program make - * sure the administrator has allocated enough default sized huge pages - * to cover the 256 MB allocation. - */ -#include -#include -#include -#include -#include -#include "vm_util.h" -#include "kselftest.h" - -#define LENGTH (256UL*1024*1024) -#define PROTECTION (PROT_READ | PROT_WRITE) - -static void check_bytes(char *addr) -{ - ksft_print_msg("First hex is %x\n", *((unsigned int *)addr)); -} - -static void write_bytes(char *addr, size_t length) -{ - unsigned long i; - - for (i =3D 0; i < length; i++) - *(addr + i) =3D (char)i; -} - -static void read_bytes(char *addr, size_t length) -{ - unsigned long i; - - check_bytes(addr); - for (i =3D 0; i < length; i++) - if (*(addr + i) !=3D (char)i) - ksft_exit_fail_msg("Mismatch at %lu\n", i); - - ksft_test_result_pass("Read correct data\n"); -} - -int main(int argc, char **argv) -{ - void *addr; - size_t hugepage_size; - size_t length =3D LENGTH; - int flags =3D MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB; - int shift =3D 0; - - hugepage_size =3D default_huge_page_size(); - /* munmap with fail if the length is not page aligned */ - if (hugepage_size > length) - length =3D hugepage_size; - - ksft_print_header(); - ksft_set_plan(1); - - if (argc > 1) - length =3D atol(argv[1]) << 20; - if (argc > 2) { - shift =3D atoi(argv[2]); - if (shift) - flags |=3D (shift & MAP_HUGE_MASK) << MAP_HUGE_SHIFT; - } - - if (shift) - ksft_print_msg("%u kB hugepages\n", 1 << (shift - 10)); - else - ksft_print_msg("Default size hugepages\n"); - ksft_print_msg("Mapping %lu Mbytes\n", (unsigned long)length >> 20); - - addr =3D mmap(NULL, length, PROTECTION, flags, -1, 0); - if (addr =3D=3D MAP_FAILED) - ksft_exit_fail_msg("mmap: %s\n", strerror(errno)); - - ksft_print_msg("Returned address is %p\n", addr); - check_bytes(addr); - write_bytes(addr, length); - read_bytes(addr, length); - - /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */ - if (munmap(addr, length)) - ksft_exit_fail_msg("munmap: %s\n", strerror(errno)); - - ksft_finished(); -} diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/self= tests/mm/run_vmtests.sh index e2dc9ac87bfc..61b450032af8 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -292,7 +292,6 @@ CATEGORY=3D"hugetlb" run_test ./hugepage-shm echo "$shmmax" > /proc/sys/kernel/shmmax echo "$shmall" > /proc/sys/kernel/shmall =20 -CATEGORY=3D"hugetlb" run_test ./map_hugetlb CATEGORY=3D"hugetlb" run_test ./hugepage-mremap CATEGORY=3D"hugetlb" run_test ./hugepage-vmemmap CATEGORY=3D"hugetlb" run_test ./hugetlb-madvise --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 86A0528725A; Tue, 28 Apr 2026 20:43:37 +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=1777409017; cv=none; b=Q0eSFbfecvvTJUlLqUIV/VGftI2n1WJBmgQUWKh2elajvHV4OHa9kQjb1rtpyRaTF8mbsQt3sF+ylYwtahv4nC5MO1NxhnJ9H4yIaj8RXISl5ALhvozUSKNmKP8liYXa34iYdpf9PagJCwcjJxBgBzB+OGak7QgKV9fIa3bYCyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409017; c=relaxed/simple; bh=9sC3778jKyDFz3Hjf8iXiNoDRSWAhHT+f8fPth7IqjA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tMlNZXLvEIcAOh6v02B/28GxsSnDjcJ6/cnfhv8jYQeTC+R7ypeB2PSVWXue5ga9BzrnEDLzYr81k0SVIMP/LJ+sfebKH/3tOHCsZ61BMLasuEfnITYTCc4Stx8lzcl0yPNigD0BHbBalFdqhwUJdJ+MhB5S3lw1TrIGKrvaYys= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MFRVWxxU; 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="MFRVWxxU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E9BDC2BCAF; Tue, 28 Apr 2026 20:43:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409017; bh=9sC3778jKyDFz3Hjf8iXiNoDRSWAhHT+f8fPth7IqjA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MFRVWxxU2l48pg7KdlcATzh/BQ7El7mawJuXdhfzSUId5u/FV3ENpGrpXoVv/S/5e diGcw13XfZ66wO6iK6hu/nz+PFGHcwnt5Yh9Kz8cgkfNZUENMDb/9cXjrvfidS/0En Q9CsEbrpDu2gG6VRAai5UYV/lv4uWDvGC1kM/eG6mUfifvB+4vsxxt79dAdTkvoO+w UBiE5Xg01xGq0XKss6X4SfkdurzI9BbwHtB04Jn+VmOmuutfi75GehlCP7x5cR+v0f csq7HGnKd78f9EibARdiq0bwCYC+gXAK2lSpyAw75v7VpnTjcNibWt59VaCe8g3kKA zzSHvWYTm+k8Q== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 07/54] selftests/mm: rename hugepage-* tests to hugetlb-* Date: Tue, 28 Apr 2026 23:41:53 +0300 Message-ID: <20260428204240.1924129-8-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hugepage could mean both THP and HugeTLB these days. Rename hugepage-* tests for HugeTLB to hugetlb-* to avoid confusion. Reviewed-by: Donet Tom Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Li Wang Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/.gitignore | 4 ++++ tools/testing/selftests/mm/Makefile | 8 ++++---- tools/testing/selftests/mm/hugetlb-madvise.c | 2 +- .../selftests/mm/{hugepage-mmap.c =3D> hugetlb-mmap.c} | 2 +- .../selftests/mm/{hugepage-mremap.c =3D> hugetlb-mremap.c} | 2 +- .../selftests/mm/{hugepage-shm.c =3D> hugetlb-shm.c} | 2 +- .../mm/{hugepage-vmemmap.c =3D> hugetlb-vmemmap.c} | 0 tools/testing/selftests/mm/run_vmtests.sh | 8 ++++---- 8 files changed, 16 insertions(+), 12 deletions(-) rename tools/testing/selftests/mm/{hugepage-mmap.c =3D> hugetlb-mmap.c} (9= 9%) rename tools/testing/selftests/mm/{hugepage-mremap.c =3D> hugetlb-mremap.c= } (99%) rename tools/testing/selftests/mm/{hugepage-shm.c =3D> hugetlb-shm.c} (99%) rename tools/testing/selftests/mm/{hugepage-vmemmap.c =3D> hugetlb-vmemmap= .c} (100%) diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/selftest= s/mm/.gitignore index b0c30c5ee9e3..9ccd9e1447e6 100644 --- a/tools/testing/selftests/mm/.gitignore +++ b/tools/testing/selftests/mm/.gitignore @@ -4,6 +4,10 @@ hugepage-mmap hugepage-mremap hugepage-shm hugepage-vmemmap +hugetlb-mmap +hugetlb-mremap +hugetlb-shm +hugetlb-vmemmap hugetlb-madvise hugetlb-read-hwpoison hugetlb-soft-offline diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/= mm/Makefile index cbda989f6b6a..a6955660a806 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -63,10 +63,10 @@ TEST_GEN_FILES +=3D hmm-tests TEST_GEN_FILES +=3D hugetlb-madvise TEST_GEN_FILES +=3D hugetlb-read-hwpoison TEST_GEN_FILES +=3D hugetlb-soft-offline -TEST_GEN_FILES +=3D hugepage-mmap -TEST_GEN_FILES +=3D hugepage-mremap -TEST_GEN_FILES +=3D hugepage-shm -TEST_GEN_FILES +=3D hugepage-vmemmap +TEST_GEN_FILES +=3D hugetlb-mremap +TEST_GEN_FILES +=3D hugetlb-shm +TEST_GEN_FILES +=3D hugetlb-vmemmap +TEST_GEN_FILES +=3D hugetlb-mmap TEST_GEN_FILES +=3D khugepaged TEST_GEN_FILES +=3D madv_populate TEST_GEN_FILES +=3D map_fixed_noreplace diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/s= elftests/mm/hugetlb-madvise.c index 5b12041fa310..898cc90b314f 100644 --- a/tools/testing/selftests/mm/hugetlb-madvise.c +++ b/tools/testing/selftests/mm/hugetlb-madvise.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * hugepage-madvise: + * hugetlb-madvise: * * Basic functional testing of madvise MADV_DONTNEED and MADV_REMOVE * on hugetlb mappings. diff --git a/tools/testing/selftests/mm/hugepage-mmap.c b/tools/testing/sel= ftests/mm/hugetlb-mmap.c similarity index 99% rename from tools/testing/selftests/mm/hugepage-mmap.c rename to tools/testing/selftests/mm/hugetlb-mmap.c index fa886ec148c2..9f5ea8d6d656 100644 --- a/tools/testing/selftests/mm/hugepage-mmap.c +++ b/tools/testing/selftests/mm/hugetlb-mmap.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * hugepage-mmap: + * hugetlb-mmap: * * Example of using huge page memory in a user application using the mmap * system call. Before running this application, make sure that the diff --git a/tools/testing/selftests/mm/hugepage-mremap.c b/tools/testing/s= elftests/mm/hugetlb-mremap.c similarity index 99% rename from tools/testing/selftests/mm/hugepage-mremap.c rename to tools/testing/selftests/mm/hugetlb-mremap.c index b8f7d92e5a35..1c87c39780c5 100644 --- a/tools/testing/selftests/mm/hugepage-mremap.c +++ b/tools/testing/selftests/mm/hugetlb-mremap.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * hugepage-mremap: + * hugetlb-mremap: * * Example of remapping huge page memory in a user application using the * mremap system call. The path to a file in a hugetlbfs filesystem must diff --git a/tools/testing/selftests/mm/hugepage-shm.c b/tools/testing/self= tests/mm/hugetlb-shm.c similarity index 99% rename from tools/testing/selftests/mm/hugepage-shm.c rename to tools/testing/selftests/mm/hugetlb-shm.c index ef06260802b5..de8f5d523084 100644 --- a/tools/testing/selftests/mm/hugepage-shm.c +++ b/tools/testing/selftests/mm/hugetlb-shm.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * hugepage-shm: + * hugetlb-shm: * * Example of using huge page memory in a user application using Sys V sha= red * memory system calls. In this example the app is requesting 256MB of diff --git a/tools/testing/selftests/mm/hugepage-vmemmap.c b/tools/testing/= selftests/mm/hugetlb-vmemmap.c similarity index 100% rename from tools/testing/selftests/mm/hugepage-vmemmap.c rename to tools/testing/selftests/mm/hugetlb-vmemmap.c diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/self= tests/mm/run_vmtests.sh index 61b450032af8..b9e520194634 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -282,18 +282,18 @@ run_test() { =20 echo "TAP version 13" | tap_output =20 -CATEGORY=3D"hugetlb" run_test ./hugepage-mmap +CATEGORY=3D"hugetlb" run_test ./hugetlb-mmap =20 shmmax=3D$(cat /proc/sys/kernel/shmmax) shmall=3D$(cat /proc/sys/kernel/shmall) echo 268435456 > /proc/sys/kernel/shmmax echo 4194304 > /proc/sys/kernel/shmall -CATEGORY=3D"hugetlb" run_test ./hugepage-shm +CATEGORY=3D"hugetlb" run_test ./hugetlb-shm echo "$shmmax" > /proc/sys/kernel/shmmax echo "$shmall" > /proc/sys/kernel/shmall =20 -CATEGORY=3D"hugetlb" run_test ./hugepage-mremap -CATEGORY=3D"hugetlb" run_test ./hugepage-vmemmap +CATEGORY=3D"hugetlb" run_test ./hugetlb-mremap +CATEGORY=3D"hugetlb" run_test ./hugetlb-vmemmap CATEGORY=3D"hugetlb" run_test ./hugetlb-madvise CATEGORY=3D"hugetlb" run_test ./hugetlb_dio =20 --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 0E48130594E; Tue, 28 Apr 2026 20:43:43 +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=1777409024; cv=none; b=s5Jj3f9L6cje44rNCiVuoQ+rHrKPpq2DhgrO8Dqiu+sSWIjdVf9lvxj2Dpyi2Bl8LTC1TuulsHtq938pNt41e+sFjq7BIKC2hXjl/EuOEeUV60KM/W2SGg0coQp4xlyAwmAvaM6ujqp8abHI2KGCKuknWNIq1sDEedWpl+zq+yQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409024; c=relaxed/simple; bh=dLU/bCwt/eyA3PPvWB4ap77KznBqGFR0SnU6xHYGFcc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eZskMT+vXceL7fRovEJ9oexiU+vgp5jZKv36hnqFB9R944P7g9pm+E2Ts1gsagMzLofMUkr5DCRlosSE7jlklukbm57pK+dlBNgn20n4fx2kuc2D6EFmaQFUsiIAan8MKyF/RvYrH0hmNwe8/HHsFAVHOwvFmSuRGEOvG48zsm4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mwWAMGYD; 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="mwWAMGYD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBB26C2BCAF; Tue, 28 Apr 2026 20:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409023; bh=dLU/bCwt/eyA3PPvWB4ap77KznBqGFR0SnU6xHYGFcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mwWAMGYDBm1/30LXf/9ytrjyyByqvvFyPg5pEzATYztnQDEwJ9Zw3n0dj9e1frT4Y PXNluZ5vLoTN5VWyN9Ou5WDvkwCsY7/jaLg2GJVZf/9e03WI5umRW00q5YZ9gXs1wh eC3boZrlA2bezEuyOsRjLh4VuMeAhsm9RGnzbMAEGegMZ5s86t4+egl2etx4Tmdt4o eSFiMrMAVRmJhEDjIv1I3yK5LR0DxJ4qvdQ81ZNPZ7Uxg0xApN8eEa0MN09FENMHn5 5v7WZ/XTutw2g2y4LDlGtWY2WeIYLmIe3tRMYciuthDi0wX2SMowhWrnI61sYaJdIA MUSUOGb9ULIsA== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 08/54] selftests/mm: hugetlb-shm: use kselftest framework Date: Tue, 28 Apr 2026 23:41:54 +0300 Message-ID: <20260428204240.1924129-9-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Convert hugetlb-shm test to use kselftest framework for reporting and tracking successful and failing runs. Reviewed-by: Donet Tom Reviewed-by: Mark Brown Tested-by: Sarthak Sharma Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/hugetlb-shm.c | 45 ++++++++++++------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-shm.c b/tools/testing/selft= ests/mm/hugetlb-shm.c index de8f5d523084..0f70b1a50b6b 100644 --- a/tools/testing/selftests/mm/hugetlb-shm.c +++ b/tools/testing/selftests/mm/hugetlb-shm.c @@ -28,9 +28,9 @@ #include #include =20 -#define LENGTH (256UL*1024*1024) +#include "vm_util.h" =20 -#define dprintf(x) printf(x) +#define LENGTH (256UL*1024*1024) =20 int main(void) { @@ -38,44 +38,43 @@ int main(void) unsigned long i; char *shmaddr; =20 + ksft_print_header(); + ksft_set_plan(1); + shmid =3D shmget(2, LENGTH, SHM_HUGETLB | IPC_CREAT | SHM_R | SHM_W); - if (shmid < 0) { - perror("shmget"); - exit(1); - } - printf("shmid: 0x%x\n", shmid); + if (shmid < 0) + ksft_exit_fail_perror("shmget"); + + ksft_print_msg("shmid: 0x%x\n", shmid); =20 shmaddr =3D shmat(shmid, NULL, 0); if (shmaddr =3D=3D (char *)-1) { - perror("Shared memory attach failure"); + ksft_perror("Shared memory attach failure"); shmctl(shmid, IPC_RMID, NULL); - exit(2); + ksft_exit_fail(); } - printf("shmaddr: %p\n", shmaddr); + ksft_print_msg("shmaddr: %p\n", shmaddr); =20 - dprintf("Starting the writes:\n"); - for (i =3D 0; i < LENGTH; i++) { + ksft_print_msg("Starting the writes:\n"); + for (i =3D 0; i < LENGTH; i++) shmaddr[i] =3D (char)(i); - if (!(i % (1024 * 1024))) - dprintf("."); - } - dprintf("\n"); =20 - dprintf("Starting the Check..."); + ksft_print_msg("Starting the Check..."); for (i =3D 0; i < LENGTH; i++) if (shmaddr[i] !=3D (char)i) { - printf("\nIndex %lu mismatched\n", i); - exit(3); + shmctl(shmid, IPC_RMID, NULL); + ksft_exit_fail_msg("Data mismatch at index %lu\n", i); } - dprintf("Done.\n"); + ksft_print_msg("Done.\n"); =20 if (shmdt((const void *)shmaddr) !=3D 0) { - perror("Detach failure"); + ksft_perror("Detach failure"); shmctl(shmid, IPC_RMID, NULL); - exit(4); + ksft_exit_fail(); } =20 shmctl(shmid, IPC_RMID, NULL); =20 - return 0; + ksft_test_result_pass("hugepage using SysV shmget/shmat\n"); + ksft_finished(); } --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 898A031F9B8; Tue, 28 Apr 2026 20:43:50 +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=1777409030; cv=none; b=n76bQecKn1Oq5rs7i3erX81xGTitMXMaCKFvS3V2XCYHIJ3MgMXANTvyXamU7bcF4oufnblXEGYrrI7x7Cd25ubXhRuwwbDXdKolNCp6sjcZYEyaT4uqKGZWnWDA/HY/msvzJQ+7su+m68bXunNwz40xRg2H3yhstbWuyTfxDxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409030; c=relaxed/simple; bh=bpVjE+rMZ04PnOlIbMfzh/SWaUuNZKecssAAspqsN00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fzmy+n6u/Vb2tV8OZeo53+vBuZ7WDZq1MYJPh6n0kIzsZyT7Ss/5WKaul5A8pwGgTi0SWIY1siDoup09spWjAwziqdJdwGvgnXnAi5zP9eOYF5vQwnHOL5Xc4SRJZz090wkJOO1GYiH48cmgOBbya2E9gtGxCBH2GXaw1gDbPXQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lp7BNmJf; 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="Lp7BNmJf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5442AC2BCB3; Tue, 28 Apr 2026 20:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409030; bh=bpVjE+rMZ04PnOlIbMfzh/SWaUuNZKecssAAspqsN00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lp7BNmJfBs3tnIXRwomoqgNhS3DpKCfQnJiUKp0ucl4K0f1Qr/E4L975/0TC+Tejs 8bphHhHBaxKSe3Q7WxLlL+zQmOYK67ceUwO6kM3zTrTkslmOh5U+uXc3AWHA3Wgdqw Ior2MXonGYqegGcU6qpUJ2I2cZic5sG9876hxsh/nrct7YHaLpcHZbx9n1mKXrHnmv pPi2JLgfCdbJ6pmTzVqlBUJ5rsWfkf1zMuRFIkDYfWZaFNibPhnsJC6/i68phkXOED ZHBIhZ5NZK/AoKcIZXhGvRflC+tdNyQN/dBUldyqkyFG3YpeInMFQ1s8aR5PFCv/mT VMt6K8MPkbr2Q== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 09/54] selftests/mm: hugetlb-vmemmap: use kselftest framework Date: Tue, 28 Apr 2026 23:41:55 +0300 Message-ID: <20260428204240.1924129-10-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Convert hugetlb-vmemmap test to use kselftest framework for reporting and tracking successful and failing runs. Reviewed-by: Donet Tom Reviewed-by: Mark Brown Tested-by: Sarthak Sharma Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/hugetlb-vmemmap.c | 42 +++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-vmemmap.c b/tools/testing/s= elftests/mm/hugetlb-vmemmap.c index df366a4d1b92..485a6978b40f 100644 --- a/tools/testing/selftests/mm/hugetlb-vmemmap.c +++ b/tools/testing/selftests/mm/hugetlb-vmemmap.c @@ -63,7 +63,7 @@ static int check_page_flags(unsigned long pfn) read(fd, &pageflags, sizeof(pageflags)); if ((pageflags & HEAD_PAGE_FLAGS) !=3D HEAD_PAGE_FLAGS) { close(fd); - printf("Head page flags (%lx) is invalid\n", pageflags); + ksft_print_msg("Head page flags (%lx) is invalid\n", pageflags); return -1; } =20 @@ -77,7 +77,7 @@ static int check_page_flags(unsigned long pfn) if ((pageflags & TAIL_PAGE_FLAGS) !=3D TAIL_PAGE_FLAGS || (pageflags & HEAD_PAGE_FLAGS) =3D=3D HEAD_PAGE_FLAGS) { close(fd); - printf("Tail page flags (%lx) is invalid\n", pageflags); + ksft_print_msg("Tail page flags (%lx) is invalid\n", pageflags); return -1; } } @@ -91,44 +91,38 @@ int main(int argc, char **argv) { void *addr; unsigned long pfn; + int ret; + + ksft_print_header(); + ksft_set_plan(1); =20 pagesize =3D psize(); maplength =3D default_huge_page_size(); - if (!maplength) { - printf("Unable to determine huge page size\n"); - exit(1); - } + if (!maplength) + ksft_exit_skip("Unable to determine huge page size\n"); =20 addr =3D mmap(NULL, maplength, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); - if (addr =3D=3D MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr =3D=3D MAP_FAILED) + ksft_exit_fail_perror("mmap"); =20 /* Trigger allocation of HugeTLB page. */ write_bytes(addr, maplength); =20 pfn =3D virt_to_pfn(addr); if (pfn =3D=3D -1UL) { + ksft_perror("virt_to_pfn"); munmap(addr, maplength); - perror("virt_to_pfn"); - exit(1); + ksft_exit_fail(); } =20 - printf("Returned address is %p whose pfn is %lx\n", addr, pfn); + ksft_print_msg("Returned address is %p whose pfn is %lx\n", addr, pfn); =20 - if (check_page_flags(pfn) < 0) { - munmap(addr, maplength); - perror("check_page_flags"); - exit(1); - } + ret =3D check_page_flags(pfn); =20 - /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */ - if (munmap(addr, maplength)) { - perror("munmap"); - exit(1); - } + if (munmap(addr, maplength)) + ksft_exit_fail_perror("munmap"); =20 - return 0; + ksft_test_result(!ret, "HugeTLB vmemmap page flags\n"); + ksft_finished(); } --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 5B0563101BD; Tue, 28 Apr 2026 20:43:57 +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=1777409037; cv=none; b=WAXGXoJOceH9SvxVfJUzBRnAMQxHcVB//tQxggH3K1wI0EpSBey41FrSlm23Lh25MsgQFNE99HNXlGwr0ZBjH7pzcbup6lEP1kmblt9bLetTe+EVwbR/4OubK1fJCUxrnruNMej7S9RF/8QJ20NliV4vrFcoTv4nCvbgko347Xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409037; c=relaxed/simple; bh=/xRGC6/38cN+oMRwh/sO9zPsnvisaYmcm1vP8FXfFDA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uHO6nju6IsQ21oKOLZQZFohahg91ZElu4KCKIJlg6y8EE6jj2eUu7dchL8AdBsq2aaRT8F1sNKbJ+Y3I5osN5a+/z+ki9baXWZkBzfwDjf/qojn3LIQVElXaQYBgZ7W2r18KpVFSKrbdySYB+pKVa2MCJypxdGRUenEWNxtWGJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ejLhIzq0; 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="ejLhIzq0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E12BEC2BCB7; Tue, 28 Apr 2026 20:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409037; bh=/xRGC6/38cN+oMRwh/sO9zPsnvisaYmcm1vP8FXfFDA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ejLhIzq0R2Zqb2ws9Vms/Vj1/lIAyDDed2bjwgikI0TGRfLl6OKj27bS1qudGyKq4 OIxqBQJwqwLLGCjO2KxEOzMVQyh6P0H+uNOgZW7lGWsToArUU2WVenoxLayrd2UUaS ypq8DB9BsaVTEtJMOXFqk6Hk3Lfjnr5/ZUkD2KN1sNxaNjuAx6uvaNO9PYBbm0oxdb PAtb6+K2Jn5tYcEIJUJ57gXZoi6pwXh78vj19BOYyx9KZKUbpyluC/Q/G2f6+VMrAn N/IUfVOaLsYHy10qEckp/o5R2xlCU5R6IBHAm7rAi9ddFNZjvgW91MYecGi/U9AsPw xY278yRCFRkEQ== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 10/54] selftests/mm: hugetlb-madvise: use kselftest framework Date: Tue, 28 Apr 2026 23:41:56 +0300 Message-ID: <20260428204240.1924129-11-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Convert hugetlb-madvise test to use kselftest framework for reporting and tracking successful and failing runs. Reviewed-by: Donet Tom Tested-by: Sarthak Sharma Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/hugetlb-madvise.c | 204 ++++++++----------- 1 file changed, 82 insertions(+), 122 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/s= elftests/mm/hugetlb-madvise.c index 898cc90b314f..4c6c346a3af5 100644 --- a/tools/testing/selftests/mm/hugetlb-madvise.c +++ b/tools/testing/selftests/mm/hugetlb-madvise.c @@ -26,12 +26,11 @@ =20 #define validate_free_pages(exp_free) \ do { \ - int fhp =3D get_free_hugepages(); \ - if (fhp !=3D (exp_free)) { \ - printf("Unexpected number of free huge " \ - "pages line %d\n", __LINE__); \ - exit(1); \ - } \ + unsigned long fhp =3D get_free_hugepages(); \ + if (fhp !=3D (exp_free)) \ + ksft_exit_fail_msg("Unexpected number of free " \ + "huge pages %ld, expected %ld line %d\n", \ + fhp, (exp_free), __LINE__); \ } while (0) =20 unsigned long huge_page_size; @@ -57,28 +56,24 @@ int main(int argc, char **argv) int fd; int ret; =20 + ksft_print_header(); + ksft_set_plan(1); + huge_page_size =3D default_huge_page_size(); - if (!huge_page_size) { - printf("Unable to determine huge page size, exiting!\n"); - exit(1); - } + if (!huge_page_size) + ksft_exit_skip("Unable to determine huge page size\n"); + base_page_size =3D sysconf(_SC_PAGE_SIZE); - if (!huge_page_size) { - printf("Unable to determine base page size, exiting!\n"); - exit(1); - } + if (!base_page_size) + ksft_exit_fail_msg("Unable to determine base page size\n"); =20 free_hugepages =3D get_free_hugepages(); - if (free_hugepages < MIN_FREE_PAGES) { - printf("Not enough free huge pages to test, exiting!\n"); - exit(KSFT_SKIP); - } + if (free_hugepages < MIN_FREE_PAGES) + ksft_exit_skip("Not enough free huge pages (have %lu, need %d)\n", free_= hugepages, MIN_FREE_PAGES); =20 fd =3D memfd_create(argv[0], MFD_HUGETLB); - if (fd < 0) { - perror("memfd_create() failed"); - exit(1); - } + if (fd < 0) + ksft_exit_fail_perror("memfd_create"); =20 /* * Test validity of MADV_DONTNEED addr and length arguments. mmap @@ -90,16 +85,13 @@ int main(int argc, char **argv) PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); - if (addr =3D=3D MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr =3D=3D MAP_FAILED) + ksft_exit_fail_perror("mmap"); + if (munmap(addr, huge_page_size) || munmap(addr + (NR_HUGE_PAGES + 1) * huge_page_size, - huge_page_size)) { - perror("munmap"); - exit(1); - } + huge_page_size)) + ksft_exit_fail_perror("munmap"); addr =3D addr + huge_page_size; =20 write_fault_pages(addr, NR_HUGE_PAGES); @@ -108,20 +100,14 @@ int main(int argc, char **argv) /* addr before mapping should fail */ ret =3D madvise(addr - base_page_size, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED); - if (!ret) { - printf("Unexpected success of madvise call with invalid addr line %d\n", - __LINE__); - exit(1); - } + if (!ret) + ksft_exit_fail_msg("madvise with invalid addr unexpectedly succeeded lin= e %d\n", __LINE__); =20 /* addr + length after mapping should fail */ ret =3D madvise(addr, (NR_HUGE_PAGES * huge_page_size) + base_page_size, MADV_DONTNEED); - if (!ret) { - printf("Unexpected success of madvise call with invalid length line %d\n= ", - __LINE__); - exit(1); - } + if (!ret) + ksft_exit_fail_msg("madvise with invalid length unexpectedly succeeded l= ine %d\n", __LINE__); =20 (void)munmap(addr, NR_HUGE_PAGES * huge_page_size); =20 @@ -132,10 +118,9 @@ int main(int argc, char **argv) PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); - if (addr =3D=3D MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr =3D=3D MAP_FAILED) + ksft_exit_fail_perror("mmap"); + write_fault_pages(addr, NR_HUGE_PAGES); validate_free_pages(free_hugepages - NR_HUGE_PAGES); =20 @@ -143,19 +128,14 @@ int main(int argc, char **argv) ret =3D madvise(addr + base_page_size, NR_HUGE_PAGES * huge_page_size - base_page_size, MADV_DONTNEED); - if (!ret) { - printf("Unexpected success of madvise call with unaligned start address = %d\n", - __LINE__); - exit(1); - } + if (!ret) + ksft_exit_fail_msg("madvise with unaligned start unexpectedly succeeded = line %d\n", __LINE__); =20 /* addr + length should be aligned down to huge page size */ if (madvise(addr, ((NR_HUGE_PAGES - 1) * huge_page_size) + base_page_size, - MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + MADV_DONTNEED)) + ksft_exit_fail_perror("madvise"); =20 /* should free all but last page in mapping */ validate_free_pages(free_hugepages - 1); @@ -170,17 +150,14 @@ int main(int argc, char **argv) PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); - if (addr =3D=3D MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr =3D=3D MAP_FAILED) + ksft_exit_fail_perror("mmap"); + write_fault_pages(addr, NR_HUGE_PAGES); validate_free_pages(free_hugepages - NR_HUGE_PAGES); =20 - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) + ksft_exit_fail_perror("madvise"); =20 /* should free all pages in mapping */ validate_free_pages(free_hugepages); @@ -190,29 +167,25 @@ int main(int argc, char **argv) /* * Test MADV_DONTNEED on private mapping of hugetlb file */ - if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) { - perror("fallocate"); - exit(1); - } + if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) + ksft_exit_fail_perror("fallocate"); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); =20 addr =3D mmap(NULL, NR_HUGE_PAGES * huge_page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); - if (addr =3D=3D MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr =3D=3D MAP_FAILED) + ksft_exit_fail_perror("mmap"); =20 /* read should not consume any pages */ read_fault_pages(addr, NR_HUGE_PAGES); validate_free_pages(free_hugepages - NR_HUGE_PAGES); =20 /* madvise should not free any pages */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) + ksft_exit_fail_perror("madvise"); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); =20 /* writes should allocate private pages */ @@ -220,10 +193,9 @@ int main(int argc, char **argv) validate_free_pages(free_hugepages - (2 * NR_HUGE_PAGES)); =20 /* madvise should free private pages */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) + ksft_exit_fail_perror("madvise"); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); =20 /* writes should allocate private pages */ @@ -238,10 +210,9 @@ int main(int argc, char **argv) * implementation. */ if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - 0, NR_HUGE_PAGES * huge_page_size)) { - perror("fallocate"); - exit(1); - } + 0, NR_HUGE_PAGES * huge_page_size)) + ksft_exit_fail_perror("fallocate"); + validate_free_pages(free_hugepages); =20 (void)munmap(addr, NR_HUGE_PAGES * huge_page_size); @@ -249,29 +220,25 @@ int main(int argc, char **argv) /* * Test MADV_DONTNEED on shared mapping of hugetlb file */ - if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) { - perror("fallocate"); - exit(1); - } + if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) + ksft_exit_fail_perror("fallocate"); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); =20 addr =3D mmap(NULL, NR_HUGE_PAGES * huge_page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (addr =3D=3D MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr =3D=3D MAP_FAILED) + ksft_exit_fail_perror("mmap"); =20 /* write should not consume any pages */ write_fault_pages(addr, NR_HUGE_PAGES); validate_free_pages(free_hugepages - NR_HUGE_PAGES); =20 /* madvise should not free any pages */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) + ksft_exit_fail_perror("madvise"); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); =20 /* @@ -279,29 +246,25 @@ int main(int argc, char **argv) * * madvise is same as hole punch and should free all pages. */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_REMOVE)) { - perror("madvise"); - exit(1); - } + if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_REMOVE)) + ksft_exit_fail_perror("madvise"); + validate_free_pages(free_hugepages); (void)munmap(addr, NR_HUGE_PAGES * huge_page_size); =20 /* * Test MADV_REMOVE on shared and private mapping of hugetlb file */ - if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) { - perror("fallocate"); - exit(1); - } + if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) + ksft_exit_fail_perror("fallocate"); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); =20 addr =3D mmap(NULL, NR_HUGE_PAGES * huge_page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (addr =3D=3D MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr =3D=3D MAP_FAILED) + ksft_exit_fail_perror("mmap"); =20 /* shared write should not consume any additional pages */ write_fault_pages(addr, NR_HUGE_PAGES); @@ -310,10 +273,8 @@ int main(int argc, char **argv) addr2 =3D mmap(NULL, NR_HUGE_PAGES * huge_page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); - if (addr2 =3D=3D MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr2 =3D=3D MAP_FAILED) + ksft_exit_fail_perror("mmap"); =20 /* private read should not consume any pages */ read_fault_pages(addr2, NR_HUGE_PAGES); @@ -324,17 +285,15 @@ int main(int argc, char **argv) validate_free_pages(free_hugepages - (2 * NR_HUGE_PAGES)); =20 /* madvise of shared mapping should not free any pages */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) + ksft_exit_fail_perror("madvise"); + validate_free_pages(free_hugepages - (2 * NR_HUGE_PAGES)); =20 /* madvise of private mapping should free private pages */ - if (madvise(addr2, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + if (madvise(addr2, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) + ksft_exit_fail_perror("madvise"); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); =20 /* private write should consume additional pages again */ @@ -346,15 +305,16 @@ int main(int argc, char **argv) * not correct. private pages should not be freed, but this is * expected. See comment associated with FALLOC_FL_PUNCH_HOLE call. */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_REMOVE)) { - perror("madvise"); - exit(1); - } + if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_REMOVE)) + ksft_exit_fail_perror("madvise"); + validate_free_pages(free_hugepages); =20 (void)munmap(addr, NR_HUGE_PAGES * huge_page_size); (void)munmap(addr2, NR_HUGE_PAGES * huge_page_size); =20 close(fd); - return 0; + + ksft_test_result_pass("MADV_DONTNEED and MADV_REMOVE on hugetlb\n"); + ksft_finished(); } --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 DEEA83264DD; Tue, 28 Apr 2026 20:44:03 +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=1777409043; cv=none; b=BeSYKv63X3RE+5ROAHZhzU1RMzNvMDmD+RQRIx3sy1Vi+Ign7r3MngB0+Z6F7OerLjv9Bg79x1IVAZIQy7/g+9DLRbbRE8ZV4cOaFIZuVIb+ST++byfW1/qjWkZk/KjczFdtm/royfp65GPe3FAePV9LmbhAJiFCJgTPTOfb6wM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409043; c=relaxed/simple; bh=KqI8ngJ0bHSCR5ybdrrYCtTpsduBNLFEpTEruulHsAw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Oj0MAzoBL8DMtuJdlaBY4Gw/xXMzVdP9Y9GTEqNZs1NaIXiVv1Tk/IrxRsNY1eSaW6v1noF+dZ2H53uKtuOef6kh67o/OXrv9U++hHqGnj5KEYoTYohbil8/FtvSLHHVzFvnXMLTIp8hnsycIHUw+MJrUXzeZq2wC7Vn0tozTtw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b6vyVtym; 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="b6vyVtym" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A0D1C2BCAF; Tue, 28 Apr 2026 20:43:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409043; bh=KqI8ngJ0bHSCR5ybdrrYCtTpsduBNLFEpTEruulHsAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b6vyVtymTCj2d+q+Y2oUMB5e0dcR3J7rMQC3vYUuCcn2acCgMHRIvL++NeY/DO6tX hqiegfojn5LEJcbJHvv+23wV1dpKRN7gD+UsQmxdy+hld4QS9UQaVZS/FXfG+e06a/ EsjLLe/vmaVM0LToBpQulWul0TZnK7Oh62hg7rbLCmqNaNnFoC0bwTUn/g0jldDPnk TEzlvRBf5Hi8g92hYG7hgVpEcloUGmdj/BwToL/c0+R5JxJjmOP6vlnhcCFeeZfFWC RaZlliozrcbOIEr+AnDahfOmMayXa4IATgC54fdL8tfZUUd5ZC1KJwjRwIcjoWs+V8 HapvnruYCpaAA== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 11/54] selftests/mm: hugetlb_madv_vs_map: use kselftest framework Date: Tue, 28 Apr 2026 23:41:57 +0300 Message-ID: <20260428204240.1924129-12-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Convert hugetlb_madv_vs_map test to use kselftest framework for reporting and tracking successful and failing runs. Reviewed-by: Mark Brown Reviewed-by: Donet Tom Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- .../testing/selftests/mm/hugetlb_madv_vs_map.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c b/tools/testi= ng/selftests/mm/hugetlb_madv_vs_map.c index efd774b41389..c7105c6d319b 100644 --- a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c +++ b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c @@ -25,7 +25,6 @@ #include =20 #include "vm_util.h" -#include "kselftest.h" =20 #define INLOOP_ITER 100 =20 @@ -86,12 +85,14 @@ int main(void) */ int max =3D 10; =20 + ksft_print_header(); + ksft_set_plan(1); + free_hugepages =3D get_free_hugepages(); =20 - if (free_hugepages !=3D 1) { + if (free_hugepages !=3D 1) ksft_exit_skip("This test needs one and only one page to execute. Got %l= u\n", free_hugepages); - } =20 mmap_size =3D default_huge_page_size(); =20 @@ -100,10 +101,8 @@ int main(void) MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); =20 - if ((unsigned long)huge_ptr =3D=3D -1) { - ksft_test_result_fail("Failed to allocate huge page\n"); - return KSFT_FAIL; - } + if ((unsigned long)huge_ptr =3D=3D -1) + ksft_exit_fail_msg("Failed to allocate huge page\n"); =20 pthread_create(&thread1, NULL, madv, NULL); pthread_create(&thread2, NULL, touch, NULL); @@ -115,12 +114,13 @@ int main(void) =20 if (ret) { ksft_test_result_fail("Unexpected huge page allocation\n"); - return KSFT_FAIL; + ksft_finished(); } =20 /* Unmap and restart */ munmap(huge_ptr, mmap_size); } =20 - return KSFT_PASS; + ksft_test_result_pass("No unexpected huge page allocations\n"); + ksft_finished(); } --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 82B403101BD; Tue, 28 Apr 2026 20:44:10 +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=1777409050; cv=none; b=axhbitbPqrQOHx4+5hoWvhLMDGiqTez7HUolnSr0oWfEpwe011f6L35wqVNDekN+HwSPG1ACl5vnCYlHUXm9UUTsUkqs80bOMjKdOeveKQQ+DQU3lNR94xfAl2wgrlzvGNvxpI/80xzAFc9ntmMk/Pr30cZH7AMINMON698A+LM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409050; c=relaxed/simple; bh=9K0SWl11YhYNKR49OO1EUtZ+QamHSW0oabj1cOHKjSc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=COcgCHB3b/xUJRhzHuCTgAgE5ece2I57zEqGXD+XRP1K6kYyeojJoBcHH2qG9B02sOgbbc27S1f3LXE/aj6a9khKvbSW1ea8jHlIV1RcAhKRPFPRGh0+xawVZHKRf64Hz4FsPUl3xPLzDNyxo1umUlpohd6tf22vZCIrws8Uyak= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AcKPucQl; 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="AcKPucQl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13318C2BCAF; Tue, 28 Apr 2026 20:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409050; bh=9K0SWl11YhYNKR49OO1EUtZ+QamHSW0oabj1cOHKjSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AcKPucQlH/Te28Y/gHhNIo9I6ASVFw3NuZMApHCiaAGiOFW9Q8VJVUnny7tfVumrk xcNJLDeVsdaT6xE4+Yk4QpyeVQpLoA+5oHbMFvF/2ah+mXFpvksVmDYDwuk6JljffX kdQ5Nc04/lEspbHHBuU68vsKeglgYxmLGU97oSc+y0AypwvYsP2UbSPEiOrGC7FZUx YJimCy6SM61QNaqdkom3wzc0kOwdP0SAo9E8L1ySyagbmh3JuW5VPyn1CjgptoAyW+ rrgJn7ZI+O5RApzD22l/jzpnUqUpT9NgxjFseBeAWRDPH95dGn5Gnul+63sA6Fa8OH Aq77WymJQeQ+Q== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 12/54] selftests/mm: hugetlb-read-hwpoison: use kselftest framework Date: Tue, 28 Apr 2026 23:41:58 +0300 Message-ID: <20260428204240.1924129-13-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Convert hugetlb-read-hwpoison test to use kselftest framework for reporting and tracking successful and failing runs. Reviewed-by: Donet Tom Reviewed-by: Mark Brown Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Li Wang Tested-by: Li Wang Tested-by: Luiz Capitulino --- .../selftests/mm/hugetlb-read-hwpoison.c | 118 +++++++++--------- 1 file changed, 57 insertions(+), 61 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-read-hwpoison.c b/tools/tes= ting/selftests/mm/hugetlb-read-hwpoison.c index 6bbf15f78061..01cd5465e0f8 100644 --- a/tools/testing/selftests/mm/hugetlb-read-hwpoison.c +++ b/tools/testing/selftests/mm/hugetlb-read-hwpoison.c @@ -13,9 +13,7 @@ #include =20 #include "kselftest.h" - -#define PREFIX " ... " -#define ERROR_PREFIX " !!! " +#include "vm_util.h" =20 #define MAX_WRITE_READ_CHUNK_SIZE (getpagesize() * 16) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) @@ -26,17 +24,22 @@ enum test_status { TEST_SKIPPED =3D 2, }; =20 -static char *status_to_str(enum test_status status) +static void report_status(enum test_status status, const char *test_name, + size_t chunk_size) { switch (status) { case TEST_PASSED: - return "TEST_PASSED"; + ksft_test_result_pass("%s chunk_size=3D0x%lx\n", + test_name, chunk_size); + break; case TEST_FAILED: - return "TEST_FAILED"; + ksft_test_result_fail("%s chunk_size=3D0x%lx\n", + test_name, chunk_size); + break; case TEST_SKIPPED: - return "TEST_SKIPPED"; - default: - return "TEST_???"; + ksft_test_result_skip("%s chunk_size=3D0x%lx\n", + test_name, chunk_size); + break; } } =20 @@ -59,8 +62,8 @@ static bool verify_chunk(char *buf, size_t len, char val) =20 for (i =3D 0; i < len; ++i) { if (buf[i] !=3D val) { - printf(PREFIX ERROR_PREFIX "check fail: buf[%lu] =3D %u !=3D %u\n", - i, buf[i], val); + ksft_print_msg("check fail: buf[%lu] =3D %u !=3D %u\n", + i, buf[i], val); return false; } } @@ -76,21 +79,21 @@ static bool seek_read_hugepage_filemap(int fd, size_t l= en, size_t wr_chunk_size, ssize_t total_ret_count =3D 0; char val =3D offset / wr_chunk_size + offset % wr_chunk_size; =20 - printf(PREFIX PREFIX "init val=3D%u with offset=3D0x%lx\n", val, offset); - printf(PREFIX PREFIX "expect to read 0x%lx bytes of data in total\n", - expected); + ksft_print_msg("init val=3D%u with offset=3D0x%lx\n", val, offset); + ksft_print_msg("expect to read 0x%lx bytes of data in total\n", + expected); if (lseek(fd, offset, SEEK_SET) < 0) { - perror(PREFIX ERROR_PREFIX "seek failed"); + ksft_perror("seek failed"); return false; } =20 while (offset + total_ret_count < len) { ret_count =3D read(fd, buf, wr_chunk_size); if (ret_count =3D=3D 0) { - printf(PREFIX PREFIX "read reach end of the file\n"); + ksft_print_msg("read reach end of the file\n"); break; } else if (ret_count < 0) { - perror(PREFIX ERROR_PREFIX "read failed"); + ksft_perror("read failed"); break; } ++val; @@ -99,8 +102,8 @@ static bool seek_read_hugepage_filemap(int fd, size_t le= n, size_t wr_chunk_size, =20 total_ret_count +=3D ret_count; } - printf(PREFIX PREFIX "actually read 0x%lx bytes of data in total\n", - total_ret_count); + ksft_print_msg("actually read 0x%lx bytes of data in total\n", + total_ret_count); =20 return total_ret_count =3D=3D expected; } @@ -113,15 +116,15 @@ static bool read_hugepage_filemap(int fd, size_t len, ssize_t total_ret_count =3D 0; char val =3D 0; =20 - printf(PREFIX PREFIX "expect to read 0x%lx bytes of data in total\n", - expected); + ksft_print_msg("expect to read 0x%lx bytes of data in total\n", + expected); while (total_ret_count < len) { ret_count =3D read(fd, buf, wr_chunk_size); if (ret_count =3D=3D 0) { - printf(PREFIX PREFIX "read reach end of the file\n"); + ksft_print_msg("read reach end of the file\n"); break; } else if (ret_count < 0) { - perror(PREFIX ERROR_PREFIX "read failed"); + ksft_perror("read failed"); break; } ++val; @@ -130,8 +133,8 @@ static bool read_hugepage_filemap(int fd, size_t len, =20 total_ret_count +=3D ret_count; } - printf(PREFIX PREFIX "actually read 0x%lx bytes of data in total\n", - total_ret_count); + ksft_print_msg("actually read 0x%lx bytes of data in total\n", + total_ret_count); =20 return total_ret_count =3D=3D expected; } @@ -143,14 +146,14 @@ test_hugetlb_read(int fd, size_t len, size_t wr_chunk= _size) char *filemap =3D NULL; =20 if (ftruncate(fd, len) < 0) { - perror(PREFIX ERROR_PREFIX "ftruncate failed"); + ksft_perror("ftruncate failed"); return status; } =20 filemap =3D mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, 0); if (filemap =3D=3D MAP_FAILED) { - perror(PREFIX ERROR_PREFIX "mmap for primary mapping failed"); + ksft_perror("mmap for primary mapping failed"); goto done; } =20 @@ -163,7 +166,7 @@ test_hugetlb_read(int fd, size_t len, size_t wr_chunk_s= ize) munmap(filemap, len); done: if (ftruncate(fd, 0) < 0) { - perror(PREFIX ERROR_PREFIX "ftruncate back to 0 failed"); + ksft_perror("ftruncate back to 0 failed"); status =3D TEST_FAILED; } =20 @@ -180,14 +183,14 @@ test_hugetlb_read_hwpoison(int fd, size_t len, size_t= wr_chunk_size, const unsigned long pagesize =3D getpagesize(); =20 if (ftruncate(fd, len) < 0) { - perror(PREFIX ERROR_PREFIX "ftruncate failed"); + ksft_perror("ftruncate failed"); return status; } =20 filemap =3D mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd, 0); if (filemap =3D=3D MAP_FAILED) { - perror(PREFIX ERROR_PREFIX "mmap for primary mapping failed"); + ksft_perror("mmap for primary mapping failed"); goto done; } =20 @@ -202,7 +205,7 @@ test_hugetlb_read_hwpoison(int fd, size_t len, size_t w= r_chunk_size, */ hwp_addr =3D filemap + len / 2 + pagesize; if (madvise(hwp_addr, pagesize, MADV_HWPOISON) < 0) { - perror(PREFIX ERROR_PREFIX "MADV_HWPOISON failed"); + ksft_perror("MADV_HWPOISON failed"); goto unmap; } =20 @@ -229,7 +232,7 @@ test_hugetlb_read_hwpoison(int fd, size_t len, size_t w= r_chunk_size, munmap(filemap, len); done: if (ftruncate(fd, 0) < 0) { - perror(PREFIX ERROR_PREFIX "ftruncate back to 0 failed"); + ksft_perror("ftruncate back to 0 failed"); status =3D TEST_FAILED; } =20 @@ -242,17 +245,17 @@ static int create_hugetlbfs_file(struct statfs *file_= stat) =20 fd =3D memfd_create("hugetlb_tmp", MFD_HUGETLB); if (fd < 0) { - perror(PREFIX ERROR_PREFIX "could not open hugetlbfs file"); + ksft_perror("could not open hugetlbfs file"); return -1; } =20 memset(file_stat, 0, sizeof(*file_stat)); if (fstatfs(fd, file_stat)) { - perror(PREFIX ERROR_PREFIX "fstatfs failed"); + ksft_perror("fstatfs failed"); goto close; } if (file_stat->f_type !=3D HUGETLBFS_MAGIC) { - printf(PREFIX ERROR_PREFIX "not hugetlbfs file\n"); + ksft_print_msg("not hugetlbfs file\n"); goto close; } =20 @@ -264,7 +267,7 @@ static int create_hugetlbfs_file(struct statfs *file_st= at) =20 static void sigbus_handler(int sig) { - printf(PREFIX "received SIGBUS\n"); + ksft_print_msg("received SIGBUS\n"); } =20 int main(void) @@ -279,51 +282,44 @@ int main(void) }; size_t i; =20 + ksft_print_header(); + ksft_set_plan(ARRAY_SIZE(wr_chunk_sizes) * 3); + signal(SIGBUS, sigbus_handler); for (i =3D 0; i < ARRAY_SIZE(wr_chunk_sizes); ++i) { - printf("Write/read chunk size=3D0x%lx\n", - wr_chunk_sizes[i]); + ksft_print_msg("Write/read chunk size=3D0x%lx\n", + wr_chunk_sizes[i]); =20 fd =3D create_hugetlbfs_file(&file_stat); if (fd < 0) - goto create_failure; - printf(PREFIX "HugeTLB read regression test...\n"); + ksft_exit_fail_msg("Failed to create hugetlbfs file\n"); + status =3D test_hugetlb_read(fd, file_stat.f_bsize, wr_chunk_sizes[i]); - printf(PREFIX "HugeTLB read regression test...%s\n", - status_to_str(status)); close(fd); - if (status =3D=3D TEST_FAILED) - return -1; + report_status(status, "HugeTLB read regression", + wr_chunk_sizes[i]); =20 fd =3D create_hugetlbfs_file(&file_stat); if (fd < 0) - goto create_failure; - printf(PREFIX "HugeTLB read HWPOISON test...\n"); + ksft_exit_fail_msg("Failed to create hugetlbfs file\n"); + status =3D test_hugetlb_read_hwpoison(fd, file_stat.f_bsize, wr_chunk_sizes[i], false); - printf(PREFIX "HugeTLB read HWPOISON test...%s\n", - status_to_str(status)); close(fd); - if (status =3D=3D TEST_FAILED) - return -1; + report_status(status, "HugeTLB read HWPOISON", + wr_chunk_sizes[i]); =20 fd =3D create_hugetlbfs_file(&file_stat); if (fd < 0) - goto create_failure; - printf(PREFIX "HugeTLB seek then read HWPOISON test...\n"); + ksft_exit_fail_msg("Failed to create hugetlbfs file\n"); + status =3D test_hugetlb_read_hwpoison(fd, file_stat.f_bsize, wr_chunk_sizes[i], true); - printf(PREFIX "HugeTLB seek then read HWPOISON test...%s\n", - status_to_str(status)); close(fd); - if (status =3D=3D TEST_FAILED) - return -1; + report_status(status, "HugeTLB seek then read HWPOISON", + wr_chunk_sizes[i]); } =20 - return 0; - -create_failure: - printf(ERROR_PREFIX "Abort test: failed to create hugetlbfs file\n"); - return -1; + ksft_finished(); } --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 08D46313273; Tue, 28 Apr 2026 20:44:16 +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=1777409057; cv=none; b=BncF+dMWhCMD7x0tXqjF1rv2u2fKiwoDXfv6vUEztBcbWjzv/5NtRTM6oZnI2Reqd/VcTUCc87QgJXwyPboSK7aefpc5k5OZQtZdIiHNKRE9UE+tJExAqg3pzRko+BOrF3ELdFGxlupKbx+cleg6DWEcZTVMik39Iu934F4WOe0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409057; c=relaxed/simple; bh=UcY2aZ851ybWDtG1WmSWUypuuOgK5C/YOGkz1yNU7vM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p41frcxiGP3uUzEA/A8SIfPaN5OhoNUPaCh7RjxkFxrh7oi1j8Gqb+ydffx7noA7Kpjcmc2kSclP0cGvgD/zsmLDy674bWoThQf1VOKNDE4gtGk4R4CT2HSf71iHxgbJFqqWSa2+L0SBgwh3307bAX3HPsSBWcDx2+vLt08vWqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=No0P7iwP; 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="No0P7iwP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FB29C2BCB3; Tue, 28 Apr 2026 20:44:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409056; bh=UcY2aZ851ybWDtG1WmSWUypuuOgK5C/YOGkz1yNU7vM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=No0P7iwPSUp5/3eOjmCWqYtNs5gQ3UKdHYDH1NsE0W2vodcggH/FYgkl8Cj+xo1KN rcE2m4twOPyfw7B+bYZjRlBRjVz4lZeiAfuo65HtRVkT4V31FUVXFThAJHbvM6lLPf GVbnXgtd6ofoYXGZOTZloOo5dbgM8cwGTrvh+ilbVYC3Qr8I4rk9Q3VeRXqOTFT+rz EC4L3ezv89EhnbGzDGSCuyUuAhY6AUp/RdNzvzGzuis03+xNcj9MQwx4wiAy3dRo0r kXG17Ru1V7wHj7A5LjveynkB7f7MTRkn0uAkrDVo9IKfTjnKpxoipOy+/lmNVRtjoZ HK/4jQ+e8hSFg== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 13/54] selftests/mm: khugepaged: group tests in an array Date: Tue, 28 Apr 2026 23:41:59 +0300 Message-ID: <20260428204240.1924129-14-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Currently khugepaged decides if a test can run using TEST() macro that checks what mem_ops and collapse_context are set by the command line arguments. For better compatibility with ksefltest framework, add an array of 'struct test_case's and redefine TEST() macro to conditionally add enabled tests to that array. Then execute the enabled test by looping the test_case's array. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/khugepaged.c | 43 +++++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selfte= sts/mm/khugepaged.c index 3fe7ef04ac62..10f0d3cb1b81 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -1165,6 +1165,34 @@ static void parse_test_type(int argc, char **argv) get_finfo(argv[1]); } =20 +typedef void (*test_fn)(struct collapse_context *c, struct mem_ops *ops); + +struct test_case { + struct collapse_context *ctx; + struct mem_ops *ops; + const char *desc; + test_fn fn; +}; + +#define MAX_TEST_CASES 64 +static struct test_case test_cases[MAX_TEST_CASES]; +static int nr_test_cases; + +#define TEST(t, c, o) do { \ + if (c && o) { \ + if (nr_test_cases >=3D MAX_TEST_CASES) { \ + printf("MAX_ADD_CASES is too small\n"); \ + exit(EXIT_FAILURE); \ + } \ + test_cases[nr_test_cases++] =3D (struct test_case){ \ + .ctx =3D c, \ + .ops =3D o, \ + .desc =3D #t, \ + .fn =3D t, \ + }; \ + } \ + } while (0) + int main(int argc, char **argv) { int hpage_pmd_order; @@ -1220,13 +1248,6 @@ int main(int argc, char **argv) =20 alloc_at_fault(); =20 -#define TEST(t, c, o) do { \ - if (c && o) { \ - printf("\nRun test: " #t " (%s:%s)\n", c->name, o->name); \ - t(c, o); \ - } \ - } while (0) - TEST(collapse_full, khugepaged_context, anon_ops); TEST(collapse_full, khugepaged_context, file_ops); TEST(collapse_full, khugepaged_context, shmem_ops); @@ -1286,5 +1307,13 @@ int main(int argc, char **argv) TEST(madvise_retracted_page_tables, madvise_context, file_ops); TEST(madvise_retracted_page_tables, madvise_context, shmem_ops); =20 + for (int i =3D 0; i < nr_test_cases; i++) { + struct test_case *t =3D &test_cases[i]; + + exit_status =3D KSFT_PASS; + printf("\nRun test: %s: (%s:%s)\n", t->desc, t->ctx->name, t->ops->name); + t->fn(t->ctx, t->ops); + } + restore_settings(0); } --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 961E23368BF; Tue, 28 Apr 2026 20:44:23 +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=1777409063; cv=none; b=DdJQT+UdLStWa/1ikQNY3xqqmSEEaP1gRYHf3pE7fFY9hZFMw5ICarZRlTOIKjol46yG1qGhU4k38mKllCCyrrpGbSFzCc+EKOxGxmjH8OQV+fQVeEQuPL38p5suVp/1OaYqr5iKRbyLiEfIEbrwF3rnywcMv9LApjwkHc/DuIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409063; c=relaxed/simple; bh=YwxD1PSBwkmm9KQRd9U8Wq8Q1JVvn6Vsao3P6qQmn0A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RUb9zNR4+XWb8zpGPwLTDNZx6Bl7VyDz5Z2JhAFkuhhrhcaGQbrI+tN3dS0GNEm6oo/suHgQ3pe00oz2YCGjNJ82W5d90AsMuFSmzBGOSZHWtghb/JJPggHdRVTZDsICuF6bcATF30Q7fSeMcjoPKaP+fWSzebA0LSHRik/LLlM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rc6ppOVQ; 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="rc6ppOVQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37EC0C2BCAF; Tue, 28 Apr 2026 20:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409063; bh=YwxD1PSBwkmm9KQRd9U8Wq8Q1JVvn6Vsao3P6qQmn0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rc6ppOVQ62EJvPC4yb2kxA2I+IEVY9BfdexHEl/hqynXaXpdOgbwqvuIgJY/cUpUs czKKbbVMo/FxAt/rM0lMb1OtuooUmRfDMABMNIKFH3okF4bGDLAwTmDlEV3OHiHkZA Fo3+smwVk4bmWrppUE+ZAzaVr1WupFW7bojZZistjyDqZT14GgFmg3i2mapUvqpaxU J/ZlQDziEP3eCP305RXLzHZ2GG45Gf1fbQGFDZO/IGnLPO8vHvdaITq8fjxUqdPPhr LVzravKE6n0/t/7lCIgRKFNXisr+mzsIKmcJiBv9HS7FiVdDspZBrSE19wMQ8JqEEy KvrSzD3PRDigw== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 14/54] selftests/mm: khugepaged: use ksefltest framework Date: Tue, 28 Apr 2026 23:42:00 +0300 Message-ID: <20260428204240.1924129-15-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Convert khugepaged tests to use kselftest framework for reporting and tracking successful and failing runs. The conversion is mostly about replacing printf()/perror() + exit() pairs with their ksft_ counterparts. The nice colored success and failure indications are left intact. Replace the progress report in collapse_compound_extreme() with a single ksft_print_msg() to avoid headache with formatting and make the test output more concise. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/khugepaged.c | 311 ++++++++++-------------- 1 file changed, 128 insertions(+), 183 deletions(-) diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selfte= sts/mm/khugepaged.c index 10f0d3cb1b81..2f0baa2321ca 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -83,12 +83,13 @@ static void success(const char *msg) static void fail(const char *msg) { printf(" \e[31m%s\e[0m\n", msg); - exit_status++; + exit_status =3D KSFT_FAIL; } =20 static void skip(const char *msg) { printf(" \e[33m%s\e[0m\n", msg); + exit_status =3D KSFT_SKIP; } =20 static void restore_settings_atexit(void) @@ -96,22 +97,23 @@ static void restore_settings_atexit(void) if (skip_settings_restore) return; =20 - printf("Restore THP and khugepaged settings..."); + ksft_print_msg("Restore THP and khugepaged settings..."); thp_restore_settings(); success("OK"); =20 skip_settings_restore =3D true; + ksft_finished(); } =20 static void restore_settings(int sig) { /* exit() will invoke the restore_settings_atexit handler. */ - exit(sig ? EXIT_FAILURE : exit_status); + exit(sig ? KSFT_FAIL : exit_status); } =20 static void save_settings(void) { - printf("Save THP and khugepaged settings..."); + ksft_print_msg("Save THP and khugepaged settings..."); if (file_ops && finfo.type =3D=3D VMA_FILE) thp_set_read_ahead_path(finfo.dev_queue_read_ahead_path); thp_save_settings(); @@ -135,19 +137,13 @@ static void get_finfo(const char *dir) =20 finfo.dir =3D dir; stat(finfo.dir, &path_stat); - if (!S_ISDIR(path_stat.st_mode)) { - printf("%s: Not a directory (%s)\n", __func__, finfo.dir); - exit(EXIT_FAILURE); - } + if (!S_ISDIR(path_stat.st_mode)) + ksft_exit_fail_msg("%s: Not a directory (%s)\n", __func__, finfo.dir); if (snprintf(finfo.path, sizeof(finfo.path), "%s/" TEST_FILE, - finfo.dir) >=3D sizeof(finfo.path)) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } - if (statfs(finfo.dir, &fs)) { - perror("statfs()"); - exit(EXIT_FAILURE); - } + finfo.dir) >=3D sizeof(finfo.path)) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); + if (statfs(finfo.dir, &fs)) + ksft_exit_fail_perror("statfs()"); finfo.type =3D fs.f_type =3D=3D TMPFS_MAGIC ? VMA_SHMEM : VMA_FILE; if (finfo.type =3D=3D VMA_SHMEM) return; @@ -155,40 +151,30 @@ static void get_finfo(const char *dir) /* Find owning device's queue/read_ahead_kb control */ if (snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/uevent", major(path_stat.st_dev), minor(path_stat.st_dev)) - >=3D sizeof(path)) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } - if (read_file(path, buf, sizeof(buf)) < 0) { - perror("read_file(read_num)"); - exit(EXIT_FAILURE); - } + >=3D sizeof(path)) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); + if (read_file(path, buf, sizeof(buf)) < 0) + ksft_exit_fail_perror("read_file(read_num)"); if (strstr(buf, "DEVTYPE=3Ddisk")) { /* Found it */ if (snprintf(finfo.dev_queue_read_ahead_path, sizeof(finfo.dev_queue_read_ahead_path), "/sys/dev/block/%d:%d/queue/read_ahead_kb", major(path_stat.st_dev), minor(path_stat.st_dev)) - >=3D sizeof(finfo.dev_queue_read_ahead_path)) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + >=3D sizeof(finfo.dev_queue_read_ahead_path)) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); return; } - if (!strstr(buf, "DEVTYPE=3Dpartition")) { - printf("%s: Unknown device type: %s\n", __func__, path); - exit(EXIT_FAILURE); - } + if (!strstr(buf, "DEVTYPE=3Dpartition")) + ksft_exit_fail_msg("%s: Unknown device type: %s\n", __func__, path); /* * Partition of block device - need to find actual device. * Using naming convention that devnameN is partition of * device devname. */ str =3D strstr(buf, "DEVNAME=3D"); - if (!str) { - printf("%s: Could not read: %s", __func__, path); - exit(EXIT_FAILURE); - } + if (!str) + ksft_exit_fail_msg("%s: Could not read: %s", __func__, path); str +=3D 8; end =3D str; while (*end) { @@ -197,16 +183,13 @@ static void get_finfo(const char *dir) if (snprintf(finfo.dev_queue_read_ahead_path, sizeof(finfo.dev_queue_read_ahead_path), "/sys/block/%s/queue/read_ahead_kb", - str) >=3D sizeof(finfo.dev_queue_read_ahead_path)) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + str) >=3D sizeof(finfo.dev_queue_read_ahead_path)) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); return; } ++end; } - printf("%s: Could not read: %s\n", __func__, path); - exit(EXIT_FAILURE); + ksft_exit_fail_msg("%s: Could not read: %s\n", __func__, path); } =20 static bool check_swap(void *addr, unsigned long size) @@ -219,26 +202,19 @@ static bool check_swap(void *addr, unsigned long size) =20 ret =3D snprintf(addr_pattern, MAX_LINE_LENGTH, "%08lx-", (unsigned long) addr); - if (ret >=3D MAX_LINE_LENGTH) { - printf("%s: Pattern is too long\n", __func__); - exit(EXIT_FAILURE); - } - + if (ret >=3D MAX_LINE_LENGTH) + ksft_exit_fail_msg("%s: Pattern is too long\n", __func__); =20 fp =3D fopen(PID_SMAPS, "r"); - if (!fp) { - printf("%s: Failed to open file %s\n", __func__, PID_SMAPS); - exit(EXIT_FAILURE); - } + if (!fp) + ksft_exit_fail_msg("%s: Failed to open file %s\n", __func__, PID_SMAPS); if (!check_for_pattern(fp, addr_pattern, buffer, sizeof(buffer))) goto err_out; =20 ret =3D snprintf(addr_pattern, MAX_LINE_LENGTH, "Swap:%19ld kB", size >> 10); - if (ret >=3D MAX_LINE_LENGTH) { - printf("%s: Pattern is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >=3D MAX_LINE_LENGTH) + ksft_exit_fail_msg("%s: Pattern is too long\n", __func__); /* * Fetch the Swap: in the same block and check whether it got * the expected number of hugeepages next. @@ -261,10 +237,8 @@ static void *alloc_mapping(int nr) =20 p =3D mmap(BASE_ADDR, nr * hpage_pmd_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - if (p !=3D BASE_ADDR) { - printf("Failed to allocate VMA at %p\n", BASE_ADDR); - exit(EXIT_FAILURE); - } + if (p !=3D BASE_ADDR) + ksft_exit_fail_msg("Failed to allocate VMA at %p\n", BASE_ADDR); =20 return p; } @@ -314,19 +288,13 @@ static void *alloc_hpage(struct mem_ops *ops) * khugepaged on low-load system (like a test machine), which * would cause MADV_COLLAPSE to fail with EAGAIN. */ - printf("Allocate huge page..."); - if (madvise_collapse_retry(p, hpage_pmd_size)) { - perror("madvise(MADV_COLLAPSE)"); - exit(EXIT_FAILURE); - } - if (!ops->check_huge(p, 1)) { - perror("madvise(MADV_COLLAPSE)"); - exit(EXIT_FAILURE); - } - if (madvise(p, hpage_pmd_size, MADV_HUGEPAGE)) { - perror("madvise(MADV_HUGEPAGE)"); - exit(EXIT_FAILURE); - } + ksft_print_msg("Allocate huge page..."); + if (madvise_collapse_retry(p, hpage_pmd_size)) + ksft_exit_fail_perror("madvise(MADV_COLLAPSE)"); + if (!ops->check_huge(p, 1)) + ksft_exit_fail_perror("madvise(MADV_COLLAPSE)"); + if (madvise(p, hpage_pmd_size, MADV_HUGEPAGE)) + ksft_exit_fail_perror("madvise(MADV_HUGEPAGE)"); success("OK"); return p; } @@ -336,11 +304,9 @@ static void validate_memory(int *p, unsigned long star= t, unsigned long end) int i; =20 for (i =3D start / page_size; i < end / page_size; i++) { - if (p[i * page_size / sizeof(*p)] !=3D i + 0xdead0000) { - printf("Page %d is corrupted: %#x\n", - i, p[i * page_size / sizeof(*p)]); - exit(EXIT_FAILURE); - } + if (p[i * page_size / sizeof(*p)] !=3D i + 0xdead0000) + ksft_exit_fail_msg("Page %d is corrupted: %#x\n", + i, p[i * page_size / sizeof(*p)]); } } =20 @@ -371,14 +337,12 @@ static void *file_setup_area(int nr_hpages) unsigned long size; =20 unlink(finfo.path); /* Cleanup from previous failed tests */ - printf("Creating %s for collapse%s...", finfo.path, - finfo.type =3D=3D VMA_SHMEM ? " (tmpfs)" : ""); + ksft_print_msg("Creating %s for collapse%s...", finfo.path, + finfo.type =3D=3D VMA_SHMEM ? " (tmpfs)" : ""); fd =3D open(finfo.path, O_DSYNC | O_CREAT | O_RDWR | O_TRUNC | O_EXCL, 777); - if (fd < 0) { - perror("open()"); - exit(EXIT_FAILURE); - } + if (fd < 0) + ksft_exit_fail_perror("open()"); =20 size =3D nr_hpages * hpage_pmd_size; p =3D alloc_mapping(nr_hpages); @@ -388,18 +352,14 @@ static void *file_setup_area(int nr_hpages) munmap(p, size); success("OK"); =20 - printf("Opening %s read only for collapse...", finfo.path); + ksft_print_msg("Opening %s read only for collapse...", finfo.path); finfo.fd =3D open(finfo.path, O_RDONLY, 777); - if (finfo.fd < 0) { - perror("open()"); - exit(EXIT_FAILURE); - } + if (finfo.fd < 0) + ksft_exit_fail_perror("open()"); p =3D mmap(BASE_ADDR, size, PROT_READ, MAP_PRIVATE, finfo.fd, 0); - if (p =3D=3D MAP_FAILED || p !=3D BASE_ADDR) { - perror("mmap()"); - exit(EXIT_FAILURE); - } + if (p =3D=3D MAP_FAILED || p !=3D BASE_ADDR) + ksft_exit_fail_perror("mmap()"); =20 /* Drop page cache */ write_file("/proc/sys/vm/drop_caches", "3", 2); @@ -416,10 +376,8 @@ static void file_cleanup_area(void *p, unsigned long s= ize) =20 static void file_fault(void *p, unsigned long start, unsigned long end) { - if (madvise(((char *)p) + start, end - start, MADV_POPULATE_READ)) { - perror("madvise(MADV_POPULATE_READ"); - exit(EXIT_FAILURE); - } + if (madvise(((char *)p) + start, end - start, MADV_POPULATE_READ)) + ksft_exit_fail_perror("madvise(MADV_POPULATE_READ"); } =20 static bool file_check_huge(void *addr, int nr_hpages) @@ -441,20 +399,14 @@ static void *shmem_setup_area(int nr_hpages) unsigned long size =3D nr_hpages * hpage_pmd_size; =20 finfo.fd =3D memfd_create("khugepaged-selftest-collapse-shmem", 0); - if (finfo.fd < 0) { - perror("memfd_create()"); - exit(EXIT_FAILURE); - } - if (ftruncate(finfo.fd, size)) { - perror("ftruncate()"); - exit(EXIT_FAILURE); - } + if (finfo.fd < 0) + ksft_exit_fail_perror("memfd_create()"); + if (ftruncate(finfo.fd, size)) + ksft_exit_fail_perror("ftruncate()"); p =3D mmap(BASE_ADDR, size, PROT_READ | PROT_WRITE, MAP_SHARED, finfo.fd, 0); - if (p !=3D BASE_ADDR) { - perror("mmap()"); - exit(EXIT_FAILURE); - } + if (p !=3D BASE_ADDR) + ksft_exit_fail_perror("mmap()"); return p; } =20 @@ -499,7 +451,7 @@ static void __madvise_collapse(const char *msg, char *p= , int nr_hpages, int ret; struct thp_settings settings =3D *thp_current_settings(); =20 - printf("%s...", msg); + ksft_print_msg("%s...", msg); =20 /* * Prevent khugepaged interference and tests that MADV_COLLAPSE @@ -526,10 +478,8 @@ static void madvise_collapse(const char *msg, char *p,= int nr_hpages, struct mem_ops *ops, bool expect) { /* Sanity check */ - if (!ops->check_huge(p, 0)) { - printf("Unexpected huge page\n"); - exit(EXIT_FAILURE); - } + if (!ops->check_huge(p, 0)) + ksft_exit_fail_msg("Unexpected huge page\n"); __madvise_collapse(msg, p, nr_hpages, ops, expect); } =20 @@ -541,17 +491,15 @@ static bool wait_for_scan(const char *msg, char *p, i= nt nr_hpages, int timeout =3D 6; /* 3 seconds */ =20 /* Sanity check */ - if (!ops->check_huge(p, 0)) { - printf("Unexpected huge page\n"); - exit(EXIT_FAILURE); - } + if (!ops->check_huge(p, 0)) + ksft_exit_fail_msg("Unexpected huge page\n"); =20 madvise(p, nr_hpages * hpage_pmd_size, MADV_HUGEPAGE); =20 /* Wait until the second full_scan completed */ full_scans =3D thp_read_num("khugepaged/full_scans") + 2; =20 - printf("%s...", msg); + ksft_print_msg("%s...", msg); while (timeout--) { if (ops->check_huge(p, nr_hpages)) break; @@ -621,7 +569,7 @@ static void alloc_at_fault(void) =20 p =3D alloc_mapping(1); *p =3D 1; - printf("Allocate huge page on fault..."); + ksft_print_msg("Allocate huge page on fault..."); if (check_huge_anon(p, 1, hpage_pmd_size)) success("OK"); else @@ -630,12 +578,14 @@ static void alloc_at_fault(void) thp_pop_settings(); =20 madvise(p, page_size, MADV_DONTNEED); - printf("Split huge PMD on MADV_DONTNEED..."); + ksft_print_msg("Split huge PMD on MADV_DONTNEED..."); if (check_huge_anon(p, 0, hpage_pmd_size)) success("OK"); else fail("Fail"); munmap(p, hpage_pmd_size); + + ksft_test_result_report(exit_status, "allocate on fault and split\n"); } =20 static void collapse_full(struct collapse_context *c, struct mem_ops *ops) @@ -650,6 +600,8 @@ static void collapse_full(struct collapse_context *c, s= truct mem_ops *ops) ops, true); validate_memory(p, 0, size); ops->cleanup_area(p, size); + + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void collapse_empty(struct collapse_context *c, struct mem_ops *ops) @@ -659,6 +611,7 @@ static void collapse_empty(struct collapse_context *c, = struct mem_ops *ops) p =3D ops->setup_area(1); c->collapse("Do not collapse empty PTE table", p, 1, ops, false); ops->cleanup_area(p, hpage_pmd_size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void collapse_single_pte_entry(struct collapse_context *c, struct m= em_ops *ops) @@ -670,6 +623,7 @@ static void collapse_single_pte_entry(struct collapse_c= ontext *c, struct mem_ops c->collapse("Collapse PTE table with single PTE entry present", p, 1, ops, true); ops->cleanup_area(p, hpage_pmd_size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void collapse_max_ptes_none(struct collapse_context *c, struct mem_= ops *ops) @@ -706,6 +660,7 @@ static void collapse_max_ptes_none(struct collapse_cont= ext *c, struct mem_ops *o skip: ops->cleanup_area(p, hpage_pmd_size); thp_pop_settings(); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void collapse_swapin_single_pte(struct collapse_context *c, struct = mem_ops *ops) @@ -715,11 +670,9 @@ static void collapse_swapin_single_pte(struct collapse= _context *c, struct mem_op p =3D ops->setup_area(1); ops->fault(p, 0, hpage_pmd_size); =20 - printf("Swapout one page..."); - if (madvise(p, page_size, MADV_PAGEOUT)) { - perror("madvise(MADV_PAGEOUT)"); - exit(EXIT_FAILURE); - } + ksft_print_msg("Swapout one page..."); + if (madvise(p, page_size, MADV_PAGEOUT)) + ksft_exit_fail_perror("madvise(MADV_PAGEOUT)"); if (check_swap(p, page_size)) { success("OK"); } else { @@ -732,6 +685,7 @@ static void collapse_swapin_single_pte(struct collapse_= context *c, struct mem_op validate_memory(p, 0, hpage_pmd_size); out: ops->cleanup_area(p, hpage_pmd_size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void collapse_max_ptes_swap(struct collapse_context *c, struct mem_= ops *ops) @@ -742,11 +696,9 @@ static void collapse_max_ptes_swap(struct collapse_con= text *c, struct mem_ops *o p =3D ops->setup_area(1); ops->fault(p, 0, hpage_pmd_size); =20 - printf("Swapout %d of %d pages...", max_ptes_swap + 1, hpage_pmd_nr); - if (madvise(p, (max_ptes_swap + 1) * page_size, MADV_PAGEOUT)) { - perror("madvise(MADV_PAGEOUT)"); - exit(EXIT_FAILURE); - } + ksft_print_msg("Swapout %d of %d pages...", max_ptes_swap + 1, hpage_pmd_= nr); + if (madvise(p, (max_ptes_swap + 1) * page_size, MADV_PAGEOUT)) + ksft_exit_fail_perror("madvise(MADV_PAGEOUT)"); if (check_swap(p, (max_ptes_swap + 1) * page_size)) { success("OK"); } else { @@ -760,12 +712,10 @@ static void collapse_max_ptes_swap(struct collapse_co= ntext *c, struct mem_ops *o =20 if (c->enforce_pte_scan_limits) { ops->fault(p, 0, hpage_pmd_size); - printf("Swapout %d of %d pages...", max_ptes_swap, + ksft_print_msg("Swapout %d of %d pages...", max_ptes_swap, hpage_pmd_nr); - if (madvise(p, max_ptes_swap * page_size, MADV_PAGEOUT)) { - perror("madvise(MADV_PAGEOUT)"); - exit(EXIT_FAILURE); - } + if (madvise(p, max_ptes_swap * page_size, MADV_PAGEOUT)) + ksft_exit_fail_perror("madvise(MADV_PAGEOUT)"); if (check_swap(p, max_ptes_swap * page_size)) { success("OK"); } else { @@ -779,6 +729,7 @@ static void collapse_max_ptes_swap(struct collapse_cont= ext *c, struct mem_ops *o } out: ops->cleanup_area(p, hpage_pmd_size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void collapse_single_pte_entry_compound(struct collapse_context *c,= struct mem_ops *ops) @@ -795,7 +746,7 @@ static void collapse_single_pte_entry_compound(struct c= ollapse_context *c, struc } =20 madvise(p, hpage_pmd_size, MADV_NOHUGEPAGE); - printf("Split huge page leaving single PTE mapping compound page..."); + ksft_print_msg("Split huge page leaving single PTE mapping compound page.= .."); madvise(p + page_size, hpage_pmd_size - page_size, MADV_DONTNEED); if (ops->check_huge(p, 0)) success("OK"); @@ -807,6 +758,7 @@ static void collapse_single_pte_entry_compound(struct c= ollapse_context *c, struc validate_memory(p, 0, page_size); skip: ops->cleanup_area(p, hpage_pmd_size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void collapse_full_of_compound(struct collapse_context *c, struct m= em_ops *ops) @@ -814,7 +766,7 @@ static void collapse_full_of_compound(struct collapse_c= ontext *c, struct mem_ops void *p; =20 p =3D alloc_hpage(ops); - printf("Split huge page leaving single PTE page table full of compound pa= ges..."); + ksft_print_msg("Split huge page leaving single PTE page table full of com= pound pages..."); madvise(p, page_size, MADV_NOHUGEPAGE); madvise(p, hpage_pmd_size, MADV_NOHUGEPAGE); if (ops->check_huge(p, 0)) @@ -826,6 +778,7 @@ static void collapse_full_of_compound(struct collapse_c= ontext *c, struct mem_ops true); validate_memory(p, 0, hpage_pmd_size); ops->cleanup_area(p, hpage_pmd_size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void collapse_compound_extreme(struct collapse_context *c, struct m= em_ops *ops) @@ -834,16 +787,12 @@ static void collapse_compound_extreme(struct collapse= _context *c, struct mem_ops int i; =20 p =3D ops->setup_area(1); + ksft_print_msg("Construct PTE page table full of different PTE-mapped com= pound pagesd\n"); for (i =3D 0; i < hpage_pmd_nr; i++) { - printf("\rConstruct PTE page table full of different PTE-mapped compound= pages %3d/%d...", - i + 1, hpage_pmd_nr); - madvise(BASE_ADDR, hpage_pmd_size, MADV_HUGEPAGE); ops->fault(BASE_ADDR, 0, hpage_pmd_size); - if (!ops->check_huge(BASE_ADDR, 1)) { - printf("Failed to allocate huge page\n"); - exit(EXIT_FAILURE); - } + if (!ops->check_huge(BASE_ADDR, 1)) + ksft_exit_fail_msg("Failed to allocate huge page\n"); madvise(BASE_ADDR, hpage_pmd_size, MADV_NOHUGEPAGE); =20 p =3D mremap(BASE_ADDR - i * page_size, @@ -851,20 +800,16 @@ static void collapse_compound_extreme(struct collapse= _context *c, struct mem_ops (i + 1) * page_size, MREMAP_MAYMOVE | MREMAP_FIXED, BASE_ADDR + 2 * hpage_pmd_size); - if (p =3D=3D MAP_FAILED) { - perror("mremap+unmap"); - exit(EXIT_FAILURE); - } + if (p =3D=3D MAP_FAILED) + ksft_exit_fail_perror("mremap+unmap"); =20 p =3D mremap(BASE_ADDR + 2 * hpage_pmd_size, (i + 1) * page_size, (i + 1) * page_size + hpage_pmd_size, MREMAP_MAYMOVE | MREMAP_FIXED, BASE_ADDR - (i + 1) * page_size); - if (p =3D=3D MAP_FAILED) { - perror("mremap+alloc"); - exit(EXIT_FAILURE); - } + if (p =3D=3D MAP_FAILED) + ksft_exit_fail_perror("mremap+alloc"); } =20 ops->cleanup_area(BASE_ADDR, hpage_pmd_size); @@ -879,6 +824,7 @@ static void collapse_compound_extreme(struct collapse_c= ontext *c, struct mem_ops =20 validate_memory(p, 0, hpage_pmd_size); ops->cleanup_area(p, hpage_pmd_size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void collapse_fork(struct collapse_context *c, struct mem_ops *ops) @@ -888,18 +834,17 @@ static void collapse_fork(struct collapse_context *c,= struct mem_ops *ops) =20 p =3D ops->setup_area(1); =20 - printf("Allocate small page..."); + ksft_print_msg("Allocate small page..."); ops->fault(p, 0, page_size); if (ops->check_huge(p, 0)) success("OK"); else fail("Fail"); =20 - printf("Share small page over fork()..."); + ksft_print_msg("Share small page over fork()..."); if (!fork()) { /* Do not touch settings on child exit */ skip_settings_restore =3D true; - exit_status =3D 0; =20 if (ops->check_huge(p, 0)) success("OK"); @@ -916,15 +861,16 @@ static void collapse_fork(struct collapse_context *c,= struct mem_ops *ops) } =20 wait(&wstatus); - exit_status +=3D WEXITSTATUS(wstatus); + exit_status =3D WEXITSTATUS(wstatus); =20 - printf("Check if parent still has small page..."); + ksft_print_msg("Check if parent still has small page..."); if (ops->check_huge(p, 0)) success("OK"); else fail("Fail"); validate_memory(p, 0, page_size); ops->cleanup_area(p, hpage_pmd_size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void collapse_fork_compound(struct collapse_context *c, struct mem_= ops *ops) @@ -933,18 +879,17 @@ static void collapse_fork_compound(struct collapse_co= ntext *c, struct mem_ops *o void *p; =20 p =3D alloc_hpage(ops); - printf("Share huge page over fork()..."); + ksft_print_msg("Share huge page over fork()..."); if (!fork()) { /* Do not touch settings on child exit */ skip_settings_restore =3D true; - exit_status =3D 0; =20 if (ops->check_huge(p, 1)) success("OK"); else fail("Fail"); =20 - printf("Split huge page PMD in child process..."); + ksft_print_msg("Split huge page PMD in child process..."); madvise(p, page_size, MADV_NOHUGEPAGE); madvise(p, hpage_pmd_size, MADV_NOHUGEPAGE); if (ops->check_huge(p, 0)) @@ -965,15 +910,16 @@ static void collapse_fork_compound(struct collapse_co= ntext *c, struct mem_ops *o } =20 wait(&wstatus); - exit_status +=3D WEXITSTATUS(wstatus); + exit_status =3D WEXITSTATUS(wstatus); =20 - printf("Check if parent still has huge page..."); + ksft_print_msg("Check if parent still has huge page..."); if (ops->check_huge(p, 1)) success("OK"); else fail("Fail"); validate_memory(p, 0, hpage_pmd_size); ops->cleanup_area(p, hpage_pmd_size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void collapse_max_ptes_shared(struct collapse_context *c, struct me= m_ops *ops) @@ -983,18 +929,17 @@ static void collapse_max_ptes_shared(struct collapse_= context *c, struct mem_ops void *p; =20 p =3D alloc_hpage(ops); - printf("Share huge page over fork()..."); + ksft_print_msg("Share huge page over fork()..."); if (!fork()) { /* Do not touch settings on child exit */ skip_settings_restore =3D true; - exit_status =3D 0; =20 if (ops->check_huge(p, 1)) success("OK"); else fail("Fail"); =20 - printf("Trigger CoW on page %d of %d...", + ksft_print_msg("Trigger CoW on page %d of %d...", hpage_pmd_nr - max_ptes_shared - 1, hpage_pmd_nr); ops->fault(p, 0, (hpage_pmd_nr - max_ptes_shared - 1) * page_size); if (ops->check_huge(p, 0)) @@ -1006,7 +951,7 @@ static void collapse_max_ptes_shared(struct collapse_c= ontext *c, struct mem_ops 1, ops, !c->enforce_pte_scan_limits); =20 if (c->enforce_pte_scan_limits) { - printf("Trigger CoW on page %d of %d...", + ksft_print_msg("Trigger CoW on page %d of %d...", hpage_pmd_nr - max_ptes_shared, hpage_pmd_nr); ops->fault(p, 0, (hpage_pmd_nr - max_ptes_shared) * page_size); @@ -1025,15 +970,16 @@ static void collapse_max_ptes_shared(struct collapse= _context *c, struct mem_ops } =20 wait(&wstatus); - exit_status +=3D WEXITSTATUS(wstatus); + exit_status =3D WEXITSTATUS(wstatus); =20 - printf("Check if parent still has huge page..."); + ksft_print_msg("Check if parent still has huge page..."); if (ops->check_huge(p, 1)) success("OK"); else fail("Fail"); validate_memory(p, 0, hpage_pmd_size); ops->cleanup_area(p, hpage_pmd_size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void madvise_collapse_existing_thps(struct collapse_context *c, @@ -1050,6 +996,7 @@ static void madvise_collapse_existing_thps(struct coll= apse_context *c, __madvise_collapse("Re-collapse PMD-mapped hugepage", p, 1, ops, true); validate_memory(p, 0, hpage_pmd_size); ops->cleanup_area(p, hpage_pmd_size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 /* @@ -1077,6 +1024,7 @@ static void madvise_retracted_page_tables(struct coll= apse_context *c, true); validate_memory(p, 0, size); ops->cleanup_area(p, size); + ksft_test_result_report(exit_status, "%s\n", __func__); } =20 static void usage(void) @@ -1180,10 +1128,8 @@ static int nr_test_cases; =20 #define TEST(t, c, o) do { \ if (c && o) { \ - if (nr_test_cases >=3D MAX_TEST_CASES) { \ - printf("MAX_ADD_CASES is too small\n"); \ - exit(EXIT_FAILURE); \ - } \ + if (nr_test_cases >=3D MAX_TEST_CASES) \ + ksft_exit_fail_msg("MAX_ADD_CASES is too small\n"); \ test_cases[nr_test_cases++] =3D (struct test_case){ \ .ctx =3D c, \ .ops =3D o, \ @@ -1216,10 +1162,10 @@ int main(int argc, char **argv) .read_ahead_kb =3D 0, }; =20 - if (!thp_is_enabled()) { - printf("Transparent Hugepages not available\n"); - return KSFT_SKIP; - } + ksft_print_header(); + + if (!thp_is_enabled()) + ksft_exit_skip("Transparent Hugepages not available\n"); =20 parse_test_type(argc, argv); =20 @@ -1227,10 +1173,8 @@ int main(int argc, char **argv) =20 page_size =3D getpagesize(); hpage_pmd_size =3D read_pmd_pagesize(); - if (!hpage_pmd_size) { - printf("Reading PMD pagesize failed"); - exit(EXIT_FAILURE); - } + if (!hpage_pmd_size) + ksft_exit_fail_msg("Reading PMD pagesize failed\n"); hpage_pmd_nr =3D hpage_pmd_size / page_size; hpage_pmd_order =3D __builtin_ctz(hpage_pmd_nr); =20 @@ -1246,8 +1190,6 @@ int main(int argc, char **argv) save_settings(); thp_push_settings(&default_settings); =20 - alloc_at_fault(); - TEST(collapse_full, khugepaged_context, anon_ops); TEST(collapse_full, khugepaged_context, file_ops); TEST(collapse_full, khugepaged_context, shmem_ops); @@ -1307,11 +1249,14 @@ int main(int argc, char **argv) TEST(madvise_retracted_page_tables, madvise_context, file_ops); TEST(madvise_retracted_page_tables, madvise_context, shmem_ops); =20 + ksft_set_plan(nr_test_cases + 1); + + alloc_at_fault(); for (int i =3D 0; i < nr_test_cases; i++) { struct test_case *t =3D &test_cases[i]; =20 exit_status =3D KSFT_PASS; - printf("\nRun test: %s: (%s:%s)\n", t->desc, t->ctx->name, t->ops->name); + ksft_print_msg("\nRun test: %s: (%s:%s)\n", t->desc, t->ctx->name, t->op= s->name); t->fn(t->ctx, t->ops); } =20 --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 6AC03335067; Tue, 28 Apr 2026 20:44:30 +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=1777409070; cv=none; b=qX1FUNSUdvnAO3VAm/ctEfcJdsRvnYql8AEEH58V0XoQNTJpfE/lBKEtGmKYEgZYAFKUTyFVUewuyoX08mgxw8ziss3mpfqebgHx6NslXvohWFYYs9HnBWz3IZJh+0wcIRZ8+P32V7cKeIn5+HuAwK0lAPZG65smAvsEzvL7ZRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409070; c=relaxed/simple; bh=xsBdrafAcXHUzee2NfWszrgSyC/tQCheWL0+4hzUfOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EQzeRPj3U6K31QjM7SGBQj2qD75IDsQo6ht/PYVoERQbP8BTaqvujwYAUdWTCRxX7Gwpi/mrQfvoW8SpFmWceQBRAQdSQ2CtsD8yYQK0o9tyl2JEPA8oLsNPKkD7Ghvm6nNHw+kcCN0yzeZFY+qmrqQmEWDkF58w+UPoLsvNhU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EaYnb5O4; 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="EaYnb5O4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03364C2BCAF; Tue, 28 Apr 2026 20:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409070; bh=xsBdrafAcXHUzee2NfWszrgSyC/tQCheWL0+4hzUfOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EaYnb5O4VMdme+q7lnB34iWoI+U1jjtCvLZmRlNIe9TSLc3O48kINCWBsNWr6VnKY 7+Cgf/x+DKVMb2vB/DAnj2t1E3RKVlqITaFC+T2iyIbGS8eDLuNcE3qVFl4U2sSbs7 wyd+tEI7hPwIQseTZhxLISWhsE7E5kOhvH3UbOuFqXl3ngjMao6Huqz2XmwxfXgaCl Z+oez/xDfmw6SjXEAFJb19avON4QCv49b6/cb2Xr5BQMr/dE+KebJviFIf8tFDIqZm Z0KzMntmS11RyWl7+QLcC98Nx+zZTf5l7/fjBa4g/cDof+eINvrfYXGCCGxC/iqvDl Mhiu2ykZo7oLw== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 15/54] selftests/mm: ksm_tests: use kselftest framework Date: Tue, 28 Apr 2026 23:42:01 +0300 Message-ID: <20260428204240.1924129-16-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Convert ksm_tests to use kselftest framework for reporting and tracking successful and failing runs. Reviewed by: Donet Tom Reviewed-by: Mark Brown Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/ksm_tests.c | 180 +++++++++++-------------- 1 file changed, 81 insertions(+), 99 deletions(-) diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftes= ts/mm/ksm_tests.c index a0b48b839d54..752a2c0d06ab 100644 --- a/tools/testing/selftests/mm/ksm_tests.c +++ b/tools/testing/selftests/mm/ksm_tests.c @@ -175,12 +175,12 @@ static void *allocate_memory(void *ptr, int prot, in= t mapping, char data, size_ void *map_ptr =3D mmap(ptr, map_size, PROT_WRITE, mapping, -1, 0); =20 if (!map_ptr) { - perror("mmap"); + ksft_perror("mmap"); return NULL; } memset(map_ptr, data, map_size); if (mprotect(map_ptr, map_size, prot)) { - perror("mprotect"); + ksft_perror("mprotect"); munmap(map_ptr, map_size); return NULL; } @@ -201,11 +201,11 @@ static int ksm_do_scan(int scan_count, struct timespe= c start_time, int timeout) if (ksm_read_sysfs(KSM_FP("full_scans"), &cur_scan)) return 1; if (clock_gettime(CLOCK_MONOTONIC_RAW, &cur_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); return 1; } if ((cur_time.tv_sec - start_time.tv_sec) > timeout) { - printf("Scan time limit exceeded\n"); + ksft_print_msg("Scan time limit exceeded\n"); return 1; } } @@ -218,12 +218,12 @@ static int ksm_merge_pages(int merge_type, void *addr= , size_t size, { if (merge_type =3D=3D KSM_MERGE_MADVISE) { if (madvise(addr, size, MADV_MERGEABLE)) { - perror("madvise"); + ksft_perror("madvise"); return 1; } } else if (merge_type =3D=3D KSM_MERGE_PRCTL) { if (prctl(PR_SET_MEMORY_MERGE, 1, 0, 0, 0)) { - perror("prctl"); + ksft_perror("prctl"); return 1; } } @@ -242,7 +242,7 @@ static int ksm_unmerge_pages(void *addr, size_t size, struct timespec start_time, int timeout) { if (madvise(addr, size, MADV_UNMERGEABLE)) { - perror("madvise"); + ksft_perror("madvise"); return 1; } return 0; @@ -324,7 +324,7 @@ static int check_ksm_merge(int merge_type, int mapping,= int prot, struct timespec start_time; =20 if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); return KSFT_FAIL; } =20 @@ -338,7 +338,6 @@ static int check_ksm_merge(int merge_type, int mapping,= int prot, =20 /* verify that the right number of pages are merged */ if (assert_ksm_pages_count(page_count)) { - printf("OK\n"); munmap(map_ptr, page_size * page_count); if (merge_type =3D=3D KSM_MERGE_PRCTL) prctl(PR_SET_MEMORY_MERGE, 0, 0, 0, 0); @@ -346,7 +345,6 @@ static int check_ksm_merge(int merge_type, int mapping,= int prot, } =20 err_out: - printf("Not OK\n"); munmap(map_ptr, page_size * page_count); return KSFT_FAIL; } @@ -358,7 +356,7 @@ static int check_ksm_unmerge(int merge_type, int mappin= g, int prot, int timeout, int page_count =3D 2; =20 if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); return KSFT_FAIL; } =20 @@ -380,13 +378,11 @@ static int check_ksm_unmerge(int merge_type, int mapp= ing, int prot, int timeout, =20 /* check that unmerging was successful and 0 pages are currently merged */ if (assert_ksm_pages_count(0)) { - printf("OK\n"); munmap(map_ptr, page_size * page_count); return KSFT_PASS; } =20 err_out: - printf("Not OK\n"); munmap(map_ptr, page_size * page_count); return KSFT_FAIL; } @@ -398,7 +394,7 @@ static int check_ksm_zero_page_merge(int merge_type, in= t mapping, int prot, long struct timespec start_time; =20 if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); return KSFT_FAIL; } =20 @@ -425,12 +421,10 @@ static int check_ksm_zero_page_merge(int merge_type, = int mapping, int prot, long else if (!use_zero_pages && !assert_ksm_pages_count(page_count)) goto err_out; =20 - printf("OK\n"); munmap(map_ptr, page_size * page_count); return KSFT_PASS; =20 err_out: - printf("Not OK\n"); munmap(map_ptr, page_size * page_count); return KSFT_FAIL; } @@ -465,16 +459,16 @@ static int check_ksm_numa_merge(int merge_type, int m= apping, int prot, int timeo int first_node; =20 if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); return KSFT_FAIL; } =20 if (numa_available() < 0) { - perror("NUMA support not enabled"); + ksft_perror("NUMA support not enabled"); return KSFT_SKIP; } if (numa_num_configured_nodes() <=3D 1) { - printf("At least 2 NUMA nodes must be available\n"); + ksft_print_msg("At least 2 NUMA nodes must be available\n"); return KSFT_SKIP; } if (ksm_write_sysfs(KSM_FP("merge_across_nodes"), merge_across_nodes)) @@ -485,7 +479,7 @@ static int check_ksm_numa_merge(int merge_type, int map= ping, int prot, int timeo numa1_map_ptr =3D numa_alloc_onnode(page_size, first_node); numa2_map_ptr =3D numa_alloc_onnode(page_size, get_next_mem_node(first_no= de)); if (!numa1_map_ptr || !numa2_map_ptr) { - perror("numa_alloc_onnode"); + ksft_perror("numa_alloc_onnode"); return KSFT_FAIL; } =20 @@ -510,13 +504,11 @@ static int check_ksm_numa_merge(int merge_type, int m= apping, int prot, int timeo =20 numa_free(numa1_map_ptr, page_size); numa_free(numa2_map_ptr, page_size); - printf("OK\n"); return KSFT_PASS; =20 err_out: numa_free(numa1_map_ptr, page_size); numa_free(numa2_map_ptr, page_size); - printf("Not OK\n"); return KSFT_FAIL; } =20 @@ -529,7 +521,7 @@ static int ksm_merge_hugepages_time(int merge_type, int= mapping, int prot, int pagemap_fd, n_normal_pages, n_huge_pages; =20 if (!thp_is_enabled()) { - printf("Transparent Hugepages not available\n"); + ksft_print_msg("Transparent Hugepages not available\n"); return KSFT_SKIP; } =20 @@ -559,36 +551,35 @@ static int ksm_merge_hugepages_time(int merge_type, i= nt mapping, int prot, else n_huge_pages++; } - printf("Number of normal pages: %d\n", n_normal_pages); - printf("Number of huge pages: %d\n", n_huge_pages); + ksft_print_msg("Number of normal pages: %d\n", n_normal_pages); + ksft_print_msg("Number of huge pages: %d\n", n_huge_pages); =20 memset(map_ptr, '*', len); =20 if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); goto err_out; } if (ksm_merge_pages(merge_type, map_ptr, map_size, start_time, timeout)) goto err_out; if (clock_gettime(CLOCK_MONOTONIC_RAW, &end_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); goto err_out; } =20 scan_time_ns =3D (end_time.tv_sec - start_time.tv_sec) * NSEC_PER_SEC + (end_time.tv_nsec - start_time.tv_nsec); =20 - printf("Total size: %lu MiB\n", map_size / MB); - printf("Total time: %ld.%09ld s\n", scan_time_ns / NSEC_PER_SEC, + ksft_print_msg("Total size: %lu MiB\n", map_size / MB); + ksft_print_msg("Total time: %ld.%09ld s\n", scan_time_ns / NSEC_PER_SE= C, scan_time_ns % NSEC_PER_SEC); - printf("Average speed: %.3f MiB/s\n", (map_size / MB) / + ksft_print_msg("Average speed: %.3f MiB/s\n", (map_size / MB) / ((double)scan_time_ns / NSEC_PER_SEC)); =20 munmap(map_ptr_orig, len + HPAGE_SIZE); return KSFT_PASS; =20 err_out: - printf("Not OK\n"); munmap(map_ptr_orig, len + HPAGE_SIZE); return KSFT_FAIL; } @@ -606,30 +597,29 @@ static int ksm_merge_time(int merge_type, int mapping= , int prot, int timeout, si return KSFT_FAIL; =20 if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); goto err_out; } if (ksm_merge_pages(merge_type, map_ptr, map_size, start_time, timeout)) goto err_out; if (clock_gettime(CLOCK_MONOTONIC_RAW, &end_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); goto err_out; } =20 scan_time_ns =3D (end_time.tv_sec - start_time.tv_sec) * NSEC_PER_SEC + (end_time.tv_nsec - start_time.tv_nsec); =20 - printf("Total size: %lu MiB\n", map_size / MB); - printf("Total time: %ld.%09ld s\n", scan_time_ns / NSEC_PER_SEC, + ksft_print_msg("Total size: %lu MiB\n", map_size / MB); + ksft_print_msg("Total time: %ld.%09ld s\n", scan_time_ns / NSEC_PER_SE= C, scan_time_ns % NSEC_PER_SEC); - printf("Average speed: %.3f MiB/s\n", (map_size / MB) / + ksft_print_msg("Average speed: %.3f MiB/s\n", (map_size / MB) / ((double)scan_time_ns / NSEC_PER_SEC)); =20 munmap(map_ptr, map_size); return KSFT_PASS; =20 err_out: - printf("Not OK\n"); munmap(map_ptr, map_size); return KSFT_FAIL; } @@ -646,37 +636,36 @@ static int ksm_unmerge_time(int merge_type, int mappi= ng, int prot, int timeout, if (!map_ptr) return KSFT_FAIL; if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); goto err_out; } if (ksm_merge_pages(merge_type, map_ptr, map_size, start_time, timeout)) goto err_out; =20 if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); goto err_out; } if (ksm_unmerge_pages(map_ptr, map_size, start_time, timeout)) goto err_out; if (clock_gettime(CLOCK_MONOTONIC_RAW, &end_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); goto err_out; } =20 scan_time_ns =3D (end_time.tv_sec - start_time.tv_sec) * NSEC_PER_SEC + (end_time.tv_nsec - start_time.tv_nsec); =20 - printf("Total size: %lu MiB\n", map_size / MB); - printf("Total time: %ld.%09ld s\n", scan_time_ns / NSEC_PER_SEC, + ksft_print_msg("Total size: %lu MiB\n", map_size / MB); + ksft_print_msg("Total time: %ld.%09ld s\n", scan_time_ns / NSEC_PER_SE= C, scan_time_ns % NSEC_PER_SEC); - printf("Average speed: %.3f MiB/s\n", (map_size / MB) / + ksft_print_msg("Average speed: %.3f MiB/s\n", (map_size / MB) / ((double)scan_time_ns / NSEC_PER_SEC)); =20 munmap(map_ptr, map_size); return KSFT_PASS; =20 err_out: - printf("Not OK\n"); munmap(map_ptr, map_size); return KSFT_FAIL; } @@ -695,24 +684,24 @@ static int ksm_cow_time(int merge_type, int mapping, = int prot, int timeout, size return KSFT_FAIL; =20 if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); return KSFT_FAIL; } for (size_t i =3D 0; i < page_count - 1; i =3D i + 2) memset(map_ptr + page_size * i, '-', 1); if (clock_gettime(CLOCK_MONOTONIC_RAW, &end_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); return KSFT_FAIL; } =20 cow_time_ns =3D (end_time.tv_sec - start_time.tv_sec) * NSEC_PER_SEC + (end_time.tv_nsec - start_time.tv_nsec); =20 - printf("Total size: %lu MiB\n\n", (page_size * page_count) / MB); - printf("Not merged pages:\n"); - printf("Total time: %ld.%09ld s\n", cow_time_ns / NSEC_PER_SEC, + ksft_print_msg("Total size: %lu MiB\n\n", (page_size * page_count) / M= B); + ksft_print_msg("Not merged pages:\n"); + ksft_print_msg("Total time: %ld.%09ld s\n", cow_time_ns / NSEC_PER_SE= C, cow_time_ns % NSEC_PER_SEC); - printf("Average speed: %.3f MiB/s\n\n", ((page_size * (page_count / 2)) = / MB) / + ksft_print_msg("Average speed: %.3f MiB/s\n\n", ((page_size * (page_coun= t / 2)) / MB) / ((double)cow_time_ns / NSEC_PER_SEC)); =20 /* Create 2000 pairs of duplicate pages */ @@ -724,30 +713,29 @@ static int ksm_cow_time(int merge_type, int mapping, = int prot, int timeout, size goto err_out; =20 if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); goto err_out; } for (size_t i =3D 0; i < page_count - 1; i =3D i + 2) memset(map_ptr + page_size * i, '-', 1); if (clock_gettime(CLOCK_MONOTONIC_RAW, &end_time)) { - perror("clock_gettime"); + ksft_perror("clock_gettime"); goto err_out; } =20 cow_time_ns =3D (end_time.tv_sec - start_time.tv_sec) * NSEC_PER_SEC + (end_time.tv_nsec - start_time.tv_nsec); =20 - printf("Merged pages:\n"); - printf("Total time: %ld.%09ld s\n", cow_time_ns / NSEC_PER_SEC, + ksft_print_msg("Merged pages:\n"); + ksft_print_msg("Total time: %ld.%09ld s\n", cow_time_ns / NSEC_PER_SE= C, cow_time_ns % NSEC_PER_SEC); - printf("Average speed: %.3f MiB/s\n", ((page_size * (page_count / 2)) / = MB) / + ksft_print_msg("Average speed: %.3f MiB/s\n", ((page_size * (page_count = / 2)) / MB) / ((double)cow_time_ns / NSEC_PER_SEC)); =20 munmap(map_ptr, page_size * page_count); return KSFT_PASS; =20 err_out: - printf("Not OK\n"); munmap(map_ptr, page_size * page_count); return KSFT_FAIL; } @@ -765,6 +753,10 @@ int main(int argc, char *argv[]) bool use_zero_pages =3D KSM_USE_ZERO_PAGES_DEFAULT; bool merge_across_nodes =3D KSM_MERGE_ACROSS_NODES_DEFAULT; long size_MB =3D 0; + const char *test_descr =3D "KSM merging"; + + ksft_print_header(); + ksft_set_plan(1); =20 while ((opt =3D getopt(argc, argv, "dha:p:l:z:m:s:t:MUZNPCHD")) !=3D -1) { switch (opt) { @@ -773,17 +765,13 @@ int main(int argc, char *argv[]) break; case 'p': page_count =3D atol(optarg); - if (page_count <=3D 0) { - printf("The number of pages must be greater than 0\n"); - return KSFT_FAIL; - } + if (page_count <=3D 0) + ksft_exit_fail_msg("The number of pages must be greater than 0\n"); break; case 'l': ksm_scan_limit_sec =3D atoi(optarg); - if (ksm_scan_limit_sec <=3D 0) { - printf("Timeout value must be greater than 0\n"); - return KSFT_FAIL; - } + if (ksm_scan_limit_sec <=3D 0) + ksft_exit_fail_msg("Timeout value must be greater than 0\n"); break; case 'h': print_help(); @@ -805,19 +793,15 @@ int main(int argc, char *argv[]) break; case 's': size_MB =3D atoi(optarg); - if (size_MB <=3D 0) { - printf("Size must be greater than 0\n"); - return KSFT_FAIL; - } + if (size_MB <=3D 0) + ksft_exit_fail_msg("Size must be greater than 0\n"); break; case 't': { int tmp =3D atoi(optarg); =20 - if (tmp < 0 || tmp > KSM_MERGE_LAST) { - printf("Invalid merge type\n"); - return KSFT_FAIL; - } + if (tmp < 0 || tmp > KSM_MERGE_LAST) + ksft_exit_fail_msg("Invalid merge type\n"); merge_type =3D tmp; } break; @@ -845,82 +829,80 @@ int main(int argc, char *argv[]) test_name =3D KSM_COW_TIME; break; default: - return KSFT_FAIL; + ksft_exit_fail_msg("Unknown option\n"); } } =20 if (prot =3D=3D 0) prot =3D str_to_prot(KSM_PROT_STR_DEFAULT); =20 - if (access(KSM_SYSFS_PATH, F_OK)) { - printf("Config KSM not enabled\n"); - return KSFT_SKIP; - } + if (access(KSM_SYSFS_PATH, F_OK)) + ksft_exit_skip("Config KSM not enabled\n"); =20 - if (ksm_save_def(&ksm_sysfs_old)) { - printf("Cannot save default tunables\n"); - return KSFT_FAIL; - } + if (ksm_save_def(&ksm_sysfs_old)) + ksft_exit_fail_msg("Cannot save default tunables\n"); =20 if (ksm_write_sysfs(KSM_FP("run"), 2) || ksm_write_sysfs(KSM_FP("sleep_millisecs"), 0) || numa_available() ? 0 : ksm_write_sysfs(KSM_FP("merge_across_nodes"), 1) || ksm_write_sysfs(KSM_FP("pages_to_scan"), page_count)) - return KSFT_FAIL; + ksft_exit_fail_msg("Cannot set up KSM tunables\n"); =20 switch (test_name) { case CHECK_KSM_MERGE: + test_descr =3D "KSM merging"; ret =3D check_ksm_merge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, p= age_count, ksm_scan_limit_sec, page_size); break; case CHECK_KSM_UNMERGE: + test_descr =3D "KSM unmerging"; ret =3D check_ksm_unmerge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, page_size); break; case CHECK_KSM_ZERO_PAGE_MERGE: + test_descr =3D "KSM zero page merging"; ret =3D check_ksm_zero_page_merge(merge_type, MAP_PRIVATE | MAP_ANONYMOU= S, prot, page_count, ksm_scan_limit_sec, use_zero_pages, page_size); break; case CHECK_KSM_NUMA_MERGE: + test_descr =3D "KSM NUMA merging"; ret =3D check_ksm_numa_merge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, pr= ot, ksm_scan_limit_sec, merge_across_nodes, page_size); break; case KSM_MERGE_TIME: - if (size_MB =3D=3D 0) { - printf("Option '-s' is required.\n"); - return KSFT_FAIL; - } + if (size_MB =3D=3D 0) + ksft_exit_fail_msg("Option '-s' is required\n"); + test_descr =3D "KSM merge time"; ret =3D ksm_merge_time(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, size_MB); break; case KSM_MERGE_TIME_HUGE_PAGES: - if (size_MB =3D=3D 0) { - printf("Option '-s' is required.\n"); - return KSFT_FAIL; - } + if (size_MB =3D=3D 0) + ksft_exit_fail_msg("Option '-s' is required\n"); + test_descr =3D "KSM merge time with huge pages"; ret =3D ksm_merge_hugepages_time(merge_type, MAP_PRIVATE | MAP_ANONYMOUS= , prot, ksm_scan_limit_sec, size_MB); break; case KSM_UNMERGE_TIME: - if (size_MB =3D=3D 0) { - printf("Option '-s' is required.\n"); - return KSFT_FAIL; - } + if (size_MB =3D=3D 0) + ksft_exit_fail_msg("Option '-s' is required\n"); + test_descr =3D "KSM unmerge time"; ret =3D ksm_unmerge_time(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, size_MB); break; case KSM_COW_TIME: + test_descr =3D "KSM COW time"; ret =3D ksm_cow_time(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, page_size); break; } =20 - if (ksm_restore(&ksm_sysfs_old)) { - printf("Cannot restore default tunables\n"); - return KSFT_FAIL; - } + if (ksm_restore(&ksm_sysfs_old)) + ksft_print_msg("Cannot restore default tunables\n"); + + ksft_test_result_report(ret, "%s\n", test_descr); =20 - return ret; + ksft_finished(); } --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 C72E8339844; Tue, 28 Apr 2026 20:44:37 +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=1777409077; cv=none; b=Jx4oUzxa12e3fmhdTzsuJekTdliRVKXM+Adkz7xCoXD3pRWTbCIk/LGzVlkaSHqekgdbIfPyBcglCX0GF12FSTI5qNLR4Jsg/SJQoBqjvDRHx9A6JolcG0t/fz/RMi/TImGV5xXmWFHdyw6phvFmBa7tds+RBrnR6sH3XXWnDcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409077; c=relaxed/simple; bh=fVCj9egQfI3xfmHaM59sAXV1x5+dV8VoGPx5qmYr/HI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gtz6Fd71m5ve0lEl32Ez0CSG+3KUq++1xgNFBMEHX8GRfXxEG9wndlUWUeFTOE3m4SPwBDwkHrBdrvIfl+h6ZyLKzQxlYfGff93nTLDtos4G3rYRpDW2a13e2lugsxdQV/Fw83KGpbxOtsGh9Bh5HjQ4tjKZSP34NMgy8V78STU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YDcC27la; 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="YDcC27la" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F3A6C2BCAF; Tue, 28 Apr 2026 20:44:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409076; bh=fVCj9egQfI3xfmHaM59sAXV1x5+dV8VoGPx5qmYr/HI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YDcC27laQpZlXBDwVn9TC7PuyP8ixtdqjmm78azLyOACYs+mYtDRWfOuJcYQrMDOO RvcF4lasiaWiFizAzCKXNCIWGntXkDlHN4N/uEF8CLj3l9faWXa7SEV70JVRQ2pWYD 0EYfhniaqgcJXMtJLLHWrAMUpze+B9TBtogsbaGrfP2sr5z+Z3LMqAKgxmdReAE3Ot G8pAbY1Or1AXLJj1rXmgXRuyk9Qf6eB6IpBcsyOO9ieo0ohOeYC1IRu28IHZWXJFjq 8GpALg0WGNOaiuu0aX1CVZ05nOhGvXay2zmOAROkASuL8FisKvTzVz+g1jrKw287IF vDRRA/8UtP83g== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 16/54] selftests/mm: protection_keys: use descriptive test names in TAP output Date: Tue, 28 Apr 2026 23:42:02 +0300 Message-ID: <20260428204240.1924129-17-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Replace the numeric test index in TAP output with the actual test function name. Use a structure containing function pointer and its name rather than only the function pointer in the pkey_tests array. Reviewed by: Donet Tom Reviewed-by: Mark Brown Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/protection_keys.c | 55 +++++++++++--------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/s= elftests/mm/protection_keys.c index 2085982dba69..80c6124e8378 100644 --- a/tools/testing/selftests/mm/protection_keys.c +++ b/tools/testing/selftests/mm/protection_keys.c @@ -1692,29 +1692,36 @@ static void test_mprotect_pkey_on_unsupported_cpu(i= nt *ptr, u16 pkey) pkey_assert(sret < 0); } =20 -static void (*pkey_tests[])(int *ptr, u16 pkey) =3D { - test_read_of_write_disabled_region, - test_read_of_access_disabled_region, - test_read_of_access_disabled_region_with_page_already_mapped, - test_write_of_write_disabled_region, - test_write_of_write_disabled_region_with_page_already_mapped, - test_write_of_access_disabled_region, - test_write_of_access_disabled_region_with_page_already_mapped, - test_kernel_write_of_access_disabled_region, - test_kernel_write_of_write_disabled_region, - test_kernel_gup_of_access_disabled_region, - test_kernel_gup_write_to_write_disabled_region, - test_executing_on_unreadable_memory, - test_implicit_mprotect_exec_only_memory, - test_mprotect_with_pkey_0, - test_ptrace_of_child, - test_pkey_init_state, - test_pkey_syscalls_on_non_allocated_pkey, - test_pkey_syscalls_bad_args, - test_pkey_alloc_exhaust, - test_pkey_alloc_free_attach_pkey0, +struct pkey_test { + void (*func)(int *ptr, u16 pkey); + const char *name; +}; + +#define PKEY_TEST(fn) { fn, #fn } + +static struct pkey_test pkey_tests[] =3D { + PKEY_TEST(test_read_of_write_disabled_region), + PKEY_TEST(test_read_of_access_disabled_region), + PKEY_TEST(test_read_of_access_disabled_region_with_page_already_mapped), + PKEY_TEST(test_write_of_write_disabled_region), + PKEY_TEST(test_write_of_write_disabled_region_with_page_already_mapped), + PKEY_TEST(test_write_of_access_disabled_region), + PKEY_TEST(test_write_of_access_disabled_region_with_page_already_mapped), + PKEY_TEST(test_kernel_write_of_access_disabled_region), + PKEY_TEST(test_kernel_write_of_write_disabled_region), + PKEY_TEST(test_kernel_gup_of_access_disabled_region), + PKEY_TEST(test_kernel_gup_write_to_write_disabled_region), + PKEY_TEST(test_executing_on_unreadable_memory), + PKEY_TEST(test_implicit_mprotect_exec_only_memory), + PKEY_TEST(test_mprotect_with_pkey_0), + PKEY_TEST(test_ptrace_of_child), + PKEY_TEST(test_pkey_init_state), + PKEY_TEST(test_pkey_syscalls_on_non_allocated_pkey), + PKEY_TEST(test_pkey_syscalls_bad_args), + PKEY_TEST(test_pkey_alloc_exhaust), + PKEY_TEST(test_pkey_alloc_free_attach_pkey0), #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) - test_ptrace_modifies_pkru, + PKEY_TEST(test_ptrace_modifies_pkru), #endif }; =20 @@ -1735,7 +1742,7 @@ static void run_tests_once(void) dprintf1("test %d starting with pkey: %d\n", test_nr, pkey); ptr =3D malloc_pkey(PAGE_SIZE, prot, pkey); dprintf1("test %d starting...\n", test_nr); - pkey_tests[test_nr](ptr, pkey); + pkey_tests[test_nr].func(ptr, pkey); dprintf1("freeing test memory: %p\n", ptr); free_pkey_malloc(ptr); sys_pkey_free(pkey); @@ -1746,7 +1753,7 @@ static void run_tests_once(void) tracing_off(); close_test_fds(); =20 - printf("test %2d PASSED (iteration %d)\n", test_nr, iteration_nr); + printf("test %s PASSED (iteration %d)\n", pkey_tests[test_nr].name, iter= ation_nr); dprintf1("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D\n\n"); } iteration_nr++; --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 8E249335067; Tue, 28 Apr 2026 20:44:43 +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=1777409083; cv=none; b=KWIASDgpmClZeoyUHTRsoHWbDmRTPTqthz5bxL7XFk6nVXH7Bul0474ejvvyiermyuD7PsD+OJ0BZRUQQsysfzekD2JYTph1Ijh5wohMFP2yPmJRG7CyRQnE+sMEkGuqaaaF8YropLrinX+i+pXaCUjzboY66EgLL5pLKGtrCUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409083; c=relaxed/simple; bh=FcE7V5Mvmmd2+FOco4bSM+J6XXXcmQOY5rP3hPMkKUk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dsiki24LPSw9ILl3UdK2n17k91qqr6+b422pq4DrDI36ooPXFIdxsenfphdosmGI2EZO2jzd7bfxPnL1JfXxJzaJnUPS+hOBs+7T4sSLXn2bzne+hu80x3X08S6TvSDXqCSpGgUTaMnFuVaH7crq1XsqKEDi0MprO6JQpvi53q8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Id4M4KXK; 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="Id4M4KXK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26A77C2BCB3; Tue, 28 Apr 2026 20:44:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409083; bh=FcE7V5Mvmmd2+FOco4bSM+J6XXXcmQOY5rP3hPMkKUk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Id4M4KXK8BtwDs6OdHyCqMPWKhqfZvnSgajs8Q3H3UpHX7SSt+GopMiO3xLRE+M4p E+L/cC7StlMzfmUtEpLoXrbIq/3fIPC8TVggZQM8hpfh+YAWUEHEHMW43OCcG4oZQ9 O5apk3wWg4Reii+dfXqf2e2tBbiSN+B9H+kXtwfU177WvC9bpT+27XpxLliNpgdFh6 OoGtQ7EGGMwCCauDQG43CZhcdGyAJnaU97OXStYmPumHe2LnBwM2zFlmZ/z57FfB9Y sRoOl6EAJauiYdm6d7tt7WMmrm4p2yLq68YKj5Nu3S6gZ3FULrcDyL5v59tXfXLoh/ fA9h0KNPe4e6A== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 17/54] selftests/mm: protection_keys: use kselftest framework Date: Tue, 28 Apr 2026 23:42:03 +0300 Message-ID: <20260428204240.1924129-18-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Convert protection_keys test to use kselftest framework for reporting and tracking successful and failing runs. Adjust dprintf0() printouts to use "#" in the beginning of the line for TAP compatibility. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/pkey-helpers.h | 6 +++-- tools/testing/selftests/mm/protection_keys.c | 26 +++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/self= tests/mm/pkey-helpers.h index 7c29f075e40b..ae010b075417 100644 --- a/tools/testing/selftests/mm/pkey-helpers.h +++ b/tools/testing/selftests/mm/pkey-helpers.h @@ -71,10 +71,12 @@ static inline void sigsafe_printf(const char *format, .= ..) extern void abort_hooks(void); #define pkey_assert(condition) do { \ if (!(condition)) { \ - dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \ + dprintf0("# assert() at %s::%d test_nr: %d iteration: %d\n", \ __FILE__, __LINE__, \ test_nr, iteration_nr); \ - dprintf0("errno at assert: %d", errno); \ + dprintf0("# errno at assert: %d\n", errno); \ + ksft_test_result_fail("test %d (iteration %d)\n", \ + test_nr, iteration_nr); \ abort_hooks(); \ exit(__LINE__); \ } \ diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/s= elftests/mm/protection_keys.c index 80c6124e8378..d617b41dda6b 100644 --- a/tools/testing/selftests/mm/protection_keys.c +++ b/tools/testing/selftests/mm/protection_keys.c @@ -136,6 +136,7 @@ static void tracing_off(void) =20 void abort_hooks(void) { + fflush(stdout); fprintf(stderr, "running %s()...\n", __func__); tracing_off(); #ifdef SLEEP_ON_ABORT @@ -370,8 +371,8 @@ static void signal_handler(int signum, siginfo_t *si, v= oid *vucontext) if ((si->si_code =3D=3D SEGV_MAPERR) || (si->si_code =3D=3D SEGV_ACCERR) || (si->si_code =3D=3D SEGV_BNDERR)) { - printf("non-PK si_code, exiting...\n"); - exit(4); + dprintf0("# non-PK si_code: %d, exiting...\n", si->si_code); + exit(1); } =20 si_pkey_ptr =3D siginfo_get_pkey_ptr(si); @@ -719,7 +720,7 @@ static void setup_hugetlbfs(void) long hpagesz_mb; =20 if (geteuid() !=3D 0) { - fprintf(stderr, "WARNING: not run as root, can not do hugetlb test\n"); + ksft_print_msg("WARNING: not run as root, can not do hugetlb test\n"); return; } =20 @@ -855,7 +856,7 @@ void expected_pkey_fault(int pkey) =20 #define do_not_expect_pkey_fault(msg) do { \ if (last_pkey_faults !=3D pkey_faults) \ - dprintf0("unexpected PKey fault: %s\n", msg); \ + dprintf0("# unexpected PKey fault: %s\n", msg); \ pkey_assert(last_pkey_faults =3D=3D pkey_faults); \ } while (0) =20 @@ -1753,7 +1754,7 @@ static void run_tests_once(void) tracing_off(); close_test_fds(); =20 - printf("test %s PASSED (iteration %d)\n", pkey_tests[test_nr].name, iter= ation_nr); + ksft_test_result_pass("test %s (iteration %d)\n", pkey_tests[test_nr].na= me, iteration_nr); dprintf1("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D\n\n"); } iteration_nr++; @@ -1773,27 +1774,30 @@ int main(void) =20 setup_handlers(); =20 - printf("has pkeys: %d\n", pkeys_supported); + ksft_print_header(); =20 if (!pkeys_supported) { int size =3D PAGE_SIZE; int *ptr; =20 - printf("running PKEY tests for unsupported CPU/OS\n"); + ksft_set_plan(1); + ksft_print_msg("running PKEY tests for unsupported CPU/OS\n"); =20 ptr =3D mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); assert(ptr !=3D (void *)-1); test_mprotect_pkey_on_unsupported_cpu(ptr, 1); - exit(0); + ksft_test_result_pass("pkey on unsupported CPU/OS\n"); + ksft_finished(); } =20 + ksft_set_plan(ARRAY_SIZE(pkey_tests) * nr_iterations); + pkey_setup_shadow(); - printf("startup pkey_reg: %016llx\n", read_pkey_reg()); + ksft_print_msg("startup pkey_reg: %016llx\n", read_pkey_reg()); setup_hugetlbfs(); =20 while (nr_iterations-- > 0) run_tests_once(); =20 - printf("done (all tests OK)\n"); - return 0; + ksft_finished(); } --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 2D080331218; Tue, 28 Apr 2026 20:44: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=1777409090; cv=none; b=QJKn8FF1SOaaLb+Lu3dwyrqXwV45yw75SdW/Ty6WBaWAeeBGiwYRK86/ogt2CWRE6t5jvXuz6p5USVXMi6rtJChtKOKJhskToIJ2M93KYtF/+MycRHjad5SIsyyk2YGAqWNXRwKWmW5leWugv+5Y5AiV8asMb7aDZuIOJEydvIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409090; c=relaxed/simple; bh=7qKHzCadzgEQAQzNVqCf6fre80BxdReFv76mDf7/IKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fCUF109OUMBtENu6MiX/egAP1UnnoZN//I56Fs3q1TcQgkS+jDYVGxA/ZziOCSqEMRP2RWiMRh2/a0trfT0iFWLkT+St1/cLLRfZE1JxYcAPGQX5SC2J5acsHQvMuc8bTj+guKDWVXh0rTPYYL/K5nabNQ6RYYhU+sRd56EkEY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EXmOL9ou; 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="EXmOL9ou" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2EFBC2BCB3; Tue, 28 Apr 2026 20:44:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409089; bh=7qKHzCadzgEQAQzNVqCf6fre80BxdReFv76mDf7/IKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EXmOL9ou5pb28Qr8PTiAefwZfwy88snUIzJS8rYsQHY0Zl+Z0b3Jh5GOP8TO2lVSV pEvW97yjRJoPizvGmLDImbmW4ewcXa8F33xnWt7pyp5cuXmKanuTgK9L/Wd+5jq5Ju TiA4/T9qHWfLhPNQCjNb0gNwENQ1ftUsC91Ky9NonciIwfyoHgSjQbcWvTjmqVRgZJ k6FYkUKxvk0QQUUzA1yQmggAkvy3ty2U1sVv9Q2p0CT2BuyQzwr91/41QjC3lbMnXA Lnxv5JQhLdeXJZk7DABLvQ1y0vpjuXSWAK/NAE7w+sa9D5FRdGm8XmCY5u9MCRE9iH U6NlWwOIJ4PEA== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 18/54] selftests/mm: uffd-stress: use kselftest framework Date: Tue, 28 Apr 2026 23:42:04 +0300 Message-ID: <20260428204240.1924129-19-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Convert uffd-stress test to use kselftest framework for reporting and tracking successful and failing runs. Reviewed-by: Mark Brown Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/uffd-stress.c | 41 +++++++++++------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selft= ests/mm/uffd-stress.c index 700fbaa18d44..e92a85463eb1 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -286,19 +286,12 @@ static int userfaultfd_stress(uffd_global_test_opts_t= *gopts) pthread_attr_setstacksize(&attr, 16*1024*1024); =20 while (bounces--) { - printf("bounces: %d, mode:", bounces); - if (bounces & BOUNCE_RANDOM) - printf(" rnd"); - if (bounces & BOUNCE_RACINGFAULTS) - printf(" racing"); - if (bounces & BOUNCE_VERIFY) - printf(" ver"); - if (bounces & BOUNCE_POLL) - printf(" poll"); - else - printf(" read"); - printf(", "); - fflush(stdout); + ksft_print_msg("bounces: %d, mode:%s%s%s%s, ", + bounces, + bounces & BOUNCE_RANDOM ? " rnd" : "", + bounces & BOUNCE_RACINGFAULTS ? " racing" : "", + bounces & BOUNCE_VERIFY ? " ver" : "", + bounces & BOUNCE_POLL ? " poll" : " read"); =20 if (bounces & BOUNCE_POLL) fcntl(gopts->uffd, F_SETFL, gopts->uffd_flags | O_NONBLOCK); @@ -456,6 +449,9 @@ int main(int argc, char **argv) unsigned long nr_cpus; size_t bytes; =20 + ksft_print_header(); + ksft_set_plan(1); + gopts =3D (uffd_global_test_opts_t *) malloc(sizeof(uffd_global_test_opts= _t)); =20 if (argc < 4) @@ -484,10 +480,8 @@ int main(int argc, char **argv) * for racy extra reservation of hugepages. */ if (gopts->test_type =3D=3D TEST_HUGETLB && - get_free_hugepages() < 2 * (bytes / gopts->page_size) + gopts->nr_para= llel - 1) { - printf("skip: Skipping userfaultfd... not enough hugepages\n"); - return KSFT_SKIP; - } + get_free_hugepages() < 2 * (bytes / gopts->page_size) + gopts->nr_para= llel - 1) + ksft_exit_skip("Skipping userfaultfd... not enough hugepages\n"); =20 gopts->nr_pages_per_cpu =3D bytes / gopts->page_size / gopts->nr_parallel; if (!gopts->nr_pages_per_cpu) { @@ -503,9 +497,12 @@ int main(int argc, char **argv) } gopts->nr_pages =3D gopts->nr_pages_per_cpu * gopts->nr_parallel; =20 - printf("nr_pages: %lu, nr_pages_per_cpu: %lu\n", - gopts->nr_pages, gopts->nr_pages_per_cpu); - return userfaultfd_stress(gopts); + ksft_print_msg("nr_pages: %lu, nr_pages_per_cpu: %lu\n", + gopts->nr_pages, gopts->nr_pages_per_cpu); + + ksft_test_result(!userfaultfd_stress(gopts), + "uffd-stress %s\n", argv[1]); + ksft_finished(); } =20 #else /* __NR_userfaultfd */ @@ -514,8 +511,8 @@ int main(int argc, char **argv) =20 int main(void) { - printf("skip: Skipping userfaultfd test (missing __NR_userfaultfd)\n"); - return KSFT_SKIP; + ksft_print_header(); + ksft_exit_skip("missing __NR_userfaultfd definition\n"); } =20 #endif /* __NR_userfaultfd */ --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 C22CE332EA0; Tue, 28 Apr 2026 20:44:56 +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=1777409096; cv=none; b=gF1CphcgaiC8SEA/VECTeeWfYaONKDvmxx1p5Yh0y18Oo8cbboe7e+Lg2oO3HlME0Wp6+lUWZTUqHn6UuvAu6FjqbBvpe8C1WDDrzHetbSFXw8/M69/9qAkrtTjRlDkY+4hlGuPQ8qf9eVna2kgviwe8wKzPoOul5biMxmNEC4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409096; c=relaxed/simple; bh=/VHYsNQ9mu4gXMtGoRr+26k5iHfnClRvZmbB31xolG4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F4EDXaGcbeVjb7QuBb3eoShA4pmiVsgxA0rLGQY759HT7oDPZw6mpWwGvBEJosddtXN0AAvx6b4s9MpFkcuIn3zt39hetHLFEV2Bkkdg34eJl7eYOIcKbNDAb+/FsqdFHzD6E4NG0eGTze/104VtU2WOMeA1ZaptZTyqDmJPILg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qwT0gCvv; 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="qwT0gCvv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B217C2BCAF; Tue, 28 Apr 2026 20:44:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409096; bh=/VHYsNQ9mu4gXMtGoRr+26k5iHfnClRvZmbB31xolG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qwT0gCvvMjOaBS8YabVlq3OHeNm/YlUpXm0dEeuGiuiSqiAexEePOfSHcvgZ2sBwr DIyQCgiDlQWOhId1P0q85ZdNOyExDIseXnptwi6k7vPuQwqaQFlHUVDdBuTuWdOkrh 1CqcHgcz3kEVidEEZ7gQdjGPZxEWIhb562Z3z8NnuXpcRYzBdQ4dvkVBk3SA2KIpjm NW9BnEWKC88l30mDHw6ziArdYDUyIkiGAxOil9cbMxhNbs047Cl/KRhVY+OtYBwjqw aSO4XL6a1YrvtcHMgozdNT9orcoTZHe2Mxl153/c/RSIIvea0H78jznr2wizySp7Op 13ab7tzEm6sew== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 19/54] selftests/mm: uffd-unit-tests: use kselftest framework Date: Tue, 28 Apr 2026 23:42:05 +0300 Message-ID: <20260428204240.1924129-20-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Convert uffd-unit-tests to use kselftest framework for reporting and tracking successful and failing runs. Reviewed by: Donet Tom Reviewed-by: Mark Brown Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/uffd-unit-tests.c | 79 +++++++++++--------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/s= elftests/mm/uffd-unit-tests.c index 6f5e404a446c..1a33db281f8a 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -86,39 +86,24 @@ typedef struct { uffd_test_case_ops_t *test_case_ops; } uffd_test_case_t; =20 -static void uffd_test_report(void) -{ - printf("Userfaults unit tests: pass=3D%u, skip=3D%u, fail=3D%u (total=3D%= u)\n", - ksft_get_pass_cnt(), - ksft_get_xskip_cnt(), - ksft_get_fail_cnt(), - ksft_test_num()); -} +static char current_test[256]; =20 static void uffd_test_pass(void) { - printf("done\n"); - ksft_inc_pass_cnt(); + ksft_test_result_pass("%s\n", current_test); } =20 #define uffd_test_start(...) do { \ - printf("Testing "); \ - printf(__VA_ARGS__); \ - printf("... "); \ - fflush(stdout); \ + snprintf(current_test, sizeof(current_test), __VA_ARGS__); \ } while (0) =20 #define uffd_test_fail(...) do { \ - printf("failed [reason: "); \ - printf(__VA_ARGS__); \ - printf("]\n"); \ - ksft_inc_fail_cnt(); \ + ksft_test_result_fail("%s\n", current_test); \ } while (0) =20 static void uffd_test_skip(const char *message) { - printf("skipped [reason: %s]\n", message); - ksft_inc_xskip_cnt(); + ksft_test_result_skip("%s (%s)\n", current_test, message); } =20 /* @@ -1701,6 +1686,26 @@ static void usage(const char *prog) exit(KSFT_FAIL); } =20 +static int uffd_count_tests(int n_tests, int n_mems, const char *test_filt= er) +{ + uffd_test_case_t *test; + int i, j, count =3D 0; + + if (!test_filter) + count +=3D 2; /* test_uffd_api(false) + test_uffd_api(true) */ + + for (i =3D 0; i < n_tests; i++) { + test =3D &uffd_tests[i]; + if (test_filter && !strstr(test->name, test_filter)) + continue; + for (j =3D 0; j < n_mems; j++) + if (test->mem_targets & mem_types[j].mem_flag) + count++; + } + + return count; +} + int main(int argc, char *argv[]) { int n_tests =3D sizeof(uffd_tests) / sizeof(uffd_test_case_t); @@ -1730,24 +1735,31 @@ int main(int argc, char *argv[]) } } =20 - if (!test_filter && !list_only) { + if (list_only) { + for (i =3D 0; i < n_tests; i++) { + test =3D &uffd_tests[i]; + if (test_filter && !strstr(test->name, test_filter)) + continue; + printf("%s\n", test->name); + } + return KSFT_PASS; + } + + ksft_print_header(); + ksft_set_plan(uffd_count_tests(n_tests, n_mems, test_filter)); + + if (!test_filter) { has_uffd =3D test_uffd_api(false); has_uffd |=3D test_uffd_api(true); =20 - if (!has_uffd) { - printf("Userfaultfd not supported or unprivileged, skip all tests\n"); - exit(KSFT_SKIP); - } + if (!has_uffd) + ksft_exit_skip("Userfaultfd not supported or unprivileged\n"); } =20 for (i =3D 0; i < n_tests; i++) { test =3D &uffd_tests[i]; if (test_filter && !strstr(test->name, test_filter)) continue; - if (list_only) { - printf("%s\n", test->name); - continue; - } for (j =3D 0; j < n_mems; j++) { mem_type =3D &mem_types[j]; =20 @@ -1794,10 +1806,7 @@ int main(int argc, char *argv[]) } } =20 - if (!list_only) - uffd_test_report(); - - return ksft_get_fail_cnt() ? KSFT_FAIL : KSFT_PASS; + ksft_finished(); } =20 #else /* __NR_userfaultfd */ @@ -1806,8 +1815,8 @@ int main(int argc, char *argv[]) =20 int main(void) { - printf("Skipping %s (missing __NR_userfaultfd)\n", __file__); - return KSFT_SKIP; + ksft_print_header(); + ksft_exit_skip("missing __NR_userfaultfd definition\n"); } =20 #endif /* __NR_userfaultfd */ --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 A7CE81FFC48; Tue, 28 Apr 2026 20:45:03 +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=1777409103; cv=none; b=Kg5CF3dC46AaP6R1uGGQcwbdEI8B3Fhvikra+D7Coexz4DoAG+CQ5duhIz+muXDSvlPJksaTgnqOlyFNXB7VXOKaadDtXXRYYT3JCUxHvIPXQjjTRGjp0fZsTFdQRmCL0c+xY9G1hKTU2zksiBLK2CgxGfA0AN5wcfHWQtZ8CEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409103; c=relaxed/simple; bh=pVenT6kXm2JiaCrXk0cfnUIIgxC+0Du4A0hv+H/HwsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DD1IhyYkXrZDALRFYD9xNND51+aQXWf/GcWNYbTNUsQNPxPiO0bWDsI+ml3g/TdxtvLVaYDYhQvgUHUd8YoX4xzeQ58Z4W0qI69dnmhNtjLTK3k+0/Apd1iF3S2/jN04BysgcLMuJvBaOXNRa7zyPJdISZD37Suyy45YtiW6Vcg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P65sTN5s; 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="P65sTN5s" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF202C2BCB3; Tue, 28 Apr 2026 20:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409103; bh=pVenT6kXm2JiaCrXk0cfnUIIgxC+0Du4A0hv+H/HwsY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P65sTN5sY8cpNcym7Tn18YC9GdenJ1QnEX9IZQF/c5NzKm3q+04G6pvsebbX4IJdM /znXgnc76JesXrwbhtSspUSRRUsYL0wtEU1uigCpLhQ6iPg4kMu2xLT8PvlQF10icO bz9mo4hxqfY+LrBKfV4YsZ+a4jQzoXgkr17S+QlSzS1Iwz/Y7az8DpXKJYYTL2l2/S 5Iez7jBaO5wLedg5qp6sV/+IZjac+tZ7w7NRQJaI/nhiw+H4a+aGB1DdN1QUmMbEFu jcwNML8zL9BWdJiSS+lbT9sJyMJacqYuHmWDWeaN8qctOIRZkyrXj77MQdqdEo2l/Z S3rDeXfgRfcZw== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 20/54] selftests/mm: va_high_addr_switch: use kselftest framework Date: Tue, 28 Apr 2026 23:42:06 +0300 Message-ID: <20260428204240.1924129-21-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Convert va_high_addr_switch test to use kselftest framework for reporting and tracking successful and failing runs. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Luiz Capitulino Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- .../selftests/mm/va_high_addr_switch.c | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/tools/testing/selftests/mm/va_high_addr_switch.c b/tools/testi= ng/selftests/mm/va_high_addr_switch.c index 51401e081b20..5d38735ea60e 100644 --- a/tools/testing/selftests/mm/va_high_addr_switch.c +++ b/tools/testing/selftests/mm/va_high_addr_switch.c @@ -257,40 +257,35 @@ void testcases_init(void) switch_hint =3D addr_switch_hint; } =20 -static int run_test(struct testcase *test, int count) +static void run_test(struct testcase *test, int count) { void *p; - int i, ret =3D KSFT_PASS; + int i; =20 for (i =3D 0; i < count; i++) { struct testcase *t =3D test + i; =20 p =3D mmap(t->addr, t->size, PROT_READ | PROT_WRITE, t->flags, -1, 0); - - printf("%s: %p - ", t->msg, p); - if (p =3D=3D MAP_FAILED) { - printf("FAILED\n"); - ret =3D KSFT_FAIL; + ksft_perror("MAP_FAILED"); + ksft_test_result_fail("%s\n", t->msg); continue; } =20 if (t->low_addr_required && p >=3D (void *)(switch_hint)) { - printf("FAILED\n"); - ret =3D KSFT_FAIL; + ksft_print_msg("%p not below switch hint\n", p); + ksft_test_result_fail("%s\n", t->msg); } else { /* * Do a dereference of the address returned so that we catch * bugs in page fault handling */ memset(p, 0, t->size); - printf("OK\n"); + ksft_test_result_pass("%s\n", t->msg); } if (!t->keep_mapped) munmap(p, t->size); } - - return ret; } =20 #ifdef __aarch64__ @@ -322,19 +317,23 @@ static int supported_arch(void) =20 int main(int argc, char **argv) { - int ret, hugetlb_ret =3D KSFT_PASS; + bool run_hugetlb =3D false; + + ksft_print_header(); =20 if (!supported_arch()) - return KSFT_SKIP; + ksft_exit_skip("Architecture not supported\n"); + + if (argc =3D=3D 2 && !strcmp(argv[1], "--run-hugetlb")) + run_hugetlb =3D true; =20 testcases_init(); =20 - ret =3D run_test(testcases, sz_testcases); - if (argc =3D=3D 2 && !strcmp(argv[1], "--run-hugetlb")) - hugetlb_ret =3D run_test(hugetlb_testcases, sz_hugetlb_testcases); + ksft_set_plan(sz_testcases + (run_hugetlb ? sz_hugetlb_testcases : 0)); + + run_test(testcases, sz_testcases); + if (run_hugetlb) + run_test(hugetlb_testcases, sz_hugetlb_testcases); =20 - if (ret =3D=3D KSFT_PASS && hugetlb_ret =3D=3D KSFT_PASS) - return KSFT_PASS; - else - return KSFT_FAIL; + ksft_finished(); } --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 D774C1FFC48; Tue, 28 Apr 2026 20:45:09 +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=1777409109; cv=none; b=AtToaancUJFYbsBF7lPB/fDUoYVt9D6T0ggFbW9qeAtcH1prisnsiKBiIcmwU2JUTXbIa+UrV5MoE4oahptn6Lt2nGvG9fdIz12I037xVo95Xbzl1KwqMcTkkMusnUN9YndmVEt6CNcMwm1qEuoN1+tLqtNooPzxIAWOK1tyCt8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409109; c=relaxed/simple; bh=gVU+NxBS58ndkAl4KdeNWT7uSAZiwRivKfRFLz7HiUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jXCyiR3i9FGll4zDvwzAARlgCdpglaIbBPdE8qj2zH1pTuW+6qSNINl61FJ7wuZG8nVT/5GZi+AHdVRTnR2RkyUKG5T8sd5tXuyXNEY8EFDgYWswgnf5GFbQxXDi7VDIEaFQZ22Z3E9oqpyxeYoS+5sIzyKGnXk3vmYGCBCV/Sw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nitaGYyg; 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="nitaGYyg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ABACFC2BCAF; Tue, 28 Apr 2026 20:45:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409109; bh=gVU+NxBS58ndkAl4KdeNWT7uSAZiwRivKfRFLz7HiUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nitaGYyggSlLWsIVkpEsoRkkTis2eaPVf9ZfYRijDkozg64rpFStEVydukPk21Zlu Qw34ZYsAvetVYaLuB9sLrAep8WNmRplx0USdAHSy6ymmd9nN9VyELgmveo+EtFZNvR xxMsaFAxLZ6JluCihJ6hM7KuxjpNDlPwBHXEYRrpvUBendqWrfRNrAK/jSM0mOgcLw RTfrwIK82UjcD7FTHqtBLDyLGCW39/TpsZIBDYbcjDveRYfUAZEAGs9icb6Cejsse1 GYUaR7AkWyzYO/UItvFjauGu4tLeKMIAH2Aq/Fen7KAsouItEEiFDL5CjS6fysgf1z NG8icHfoXfmOA== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 21/54] selftests/mm: add atexit() and signal handlers to thp_settings Date: Tue, 28 Apr 2026 23:42:07 +0300 Message-ID: <20260428204240.1924129-22-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" khugepaged registers atexit() and signal handlers that ensure that THP settings are restored regardless of how the test exited. Make these handlers available for all users of thp_settings. The call to thp_save_settings() installs thp_restore_settings as the atexit() callback and makes sure that signals that kill a process would still call exit() and atexit() callback. Update child process in tests using thp_settings to use _exit() instead of exit() to avoid altering THP settings in the middle of a test. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/cow.c | 21 +++++------ tools/testing/selftests/mm/khugepaged.c | 40 +++------------------ tools/testing/selftests/mm/thp_settings.c | 28 ++++++++++++++- tools/testing/selftests/mm/uffd-wp-mremap.c | 4 --- 4 files changed, 39 insertions(+), 54 deletions(-) diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/= cow.c index d9c69c04b67d..6abdcb30aba8 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -202,7 +202,7 @@ static void do_test_cow_in_parent(char *mem, size_t siz= e, bool do_mprotect, log_test_result(KSFT_FAIL); goto close_comm_pipes; } else if (!ret) { - exit(fn(mem, size, &comm_pipes)); + _exit(fn(mem, size, &comm_pipes)); } =20 while (read(comm_pipes.child_ready[0], &buf, 1) !=3D 1) @@ -333,7 +333,7 @@ static void do_test_vmsplice_in_parent(char *mem, size_= t size, ; /* Modify page content in the child. */ memset(mem, 0xff, size); - exit(0); + _exit(0); } =20 if (!before_fork) { @@ -480,7 +480,7 @@ static void do_test_iouring(char *mem, size_t size, boo= l use_fork) write(comm_pipes.child_ready[1], "0", 1); while (read(comm_pipes.parent_ready[0], &buf, 1) !=3D 1) ; - exit(0); + _exit(0); } =20 while (read(comm_pipes.child_ready[0], &buf, 1) !=3D 1) @@ -645,7 +645,7 @@ static void do_test_ro_pin(char *mem, size_t size, enum= ro_pin_test test, write(comm_pipes.child_ready[1], "0", 1); while (read(comm_pipes.parent_ready[0], &buf, 1) !=3D 1) ; - exit(0); + _exit(0); } =20 /* Wait until our child is ready. */ @@ -956,7 +956,7 @@ static void do_run_with_thp(test_fn fn, enum thp_run th= p_run, size_t thpsize) log_test_result(KSFT_FAIL); goto munmap; } else if (!ret) { - exit(0); + _exit(0); } wait(&ret); /* Allow for sharing all pages again. */ @@ -1347,13 +1347,13 @@ static void do_test_anon_thp_collapse(char *mem, si= ze_t size, switch (test) { case ANON_THP_COLLAPSE_UNSHARED: case ANON_THP_COLLAPSE_FULLY_SHARED: - exit(child_memcmp_fn(mem, size, &comm_pipes)); + _exit(child_memcmp_fn(mem, size, &comm_pipes)); break; case ANON_THP_COLLAPSE_LOWER_SHARED: - exit(child_memcmp_fn(mem, size / 2, &comm_pipes)); + _exit(child_memcmp_fn(mem, size / 2, &comm_pipes)); break; case ANON_THP_COLLAPSE_UPPER_SHARED: - exit(child_memcmp_fn(mem + size / 2, size / 2, + _exit(child_memcmp_fn(mem + size / 2, size / 2, &comm_pipes)); break; default: @@ -1911,10 +1911,5 @@ int main(int argc, char **argv) run_anon_thp_test_cases(); run_non_anon_test_cases(); =20 - if (pmdsize) { - /* Only if THP is supported. */ - thp_restore_settings(); - } - ksft_finished(); } diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selfte= sts/mm/khugepaged.c index 2f0baa2321ca..ef3b6464ff3f 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -72,7 +72,6 @@ struct file_info { }; =20 static struct file_info finfo; -static bool skip_settings_restore; static int exit_status; =20 static void success(const char *msg) @@ -92,25 +91,6 @@ static void skip(const char *msg) exit_status =3D KSFT_SKIP; } =20 -static void restore_settings_atexit(void) -{ - if (skip_settings_restore) - return; - - ksft_print_msg("Restore THP and khugepaged settings..."); - thp_restore_settings(); - success("OK"); - - skip_settings_restore =3D true; - ksft_finished(); -} - -static void restore_settings(int sig) -{ - /* exit() will invoke the restore_settings_atexit handler. */ - exit(sig ? KSFT_FAIL : exit_status); -} - static void save_settings(void) { ksft_print_msg("Save THP and khugepaged settings..."); @@ -119,12 +99,6 @@ static void save_settings(void) thp_save_settings(); =20 success("OK"); - - atexit(restore_settings_atexit); - signal(SIGTERM, restore_settings); - signal(SIGINT, restore_settings); - signal(SIGHUP, restore_settings); - signal(SIGQUIT, restore_settings); } =20 static void get_finfo(const char *dir) @@ -844,8 +818,6 @@ static void collapse_fork(struct collapse_context *c, s= truct mem_ops *ops) ksft_print_msg("Share small page over fork()..."); if (!fork()) { /* Do not touch settings on child exit */ - skip_settings_restore =3D true; - if (ops->check_huge(p, 0)) success("OK"); else @@ -857,7 +829,7 @@ static void collapse_fork(struct collapse_context *c, s= truct mem_ops *ops) =20 validate_memory(p, 0, page_size); ops->cleanup_area(p, hpage_pmd_size); - exit(exit_status); + _exit(exit_status); } =20 wait(&wstatus); @@ -882,8 +854,6 @@ static void collapse_fork_compound(struct collapse_cont= ext *c, struct mem_ops *o ksft_print_msg("Share huge page over fork()..."); if (!fork()) { /* Do not touch settings on child exit */ - skip_settings_restore =3D true; - if (ops->check_huge(p, 1)) success("OK"); else @@ -906,7 +876,7 @@ static void collapse_fork_compound(struct collapse_cont= ext *c, struct mem_ops *o =20 validate_memory(p, 0, hpage_pmd_size); ops->cleanup_area(p, hpage_pmd_size); - exit(exit_status); + _exit(exit_status); } =20 wait(&wstatus); @@ -932,8 +902,6 @@ static void collapse_max_ptes_shared(struct collapse_co= ntext *c, struct mem_ops ksft_print_msg("Share huge page over fork()..."); if (!fork()) { /* Do not touch settings on child exit */ - skip_settings_restore =3D true; - if (ops->check_huge(p, 1)) success("OK"); else @@ -966,7 +934,7 @@ static void collapse_max_ptes_shared(struct collapse_co= ntext *c, struct mem_ops =20 validate_memory(p, 0, hpage_pmd_size); ops->cleanup_area(p, hpage_pmd_size); - exit(exit_status); + _exit(exit_status); } =20 wait(&wstatus); @@ -1260,5 +1228,5 @@ int main(int argc, char **argv) t->fn(t->ctx, t->ops); } =20 - restore_settings(0); + ksft_finished(); } diff --git a/tools/testing/selftests/mm/thp_settings.c b/tools/testing/self= tests/mm/thp_settings.c index e748ebfb3d4e..f38ba8a27b30 100644 --- a/tools/testing/selftests/mm/thp_settings.c +++ b/tools/testing/selftests/mm/thp_settings.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include #include @@ -15,6 +16,7 @@ static struct thp_settings settings_stack[MAX_SETTINGS_DE= PTH]; static int settings_index; static struct thp_settings saved_settings; static char dev_queue_read_ahead_path[PATH_MAX]; +static bool thp_settings_saved; =20 static const char * const thp_enabled_strings[] =3D { "never", @@ -298,12 +300,36 @@ void thp_pop_settings(void) =20 void thp_restore_settings(void) { - thp_write_settings(&saved_settings); + if (thp_settings_saved) + thp_write_settings(&saved_settings); +} + +static void thp_restore_settings_atexit(void) +{ + thp_restore_settings(); +} + +static void thp_restore_settings_sighandler(int sig) +{ + /* exit() will invoke the thp_restore_settings_atexit handler. */ + exit(KSFT_FAIL); } =20 void thp_save_settings(void) { thp_read_settings(&saved_settings); + + /* + * setup exit hooks to make sure THP settings are restored on graceful + * and error exits and signals + */ + atexit(thp_restore_settings_atexit); + signal(SIGTERM, thp_restore_settings_sighandler); + signal(SIGINT, thp_restore_settings_sighandler); + signal(SIGHUP, thp_restore_settings_sighandler); + signal(SIGQUIT, thp_restore_settings_sighandler); + + thp_settings_saved =3D true; } =20 void thp_set_read_ahead_path(char *path) diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/se= lftests/mm/uffd-wp-mremap.c index 17186d4a4147..516c35d236e1 100644 --- a/tools/testing/selftests/mm/uffd-wp-mremap.c +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c @@ -368,10 +368,6 @@ int main(int argc, char **argv) tc->swapout, tc->hugetlb); } =20 - /* If THP is supported, restore original THP settings. */ - if (nr_thpsizes) - thp_restore_settings(); - i =3D ksft_get_fail_cnt(); if (i) ksft_exit_fail_msg("%d out of %d tests failed\n", --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 8946D29B20A; Tue, 28 Apr 2026 20:45:16 +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=1777409116; cv=none; b=F91O4EkYPMUJ91kLvnYaRn4Q0wvdjBUh/A8ZkarQqufgWDH1xZqLN+XD4/eDs8Y7qJCyWq6yR44IcCdO9PxtJL79+gdJbOIHNJua6rXn8+Xw6jEK/2I7bRposzPQesvm/STF2Iolj3c8V8zuS3uJOVv5yRK0NG4EfFHjjgYdjhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409116; c=relaxed/simple; bh=yl3DcYUkZRaQ+ub527Rq2rXetVK21fIqVTn3MxdOY9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tKfRp9TCkbYwYWDBt60+cjK0lAljGSfuoDIMz0Lew8/tLbSc85oB/yd6PJKjl6z6Y+cVvWIBPtsfuDnyjucRh76QxG/961rGkAF0EreT99RTuwybb429uPfnwhxWY4FjkysYmAAYYQh1V845Rzbvh59cCWcWF2zyPRvY+Vp8+N4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FIabE277; 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="FIabE277" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43E26C2BCAF; Tue, 28 Apr 2026 20:45:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409116; bh=yl3DcYUkZRaQ+ub527Rq2rXetVK21fIqVTn3MxdOY9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FIabE277dGFIjWcvHSAVIpZbuctjYJFAbzAIaEigMZxuR3ljO7MZoCjpMjhS1g7EQ SV3Sm+KvI6HooC/VafcbPTWNRzpRkyLosLeOi5pXjbWJIwv5sbZxkKXlouIDTCvF6x 4vNz5GYHJIBMYWvIuoVJCGzqb0k9yjuc+UEFTPZwGIDCHLg1U6X4p9bihlgABpvLvM TsmU5nv2hfgRXyeMd6Do4BA3JPJ3deD2A7EexpcnYjLHbmXVQtmYJHQmPbcmFovwJq 5XgEKo6VZBYmffm2rKJePrVLD561D13IdFLAboj5lcCyxZdBsdpCBH0XfvWINjAYVz hdRM/w3fxxodg== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 22/54] selftests/mm: rename thp_settings.[ch] to hugepage_settings.[ch] Date: Tue, 28 Apr 2026 23:42:08 +0300 Message-ID: <20260428204240.1924129-23-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" ... for upcoming addition of HugeTLB helpers. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Sarthak Sharma Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/Makefile | 4 ++-- tools/testing/selftests/mm/cow.c | 2 +- tools/testing/selftests/mm/folio_split_race_test.c | 2 +- tools/testing/selftests/mm/guard-regions.c | 2 +- .../selftests/mm/{thp_settings.c =3D> hugepage_settings.c} | 2 +- .../selftests/mm/{thp_settings.h =3D> hugepage_settings.h} | 0 tools/testing/selftests/mm/khugepaged.c | 2 +- tools/testing/selftests/mm/ksm_tests.c | 2 +- tools/testing/selftests/mm/migration.c | 2 +- tools/testing/selftests/mm/prctl_thp_disable.c | 2 +- tools/testing/selftests/mm/soft-dirty.c | 2 +- tools/testing/selftests/mm/split_huge_page_test.c | 2 +- tools/testing/selftests/mm/transhuge-stress.c | 2 +- tools/testing/selftests/mm/uffd-wp-mremap.c | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) rename tools/testing/selftests/mm/{thp_settings.c =3D> hugepage_settings.c= } (99%) rename tools/testing/selftests/mm/{thp_settings.h =3D> hugepage_settings.h= } (100%) diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/= mm/Makefile index a6955660a806..a1d103b38485 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -186,8 +186,8 @@ TEST_FILES +=3D write_hugetlb_memory.sh =20 include ../lib.mk =20 -$(TEST_GEN_PROGS): vm_util.c thp_settings.c -$(TEST_GEN_FILES): vm_util.c thp_settings.c +$(TEST_GEN_PROGS): vm_util.c hugepage_settings.c +$(TEST_GEN_FILES): vm_util.c hugepage_settings.c =20 $(OUTPUT)/uffd-stress: uffd-common.c $(OUTPUT)/uffd-unit-tests: uffd-common.c diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/= cow.c index 6abdcb30aba8..4321f4208fe3 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -29,7 +29,7 @@ #include "../../../../mm/gup_test.h" #include "kselftest.h" #include "vm_util.h" -#include "thp_settings.h" +#include "hugepage_settings.h" =20 static size_t pagesize; static int pagemap_fd; diff --git a/tools/testing/selftests/mm/folio_split_race_test.c b/tools/tes= ting/selftests/mm/folio_split_race_test.c index ff026f183ac7..7ede4793c778 100644 --- a/tools/testing/selftests/mm/folio_split_race_test.c +++ b/tools/testing/selftests/mm/folio_split_race_test.c @@ -25,7 +25,7 @@ #include #include "vm_util.h" #include "kselftest.h" -#include "thp_settings.h" +#include "hugepage_settings.h" =20 uint64_t page_size; uint64_t pmd_pagesize; diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/sel= ftests/mm/guard-regions.c index 48e8b1539be3..feb50b415f52 100644 --- a/tools/testing/selftests/mm/guard-regions.c +++ b/tools/testing/selftests/mm/guard-regions.c @@ -21,7 +21,7 @@ #include #include #include "vm_util.h" -#include "thp_settings.h" +#include "hugepage_settings.h" =20 #include "../pidfd/pidfd.h" =20 diff --git a/tools/testing/selftests/mm/thp_settings.c b/tools/testing/self= tests/mm/hugepage_settings.c similarity index 99% rename from tools/testing/selftests/mm/thp_settings.c rename to tools/testing/selftests/mm/hugepage_settings.c index f38ba8a27b30..87ecb309b430 100644 --- a/tools/testing/selftests/mm/thp_settings.c +++ b/tools/testing/selftests/mm/hugepage_settings.c @@ -8,7 +8,7 @@ #include =20 #include "vm_util.h" -#include "thp_settings.h" +#include "hugepage_settings.h" =20 #define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/" #define MAX_SETTINGS_DEPTH 4 diff --git a/tools/testing/selftests/mm/thp_settings.h b/tools/testing/self= tests/mm/hugepage_settings.h similarity index 100% rename from tools/testing/selftests/mm/thp_settings.h rename to tools/testing/selftests/mm/hugepage_settings.h diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selfte= sts/mm/khugepaged.c index ef3b6464ff3f..7563d7600ce7 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -22,7 +22,7 @@ #include "linux/magic.h" =20 #include "vm_util.h" -#include "thp_settings.h" +#include "hugepage_settings.h" =20 #define BASE_ADDR ((void *)(1UL << 30)) static unsigned long hpage_pmd_size; diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftes= ts/mm/ksm_tests.c index 752a2c0d06ab..fb355f869401 100644 --- a/tools/testing/selftests/mm/ksm_tests.c +++ b/tools/testing/selftests/mm/ksm_tests.c @@ -15,7 +15,7 @@ #include "kselftest.h" #include #include "vm_util.h" -#include "thp_settings.h" +#include "hugepage_settings.h" =20 #define KSM_SYSFS_PATH "/sys/kernel/mm/ksm/" #define KSM_FP(s) (KSM_SYSFS_PATH s) diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftes= ts/mm/migration.c index 76e380b74658..0212cd5bde6e 100644 --- a/tools/testing/selftests/mm/migration.c +++ b/tools/testing/selftests/mm/migration.c @@ -5,7 +5,7 @@ */ =20 #include "kselftest_harness.h" -#include "thp_settings.h" +#include "hugepage_settings.h" =20 #include #include diff --git a/tools/testing/selftests/mm/prctl_thp_disable.c b/tools/testing= /selftests/mm/prctl_thp_disable.c index ca27200596a4..d8d9d1de57b8 100644 --- a/tools/testing/selftests/mm/prctl_thp_disable.c +++ b/tools/testing/selftests/mm/prctl_thp_disable.c @@ -14,7 +14,7 @@ #include =20 #include "kselftest_harness.h" -#include "thp_settings.h" +#include "hugepage_settings.h" #include "vm_util.h" =20 #ifndef PR_THP_DISABLE_EXCEPT_ADVISED diff --git a/tools/testing/selftests/mm/soft-dirty.c b/tools/testing/selfte= sts/mm/soft-dirty.c index bcfcac99b436..c426c4636ef5 100644 --- a/tools/testing/selftests/mm/soft-dirty.c +++ b/tools/testing/selftests/mm/soft-dirty.c @@ -9,7 +9,7 @@ =20 #include "kselftest.h" #include "vm_util.h" -#include "thp_settings.h" +#include "hugepage_settings.h" =20 #define PAGEMAP_FILE_PATH "/proc/self/pagemap" #define TEST_ITERATIONS 10000 diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/test= ing/selftests/mm/split_huge_page_test.c index 500d07c4938b..cc99294bdd5a 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -21,7 +21,7 @@ #include #include "vm_util.h" #include "kselftest.h" -#include "thp_settings.h" +#include "hugepage_settings.h" =20 uint64_t pagesize; unsigned int pageshift; diff --git a/tools/testing/selftests/mm/transhuge-stress.c b/tools/testing/= selftests/mm/transhuge-stress.c index 7a9f1035099b..8eb0c5630e7e 100644 --- a/tools/testing/selftests/mm/transhuge-stress.c +++ b/tools/testing/selftests/mm/transhuge-stress.c @@ -17,7 +17,7 @@ #include #include "vm_util.h" #include "kselftest.h" -#include "thp_settings.h" +#include "hugepage_settings.h" =20 int backing_fd =3D -1; int mmap_flags =3D MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE; diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/se= lftests/mm/uffd-wp-mremap.c index 516c35d236e1..9d67b11c2f28 100644 --- a/tools/testing/selftests/mm/uffd-wp-mremap.c +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c @@ -8,7 +8,7 @@ #include #include #include "kselftest.h" -#include "thp_settings.h" +#include "hugepage_settings.h" #include "uffd-common.h" =20 static int pagemap_fd; --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 42B492F49FD; Tue, 28 Apr 2026 20:45:23 +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=1777409123; cv=none; b=RM45XZfG0Y0188tQlJZdhHis+ZLf4HDQeAySmfISaxNsqPm4KyabKlX+ZTa2qYf9dpTxusFoLDAy4HgpOGCDSez+tvRoSP2TiDcSjiH6G2HS4TDk+kM3pCbjLNWjyQT+KdZ2GSnYafbVC8WN4cbfSGW24+yq/ESPu9VGhKwb4cE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409123; c=relaxed/simple; bh=1kInTRxPtmsL3CGo2Vf9dpLuXJPc/YEBelMYPMeVdwg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KUvy/cDntboOW79Tg6hxKuhxqsWkdvlDPAUn0h3OBADYHZSim11wwu78p1nHN1ttUWK1ec82NBxE5TfFfO3v9zTG5MHJRnu1WzSmGbxFNDTkAai7JU1q6Va75mL9V9EMD73h5nSkWwsQIh7SyyIM/JvGaJLBj4oN4xg9rVbckNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PNXy3J1j; 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="PNXy3J1j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEE30C2BCB3; Tue, 28 Apr 2026 20:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409122; bh=1kInTRxPtmsL3CGo2Vf9dpLuXJPc/YEBelMYPMeVdwg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PNXy3J1j+d5x6Tr7wNZh2ACxXgkDf46Bcw7UUJT6SCpITo85qrz9S9ttIvSCbAvbD kuOgtUUAWDBi7o0LsVrfg3eaP6nXAqE4JF6O65EplRfEl+MDFxAQyLghHyqdN0MyLu QAOJXinFry9vMe98kZkgsXADq+85e4y0g5vH8e9Ku8LsMLL/05Y01v8O8g7WUEBgCG c+r/1czU/0fUw9zCxBc8cWqXx3Sp6AUg//bScWE+h0NviZeZJsk0KzuQyrXJ0PmyBb z6y+PsM/GLci/zeuyEXglqqHN0H40korranmbrt+L6IaWADAIZZriap/pXVxKi7mHH cTRE17LY6mcyw== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 23/54] selftests/mm: move HugeTLB helpers to hugepage_settings Date: Tue, 28 Apr 2026 23:42:09 +0300 Message-ID: <20260428204240.1924129-24-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Move library functions that abstract HugeTLB /proc and /sysfs access from vm_util to hugepage_settings. This will help creating common helpers that save and restore HugeTLB and THP settings. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Sarthak Sharma Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/gup_longterm.c | 1 + tools/testing/selftests/mm/hmm-tests.c | 2 +- .../testing/selftests/mm/hugepage_settings.c | 68 +++++++++++++++++++ .../testing/selftests/mm/hugepage_settings.h | 8 +++ tools/testing/selftests/mm/hugetlb-madvise.c | 1 + tools/testing/selftests/mm/hugetlb-mmap.c | 1 + tools/testing/selftests/mm/hugetlb-vmemmap.c | 1 + tools/testing/selftests/mm/hugetlb_dio.c | 1 + .../selftests/mm/hugetlb_fault_after_madv.c | 1 + .../selftests/mm/hugetlb_madv_vs_map.c | 1 + tools/testing/selftests/mm/thuge-gen.c | 1 + tools/testing/selftests/mm/uffd-common.h | 1 + .../selftests/mm/va_high_addr_switch.c | 1 + tools/testing/selftests/mm/vm_util.c | 66 ------------------ tools/testing/selftests/mm/vm_util.h | 3 - 15 files changed, 87 insertions(+), 70 deletions(-) diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/self= tests/mm/gup_longterm.c index f61150d28eb2..ab4eaf4feb7c 100644 --- a/tools/testing/selftests/mm/gup_longterm.c +++ b/tools/testing/selftests/mm/gup_longterm.c @@ -29,6 +29,7 @@ #include "../../../../mm/gup_test.h" #include "kselftest.h" #include "vm_util.h" +#include "hugepage_settings.h" =20 static size_t pagesize; static int nr_hugetlbsizes; diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftes= ts/mm/hmm-tests.c index 788689497e92..409b11cad4bc 100644 --- a/tools/testing/selftests/mm/hmm-tests.c +++ b/tools/testing/selftests/mm/hmm-tests.c @@ -11,6 +11,7 @@ */ =20 #include "kselftest_harness.h" +#include "hugepage_settings.h" =20 #include #include @@ -27,7 +28,6 @@ #include #include =20 - /* * This is a private UAPI to the kernel test module so it isn't exported * in the usual include/uapi/... directory. diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing= /selftests/mm/hugepage_settings.c index 87ecb309b430..ebaa621c45c6 100644 --- a/tools/testing/selftests/mm/hugepage_settings.c +++ b/tools/testing/selftests/mm/hugepage_settings.c @@ -1,7 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include #include +#include #include #include #include @@ -396,3 +398,69 @@ bool thp_is_enabled(void) /* THP is considered enabled if it's either "always" or "madvise" */ return mode =3D=3D 1 || mode =3D=3D 3; } + +int detect_hugetlb_page_sizes(size_t sizes[], int max) +{ + DIR *dir =3D opendir("/sys/kernel/mm/hugepages/"); + int count =3D 0; + + if (!dir) + return 0; + + while (count < max) { + struct dirent *entry =3D readdir(dir); + size_t kb; + + if (!entry) + break; + if (entry->d_type !=3D DT_DIR) + continue; + if (sscanf(entry->d_name, "hugepages-%zukB", &kb) !=3D 1) + continue; + sizes[count++] =3D kb * 1024; + ksft_print_msg("[INFO] detected hugetlb page size: %zu KiB\n", + kb); + } + closedir(dir); + return count; +} + +unsigned long default_huge_page_size(void) +{ + unsigned long hps =3D 0; + char *line =3D NULL; + size_t linelen =3D 0; + FILE *f =3D fopen("/proc/meminfo", "r"); + + if (!f) + return 0; + while (getline(&line, &linelen, f) > 0) { + if (sscanf(line, "Hugepagesize: %lu kB", &hps) =3D=3D 1) { + hps <<=3D 10; + break; + } + } + + free(line); + fclose(f); + return hps; +} + +unsigned long get_free_hugepages(void) +{ + unsigned long fhp =3D 0; + char *line =3D NULL; + size_t linelen =3D 0; + FILE *f =3D fopen("/proc/meminfo", "r"); + + if (!f) + return fhp; + while (getline(&line, &linelen, f) > 0) { + if (sscanf(line, "HugePages_Free: %lu", &fhp) =3D=3D 1) + break; + } + + free(line); + fclose(f); + return fhp; +} diff --git a/tools/testing/selftests/mm/hugepage_settings.h b/tools/testing= /selftests/mm/hugepage_settings.h index 7748a9009191..320b97e768e8 100644 --- a/tools/testing/selftests/mm/hugepage_settings.h +++ b/tools/testing/selftests/mm/hugepage_settings.h @@ -6,6 +6,8 @@ #include #include =20 +/* Transparent Huge Pages (THP) */ + enum thp_enabled { THP_NEVER, THP_ALWAYS, @@ -86,4 +88,10 @@ unsigned long thp_shmem_supported_orders(void); bool thp_available(void); bool thp_is_enabled(void); =20 +/* HugeTLB */ + +int detect_hugetlb_page_sizes(size_t sizes[], int max); +unsigned long default_huge_page_size(void); +unsigned long get_free_hugepages(void); + #endif /* __THP_SETTINGS_H__ */ diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/s= elftests/mm/hugetlb-madvise.c index 4c6c346a3af5..316384d919db 100644 --- a/tools/testing/selftests/mm/hugetlb-madvise.c +++ b/tools/testing/selftests/mm/hugetlb-madvise.c @@ -20,6 +20,7 @@ #include #include "vm_util.h" #include "kselftest.h" +#include "hugepage_settings.h" =20 #define MIN_FREE_PAGES 20 #define NR_HUGE_PAGES 10 /* common number of pages to map/allocate */ diff --git a/tools/testing/selftests/mm/hugetlb-mmap.c b/tools/testing/self= tests/mm/hugetlb-mmap.c index 9f5ea8d6d656..031085cb7d17 100644 --- a/tools/testing/selftests/mm/hugetlb-mmap.c +++ b/tools/testing/selftests/mm/hugetlb-mmap.c @@ -18,6 +18,7 @@ #include #include "vm_util.h" #include "kselftest.h" +#include "hugepage_settings.h" =20 #define LENGTH (256UL*1024*1024) #define PROTECTION (PROT_READ | PROT_WRITE) diff --git a/tools/testing/selftests/mm/hugetlb-vmemmap.c b/tools/testing/s= elftests/mm/hugetlb-vmemmap.c index 485a6978b40f..af5786bebfd1 100644 --- a/tools/testing/selftests/mm/hugetlb-vmemmap.c +++ b/tools/testing/selftests/mm/hugetlb-vmemmap.c @@ -11,6 +11,7 @@ #include #include #include "vm_util.h" +#include "hugepage_settings.h" =20 #define PAGE_COMPOUND_HEAD (1UL << 15) #define PAGE_COMPOUND_TAIL (1UL << 16) diff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selft= ests/mm/hugetlb_dio.c index 31a054fa8134..81e3f7bc8e76 100644 --- a/tools/testing/selftests/mm/hugetlb_dio.c +++ b/tools/testing/selftests/mm/hugetlb_dio.c @@ -20,6 +20,7 @@ #include #include "vm_util.h" #include "kselftest.h" +#include "hugepage_settings.h" =20 #ifndef STATX_DIOALIGN #define STATX_DIOALIGN 0x00002000U diff --git a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c b/tools/= testing/selftests/mm/hugetlb_fault_after_madv.c index b4b257775b74..abc3904c5268 100644 --- a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c +++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c @@ -10,6 +10,7 @@ =20 #include "vm_util.h" #include "kselftest.h" +#include "hugepage_settings.h" =20 #define INLOOP_ITER 100 =20 diff --git a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c b/tools/testi= ng/selftests/mm/hugetlb_madv_vs_map.c index c7105c6d319b..ac60b4f18784 100644 --- a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c +++ b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c @@ -25,6 +25,7 @@ #include =20 #include "vm_util.h" +#include "hugepage_settings.h" =20 #define INLOOP_ITER 100 =20 diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftes= ts/mm/thuge-gen.c index 77813d34dcc2..1007bc8aa57c 100644 --- a/tools/testing/selftests/mm/thuge-gen.c +++ b/tools/testing/selftests/mm/thuge-gen.c @@ -28,6 +28,7 @@ #include #include "vm_util.h" #include "kselftest.h" +#include "hugepage_settings.h" =20 #if !defined(MAP_HUGETLB) #define MAP_HUGETLB 0x40000 diff --git a/tools/testing/selftests/mm/uffd-common.h b/tools/testing/selft= ests/mm/uffd-common.h index 844a85ab31eb..6c5aca9cb63e 100644 --- a/tools/testing/selftests/mm/uffd-common.h +++ b/tools/testing/selftests/mm/uffd-common.h @@ -37,6 +37,7 @@ =20 #include "kselftest.h" #include "vm_util.h" +#include "hugepage_settings.h" =20 #define UFFD_FLAGS (O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY) =20 diff --git a/tools/testing/selftests/mm/va_high_addr_switch.c b/tools/testi= ng/selftests/mm/va_high_addr_switch.c index 5d38735ea60e..0b69bd4b901d 100644 --- a/tools/testing/selftests/mm/va_high_addr_switch.c +++ b/tools/testing/selftests/mm/va_high_addr_switch.c @@ -11,6 +11,7 @@ =20 #include "vm_util.h" #include "kselftest.h" +#include "hugepage_settings.h" =20 /* * The hint addr value is used to allocate addresses diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests= /mm/vm_util.c index db94564f4431..e62e2a473123 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -291,53 +291,6 @@ int64_t allocate_transhuge(void *ptr, int pagemap_fd) return -1; } =20 -unsigned long default_huge_page_size(void) -{ - unsigned long hps =3D 0; - char *line =3D NULL; - size_t linelen =3D 0; - FILE *f =3D fopen("/proc/meminfo", "r"); - - if (!f) - return 0; - while (getline(&line, &linelen, f) > 0) { - if (sscanf(line, "Hugepagesize: %lu kB", &hps) =3D=3D 1) { - hps <<=3D 10; - break; - } - } - - free(line); - fclose(f); - return hps; -} - -int detect_hugetlb_page_sizes(size_t sizes[], int max) -{ - DIR *dir =3D opendir("/sys/kernel/mm/hugepages/"); - int count =3D 0; - - if (!dir) - return 0; - - while (count < max) { - struct dirent *entry =3D readdir(dir); - size_t kb; - - if (!entry) - break; - if (entry->d_type !=3D DT_DIR) - continue; - if (sscanf(entry->d_name, "hugepages-%zukB", &kb) !=3D 1) - continue; - sizes[count++] =3D kb * 1024; - ksft_print_msg("[INFO] detected hugetlb page size: %zu KiB\n", - kb); - } - closedir(dir); - return count; -} - int pageflags_get(unsigned long pfn, int kpageflags_fd, uint64_t *flags) { size_t count; @@ -396,25 +349,6 @@ int uffd_unregister(int uffd, void *addr, uint64_t len) return ret; } =20 -unsigned long get_free_hugepages(void) -{ - unsigned long fhp =3D 0; - char *line =3D NULL; - size_t linelen =3D 0; - FILE *f =3D fopen("/proc/meminfo", "r"); - - if (!f) - return fhp; - while (getline(&line, &linelen, f) > 0) { - if (sscanf(line, "HugePages_Free: %lu", &fhp) =3D=3D 1) - break; - } - - free(line); - fclose(f); - return fhp; -} - static bool check_vmflag(void *addr, const char *flag) { char buffer[MAX_LINE_LENGTH]; diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests= /mm/vm_util.h index 1a07305ceff4..195bf2e26792 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -94,8 +94,6 @@ bool check_huge_anon(void *addr, int nr_hpages, uint64_t = hpage_size); bool check_huge_file(void *addr, int nr_hpages, uint64_t hpage_size); bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size); int64_t allocate_transhuge(void *ptr, int pagemap_fd); -unsigned long default_huge_page_size(void); -int detect_hugetlb_page_sizes(size_t sizes[], int max); int pageflags_get(unsigned long pfn, int kpageflags_fd, uint64_t *flags); =20 int uffd_register(int uffd, void *addr, uint64_t len, @@ -103,7 +101,6 @@ int uffd_register(int uffd, void *addr, uint64_t len, int uffd_unregister(int uffd, void *addr, uint64_t len); int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len, bool miss, bool wp, bool minor, uint64_t *ioctls); -unsigned long get_free_hugepages(void); bool check_vmflag_io(void *addr); bool check_vmflag_pfnmap(void *addr); bool check_vmflag_guard(void *addr); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 91202340A59; Tue, 28 Apr 2026 20:45:29 +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=1777409129; cv=none; b=mzQv/4UqE/eHvqC/UWeyj5xytY1kQxIxi97whdSq2I83ql4vnaVnKl/jt1+kLKUgOE6qu5ZVZC69BeU3x6zia6TkAPWVxqvqbvRQ6latD4YxxcK4QXzvgZsuTUX3WvLW2sqMhw/QnAyZHoGkMlej47goFSt+t/VPi5orkdFL/yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409129; c=relaxed/simple; bh=/Wvi9uebpP/hGBuUfLX+2dm76zvxNiYlkCrT9K3LAcE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nQ3Cdg4qII39nXrJmfsJ16U0HHRnyF5SxKcU1Y6D04MH/u+SWMBM7ceLB9GKwSzAYEN6uEneCO09umbIhLsDFD735obGuCvpB3ysMZwsIJwM2aNGiToXlcYDOtGOaTLH2ZIOCkQ3hzkiJtqlkMPWc4IZ0dp4U2XWPqhPKZGNrTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fh9A3V+y; 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="fh9A3V+y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66919C2BCAF; Tue, 28 Apr 2026 20:45:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409129; bh=/Wvi9uebpP/hGBuUfLX+2dm76zvxNiYlkCrT9K3LAcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fh9A3V+ypXR4GS5oRIKpQ2uyi2xl8u++OvGhWngaOa12qIEfDGSBqgWfoZi1hBof1 Yuuj0h94pGo39vk61AUVl1FOf789apcQAHiXFIYLZV3ZDw8iWNyOKDSUpKmB/MQD5Y GTI9BjMV/vQaNnGP2xoz5xYmzvDVje+KZba7CwbxO/1xu16tkCK8Pc3RkU/y9HAYkO Y1SfAhDpaM85FAdkwu/aYPSdaTvgz3HoZttOwzYZKV2uAbKSk0YfedSiCyZ46Xq89i 239DVDEXi6HKISnYp9CNKV4iNV4QHorwTTNf3P54RhKwyYbMgN4i/ajmgkISj6s3N6 1m54VeTDYLneg== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 24/54] selftests/mm: hugepage_settings: use unsigned long in detect_hugetlb_page_size Date: Tue, 28 Apr 2026 23:42:10 +0300 Message-ID: <20260428204240.1924129-25-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" ... instead of size_t to avoid type mismatch in 32 and 64 bit builds. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Sarthak Sharma Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/hugepage_settings.c | 2 +- tools/testing/selftests/mm/hugepage_settings.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing= /selftests/mm/hugepage_settings.c index ebaa621c45c6..8f563315b1fc 100644 --- a/tools/testing/selftests/mm/hugepage_settings.c +++ b/tools/testing/selftests/mm/hugepage_settings.c @@ -399,7 +399,7 @@ bool thp_is_enabled(void) return mode =3D=3D 1 || mode =3D=3D 3; } =20 -int detect_hugetlb_page_sizes(size_t sizes[], int max) +int detect_hugetlb_page_sizes(unsigned long sizes[], int max) { DIR *dir =3D opendir("/sys/kernel/mm/hugepages/"); int count =3D 0; diff --git a/tools/testing/selftests/mm/hugepage_settings.h b/tools/testing= /selftests/mm/hugepage_settings.h index 320b97e768e8..9357d07e6c1b 100644 --- a/tools/testing/selftests/mm/hugepage_settings.h +++ b/tools/testing/selftests/mm/hugepage_settings.h @@ -90,7 +90,7 @@ bool thp_is_enabled(void); =20 /* HugeTLB */ =20 -int detect_hugetlb_page_sizes(size_t sizes[], int max); +int detect_hugetlb_page_sizes(unsigned long sizes[], int max); unsigned long default_huge_page_size(void); unsigned long get_free_hugepages(void); =20 --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 47A4333ADAE; Tue, 28 Apr 2026 20:45:36 +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=1777409136; cv=none; b=Fnqrmz+nuhDYD/U65W+POTBbD4BZ1dv1wgQNKpefPF6dZdj/tNEtAkLO9bQtaKcOHyZPUqK/yxIpb7sLWms+08eGSxcvV7IKEQB55VjGOpkioLb4QZHVEYOVmc73mU4RTGXPGpDy6cP8nkl7efCUaK14JpViVhOZygdC6mh2/PU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409136; c=relaxed/simple; bh=6tmwrYqrWIbuMw5GfhGQhH/MUUQ+JMHsDHml8bmka3I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D+jk0G+yjVVhTpQIhus3qWWSIaingfX4fT+WFl+v+89Q80gbEHWTND7VGMhdkLmUvnfilJJdEP0BvohUVlgGAau0BTL7O8omOsNCJf+xEE3/YAlhKZ+6FtjnvXHMFus2k2IU8Uz4AdsEslDYT2/dq/i5FLG2tnOnkpWvofBdBEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q2Yk6W1T; 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="q2Yk6W1T" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1F61C4AF09; Tue, 28 Apr 2026 20:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409136; bh=6tmwrYqrWIbuMw5GfhGQhH/MUUQ+JMHsDHml8bmka3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q2Yk6W1Tup/ZKaBNBSStPROW97IQHtgQWyBmaOm5+R37bRMYIQJ7GHA3ktQ/z/LiK nX2UGEfOWlweXBNBx4SnO3CWQq7yqnB1GEu+Ma0CC0m1wGge9NjWH2qT4yfXA/CzHn h0LJFmfeHrO2kO2Myyjdk6ztJ0aLOVm8sHGMovafiXVeX3WRJ3wMRIzt1MnwL+0Cly VFUY/m2GrrJ7HrS6dIz/VAagWeXXOh564Yb4BsQI/270BYsWtReYEjbWt0kQSHngru li09iiog7F9s8PKsg7EzlxiA8ZHCFFieMcwxuTE9l86B1QSECVusLnkoxALJbXFlTZ 137gvmJ8Y35JA== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 25/54] selftests/mm: hugepage_settings: add APIs to get and set nr_hugepages Date: Tue, 28 Apr 2026 23:42:11 +0300 Message-ID: <20260428204240.1924129-26-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Add APIs that allow reading and writing of /sys/kernel/mm/hugepages/hugepages-NkB/nr_hugepages to detect and change the amount of HugeTLB pages of different sizes. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Luiz Capitulino Reviewed-by: Sarthak Sharma Tested-by: Luiz Capitulino --- .../testing/selftests/mm/hugepage_settings.c | 25 +++++++++++++++++++ .../testing/selftests/mm/hugepage_settings.h | 23 +++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing= /selftests/mm/hugepage_settings.c index 8f563315b1fc..5961229b9931 100644 --- a/tools/testing/selftests/mm/hugepage_settings.c +++ b/tools/testing/selftests/mm/hugepage_settings.c @@ -464,3 +464,28 @@ unsigned long get_free_hugepages(void) fclose(f); return fhp; } + +static void hugetlb_sysfs_path(char *buf, size_t buflen, + unsigned long size, const char *attr) +{ + snprintf(buf, buflen, "/sys/kernel/mm/hugepages/hugepages-%lukB/%s", + size / 1024, attr); +} + +unsigned long hugetlb_nr_pages(unsigned long size) +{ + char path[PATH_MAX]; + + hugetlb_sysfs_path(path, sizeof(path), size, "nr_hugepages"); + + return read_num(path); +} + +void hugetlb_set_nr_pages(unsigned long size, unsigned long nr) +{ + char path[PATH_MAX]; + + hugetlb_sysfs_path(path, sizeof(path), size, "nr_hugepages"); + + write_num(path, nr); +} diff --git a/tools/testing/selftests/mm/hugepage_settings.h b/tools/testing= /selftests/mm/hugepage_settings.h index 9357d07e6c1b..d6f41a45e8ee 100644 --- a/tools/testing/selftests/mm/hugepage_settings.h +++ b/tools/testing/selftests/mm/hugepage_settings.h @@ -94,4 +94,27 @@ int detect_hugetlb_page_sizes(unsigned long sizes[], int= max); unsigned long default_huge_page_size(void); unsigned long get_free_hugepages(void); =20 +unsigned long hugetlb_nr_pages(unsigned long size); +void hugetlb_set_nr_pages(unsigned long size, unsigned long nr); + +static inline unsigned long hugetlb_nr_default_pages(void) +{ + unsigned long size =3D default_huge_page_size(); + + if (!size) + return 0; + + return hugetlb_nr_pages(size); +} + +static inline void hugetlb_set_nr_default_pages(unsigned long nr) +{ + unsigned long size =3D default_huge_page_size(); + + if (!size) + return; + + hugetlb_set_nr_pages(size, nr); +} + #endif /* __THP_SETTINGS_H__ */ --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 C344534CFD0; Tue, 28 Apr 2026 20:45:42 +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=1777409142; cv=none; b=ZncZuZpKcmEsdnYSqoI1pNFm4pTw8hQGEMLUHM7LjK0OmV4D4FsJUkzUHFp0l4bJAk1vAG9gcYBRtAsiJqnIXQnmjC4UdiOlpSdDMSTcVfDDex8B7QF7VmLAC7G56G9IiK14oRY24r5wgex5Gv9h/9ps2wv96YviTpStT/dPq7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409142; c=relaxed/simple; bh=jAQxw9MbYkXsl544OFupWFjq2DLx0d+HujNgYQfq/0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jc+dzDMbxpHX/zVVhbd7aP/rseDL6obio5d5FFy0s6saqOXc8KlJItOPBMFlsfGzc08nDg6vcVDzalNDMx9cwml9vXwodxhBT/Uqk8osg0jpmeCRYKwMVXZirus5EY/Bivx51J99q6oxIq2h04facavr0meNeTlrPQVK+7uuw84= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V+4Vny5l; 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="V+4Vny5l" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89FAEC2BCAF; Tue, 28 Apr 2026 20:45:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409142; bh=jAQxw9MbYkXsl544OFupWFjq2DLx0d+HujNgYQfq/0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V+4Vny5lUCOs29DUa+TMA1hirYtTwid7QaRPEsnAPG62zvxRp5MURNS0bKB60YaD2 chTPM8zaivb1d3pSwMsyJQxeryhrR246XjgWmy0/dZZ55AkiJuezn5oWPf4IDNUNBP P4K00tKgjHiHaxBcb7PBJoXwoP52y/ce4SEIO/YJqpuZPmgPByQbdwnKH8tnt1eU10 GUnLK9G8HN1iKbmrKYPTGvuVNlOsExVu6PVl0Rfr8xYpg2/grLZ29C+oY2XpK258Vl YqL0ceMsB1/C3TM1c8CRjtkpddQKnz17y4Wq1+q6zEd2gQT7T/z6Nxq7QB0wTjC3VE 0gMgCjCN/hssg== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 26/54] selftests/mm: hugepage_settings: rename get_free_hugepages() Date: Tue, 28 Apr 2026 23:42:12 +0300 Message-ID: <20260428204240.1924129-27-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" ... to hugetlb_free_default_hugepages() for consistency with hugetlb_nr_default_pages(). Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- .../testing/selftests/mm/hugepage_settings.c | 28 ++++++------------- .../testing/selftests/mm/hugepage_settings.h | 12 +++++++- tools/testing/selftests/mm/hugetlb-madvise.c | 4 +-- tools/testing/selftests/mm/hugetlb_dio.c | 6 ++-- .../selftests/mm/hugetlb_fault_after_madv.c | 2 +- .../selftests/mm/hugetlb_madv_vs_map.c | 2 +- tools/testing/selftests/mm/uffd-stress.c | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing= /selftests/mm/hugepage_settings.c index 5961229b9931..4ae7332b5e1b 100644 --- a/tools/testing/selftests/mm/hugepage_settings.c +++ b/tools/testing/selftests/mm/hugepage_settings.c @@ -446,25 +446,6 @@ unsigned long default_huge_page_size(void) return hps; } =20 -unsigned long get_free_hugepages(void) -{ - unsigned long fhp =3D 0; - char *line =3D NULL; - size_t linelen =3D 0; - FILE *f =3D fopen("/proc/meminfo", "r"); - - if (!f) - return fhp; - while (getline(&line, &linelen, f) > 0) { - if (sscanf(line, "HugePages_Free: %lu", &fhp) =3D=3D 1) - break; - } - - free(line); - fclose(f); - return fhp; -} - static void hugetlb_sysfs_path(char *buf, size_t buflen, unsigned long size, const char *attr) { @@ -489,3 +470,12 @@ void hugetlb_set_nr_pages(unsigned long size, unsigned= long nr) =20 write_num(path, nr); } + +unsigned long hugetlb_free_pages(unsigned long size) +{ + char path[PATH_MAX]; + + hugetlb_sysfs_path(path, sizeof(path), size, "free_hugepages"); + + return read_num(path); +} diff --git a/tools/testing/selftests/mm/hugepage_settings.h b/tools/testing= /selftests/mm/hugepage_settings.h index d6f41a45e8ee..57fbf2f57e13 100644 --- a/tools/testing/selftests/mm/hugepage_settings.h +++ b/tools/testing/selftests/mm/hugepage_settings.h @@ -92,10 +92,10 @@ bool thp_is_enabled(void); =20 int detect_hugetlb_page_sizes(unsigned long sizes[], int max); unsigned long default_huge_page_size(void); -unsigned long get_free_hugepages(void); =20 unsigned long hugetlb_nr_pages(unsigned long size); void hugetlb_set_nr_pages(unsigned long size, unsigned long nr); +unsigned long hugetlb_free_pages(unsigned long size); =20 static inline unsigned long hugetlb_nr_default_pages(void) { @@ -117,4 +117,14 @@ static inline void hugetlb_set_nr_default_pages(unsign= ed long nr) hugetlb_set_nr_pages(size, nr); } =20 +static inline unsigned long hugetlb_free_default_pages(void) +{ + unsigned long size =3D default_huge_page_size(); + + if (!size) + return 0; + + return hugetlb_free_pages(size); +} + #endif /* __THP_SETTINGS_H__ */ diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/s= elftests/mm/hugetlb-madvise.c index 316384d919db..3c08eb6db6a2 100644 --- a/tools/testing/selftests/mm/hugetlb-madvise.c +++ b/tools/testing/selftests/mm/hugetlb-madvise.c @@ -27,7 +27,7 @@ =20 #define validate_free_pages(exp_free) \ do { \ - unsigned long fhp =3D get_free_hugepages(); \ + unsigned long fhp =3D hugetlb_free_default_pages(); \ if (fhp !=3D (exp_free)) \ ksft_exit_fail_msg("Unexpected number of free " \ "huge pages %ld, expected %ld line %d\n", \ @@ -68,7 +68,7 @@ int main(int argc, char **argv) if (!base_page_size) ksft_exit_fail_msg("Unable to determine base page size\n"); =20 - free_hugepages =3D get_free_hugepages(); + free_hugepages =3D hugetlb_free_default_pages(); if (free_hugepages < MIN_FREE_PAGES) ksft_exit_skip("Not enough free huge pages (have %lu, need %d)\n", free_= hugepages, MIN_FREE_PAGES); =20 diff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selft= ests/mm/hugetlb_dio.c index 81e3f7bc8e76..47019433ddaf 100644 --- a/tools/testing/selftests/mm/hugetlb_dio.c +++ b/tools/testing/selftests/mm/hugetlb_dio.c @@ -93,7 +93,7 @@ static void run_dio_using_hugetlb(int fd, unsigned int st= art_off, ksft_exit_fail_perror("lseek failed\n"); =20 /* Get the free huge pages before allocation */ - free_hpage_b =3D get_free_hugepages(); + free_hpage_b =3D hugetlb_free_default_pages(); if (free_hpage_b =3D=3D 0) { close(fd); ksft_exit_skip("No free hugepage, exiting!\n"); @@ -121,7 +121,7 @@ static void run_dio_using_hugetlb(int fd, unsigned int = start_off, munmap(orig_buffer, h_pagesize); =20 /* Get the free huge pages after unmap*/ - free_hpage_a =3D get_free_hugepages(); + free_hpage_a =3D hugetlb_free_default_pages(); =20 ksft_print_msg("No. Free pages before allocation : %d\n", free_hpage_b); ksft_print_msg("No. Free pages after munmap : %d\n", free_hpage_a); @@ -142,7 +142,7 @@ int main(void) ksft_print_header(); =20 /* Check if huge pages are free */ - if (!get_free_hugepages()) + if (!hugetlb_free_default_pages()) ksft_exit_skip("No free hugepage, exiting\n"); =20 fd =3D open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664); diff --git a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c b/tools/= testing/selftests/mm/hugetlb_fault_after_madv.c index abc3904c5268..c718dd065d53 100644 --- a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c +++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c @@ -78,7 +78,7 @@ int main(void) ksft_print_msg("[INFO] detected default hugetlb page size: %zu KiB\n", huge_page_size / 1024); =20 - free_hugepages =3D get_free_hugepages(); + free_hugepages =3D hugetlb_free_default_pages(); if (free_hugepages !=3D 1) { ksft_exit_skip("This test needs one and only one page to execute. Got %l= u\n", free_hugepages); diff --git a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c b/tools/testi= ng/selftests/mm/hugetlb_madv_vs_map.c index ac60b4f18784..dfbd71a7f709 100644 --- a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c +++ b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c @@ -89,7 +89,7 @@ int main(void) ksft_print_header(); ksft_set_plan(1); =20 - free_hugepages =3D get_free_hugepages(); + free_hugepages =3D hugetlb_free_default_pages(); =20 if (free_hugepages !=3D 1) ksft_exit_skip("This test needs one and only one page to execute. Got %l= u\n", diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selft= ests/mm/uffd-stress.c index e92a85463eb1..7e37cf3d27f6 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -480,7 +480,7 @@ int main(int argc, char **argv) * for racy extra reservation of hugepages. */ if (gopts->test_type =3D=3D TEST_HUGETLB && - get_free_hugepages() < 2 * (bytes / gopts->page_size) + gopts->nr_para= llel - 1) + hugetlb_free_default_pages() < 2 * (bytes / gopts->page_size) + gopts-= >nr_parallel - 1) ksft_exit_skip("Skipping userfaultfd... not enough hugepages\n"); =20 gopts->nr_pages_per_cpu =3D bytes / gopts->page_size / gopts->nr_parallel; --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 8CFC0524F; Tue, 28 Apr 2026 20: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=1777409149; cv=none; b=WdLK5x75XcR2DqP6XSeQIAgtg1vJWsc/H7I7COpijNHk+MAO2CD6rjz2T9SLY4zD3XIB7WdA8hnJAcpphzHFv7/Qluv0KGXt74MoZGycd32kClrzwrp68gzDkbjGnBG/ebgrlMZVCNdt3388lwTlrF0YsQnoAB9JM19RjAhZdFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409149; c=relaxed/simple; bh=OlIUBzF1pm75Atj7loyFKXAz39qc33UiLBzlYum8j8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WCZGtQ1B+tEWHfcbAcvn6rYosXp8evTIhneeicP11cfAKMa8fBt63rw8B7h+Z0YSZ8Tekz2MaGkPISPEeNs5s1kBfq8spNk6l/VAD19m6XTsdpLWegoy930904Tk9RQu8AQmSOXc4LWtsIlxxiEmfqRsX8Rsm7zQNH3E0cS+Bgw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k/UGjFeJ; 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="k/UGjFeJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21992C2BCAF; Tue, 28 Apr 2026 20:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409149; bh=OlIUBzF1pm75Atj7loyFKXAz39qc33UiLBzlYum8j8I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k/UGjFeJw0dt9uKzNCvUdtfovqatLZx9o4OUbHhk/quGTcjQhiWZi1jFcvGCJ/vOH HE7VV1znvB9Y9XYTnwqK5FbyW8sFx2HP1PN+pSWrVLTtr9yZXkKYrj4k1/N1/bH5gj kIYZNJvZo3oM8GMOt0tkI20KiJM44eNfDbsehM6yjiw7QSe2ooisV59hkLJwFvSW1J ciReWNIL4cMrnh7Q2J3f2dquu5mbc/OoGHYnVEZkeHEuOFJdeUpOAUwc58YC9MFTtA 8rP1bSO8ITo+SgVpwdyuREMBBBMoNFl3n5Q1GzfgRnHlSuBr0C4uDUTHvuAs2/y5V6 pdau8Y2vkJh1g== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 27/54] selftests/mm: hugepage_settings: add APIs for HugeTLB setup and teardown Date: Tue, 28 Apr 2026 23:42:13 +0300 Message-ID: <20260428204240.1924129-28-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" A lot of tests require free HugeTLB pages. Some need just a few default huge pages, some need a certain amount of memory available as HugeTLB, and some just skip lots of tests if huge pages of all supported sizes are not available. This all resulted in a huge mess in run_vmtests.sh that sets up some huge pages, adjusts them later and restores some of the settings if the stars align. Add APIs that allow saving the state of HugeTLB and setting up the desired amount of HugeTLB pages. Saving the state also registers atexit() callback and signal handler that will ensure restoration of HugeTLB state. Since many tests use both HugeTLB and THP, the atexit() callbacks and signal handler are restoring both. For kselftest_harness tests that run fixture setups and test in child processes add a constructor that will save and restore settings in the main process. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Sarthak Sharma Tested-by: Luiz Capitulino --- .../testing/selftests/mm/hugepage_settings.c | 178 +++++++++++++++--- .../testing/selftests/mm/hugepage_settings.h | 30 ++- 2 files changed, 183 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing= /selftests/mm/hugepage_settings.c index 4ae7332b5e1b..9d31b53dbc67 100644 --- a/tools/testing/selftests/mm/hugepage_settings.c +++ b/tools/testing/selftests/mm/hugepage_settings.c @@ -306,31 +306,12 @@ void thp_restore_settings(void) thp_write_settings(&saved_settings); } =20 -static void thp_restore_settings_atexit(void) +static void __thp_save_settings(void) { - thp_restore_settings(); -} - -static void thp_restore_settings_sighandler(int sig) -{ - /* exit() will invoke the thp_restore_settings_atexit handler. */ - exit(KSFT_FAIL); -} + if (!thp_available()) + return; =20 -void thp_save_settings(void) -{ thp_read_settings(&saved_settings); - - /* - * setup exit hooks to make sure THP settings are restored on graceful - * and error exits and signals - */ - atexit(thp_restore_settings_atexit); - signal(SIGTERM, thp_restore_settings_sighandler); - signal(SIGINT, thp_restore_settings_sighandler); - signal(SIGHUP, thp_restore_settings_sighandler); - signal(SIGQUIT, thp_restore_settings_sighandler); - thp_settings_saved =3D true; } =20 @@ -399,11 +380,31 @@ bool thp_is_enabled(void) return mode =3D=3D 1 || mode =3D=3D 3; } =20 +#define HUGETLB_MAX_NR_PAGESIZES 10 +struct hugetlb_settings { + unsigned long free_hugepages[HUGETLB_MAX_NR_PAGESIZES]; + unsigned long nr_hugepages[HUGETLB_MAX_NR_PAGESIZES]; + unsigned long sizes[HUGETLB_MAX_NR_PAGESIZES]; + unsigned long default_size; + int nr_sizes; +}; + +static struct hugetlb_settings hugetlb_saved_settings; +bool hugetlb_settings_saved; + int detect_hugetlb_page_sizes(unsigned long sizes[], int max) { - DIR *dir =3D opendir("/sys/kernel/mm/hugepages/"); + static struct hugetlb_settings *settings =3D &hugetlb_saved_settings; + DIR *dir; int count =3D 0; =20 + if (settings->nr_sizes) { + for (count =3D 0; count < settings->nr_sizes; count++) + sizes[count] =3D settings->sizes[count]; + return settings->nr_sizes; + } + + dir =3D opendir("/sys/kernel/mm/hugepages/"); if (!dir) return 0; =20 @@ -427,11 +428,16 @@ int detect_hugetlb_page_sizes(unsigned long sizes[], = int max) =20 unsigned long default_huge_page_size(void) { + static struct hugetlb_settings *settings =3D &hugetlb_saved_settings; unsigned long hps =3D 0; char *line =3D NULL; size_t linelen =3D 0; - FILE *f =3D fopen("/proc/meminfo", "r"); + FILE *f; =20 + if (settings->default_size) + return settings->default_size; + + f =3D fopen("/proc/meminfo", "r"); if (!f) return 0; while (getline(&line, &linelen, f) > 0) { @@ -479,3 +485,127 @@ unsigned long hugetlb_free_pages(unsigned long size) =20 return read_num(path); } + +bool hugetlb_setup_default(unsigned long nr) +{ + unsigned long size; + + hugetlb_save_settings(); + + size =3D default_huge_page_size(); + hugetlb_set_nr_pages(size, nr); + + return hugetlb_free_pages(size) =3D=3D nr; +} + +unsigned long hugetlb_setup(unsigned long nr, unsigned long sizes[], + int max) +{ + unsigned long enabled[10]; + int nr_sizes =3D 0; + int nr_enabled; + + hugetlb_save_settings(); + + nr_enabled =3D detect_hugetlb_page_sizes(enabled, ARRAY_SIZE(enabled)); + if (!nr_enabled) + return 0; + + if (nr_enabled > max) { + ksft_print_msg("detected %d huge page sizes, will only test %d\n", nr_en= abled, max); + nr_enabled =3D max; + } + + /* If HugeTLB is supported, request 2 HugeTLB pages of every size. */ + for (int i =3D 0; i < nr_enabled; i++) { + hugetlb_set_nr_pages(enabled[i], nr); + if (hugetlb_free_pages(enabled[i]) < nr) + continue; + + sizes[nr_sizes++] =3D enabled[i]; + } + + return nr_sizes; +} + +static void __hugetlb_save_settings(void) +{ + struct hugetlb_settings *settings =3D &hugetlb_saved_settings; + int nr_sizes; + + settings->default_size =3D default_huge_page_size(); + if (!settings->default_size) + return; + + nr_sizes =3D detect_hugetlb_page_sizes(settings->sizes, + HUGETLB_MAX_NR_PAGESIZES); + if (!nr_sizes) { + settings->default_size =3D 0; + return; + } + + for (int i =3D 0; i < nr_sizes; i++) { + unsigned long sz =3D settings->sizes[i]; + + if (!sz) + continue; + + settings->free_hugepages[i] =3D hugetlb_free_pages(sz); + settings->nr_hugepages[i] =3D hugetlb_nr_pages(sz); + } + + settings->nr_sizes =3D nr_sizes; + hugetlb_settings_saved =3D true; +} + +void hugetlb_restore_settings(void) +{ + struct hugetlb_settings *settings =3D &hugetlb_saved_settings; + + if (!hugetlb_settings_saved || !settings->default_size) + return; + + for (int i =3D 0; i < HUGETLB_MAX_NR_PAGESIZES; i++) { + unsigned long sz =3D settings->sizes[i]; + + if (!sz) + continue; + + hugetlb_set_nr_pages(sz, settings->nr_hugepages[i]); + } +} + +static void hugepage_restore_settings_atexit(void) +{ + if (thp_settings_saved) + thp_restore_settings(); + if (hugetlb_settings_saved) + hugetlb_restore_settings(); +} + +static void hugepage_restore_settings_sighandler(int sig) +{ + /* exit() will invoke the hugetlb_restore_settings_atexit handler. */ + exit(KSFT_FAIL); +} + +void hugepage_save_settings(bool thp, bool hugetlb) +{ + if (!thp && !hugetlb) + return; + + if (thp) + __thp_save_settings(); + if (hugetlb) + __hugetlb_save_settings(); + + /* + * setup exit hooks to make sure THP settings are restored on graceful + * and error exits and signals + */ + atexit(hugepage_restore_settings_atexit); + signal(SIGTERM, hugepage_restore_settings_sighandler); + signal(SIGINT, hugepage_restore_settings_sighandler); + signal(SIGHUP, hugepage_restore_settings_sighandler); + signal(SIGQUIT, hugepage_restore_settings_sighandler); +} diff --git a/tools/testing/selftests/mm/hugepage_settings.h b/tools/testing= /selftests/mm/hugepage_settings.h index 57fbf2f57e13..d6a1b4e5f734 100644 --- a/tools/testing/selftests/mm/hugepage_settings.h +++ b/tools/testing/selftests/mm/hugepage_settings.h @@ -6,6 +6,8 @@ #include #include =20 +void hugepage_save_settings(bool thp, bool hugetlb); + /* Transparent Huge Pages (THP) */ =20 enum thp_enabled { @@ -79,7 +81,11 @@ struct thp_settings *thp_current_settings(void); void thp_push_settings(struct thp_settings *settings); void thp_pop_settings(void); void thp_restore_settings(void); -void thp_save_settings(void); + +static inline void thp_save_settings(void) +{ + hugepage_save_settings(/* thp =3D */ true, /* hugetlb =3D */ false); +} =20 void thp_set_read_ahead_path(char *path); unsigned long thp_supported_orders(void); @@ -97,6 +103,13 @@ unsigned long hugetlb_nr_pages(unsigned long size); void hugetlb_set_nr_pages(unsigned long size, unsigned long nr); unsigned long hugetlb_free_pages(unsigned long size); =20 +static inline void hugetlb_save_settings(void) +{ + hugepage_save_settings(/* thp =3D */ false, /* hugetlb =3D */ true); +} + +void hugetlb_restore_settings(void); + static inline unsigned long hugetlb_nr_default_pages(void) { unsigned long size =3D default_huge_page_size(); @@ -127,4 +140,19 @@ static inline unsigned long hugetlb_free_default_pages= (void) return hugetlb_free_pages(size); } =20 +static inline bool hugetlb_available(void) +{ + return default_huge_page_size() !=3D 0; +} + +bool hugetlb_setup_default(unsigned long nr); +unsigned long hugetlb_setup(unsigned long nr, unsigned long sizes[], + int max); + +#define HUGETLB_SETUP_DEFAULT_PAGES(nr_pages) \ +static void __attribute__((constructor)) __hugetlb_setup_default(void) \ +{ \ + hugetlb_setup_default((nr_pages)); \ +} + #endif /* __THP_SETTINGS_H__ */ --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 1A6312E8B82; Tue, 28 Apr 2026 20:45:55 +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=1777409156; cv=none; b=uY8k6MxQMByTJ3PmmlZTNS/nGKrVcRI2p0me2iJZo2For6DxYGafilvQzCEkcMO/T/tUnmi/VHGhPtmbN2d2YLa/nd1gCG9vZ4aHuULJ8fFCPF4j8x2ncDfXzixaXIRzvDroN4P7VzR10o5gfgSNImsl8oCr3EsT+EsY8fSuqAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409156; c=relaxed/simple; bh=gpSR6Q48MYhV0thDfaQc0u3uDky+1QVh/9VDybETiJU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mqQ07x70i4zOvGrj7TjQYIPalRIW9dYXn0zFej8n0UAnFvdKLpPhnFV7W7tjpl9bwnx4cmXnktQ5rQB8371x5m/uWPYT4D/aVjz+dzOQht/aMxX95T516H5dWrU6sYeMd53XidFGgZkFRH03BOVjNafspQO3IyeYBPYTv2BcWEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SXAX8Zde; 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="SXAX8Zde" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF0B7C2BCAF; Tue, 28 Apr 2026 20:45:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409155; bh=gpSR6Q48MYhV0thDfaQc0u3uDky+1QVh/9VDybETiJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SXAX8ZdeY0TzLzh/4N6hGDybK1UkN0xYH7D0pq4KuLPf6Jiu0cR1w0SoTuounRAFK iL3XykeSo3R0SjXZV/6gpIw0eOClOQwg/JkmgAIJdyJi49fuf/+/pqB82a/aJFFadF 8Xvwl7MEt67qVx1MxGisg3npyZ42rophkfR8ZLbKBkcmPnhmTYvRNb/divay4JN0fB ca6PZG1Fg0Ed8Gr26IEiAEz+DUG4YA2zlhyPvexHrHTW6NbldhUel/lp8xHrXyRuOc GAk28wSvVHfnUf9vjRmqdIDzT6VI2yqHcSdgzSOFxKTQacorIUyRwH0nZSfZ1DruPP i4iBdSAXtQt9w== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 28/54] selftests/mm: move read_file(), read_num() and write_num() to vm_util Date: Tue, 28 Apr 2026 23:42:14 +0300 Message-ID: <20260428204240.1924129-29-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" These are useful helpers for writing and reading sysfs and proc files. Make them available to the tests that don't use thp_settings. While on it make write_num() use "%lu" instead of "%ld" to match 'unsigned long num' argument type. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Sarthak Sharma Tested-by: Luiz Capitulino --- .../testing/selftests/mm/hugepage_settings.c | 41 ------------------- .../testing/selftests/mm/hugepage_settings.h | 4 -- tools/testing/selftests/mm/vm_util.c | 39 ++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 3 ++ 4 files changed, 42 insertions(+), 45 deletions(-) diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing= /selftests/mm/hugepage_settings.c index 9d31b53dbc67..097ba085f423 100644 --- a/tools/testing/selftests/mm/hugepage_settings.c +++ b/tools/testing/selftests/mm/hugepage_settings.c @@ -48,47 +48,6 @@ static const char * const shmem_enabled_strings[] =3D { NULL }; =20 -int read_file(const char *path, char *buf, size_t buflen) -{ - int fd; - ssize_t numread; - - fd =3D open(path, O_RDONLY); - if (fd =3D=3D -1) - return 0; - - numread =3D read(fd, buf, buflen - 1); - if (numread < 1) { - close(fd); - return 0; - } - - buf[numread] =3D '\0'; - close(fd); - - return (unsigned int) numread; -} - -unsigned long read_num(const char *path) -{ - char buf[21]; - - if (read_file(path, buf, sizeof(buf)) < 0) { - perror("read_file()"); - exit(EXIT_FAILURE); - } - - return strtoul(buf, NULL, 10); -} - -void write_num(const char *path, unsigned long num) -{ - char buf[21]; - - sprintf(buf, "%ld", num); - write_file(path, buf, strlen(buf) + 1); -} - int thp_read_string(const char *name, const char * const strings[]) { char path[PATH_MAX]; diff --git a/tools/testing/selftests/mm/hugepage_settings.h b/tools/testing= /selftests/mm/hugepage_settings.h index d6a1b4e5f734..3d1a4f18be30 100644 --- a/tools/testing/selftests/mm/hugepage_settings.h +++ b/tools/testing/selftests/mm/hugepage_settings.h @@ -66,10 +66,6 @@ struct thp_settings { struct shmem_hugepages_settings shmem_hugepages[NR_ORDERS]; }; =20 -int read_file(const char *path, char *buf, size_t buflen); -unsigned long read_num(const char *path); -void write_num(const char *path, unsigned long num); - int thp_read_string(const char *name, const char * const strings[]); void thp_write_string(const char *name, const char *val); unsigned long thp_read_num(const char *name); diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests= /mm/vm_util.c index e62e2a473123..752566f75c0b 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -699,6 +699,27 @@ int unpoison_memory(unsigned long pfn) return ret > 0 ? 0 : -errno; } =20 +int read_file(const char *path, char *buf, size_t buflen) +{ + int fd; + ssize_t numread; + + fd =3D open(path, O_RDONLY); + if (fd =3D=3D -1) + return 0; + + numread =3D read(fd, buf, buflen - 1); + if (numread < 1) { + close(fd); + return 0; + } + + buf[numread] =3D '\0'; + close(fd); + + return (unsigned int) numread; +} + void write_file(const char *path, const char *buf, size_t buflen) { int fd, saved_errno; @@ -722,3 +743,21 @@ void write_file(const char *path, const char *buf, siz= e_t buflen) ksft_exit_fail_msg("%s write(%.*s) is truncated, expected %zu bytes, got= %zd bytes\n", path, (int)(buflen - 1), buf, buflen - 1, numwritten); } + +unsigned long read_num(const char *path) +{ + char buf[21]; + + if (read_file(path, buf, sizeof(buf)) < 0) + ksft_exit_fail_perror("read_file()"); + + return strtoul(buf, NULL, 10); +} + +void write_num(const char *path, unsigned long num) +{ + char buf[21]; + + sprintf(buf, "%lu", num); + write_file(path, buf, strlen(buf) + 1); +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests= /mm/vm_util.h index 195bf2e26792..5fc9707f6b9a 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -165,3 +165,6 @@ int unpoison_memory(unsigned long pfn); #define PAGEMAP_PFN(ent) ((ent) & ((1ull << 55) - 1)) =20 void write_file(const char *path, const char *buf, size_t buflen); +int read_file(const char *path, char *buf, size_t buflen); +unsigned long read_num(const char *path); +void write_num(const char *path, unsigned long num); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 AFF4934F48F; Tue, 28 Apr 2026 20:46:02 +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=1777409162; cv=none; b=Es9SPHq0+biEbSmg+u22RafEYuC6bwZKT0vJWI9ik4ZargjBymk4rZ8ytb3U9LDO/Ppem3jFxUdKGz+S/PiIuvUoT0zM4H76m9gbHHMiBpARayuYb1lKxhBHsHZOf6myZJJWmEieZNIW705azCekHOqwZKzgP89pQwAjVWDB3vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409162; c=relaxed/simple; bh=tO4w/saWs4TngI1dGJjVb/BDaQv7f0xtr7dZaOtNvYY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g4CSKUxqLhbSomUJC6oqV/lrv1nisW5OA00mgnMVmrpisYoojkQaUjUPI9k9nrYU3qmfa0DJR6+vA+KBBxq3CqGGOFDOzp7Tz4z0ljJ5VfAg8P89MKQPjF+31XaYzdPfX6a7jtilIPKRILO+ayEzBlYNI+9IRgLao4zGMIIKO1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KvvrQz/H; 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="KvvrQz/H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46996C2BCAF; Tue, 28 Apr 2026 20:45:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409162; bh=tO4w/saWs4TngI1dGJjVb/BDaQv7f0xtr7dZaOtNvYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KvvrQz/H9MZvu86YAxyj5rQhIx/ZHPTpmdjW6uyN07IO7+ThUJ49IxJ86Ngu3/BjQ ViQ+H54GPyl8kerSDJPSxgtRGtytzWYqT0iSSGocFwCdIODYR/1EE3IrNgG8EjaIx/ A05BS4zchquoEri2LpJ9bokTQm7yn3pejiBpXmeLnHwS9jTEmHqJ65Lu4o3BIJt4rR NAl4TJbWorv+YtUcgbe0Vx7cCqB91HhWkciiaYFgBk+HgT0z9c6mOtwaJB2SNOVirQ xes7xvc/+tXfA6EVZ8U50mb7VkZXNd1bc7xv0te4q+8O0iJOd2uPlEcviiE8zAwh0W tIOa7kh4QNzoQ== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 29/54] selftests/mm: vm_util: add helpers to set and restore shm limits Date: Tue, 28 Apr 2026 23:42:15 +0300 Message-ID: <20260428204240.1924129-30-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hugetlb-shm and thuge-gen tests require that limits defined by /proc/sys/kernel/{shmmax,shmall} should be higher than certain values. Add helpers that allow setting these limits and restoring their settings on a test exit. They will be used later in hugetlb-shm and thuge-gen. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Sarthak Sharma Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/vm_util.c | 28 ++++++++++++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 9 +++++++++ 2 files changed, 37 insertions(+) diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests= /mm/vm_util.c index 752566f75c0b..5a89c2d903be 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -761,3 +761,31 @@ void write_num(const char *path, unsigned long num) sprintf(buf, "%lu", num); write_file(path, buf, strlen(buf) + 1); } + +static unsigned long shmall, shmmax; + +void __shm_limits_restore(void) +{ + if (shmmax) + write_num("/proc/sys/kernel/shmmax", shmmax); + if (shmall) + write_num("/proc/sys/kernel/shmall", shmall); +} + +void shm_limits_prepare(unsigned long length) +{ + unsigned long nr =3D length / psize(); + unsigned long val; + + val =3D read_num("/proc/sys/kernel/shmmax"); + if (val < length) { + write_num("/proc/sys/kernel/shmmax", length); + shmmax =3D val; + } + + val =3D read_num("/proc/sys/kernel/shmall"); + if (val < nr) { + write_num("/proc/sys/kernel/shmall", nr); + shmall =3D val; + } +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests= /mm/vm_util.h index 5fc9707f6b9a..ea8fc8fdf0eb 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -168,3 +168,12 @@ void write_file(const char *path, const char *buf, siz= e_t buflen); int read_file(const char *path, char *buf, size_t buflen); unsigned long read_num(const char *path); void write_num(const char *path, unsigned long num); + +void shm_limits_prepare(unsigned long length); +void __shm_limits_restore(void); + +#define SHM_LIMITS_RESTORE() \ +static void __attribute__((destructor)) shm_limits_restore(void) \ +{ \ + __shm_limits_restore(); \ +} --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 0CC5B4A35; Tue, 28 Apr 2026 20:46:09 +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=1777409169; cv=none; b=elLuXDxWUYtRBfQAUDA0LNmYVPSfF5uN7VBO+NUNIa66JysN6Pa+ThngBNwB9ZwIZc+khBEzzZGN2z0f5mexuEZltFpuEsLMLyKziRwlcot6e94WxuFBr9qx+4BatdOnToKTeTAzYy9A65E5BR+ZVcm74kt7/hcyO7Dm4bCmpyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409169; c=relaxed/simple; bh=t2OQ6d8PPidPjQSh+RBxS6XeDUdzwdvT/+uZ5YR7P1Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZVOOi72hUACQNChckgP97inCCASnR6oQ4DslVr+sqtnP29e2Awc6A2wNeEQegpjJ7I0aVtadmSO9NmKjiq4i/0r5yKRAtf6evFUVIIZlLWVVCO5lCaKGXqJf4ioxfLdnSYv4zxg6AbCupJ4Fh5t+/XFV23i1QD3IxJvz0X8odwU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rr0hw0LU; 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="rr0hw0LU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2E1CC2BCAF; Tue, 28 Apr 2026 20:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409168; bh=t2OQ6d8PPidPjQSh+RBxS6XeDUdzwdvT/+uZ5YR7P1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rr0hw0LUtKEvE2iGFOvQa01r4+uQhBZmgmlRCrcvNjFHvUYxNcgOXCjQg8cDxV+R3 GrkWXmjBKsDLBkYlxjqfML6Hw8vobXSCWks3yVeOGPMvzO8PRzsR7ilR4qeqsY1+84 kiaM95+umtOqNRdeiIXrpYhIjMoAQv3nMHJwTSCWbdVR9R1UV0UDzRQGCIid4SZfHY 3DrCVejINPDNVWPtRSxHTBInOLl6JmdDk00DjhEYUnd70EQ/4VW+Vq17OfcfCLHlMl 2YsWF+C+T2Oaz889Y4XNKMkBj0GonDmPT+vJt3yrnSTI7U4PqxZX8mnEaT1EdoAtcg 8bBLUlLZAN8dg== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 30/54] selftests/mm: compaction_test: use HugeTLB helpers ... Date: Tue, 28 Apr 2026 23:42:16 +0300 Message-ID: <20260428204240.1924129-31-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" ... instead of open coded access of HugeTLB parameters via /proc. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/compaction_test.c | 113 +++---------------- 1 file changed, 17 insertions(+), 96 deletions(-) diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/s= elftests/mm/compaction_test.c index 30209c40b697..962a50c3d66f 100644 --- a/tools/testing/selftests/mm/compaction_test.c +++ b/tools/testing/selftests/mm/compaction_test.c @@ -17,6 +17,7 @@ #include =20 #include "kselftest.h" +#include "hugepage_settings.h" =20 #define MAP_SIZE_MB 100 #define MAP_SIZE (MAP_SIZE_MB * 1024 * 1024) @@ -82,75 +83,33 @@ int prereq(void) return -1; } =20 -int check_compaction(unsigned long mem_free, unsigned long hugepage_size, - unsigned long initial_nr_hugepages) +int check_compaction(unsigned long mem_free, unsigned long hugepage_size) { - unsigned long nr_hugepages_ul; - int fd, ret =3D -1; + unsigned long nr_hugepages; int compaction_index =3D 0; - char nr_hugepages[20] =3D {0}; - char init_nr_hugepages[24] =3D {0}; - char target_nr_hugepages[24] =3D {0}; - int slen; - - snprintf(init_nr_hugepages, sizeof(init_nr_hugepages), - "%lu", initial_nr_hugepages); + int ret =3D -1; =20 /* We want to test with 80% of available memory. Else, OOM killer comes in to play */ mem_free =3D mem_free * 0.8; =20 - fd =3D open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK); - if (fd < 0) { - ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); - ret =3D -1; - goto out; - } - /* * Request huge pages for about half of the free memory. The Kernel * will allocate as much as it can, and we expect it will get at least 1/3 */ - nr_hugepages_ul =3D mem_free / hugepage_size / 2; - snprintf(target_nr_hugepages, sizeof(target_nr_hugepages), - "%lu", nr_hugepages_ul); - - slen =3D strlen(target_nr_hugepages); - if (write(fd, target_nr_hugepages, slen) !=3D slen) { - ksft_print_msg("Failed to write %lu to /proc/sys/vm/nr_hugepages: %s\n", - nr_hugepages_ul, strerror(errno)); - goto close_fd; - } - - lseek(fd, 0, SEEK_SET); - - if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <=3D 0) { - ksft_print_msg("Failed to re-read from /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); - goto close_fd; - } + nr_hugepages =3D mem_free / hugepage_size / 2; + hugetlb_set_nr_default_pages(nr_hugepages); =20 /* We should have been able to request at least 1/3 rd of the memory in huge pages */ - nr_hugepages_ul =3D strtoul(nr_hugepages, NULL, 10); - if (!nr_hugepages_ul) { + nr_hugepages =3D hugetlb_nr_default_pages(); + if (!nr_hugepages) { ksft_print_msg("ERROR: No memory is available as huge pages\n"); goto close_fd; } - compaction_index =3D mem_free/(nr_hugepages_ul * hugepage_size); - - lseek(fd, 0, SEEK_SET); - - if (write(fd, init_nr_hugepages, strlen(init_nr_hugepages)) - !=3D strlen(init_nr_hugepages)) { - ksft_print_msg("Failed to write value to /proc/sys/vm/nr_hugepages: %s\n= ", - strerror(errno)); - goto close_fd; - } + compaction_index =3D mem_free/(nr_hugepages * hugepage_size); =20 - ksft_print_msg("Number of huge pages allocated =3D %lu\n", - nr_hugepages_ul); + ksft_print_msg("Number of huge pages allocated =3D %lu\n", nr_hugepages); =20 if (compaction_index > 3) { ksft_print_msg("ERROR: Less than 1/%d of memory is available\n" @@ -161,48 +120,10 @@ int check_compaction(unsigned long mem_free, unsigned= long hugepage_size, ret =3D 0; =20 close_fd: - close(fd); - out: ksft_test_result(ret =3D=3D 0, "check_compaction\n"); return ret; } =20 -int set_zero_hugepages(unsigned long *initial_nr_hugepages) -{ - int fd, ret =3D -1; - char nr_hugepages[20] =3D {0}; - - fd =3D open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK); - if (fd < 0) { - ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); - goto out; - } - if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <=3D 0) { - ksft_print_msg("Failed to read from /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); - goto close_fd; - } - - lseek(fd, 0, SEEK_SET); - - /* Start with the initial condition of 0 huge pages */ - if (write(fd, "0", sizeof(char)) !=3D sizeof(char)) { - ksft_print_msg("Failed to write 0 to /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); - goto close_fd; - } - - *initial_nr_hugepages =3D strtoul(nr_hugepages, NULL, 10); - ret =3D 0; - - close_fd: - close(fd); - - out: - return ret; -} - int main(int argc, char **argv) { struct rlimit lim; @@ -212,18 +133,19 @@ int main(int argc, char **argv) unsigned long mem_free =3D 0; unsigned long hugepage_size =3D 0; long mem_fragmentable_MB =3D 0; - unsigned long initial_nr_hugepages; =20 ksft_print_header(); =20 if (prereq() || geteuid()) ksft_exit_skip("Prerequisites unsatisfied\n"); =20 - ksft_set_plan(1); - /* Start the test without hugepages reducing mem_free */ - if (set_zero_hugepages(&initial_nr_hugepages)) - ksft_exit_fail(); + hugetlb_save_settings(); + hugetlb_set_nr_default_pages(0); + if (hugetlb_nr_default_pages()) + ksft_exit_skip("Could not reset nr_hugepages\n"); + + ksft_set_plan(1); =20 lim.rlim_cur =3D RLIM_INFINITY; lim.rlim_max =3D RLIM_INFINITY; @@ -268,8 +190,7 @@ int main(int argc, char **argv) entry =3D entry->next; } =20 - if (check_compaction(mem_free, hugepage_size, - initial_nr_hugepages) =3D=3D 0) + if (check_compaction(mem_free, hugepage_size) =3D=3D 0) ksft_exit_pass(); =20 ksft_exit_fail(); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 960113783C0; Tue, 28 Apr 2026 20:46:15 +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=1777409175; cv=none; b=n9gG8xp473d4+TVoIyokCKCQcW/uYkiqaUgMvkQxwFB/uTCU28SQYkd9re7jkYfXBpWZu2yI4Nz0Ysc0UE0ib77wD7OEnWsHIJQcU3/tduvOanplKl5HZyM+iaaxBJ6j1KaXQ9iZ/PyV331Cgk5x9H+a00UqXmakrshXFeHMjwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409175; c=relaxed/simple; bh=1/ugYRnvvCSRn7Fw/zm14SmACzlAtT74uoyJWfVmAG8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KEpoqGJqY7S38SMl/8O11JFwF9L46yj4lAWjScQfowrFSdYUpipD3rbkLC//yaYHh6sZsuAtR6XWsTooRTsYMecKnlljMIe4XL7HVFcc3nlBBQH79MuT4M7MXUaHuE3M4w3DPEhtQMeU8c6vK+3+2B1jnxQgdvbvlR9pArabyL4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kTFsYnxL; 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="kTFsYnxL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C0CDC2BCAF; Tue, 28 Apr 2026 20:46:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409175; bh=1/ugYRnvvCSRn7Fw/zm14SmACzlAtT74uoyJWfVmAG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kTFsYnxLJOXZ0Q/eEhcLcg5Mlx0/S5fL9oy9PD+uUlFmgofUhqxp7PdVxkOQVCNEQ eMKvRBpPLeJ8BcHjU5lD2EBjvd0VHGsRxbwsZEjZ5Fd6Q3krz8cVblBXTqUVwJ3jQa atxv47h0dBWxJnx2wSGBFc/voKhGGWWaqc1T/NjwKkSh+GqOOqXHrQVqIo9JDmVYf4 nsr73MeVOdZyI0K7DYbKAr+KDLczHmrQhprpBvvxqCTssdFm04wNGXq4MnTC5iws1+ 29t71PuA6Af6KROAp9kammZcyZv4Q8xTEQJ7fIlU/+IDBDG6uIkfJLGgkXuM0itW1U JOMuUU8YENv6A== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 31/54] selftests/mm: cow: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:17 +0300 Message-ID: <20260428204240.1924129-32-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" cow tests skips HugeTLB tests if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/cow.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/= cow.c index 4321f4208fe3..1df513bf362d 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -1881,21 +1881,21 @@ int main(int argc, char **argv) =20 ksft_print_header(); =20 + hugepage_save_settings(true, true); + pagesize =3D getpagesize(); pmdsize =3D read_pmd_pagesize(); if (pmdsize) { /* Only if THP is supported. */ thp_read_settings(&default_settings); default_settings.hugepages[sz2ord(pmdsize, pagesize)].enabled =3D THP_IN= HERIT; - thp_save_settings(); thp_push_settings(&default_settings); =20 ksft_print_msg("[INFO] detected PMD size: %zu KiB\n", pmdsize / 1024); nr_thpsizes =3D detect_thp_sizes(thpsizes, ARRAY_SIZE(thpsizes)); } - nr_hugetlbsizes =3D detect_hugetlb_page_sizes(hugetlbsizes, - ARRAY_SIZE(hugetlbsizes)); + nr_hugetlbsizes =3D hugetlb_setup(2, hugetlbsizes, ARRAY_SIZE(hugetlbsize= s)); has_huge_zeropage =3D detect_huge_zeropage(); =20 ksft_set_plan(ARRAY_SIZE(anon_test_cases) * tests_per_anon_test_case() + --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 6AFFB1C84BC; Tue, 28 Apr 2026 20:46:22 +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=1777409182; cv=none; b=Z4f84IGiZ07fFZpgrkbkYj0pEW3pNu19xHknoVBplmg8piej+rJbCoGsZCOhzlaxPZRmMPPUNa/mi0yuz97a2Ahpdli3SGcj/37SEnFmjU0GuWw1BVwxxXBhw0bQQSqOmIsQXErG77UE3kTc9HIFgZEit6anFVUc4j3xZ9nFV8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409182; c=relaxed/simple; bh=+OvcjE79uMeuRExtXX4z8n9tjto6YL9x88apIU5Xm3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rGjNpBW0rerhzqLpanhR5Gzi+kFtwtrirbTYNh01Ltek5VzAMYJQhad4WkTyN6alzD7QVepzweU8M3Q73SABd5FKhY9c6XLCDNX1sdW05vI9jHcHQwsBNaAbTmMuT404nJ5BYUZrYdHx3aLcTv1dY8g1bck1E3X0tZ/s7b/808E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TZqr0eLx; 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="TZqr0eLx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03AD0C2BCB3; Tue, 28 Apr 2026 20:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409182; bh=+OvcjE79uMeuRExtXX4z8n9tjto6YL9x88apIU5Xm3o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TZqr0eLxhEfqMiZsaMVHWOG+AucVJcmqXOKoenveGucYc/fzs4gVFRV5G7wVa5GK4 OROazvxv4pdeMLn0lY91hU4Quqp6lB5WxBbTPvVC0ReBBQSTq+zN0Y/Xmc+r40OKJs FAuZOYgIzij5EmMXivP+r8pGWuhx68Qv4j0XRpHUPk1iSS2m1c1x+rRsUmGsnjJR3D iKAVc6PtW4qhsoUSUop8ttE4zeV6+NyaWlsg3slI1241DqcEaqRkplVMFcRpnE3/n+ vBoLSds6+Yp3MNFKBLOhaNmd7xLy2yktHRFyR4piFz0lhFdWx7/FSLbzb9pOOx2oSt gqnrzutgv+pvQ== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 32/54] selftests/mm: gup_longterm: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:18 +0300 Message-ID: <20260428204240.1924129-33-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" gup_longterm tests skips HugeTLB tests if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/gup_longterm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/self= tests/mm/gup_longterm.c index ab4eaf4feb7c..6e1de12bf28c 100644 --- a/tools/testing/selftests/mm/gup_longterm.c +++ b/tools/testing/selftests/mm/gup_longterm.c @@ -510,7 +510,7 @@ int main(int argc, char **argv) int i; =20 pagesize =3D getpagesize(); - nr_hugetlbsizes =3D detect_hugetlb_page_sizes(hugetlbsizes, + nr_hugetlbsizes =3D hugetlb_setup(2, hugetlbsizes, ARRAY_SIZE(hugetlbsizes)); =20 ksft_print_header(); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 BDD4A341660; Tue, 28 Apr 2026 20:46:28 +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=1777409188; cv=none; b=uKdh6BJIxr3O9nHjqRBJvAWHkIuW4Ltk1L50y2sje1Z69aPrC76UjwhrUzTF3ORfKrpOu8be8DPrijP2u4enDKS7ahw0Z/OK4aGY+9C0XKWgOzmzlX4OIDX3tBbzL2COxT2qx7Rrs1dVHcVcjOT5NJTbGJdH7nU2S3tBNVwrYGU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409188; c=relaxed/simple; bh=a9ftjtHwEJ6B9K8hvRWelWOu2y5v4+ZMDsKskwzolFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KBUoKaoHN5k7sxnILYTlqqaHUKXfn0sgTfIiwDL5+kgD8GHYH4MuACJHsef+O7Tq8FqQK7kQfRdZOE7oyt1l7SjuErW6UHaHKejoQ221fglwIt4v68xqo0hI8pqRZ28sf8ClZdSv3mAfydFWN62fF9mTKmq/wm7p7SPd4CPBurg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QsyGB1L+; 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="QsyGB1L+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90DEAC2BCAF; Tue, 28 Apr 2026 20:46:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409188; bh=a9ftjtHwEJ6B9K8hvRWelWOu2y5v4+ZMDsKskwzolFM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QsyGB1L+2irCrH9CMlOrIHyvURQXKBlWBwbZ5sU8dOaMwU5IKmOlS1ll+gFZmc7bx B14cXS5sleTQCEX2kd2tGAzu6RgHb9/LpiqlCv8sf0RUAZEqsJ9pZ5jFU3uqU3F7ar dg3xv5/lO54wbneplHMrptRrlNcKil+QiU/hbdxVUr3PnV7crdSOEjO7FvHAuGv9Ue QW0ZD81BwB9wOvv5sD3NzHJSgHJs/EngSwh2jatzDNIqyMFW2sQhpZukwm80lnSRIA l7aPl+0OOB3Y0Ee1QseaN4GePbYlodZsf3kiL+SmisFOYHN8CRJGH7O7GPogW6+F6S 156VBlD89XymA== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 33/54] selftests/mm: gup_test: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:19 +0300 Message-ID: <20260428204240.1924129-34-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" gup_test fails to run HugeTLB tests if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/gup_test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/mm/gup_test.c b/tools/testing/selftest= s/mm/gup_test.c index fb8f9ae49efa..ddd239a69881 100644 --- a/tools/testing/selftests/mm/gup_test.c +++ b/tools/testing/selftests/mm/gup_test.c @@ -14,6 +14,7 @@ #include #include "kselftest.h" #include "vm_util.h" +#include "hugepage_settings.h" =20 #define MB (1UL << 20) =20 @@ -94,6 +95,7 @@ int main(int argc, char **argv) int filed, i, opt, nr_pages =3D 1, thp =3D -1, write =3D 1, nthreads =3D = 1, ret; int flags =3D MAP_PRIVATE; char *file =3D "/dev/zero"; + bool hugetlb =3D false; pthread_t *tid; char *p; =20 @@ -168,6 +170,7 @@ int main(int argc, char **argv) break; case 'H': flags |=3D (MAP_HUGETLB | MAP_ANONYMOUS); + hugetlb =3D true; break; default: ksft_exit_fail_msg("Wrong argument\n"); @@ -199,6 +202,15 @@ int main(int argc, char **argv) } =20 ksft_print_header(); + + if (hugetlb) { + unsigned long hp_size =3D default_huge_page_size(); + + size =3D (size + hp_size - 1) & ~(hp_size - 1); + if (!hugetlb_setup_default(size / hp_size)) + ksft_exit_skip("Not enough huge pages\n"); + } + ksft_set_plan(nthreads); =20 filed =3D open(file, O_RDWR|O_CREAT, 0664); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 8D700524F; Tue, 28 Apr 2026 20:46:35 +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=1777409195; cv=none; b=qauneMVvZ+rfLdisyOakBCd4lzLePpNTp6nckiAKRFQra1IEaCKZYC4gEpDVA42zQ+Ot34jdqZs2j8Alpn1AXHYiLnoiIE/P2K9+xTbgQetvcr+jYrU1QopA4klBmdFkx56012rphvH62iSAh1tlgQCCIZ29uZKGPcNIiWp5j/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409195; c=relaxed/simple; bh=zjc7IuQI4jBq+AK4lBqRC09uA93LQf31iSBny8sfuNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xg4ID6uGHvLtqi57NNXwEQdyQP1F39Scpwbi5lzHsmU0ocAst71OA32BoAVnokCIyJ74Wk/Hk5kUsjn2Ns2IYb6SPwBzYbWtoKbRoCtTZSeD2w/9lZc8I2qbm/t8o0AImq/mqMS3x8BfRK+bvX6N4xaptAjivyEagvLVXhqM364= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=owzqcCHY; 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="owzqcCHY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 297C3C2BCAF; Tue, 28 Apr 2026 20:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409195; bh=zjc7IuQI4jBq+AK4lBqRC09uA93LQf31iSBny8sfuNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=owzqcCHY0PRBQDKGi7LC8tRxQtjr2qQ9qGzwOzRxNfOTuDYtpbwCie9vo8OZ6wnwo dqvpW1pyCm5QPqbXg1hg68xpgLQmVswwcvssPeH0YCO2dFc9LB4QZ7pketHltkljD2 0qwnxWvwGQnph1nLmPTp4/5a8L1PwHpwA0BLnEjz8/qI/ao2cRDgR/GdMbICRSTCw9 qrkd2LAp3hoWmrEpgoVVYYMsZEVH1whuJ53b3IdRSzz3DQUJGPsEqRqchSS/w6AtaB h7YnHPJzDNajPyqerzOK1pFNTSJnlOAfu0uDwRlo7Mq36d8Hqv9SAsjq7ZVPEE2YNW MjJEI8+77K1EA== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 34/54] selftests/mm: hmm-tests: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:20 +0300 Message-ID: <20260428204240.1924129-35-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hmm-tests skips HugeTLB tests if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Since kselftest_harness runs fixture setup and the tests in child processes, use HUGETLB_SETUP_DEFAULT_PAGES() that defines a constructor that runs in the main process and add verification that there are enough free huge pages to the tests that use them. Replace exit() calls with _exit() to avoid restoring HugeTLB settings in the middle of test and use SIGLILL to kill a child process in hmm_cow_in_device test to avoid interference with signal handlers in hugepage_restore_settings(). Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/hmm-tests.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/mm/hmm-tests.c b/tools/testing/selftes= ts/mm/hmm-tests.c index 409b11cad4bc..70c7ae989c01 100644 --- a/tools/testing/selftests/mm/hmm-tests.c +++ b/tools/testing/selftests/mm/hmm-tests.c @@ -69,6 +69,9 @@ enum { #ifndef FOLL_LONGTERM #define FOLL_LONGTERM 0x100 /* mapping lifetime is indefinite */ #endif + +HUGETLB_SETUP_DEFAULT_PAGES(1) + FIXTURE(hmm) { int fd; @@ -632,7 +635,7 @@ TEST_F(hmm, anon_write_child) } =20 close(child_fd); - exit(0); + _exit(0); } } } @@ -712,7 +715,7 @@ TEST_F(hmm, anon_write_child_shared) ASSERT_EQ(ptr[i], -i); =20 close(child_fd); - exit(0); + _exit(0); } =20 /* @@ -784,8 +787,9 @@ TEST_F(hmm, anon_write_hugetlbfs) int *ptr; int ret; =20 - if (!default_hsize) - SKIP(return, "Huge page size could not be determined"); + if (!hugetlb_free_default_pages()) + SKIP(return, "Not enough huge pages"); + default_hsize =3D default_huge_page_size(); =20 size =3D ALIGN(TWOMEG, default_hsize); npages =3D size >> self->page_shift; @@ -1564,9 +1568,9 @@ TEST_F(hmm, compound) unsigned long i; =20 /* Skip test if we can't allocate a hugetlbfs page. */ - - if (!default_hsize) - SKIP(return, "Huge page size could not be determined"); + if (!hugetlb_free_default_pages()) + SKIP(return, "Not enough huge pages"); + default_hsize =3D default_huge_page_size(); =20 size =3D ALIGN(TWOMEG, default_hsize); npages =3D size >> self->page_shift; @@ -2025,10 +2029,10 @@ TEST_F(hmm, hmm_cow_in_device) ptr[i] =3D i; =20 /* Terminate child and wait */ - EXPECT_EQ(0, kill(pid, SIGTERM)); + EXPECT_EQ(0, kill(pid, SIGKILL)); EXPECT_EQ(pid, waitpid(pid, &status, 0)); EXPECT_NE(0, WIFSIGNALED(status)); - EXPECT_EQ(SIGTERM, WTERMSIG(status)); + EXPECT_EQ(SIGKILL, WTERMSIG(status)); =20 /* Take snapshot to CPU pagetables */ ret =3D hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT, buffer, npages); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 DF787347534; Tue, 28 Apr 2026 20:46:41 +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=1777409201; cv=none; b=Aa3hIziGB24OJvPh3DLqB5ZtkD6lZAf9qizthN7DufD4QyhhpHDH1/pr8EGxG73Ob4exg0YtNbhy1WK7oXgXKubcrfle8SSW9kUaWgHb46Cm1ag6v/RLrU0d9/LdkyPxQeUyZHGCoR1It3q+XPT7b0hAatSwD24RCBfVqrIOFoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409201; c=relaxed/simple; bh=dW6FhGF6pU1ym+r/rDESusHBHIrjPAzWgWJPywW+wGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZPlw017SvB/GB1Abl8VJo2JKvoSuJXLPOama/lgsiO5LzhbJF8zMT38W9G/nJG8YlAcAZzlkwv65TrsNKCuYdd/DZYwzeWAcx7rsfl8TrrvGc0chIg7bMKuNL8ZqJGpbI2UjdMWj4ljRdOQOZzY6Fglbs/iyt5c4slEhmTm9Nlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fYuSQhSV; 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="fYuSQhSV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6DBEC2BCAF; Tue, 28 Apr 2026 20:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409201; bh=dW6FhGF6pU1ym+r/rDESusHBHIrjPAzWgWJPywW+wGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fYuSQhSVJ0ne2pgs7DvNzBdLL+G7mpiR2pp5C86jf+5176Cqh40SJcetAD5R9OMMn UROUjRqwcCbItrnjUJ9UCitoH+/D8VGH5E1o0CEXfEBBUwjChlwUxNpS064vULczf0 NwjkOyYaU5HHVj93kINvzKGKm3Y/nxQvdczmtMMXPWURgH14HTphEAGHIyqb5ij3GD AK1E0tRd7AGjK4iuxNPZsAy1jPYwds9CRgB89P4KIGtx5+YKGOi4y+y/7eC88Y9vhz ugAjg/AoCer2QAdSJloOlHPCzVkhAGf9OxkOc9azhyQBlX1jCpwI2RwBvcEDFl+bXJ c17JRcaUxrrEA== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 35/54] selftests/mm: hugepage_dio: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:21 +0300 Message-ID: <20260428204240.1924129-36-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hugepage_dio test fails if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/hugetlb_dio.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selft= ests/mm/hugetlb_dio.c index 47019433ddaf..fb4600570e13 100644 --- a/tools/testing/selftests/mm/hugetlb_dio.c +++ b/tools/testing/selftests/mm/hugetlb_dio.c @@ -85,8 +85,6 @@ static void run_dio_using_hugetlb(int fd, unsigned int st= art_off, =20 /* Get the default huge page size */ h_pagesize =3D default_huge_page_size(); - if (!h_pagesize) - ksft_exit_fail_msg("Unable to determine huge page size\n"); =20 /* Reset file position since fd is shared across tests */ if (lseek(fd, 0, SEEK_SET) < 0) @@ -94,10 +92,6 @@ static void run_dio_using_hugetlb(int fd, unsigned int s= tart_off, =20 /* Get the free huge pages before allocation */ free_hpage_b =3D hugetlb_free_default_pages(); - if (free_hpage_b =3D=3D 0) { - close(fd); - ksft_exit_skip("No free hugepage, exiting!\n"); - } =20 /* Allocate a hugetlb page */ orig_buffer =3D mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 0); @@ -141,8 +135,8 @@ int main(void) =20 ksft_print_header(); =20 - /* Check if huge pages are free */ - if (!hugetlb_free_default_pages()) + /* request a huge page */ + if (!hugetlb_setup_default(1)) ksft_exit_skip("No free hugepage, exiting\n"); =20 fd =3D open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 7CF2934E75E; Tue, 28 Apr 2026 20:46:48 +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=1777409208; cv=none; b=QAttNaIoMFdwSQhmqAt6eq7uO6EDRwvY2CPQScheoB5J9fBBrEmkRCPcndZV/9eFFHl1w/6w6bxH4R78P03TO1eBhUXpYjJhdaZKqEe2MFvaLx3TEMhtt+FAEoa4fWPZbCqVHhRzqEWJQ46qtGdRsf/fmBf77n0tQ57CQr8htZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409208; c=relaxed/simple; bh=ib9LXsJztlT6AS3f5wMdXHDwOYMXkAdeN957x1qT4BE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hk3YZa1AUHreN9b/64qE15tO7O+HjlBqfAkSzDfXFnETCZuX/3f21hfeG3Bj7NDnhfwsACYMge/SdGdybmb8UqeuOaSE0NNbs6mdfUV07ungT8vEmS5T398KuWQhMm1hddBmWs8GfG9w63GxiFcXLwhr8CG3be0jLKv1jmr4ato= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PRU3DXRA; 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="PRU3DXRA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E4D5C2BCAF; Tue, 28 Apr 2026 20:46:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409208; bh=ib9LXsJztlT6AS3f5wMdXHDwOYMXkAdeN957x1qT4BE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PRU3DXRA2mjPTJz0dlKDBKxbR8oyutEeJ5qREI7hgZj7tTUBuFefszFirMwxHaZtA wcQno4kZaVZxipoEstFNRT5Kx6+fsqYyjTZeXq2r+uZZ/p9PwSFe7IQwRuDrRPkyHj 3k7s3R1pNVsDvBBxWbiqgFyt5/iafBc8nmxOGuREw7X1QZ1ibJ4rfhmCpwKxnJFocc Gib7jpuSTVpA7GOrnpeS/LZ2KSmKYszWeZxfeWWNsvLzC07UiHqaygD+5A3xv78Te+ ni1bxIYZndp3tm7D4+ge+z8JMBNAUIcSn0XMAYNfn/WJVbwmWhe8BodXzGn0I3MkAm aJhXzi8/kqPlg== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 36/54] selftests/mm: hugetlb_fault_after_madv: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:22 +0300 Message-ID: <20260428204240.1924129-37-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hugetlb_fault_after_madv test skips testing if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/hugetlb_fault_after_madv.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c b/tools/= testing/selftests/mm/hugetlb_fault_after_madv.c index c718dd065d53..481863cc5fda 100644 --- a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c +++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c @@ -54,7 +54,6 @@ void *madv(void *unused) =20 int main(void) { - unsigned long free_hugepages; pthread_t thread1, thread2; /* * On kernel 6.4, we are able to reproduce the problem with ~1000 @@ -78,10 +77,9 @@ int main(void) ksft_print_msg("[INFO] detected default hugetlb page size: %zu KiB\n", huge_page_size / 1024); =20 - free_hugepages =3D hugetlb_free_default_pages(); - if (free_hugepages !=3D 1) { + if (!hugetlb_setup_default(1)) { ksft_exit_skip("This test needs one and only one page to execute. Got %l= u\n", - free_hugepages); + hugetlb_free_default_pages()); } =20 while (max--) { --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 6E9A037F8DB; Tue, 28 Apr 2026 20:46:55 +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=1777409215; cv=none; b=qsMDdaCo/4Mygt08LMtw7oe91j6cuPQr2w41lb8bbLt1kRaw/+JxJEB9tUHTaMXFYDOK+aA1JjnMQ4yhH8N63TPHzWGZqhCQHQzZNTlUt9SnPrKWhw0xsS4Xf1Cef/sDjjhBkYXHW3gAfuTSuDWKZEmc92B+LmGF/ZTj/701bRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409215; c=relaxed/simple; bh=1E1PaJAheFq68IlA7LKJisHu/YP5aoXijmYjIj2LOcM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L4G5T0ZymHF6CG0APoJjNOtnfS6oY3hQJGaCrSrKiBy6g8mB1ks8Fn2vLkuvZ4IFEMrBzqeJ22nJ+przhFhiNeKR8wH9xj9q5qih/CfbDfRbiHP/VC0JLJfmPvgi9w50L59F+mODnYu3fiW8RrghFw1Ee5cduO5h0nSYMmmv7L4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RfTZR8A5; 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="RfTZR8A5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAF63C4AF09; Tue, 28 Apr 2026 20:46:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409214; bh=1E1PaJAheFq68IlA7LKJisHu/YP5aoXijmYjIj2LOcM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RfTZR8A5NSaVcxV4oFGcISWB69/39YfEdkoN6L1MZWM+kttqU+LmX2bZHSnp0cWRa dwWrhk4La8ShLvJv2Ji3jwOgArl4fxnmsZv2Uguy/wDmYCATYP/MrUlCByI0rYFmSi iYlU6oNDU8Q3fV8whf1+Ll91KGJb6QpnSjR0urln9RbYBuEQwBhsa3ReYgrmJ48g4z wNBHtqFcFB5/EMiEoDB3JDRsxbF69nXhyXU++Qs/Nu++cIO2iilaHSp5ccDNRY5ngm sIDB6GzwRbOrbXw6DTIMzBKiDU057XAQF+6oHTVq/WiesNC1Ti+jzqQkv4bobaT70z Urg8jyOsVksbw== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 37/54] selftests/mm: hugetlb-madvise: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:23 +0300 Message-ID: <20260428204240.1924129-38-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hugetlb-madvise test skips testing if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/hugetlb-madvise.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/s= elftests/mm/hugetlb-madvise.c index 3c08eb6db6a2..b20648d025e6 100644 --- a/tools/testing/selftests/mm/hugetlb-madvise.c +++ b/tools/testing/selftests/mm/hugetlb-madvise.c @@ -68,9 +68,9 @@ int main(int argc, char **argv) if (!base_page_size) ksft_exit_fail_msg("Unable to determine base page size\n"); =20 + if (!hugetlb_setup_default(MIN_FREE_PAGES)) + ksft_exit_skip("Not enough free huge pages (have %lu, need %d)\n", huget= lb_free_default_pages(), MIN_FREE_PAGES); free_hugepages =3D hugetlb_free_default_pages(); - if (free_hugepages < MIN_FREE_PAGES) - ksft_exit_skip("Not enough free huge pages (have %lu, need %d)\n", free_= hugepages, MIN_FREE_PAGES); =20 fd =3D memfd_create(argv[0], MFD_HUGETLB); if (fd < 0) --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 EE61B3101A2; Tue, 28 Apr 2026 20:47:01 +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=1777409222; cv=none; b=eznIyNG5Wc4HKtOq7szcmw2L7dIlosZvk84edsF94SON9y4DwM8hazsvTM/yUXdXlHQy7w+z+mnDR2n2fy4Aixxok7Xs5bu4ye0kV8ZXFu0hZgDaJx2gLGDE4jBViDxtDaMPdteuvXFhnW7mz3ygH9GgUMRwpniBesv+Y+GTDqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409222; c=relaxed/simple; bh=nlprzoVHw1LmFezPWbTzVMDcbCMocVKEurNVLRnJdhY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ot9l0vxpqPf9sEVGJmRMGzLZi3CCY8XpeAgO5DLalpigFlu/ALfXzOtPuYuipi4fKsijCYAIeGfDomItecXha793CzdFbxd27ZKoT62UD/7YdBAQJpi1jRSuEmsaaToo+aj3mEeCfzsrnc3OeLpWs3wy5g3mNj8PGtMKreJ45sc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V57v9J9a; 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="V57v9J9a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 732E3C2BCAF; Tue, 28 Apr 2026 20:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409221; bh=nlprzoVHw1LmFezPWbTzVMDcbCMocVKEurNVLRnJdhY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V57v9J9atU6/t5FqptjBfJl92fqfYl9DPBz55qkgpDwRR/I6sgRiD6xQBGTgY8+Qs goM8lUWUX9kY3Qguku7H3K6DSrqBJtSIMCumto/brJOewZFHrh9RQ2e96HV7uO9ejA fzP59wwZuKOfemit0p/p9GaY8roQbtYVk8GqjqOfWnsC0daPMrpNFfbB4c+TX1qzIT cfEot80Lv8cNZk81LAyiIyNrHyz01HGdLP10fSzc6I0QWGObIVRBP4ZoiGenOVXLjx UGHj6odI4NSyGl2+dvvbphiPfz/BrfVlYKSs377nPAvac/iKmloBNmsHIN48xCiv+H Ta/n56MnZpn+w== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 38/54] selftests/mm: hugetlb_madv_vs_map: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:24 +0300 Message-ID: <20260428204240.1924129-39-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hugetlb_madv_vs_map test skips testing if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/hugetlb_madv_vs_map.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c b/tools/testi= ng/selftests/mm/hugetlb_madv_vs_map.c index dfbd71a7f709..6c95dd23ca81 100644 --- a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c +++ b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c @@ -77,7 +77,6 @@ void *map_extra(void *unused) int main(void) { pthread_t thread1, thread2, thread3; - unsigned long free_hugepages; void *ret; =20 /* @@ -89,11 +88,9 @@ int main(void) ksft_print_header(); ksft_set_plan(1); =20 - free_hugepages =3D hugetlb_free_default_pages(); - - if (free_hugepages !=3D 1) + if (!hugetlb_setup_default(1)) ksft_exit_skip("This test needs one and only one page to execute. Got %l= u\n", - free_hugepages); + hugetlb_free_default_pages()); =20 mmap_size =3D default_huge_page_size(); =20 --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 9FF584A35; Tue, 28 Apr 2026 20:47:08 +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=1777409228; cv=none; b=gGzqwdCP6EWn6qjVsH1Kvs5pbKvsTrt86Z4aZP4EiUNY/HdEBvJo5mADglw1/M2VWNOHIf0cVW9YKkH+7kqG7Jwf8EKeKMpw5bhUq0eF1OMX8KJOEO2PNwwyMu9R6f50wIuswwSELyfPkjlG/qW9FHkkZcV4zIzoY0g8R7Vm1us= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409228; c=relaxed/simple; bh=H40+pLu8ZXyLLCNuZ1aw7t2Lxy9FF78cv/g7Q6Z1blI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eNMiZTs7M0wx4rfvfhIB28ysVqm7ktJuIoTK5A3INcpBtaNiXjWZyNjuOcnr5qWDxXYgg9Fs68vaOWqu9K81lte7VmTQXthpvC/F0vMS4FvFVxzXxUr+dV87+fTqR760r9/rGEyhHQhh8+HFlCGhHHZV2xXaq63KE5YpGpruKJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CUpSi+Wl; 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="CUpSi+Wl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 298C0C2BCAF; Tue, 28 Apr 2026 20:47:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409228; bh=H40+pLu8ZXyLLCNuZ1aw7t2Lxy9FF78cv/g7Q6Z1blI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CUpSi+WlocgmOIRAqyCd2U0J+RRYYD0kUVlOkWBufcWndXzjq+aJv3VMiMpWVyD8z ozi9L2nDHyBbYziKZZ1i7gja3h1ARE4bu52ED0clgVQgZXX1ivXZSQWZBpTW1LgLhR IQ4OTgGQL21uWskksLhlCdonNTDXdCtIePG/Whe0MAlO0WSx+g1ilu9EinYENtB1/6 h7LBHRYPbTFIIHFWFa1BWOtAjaKwu86h9qMcDpxiXfCb+jeW7LAJ0nf20xpKYTHzF2 ComEQb8K1hGs1ctWo74laWEXNg4dFfgkEY+nMvzfEOwFs9czach7b/BvD4O9gjWYbC 6Zx00aMg0ep0A== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 39/54] selftests/mm: hugetlb-mmap: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:25 +0300 Message-ID: <20260428204240.1924129-40-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hugetlb-mmap test fails if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Luiz Capitulino Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/hugetlb-mmap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-mmap.c b/tools/testing/self= tests/mm/hugetlb-mmap.c index 031085cb7d17..f12fc288ef4f 100644 --- a/tools/testing/selftests/mm/hugetlb-mmap.c +++ b/tools/testing/selftests/mm/hugetlb-mmap.c @@ -109,16 +109,16 @@ int main(int argc, char **argv) { size_t hugepage_size; size_t length =3D LENGTH; - int shift =3D 0; + int shift =3D 0, nr; =20 ksft_print_header(); - ksft_set_plan(2); =20 if (argc > 1) length =3D atol(argv[1]) << 20; if (argc > 2) shift =3D atoi(argv[2]); =20 + hugetlb_save_settings(); if (shift) { hugepage_size =3D (1 << shift); ksft_print_msg("%u kB hugepages\n", 1 << (shift - 10)); @@ -128,9 +128,14 @@ int main(int argc, char **argv) } =20 /* munmap with fail if the length is not page aligned */ - if (hugepage_size > length) - length =3D hugepage_size; + length =3D (length + hugepage_size - 1) & ~(hugepage_size - 1); + nr =3D length / hugepage_size; + + hugetlb_set_nr_pages(hugepage_size, nr); + if (hugetlb_free_pages(hugepage_size) < nr) + ksft_exit_skip("Not enough %lu Kb pages\n", hugepage_size >> 10); =20 + ksft_set_plan(2); ksft_print_msg("Mapping %lu Mbytes\n", (unsigned long)length >> 20); =20 test_anon_mmap(length, shift); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 E00EB4A35; Tue, 28 Apr 2026 20:47:14 +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=1777409234; cv=none; b=aV+CRdkIL5FHkLUNMER6neHeX/29ksKsBwN6826es5IYXnDZF90ysP1AB9otL+hW4R9LvfmuFTscsCxZAu2RybIRUePkZi+mUrr5EK+3GyzQ6YVSIGWLzU5BOYHHWv5Di7h/VHb5Sk0wuoJsdGISgGisUVyxdyQP0d3C6QOJlwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409234; c=relaxed/simple; bh=53qqY7PQB/uAj+zPP1JxuvnMAG3AtCcj7DDDSb0K5uw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tW9+myoHuzBk+GlND71FraUERVwyYuIXclQnSU6aBDSJu2gp7hpFuwBXhbBXtMrBkVh9yyM0/lawSn+SFPBfgDHp/dxCDvFSbgXCB6w/g4f7j7ArD+SskNOwN4TAQbw7FAp+rEV6LmIishoukNOiDog4tqZf4X6Wt1oQ1UkwxPQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q5frIw2F; 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="q5frIw2F" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5B72C2BCB7; Tue, 28 Apr 2026 20:47:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409234; bh=53qqY7PQB/uAj+zPP1JxuvnMAG3AtCcj7DDDSb0K5uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q5frIw2F9h3j3tr/ZuaBgEJumVaCnozxARfMNxbPw4TvdEq+hTbY/Bbhgpvs69+l/ yTKrQL1Les69eP+oLRVWYDb3RjY52lt0DqJZx2UHfnvMKIcQN4Bop+LlvMhhKWNQwQ k8i4Iqa74XD1lFdCzKO0KQIlI4njUh2zZ3e8GpFdECDU2W37DghWfakwPnjxAvhRNE wILGlLj/dKqeZZ3Mg+6D5o+EpegtLBtGvQcj21Ti8/XhRYwtj9zdpii8jojEERa7OR IeDg6HWxg3oprDwDV22pRZn6uxfTqGWyxEAge41rkAddkkqo2K77p+dq5iRFd1wVwh pBfLayLsjYHFw== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 40/54] selftests/mm: hugetlb-mremap: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:26 +0300 Message-ID: <20260428204240.1924129-41-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hugetlb-mremap test fails if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/hugetlb-mremap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/hugetlb-mremap.c b/tools/testing/se= lftests/mm/hugetlb-mremap.c index 1c87c39780c5..09241a279ec2 100644 --- a/tools/testing/selftests/mm/hugetlb-mremap.c +++ b/tools/testing/selftests/mm/hugetlb-mremap.c @@ -26,6 +26,7 @@ #include #include "kselftest.h" #include "vm_util.h" +#include "hugepage_settings.h" =20 #define DEFAULT_LENGTH_MB 10UL #define MB_TO_BYTES(x) (x * 1024 * 1024) @@ -108,8 +109,9 @@ static void register_region_with_uffd(char *addr, size_= t len) =20 int main(int argc, char *argv[]) { + unsigned long hugepage_size; + int ret =3D 0, fd, nr; size_t length =3D 0; - int ret =3D 0, fd; =20 ksft_print_header(); ksft_set_plan(1); @@ -125,7 +127,14 @@ int main(int argc, char *argv[]) else length =3D DEFAULT_LENGTH_MB; =20 + hugepage_size =3D default_huge_page_size(); length =3D MB_TO_BYTES(length); + length =3D (length + hugepage_size) & ~(hugepage_size - 1); + nr =3D length / hugepage_size; + + if (!hugetlb_setup_default(nr)) + ksft_exit_skip("Not enough huge pages\n"); + fd =3D memfd_create(argv[0], MFD_HUGETLB); if (fd < 0) ksft_exit_fail_msg("Open failed: %s\n", strerror(errno)); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 BA1B64A35; Tue, 28 Apr 2026 20:47:21 +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=1777409241; cv=none; b=DIXsT7FAQp/jM7gBe84O1PCC3psQO/lM1xm9WIHa7gc+LIXZbDbvj/gbMmjYdx8DuxOg5gUFhZ4r6l4mDGDI98jezh7FPCEhWLWoMgu7BH2iSgvKuSO8u0sl6jw09PRh15K3qkPEqT+SU+8VOi69WrZqz4YIchdyIu/lnquFnig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409241; c=relaxed/simple; bh=V9dhOZl4qkCAKpS16UITNdHC3hzDFxj10poJSetGe5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iYQjnJL625gt6RKp7QZK3W9qn/ufNx12GDXLKrMF3WNy+DuHzFh25RiaJo2QL9xKQUOqdFwdgypwJJpcEcR9u65BopmRz9zNal/L80ziRCyFu4xyd9MYnMNtbrZPPHTqElFT34Fiq2GgK49LOqYXHxunepW3361/KWfGWqYHL6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DMV9bb2z; 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="DMV9bb2z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D6A9C2BCC4; Tue, 28 Apr 2026 20:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409241; bh=V9dhOZl4qkCAKpS16UITNdHC3hzDFxj10poJSetGe5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DMV9bb2zu8GSXHA7ukg/OlvB5BQkbNZuTTEBICiE7WqAdpr/W9GQW1X6W/Q8iMxG5 Iq8bqnlt/UNTLPSvDHk5hMP3i5vF8kLy93Y1rKY46Vmmh9ALvtbkT3VQ3q+1yutp2T y/dOziXrr3AlbCwSzOlKMdkqYAVZRWOJWXopEBpdgK25NZmC94qVPMb/tY2uc70R9D SMw2NJaOy6nRiUKbIpnBbHbB5OdIauJNYcgUS3v1Q9wEWLXBXZkjEZbi40uQTE390i 9bo+M2uolmyGuMCQOsLX7QF6anNDNywpN2xNgEbcS20hmo/INUx8E8alTDo67TtDEo /SDmsdNw/Nsmg== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 41/54] selftests/mm: hugetlb-shm: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:27 +0300 Message-ID: <20260428204240.1924129-42-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hugetlb-shm test fails if there are no free huge pages prepared by a wrapper script and shm liimts in proc are too low. Add setup of HugeTLB pages and shm limits to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/hugetlb-shm.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/testing/selftests/mm/hugetlb-shm.c b/tools/testing/selft= ests/mm/hugetlb-shm.c index 0f70b1a50b6b..7b5a5cefe458 100644 --- a/tools/testing/selftests/mm/hugetlb-shm.c +++ b/tools/testing/selftests/mm/hugetlb-shm.c @@ -29,9 +29,24 @@ #include =20 #include "vm_util.h" +#include "hugepage_settings.h" =20 #define LENGTH (256UL*1024*1024) =20 +static void prepare(void) +{ + unsigned long length, hugepage_size, nr; + + hugepage_size =3D default_huge_page_size(); + length =3D (LENGTH + hugepage_size) & ~(hugepage_size - 1); + nr =3D length / hugepage_size; + + if (!hugetlb_setup_default(nr)) + ksft_exit_skip("Not enough free huge pages\n"); + + shm_limits_prepare(length); +} + int main(void) { int shmid; @@ -41,6 +56,8 @@ int main(void) ksft_print_header(); ksft_set_plan(1); =20 + prepare(); + shmid =3D shmget(2, LENGTH, SHM_HUGETLB | IPC_CREAT | SHM_R | SHM_W); if (shmid < 0) ksft_exit_fail_perror("shmget"); @@ -78,3 +95,5 @@ int main(void) ksft_test_result_pass("hugepage using SysV shmget/shmat\n"); ksft_finished(); } + +SHM_LIMITS_RESTORE() --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 121FC3101A2; Tue, 28 Apr 2026 20:47:28 +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=1777409248; cv=none; b=Rye6C2dT6eaul9mXwS8bokOkQcTn09wlMQzh+waC0HRoEsaAnGX3qY6umIEQCDSGqfLx4G4B7l8eK7PGPxCqBFPGiSU9AwK0qvPf+756fy2tYdNHuo4EO9fdB45qRMoHv6aG2NRVcZ5gOjzOpsTYO3WGFeLUwuAxMjz1rwqBYR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409248; c=relaxed/simple; bh=Ebag/OZwcEEdNBOTVBqp4Cs1aPruonU0XrgpI45ideI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JoNNm9ggjAvhsa+SLCJwEPjImalWSAIo+MCdAhpDN4KJTVbIOGa2Upp9uPT+4jTLNgeru7yxgRi0VzBvtL2iW26sMbgixtRRxL0QhB9HvKxtNLVICYJAXiBCHjzfROyeGMKItTPD5lbmqhzOryqNR+6URKsUcZnOeM7m9sdUME8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hTSKErDk; 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="hTSKErDk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DAC85C2BCAF; Tue, 28 Apr 2026 20:47:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409247; bh=Ebag/OZwcEEdNBOTVBqp4Cs1aPruonU0XrgpI45ideI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hTSKErDkybfCmLqI5oiKe46Ogfo/Y09QcaiEPkLkkehXIETqPunPVRIRgvXEYiguP 2ArwVKUZiz44sK667Yh55r3q/rQoRx+NvAILknozgaKiPEziz+setvnb9pD85Hm4W6 FMpGTpoQyv42luUMlmkVEnyjQ4NvvJg0H5DvtOURoqmYZU5d9QF3SwmsxDKz0aRYYF byi54caBi362T1N03+DtxoirSiSHBwY0Vrp4tt7A2Iq/ESFGT6ZWuWorDEY3pYrQin qFig5BZ5odFLdQm1Wm+BtZaMJzSbZ/7dFW5idmRLtNSIvoc3uBePn0qhbnIdIfxLBO 12z1PteHCCiIg== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 42/54] selftests/mm: hugetlb-soft-online: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:28 +0300 Message-ID: <20260428204240.1924129-43-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hugetlb-soft-online test uses open coded access to /proc to determine availability of huge pages and fails if there are no enough free huget pages.. Replace open coded access to /proc with hugepage helpers and add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- .../selftests/mm/hugetlb-soft-offline.c | 45 ++++--------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-soft-offline.c b/tools/test= ing/selftests/mm/hugetlb-soft-offline.c index a8bc02688085..bc202e4ed2bd 100644 --- a/tools/testing/selftests/mm/hugetlb-soft-offline.c +++ b/tools/testing/selftests/mm/hugetlb-soft-offline.c @@ -6,9 +6,7 @@ * - if enable_soft_offline =3D 1, a hugepage should be dissolved and * nr_hugepages/free_hugepages should be reduced by 1. * - * Before running, make sure more than 2 hugepages of default_hugepagesz - * are allocated. For example, if /proc/meminfo/Hugepagesize is 2048kB: - * echo 8 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages + * The test allocates 8 default hugepages */ =20 #define _GNU_SOURCE @@ -25,6 +23,7 @@ #include =20 #include "kselftest.h" +#include "hugepage_settings.h" =20 #ifndef MADV_SOFT_OFFLINE #define MADV_SOFT_OFFLINE 101 @@ -100,32 +99,6 @@ static int set_enable_soft_offline(int value) return 0; } =20 -static int read_nr_hugepages(unsigned long hugepage_size, - unsigned long *nr_hugepages) -{ - char buffer[256] =3D {0}; - char cmd[256] =3D {0}; - - sprintf(cmd, "cat /sys/kernel/mm/hugepages/hugepages-%ldkB/nr_hugepages", - hugepage_size); - FILE *cmdfile =3D popen(cmd, "r"); - - if (cmdfile =3D=3D NULL) { - ksft_perror(EPREFIX "failed to popen nr_hugepages"); - return -1; - } - - if (!fgets(buffer, sizeof(buffer), cmdfile)) { - ksft_perror(EPREFIX "failed to read nr_hugepages"); - pclose(cmdfile); - return -1; - } - - *nr_hugepages =3D atoll(buffer); - pclose(cmdfile); - return 0; -} - static int create_hugetlbfs_file(struct statfs *file_stat) { int fd; @@ -177,20 +150,14 @@ static void test_soft_offline_common(int enable_soft_= offline) ksft_exit_fail_msg("Failed to set enable_soft_offline\n"); } =20 - if (read_nr_hugepages(hugepagesize_kb, &nr_hugepages_before) !=3D 0) { - close(fd); - ksft_exit_fail_msg("Failed to read nr_hugepages\n"); - } + nr_hugepages_before =3D hugetlb_nr_default_pages(); =20 ksft_print_msg("Before MADV_SOFT_OFFLINE nr_hugepages=3D%ld\n", nr_hugepages_before); =20 ret =3D do_soft_offline(fd, 2 * file_stat.f_bsize, expect_errno); =20 - if (read_nr_hugepages(hugepagesize_kb, &nr_hugepages_after) !=3D 0) { - close(fd); - ksft_exit_fail_msg("Failed to read nr_hugepages\n"); - } + nr_hugepages_after =3D hugetlb_nr_default_pages(); =20 ksft_print_msg("After MADV_SOFT_OFFLINE nr_hugepages=3D%ld\n", nr_hugepages_after); @@ -219,6 +186,10 @@ static void test_soft_offline_common(int enable_soft_o= ffline) int main(int argc, char **argv) { ksft_print_header(); + + if (!hugetlb_setup_default(8)) + ksft_exit_skip("not enough hugetlb pages\n"); + ksft_set_plan(2); =20 test_soft_offline_common(1); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 9EC461A9F8C; Tue, 28 Apr 2026 20:47:34 +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=1777409254; cv=none; b=IGFH7ZSlV7FAkNvipsskoQ7OfGJhqliIR5LqO4DUVZpgoSP48U4GENJe35dDpORN0BFubV9tsFiS2BULEp1VCPAjpHt1GW1B9o7jtch7uHShfpPPspjujKqlLWuPn12d7h6+DDTA+MvR+dCrkiASuMkiuThG4/yvDqvmdk9aEdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409254; c=relaxed/simple; bh=XUYa2AHXODnUwL+2gtS49wymmJEGg8QhpNWWbUz0fDg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rzCIgdHCF+QZn27k6jiMV3rlBOnXBICam+d6Ycj8o0ziMcWqp9ap5t9xFjhbZTHF9zfYnSc+napm8RZDPIsVfKqw9uOwF64vgqVZvelcv1B07EOcQU33IiBj+8kctbu6eLlpirl+/21ZW04MmRKWMijypNXMXIUSmbm5O+Gg/58= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MgHLvtOj; 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="MgHLvtOj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 730C2C2BCC4; Tue, 28 Apr 2026 20:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409254; bh=XUYa2AHXODnUwL+2gtS49wymmJEGg8QhpNWWbUz0fDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MgHLvtOj0Tc6HSaWko38b56B0Y5qzXyNyTnJk8Mao4SXWgeXfbhpanH30CpFlozrp 576l/OCiy1eQ8FWChM82uSAzhuqjVTC3nDEzm3IDhzrV06r53ZqpRfPXg1LWyO2adh Z42GCKeMC5pFyErrdhlpS3lOWo+QYKf3tAavsgBDUTSvX4eytqaTS4hUCO9fGevUfE cSCwPpggYmaunAiSaWShpXNzZKZR+l1LbijpPvVh/yNP/iPzyGO2CNdqBBzyQPf4Uq YzzIwHNFecj8x+lE6Ctx+JQKLgIUYbPj/1UT7Q5ewud8/TM6aZDrF/ZdnjUr1iXId/ msq9YyiZpG06w== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 43/54] selftests/mm: hugetlb-vmemmap: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:29 +0300 Message-ID: <20260428204240.1924129-44-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" hugetlb-vmemmap test fails if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/hugetlb-vmemmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/mm/hugetlb-vmemmap.c b/tools/testing/s= elftests/mm/hugetlb-vmemmap.c index af5786bebfd1..507df78a158d 100644 --- a/tools/testing/selftests/mm/hugetlb-vmemmap.c +++ b/tools/testing/selftests/mm/hugetlb-vmemmap.c @@ -97,6 +97,9 @@ int main(int argc, char **argv) ksft_print_header(); ksft_set_plan(1); =20 + if (!hugetlb_setup_default(1)) + ksft_exit_skip("Not enough free huge pages\n"); + pagesize =3D psize(); maplength =3D default_huge_page_size(); if (!maplength) --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 7434B383C6F; Tue, 28 Apr 2026 20:47:41 +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=1777409261; cv=none; b=ITRORMxXvIi7swDzQgxMSgXJ0SjfoQ/Pbi6TJrbE84oKMrp+MkZnPtodbR1eMvAvhBvCHXfjng8kil7q1rQAg4ny7PoOwS1HLsG3T9Hj5ygnZTczLzqOR+RfCpEw1xMqVLOrzx3HLFj6SGHRMSyoWDhcDj/EXkrR69tK4/5h0/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409261; c=relaxed/simple; bh=WQo8riTW+gdC2wg2rFje/aEFGdbZITZfBZEkLvZiGOg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VXNcWwzhz2MoRmaRCIbmB6umtBi4TIlDF8bIPvj4kEupzAbgK4JY3TKtiHFE9U6nMAk3/sZmTuE00jqzoNwUUsCB+pWQcFD/Vap0TR9vHQJyfWaPU2sDHSNu+1/j6Uo2+yR3a0jOEz0VVYmSQFvWSPBCD/BvUVbDW29luDtB938= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DfWyMyE+; 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="DfWyMyE+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B86FC2BCC7; Tue, 28 Apr 2026 20:47:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409261; bh=WQo8riTW+gdC2wg2rFje/aEFGdbZITZfBZEkLvZiGOg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DfWyMyE+wURM9Ch4JrXDDNborGc6PdSkvjRQf8LzswNdIbrYaZa/c4ViXt/F+1eWS v4Wel4es9JGNXLZSfWHoRXqrxQgv+atphmr01IE9OCGqh67batJjGKF2qg/poHm8zN JKfr7na4AcLN32XDtWYQa4XzLbyMpktAxE3pWTD/DG/2pi9ViTVaKJISeU6hQKku+s 2ThZMGJLLV9yfREP1ZXQbjGVpfkGLpQhDoIJ4ZH2VodxBG65B3q83D9JODrC/g5Ng8 rZ8xn82nE+Mb1Z6IUkm9t6BB2GJzd7/JBdDrDdD2+nUk3nyX17BRqr81pw1+dZa1Oz Y89gz8lrylySA== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 44/54] selftests/mm: migration: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:30 +0300 Message-ID: <20260428204240.1924129-45-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" migration skips HugeTLB tests if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Since kselftest_harness runs fixture setup and the tests in child processes, use HUGETLB_SETUP_DEFAULT_PAGES() that defines a constructor that runs in the main process and add verification that there are enough free huge pages to the tests that use them. Reset signal handlers to defaults in FIXTURE_SETUP() so that sending SIGTERM and SIGHUP during the tests won't cause restoration of HugeTLB settings. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma sarthak.sharma@arm.com --- tools/testing/selftests/mm/migration.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/testing/selftests/mm/migration.c b/tools/testing/selftes= ts/mm/migration.c index 0212cd5bde6e..f212c1b06455 100644 --- a/tools/testing/selftests/mm/migration.c +++ b/tools/testing/selftests/mm/migration.c @@ -23,6 +23,8 @@ #define MAX_RETRIES 100 #define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1))) =20 +HUGETLB_SETUP_DEFAULT_PAGES(1) + FIXTURE(migration) { pthread_t *threads; @@ -32,10 +34,21 @@ FIXTURE(migration) int n2; }; =20 +static void reset_signals(void) +{ + struct sigaction sa =3D { .sa_handler =3D SIG_DFL }; + + sigemptyset(&sa.sa_mask); + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGHUP, &sa, NULL); +} + FIXTURE_SETUP(migration) { int n; =20 + reset_signals(); + if (numa_available() < 0) SKIP(return, "NUMA not available"); self->nthreads =3D numa_num_task_cpus() - 2; @@ -271,6 +284,9 @@ TEST_F_TIMEOUT(migration, private_anon_htlb, 2*RUNTIME) if (!hugepage_size) SKIP(return, "Reading HugeTLB pagesize failed\n"); =20 + if (hugetlb_free_default_pages() < 1) + SKIP(return, "Not enough huge pages\n"); + ptr =3D mmap(NULL, hugepage_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); ASSERT_NE(ptr, MAP_FAILED); @@ -299,6 +315,9 @@ TEST_F_TIMEOUT(migration, shared_anon_htlb, 2*RUNTIME) if (!hugepage_size) SKIP(return, "Reading HugeTLB pagesize failed\n"); =20 + if (hugetlb_free_default_pages() < 1) + SKIP(return, "Not enough huge pages\n"); + ptr =3D mmap(NULL, hugepage_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); ASSERT_NE(ptr, MAP_FAILED); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 10133383C6F; Tue, 28 Apr 2026 20:47:47 +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=1777409268; cv=none; b=RcbtzMqsX/EqDyaQWMlJEgsnrhEX5kEJxQFnrkfkZ/am3yCiL0BIGDW0DvjIWNqKaO+4w4ecqbwvNWskVLUKbzGyIzBb5UeGwI63UC8x1ZycPn3EU4/ZeJANntNpZEyh9HBQmV+8VoOKlXASyOnJ9fh46Xnkqkc1lpCMjVPt/t4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409268; c=relaxed/simple; bh=6G+HupLEy7RoQW/oaRMLwy3Q9S37tIjtSZCXvkrmYmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PkjUwtcSm8cKdt4z9J+UzC/2sVEYmJn8CKlA6LyG6YKolAL7F2id2LV7IvfoN99vaLO6RF9MNNk5nzirpF/gsIffGkKoVmhHDHxIxkj6eDxH5JbeW2IG3Ds+7vBQEROYuQvliYPzontnIUmIT/St1BkoLGhG9hVG8RQigWs/X0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=leaz1n2j; 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="leaz1n2j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97916C2BCAF; Tue, 28 Apr 2026 20:47:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409267; bh=6G+HupLEy7RoQW/oaRMLwy3Q9S37tIjtSZCXvkrmYmU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=leaz1n2j9oxuyVx2ozTbKXqtg3ssJzMfcWnwRTkdJgKalVNCITrankiRbk1qObVTL 5D4eUTcQ+JJ/YIdTqU8lTIafIPSwMm2FvQFs13DEhFMVJCjn5Ojb9B3fPL6ocQhKHr t8VFA6JEq5pxq1H1Lia2cVmdUITLPxnocai0m9yL8/77MS0BIr5tJht43Cl95MK7H3 Qfm2NPNzaeQf7Jw+90+MFcqCs6SL4cD+vk3p7fCRt/A5KwCujpld0nUs069qpmXbkl jbgqft2eCGSHlqe2svy1Mjk03A4Qb9Xu88vmby11PwS3N0otO5cFD8aNdFPI5MAnrN rPsi4UNt6tGYQ== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 45/54] selftests/mm: pagemap_ioctl: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:31 +0300 Message-ID: <20260428204240.1924129-46-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" pagemap-ioctl skips HugeTLB tests if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/pagemap_ioctl.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/mm/pagemap_ioctl.c b/tools/testing/sel= ftests/mm/pagemap_ioctl.c index 7f9428d6062c..e2c62cb6978f 100644 --- a/tools/testing/selftests/mm/pagemap_ioctl.c +++ b/tools/testing/selftests/mm/pagemap_ioctl.c @@ -7,8 +7,6 @@ #include #include #include -#include "vm_util.h" -#include "kselftest.h" #include #include #include @@ -23,6 +21,10 @@ #include #include =20 +#include "vm_util.h" +#include "kselftest.h" +#include "hugepage_settings.h" + #define PAGEMAP_BITS_ALL (PAGE_IS_WPALLOWED | PAGE_IS_WRITTEN | \ PAGE_IS_FILE | PAGE_IS_PRESENT | \ PAGE_IS_SWAPPED | PAGE_IS_PFNZERO | \ @@ -1554,6 +1556,9 @@ int main(int __attribute__((unused)) argc, char *argv= []) if (init_uffd()) ksft_exit_skip("Failed to initialize userfaultfd\n"); =20 + if (!hugetlb_setup_default(4)) + ksft_exit_skip("Not enough huge pages\n"); + ksft_set_plan(117); =20 page_size =3D getpagesize(); @@ -1605,7 +1610,7 @@ int main(int __attribute__((unused)) argc, char *argv= []) } =20 /* 5. SHM Hugetlb page testing */ - mem_size =3D 2*1024*1024; + mem_size =3D default_huge_page_size(); mem =3D gethugetlb_mem(mem_size, &shmid); if (mem) { wp_init(mem, mem_size); @@ -1633,7 +1638,7 @@ int main(int __attribute__((unused)) argc, char *argv= []) } =20 /* 7. File Hugetlb testing */ - mem_size =3D 2*1024*1024; + mem_size =3D default_huge_page_size(); fd =3D memfd_create("uffd-test", MFD_HUGETLB | MFD_NOEXEC_SEAL); if (fd < 0) ksft_exit_fail_msg("uffd-test creation failed %d %s\n", errno, strerror(= errno)); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 5BA2337B025; Tue, 28 Apr 2026 20:47:54 +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=1777409274; cv=none; b=N53qPFxK8tckdAlfHIrnu9ut5eIHzve6nFNslwn92xk7yS61BCxuRslLuiPKTH7OqTXrYgko/zwpvf532T3CwbIcHZMUOUgcqVeB38l31tRgCfCSnvkaRw2K/tO4Elvd0hFwUHSyljPErgQ2Ps+C9YCJrmFe1tRHDbOh7dpFWTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409274; c=relaxed/simple; bh=npg4+uMs+1VXM+YeMA2PoGGD+uhEYXNx6PkYW3tjPLk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U5nF64W5Yfu/dHOQ2Lwb2ZO1z6H5vapgxW2alPUUGKSa1sgPph7WKRm3WHyPrpUAzp9sf1t/M9UiPLkBL2mSyyopSc2BFXOeVBP/2gbstq7+dBYyx9RcbyAdniE8zMYEICQeRRuL+39XHYPIR9x5coxj+aRxBmdUvkQORo3yf6s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MUQ0pFf6; 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="MUQ0pFf6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F5D1C2BCAF; Tue, 28 Apr 2026 20:47:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409274; bh=npg4+uMs+1VXM+YeMA2PoGGD+uhEYXNx6PkYW3tjPLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MUQ0pFf6316ds72ArO+ygPQWT45xuWb4xxgTNzqCoxwytGQuR9MlZUAWV6GsXlvV2 ytbd6FA/0VAnxQzVefkG7J3EbZvZ9SA8IjG7Cn2rf5j2Qe6fIP94ceP16xm3uS/Y3h T+8XE6lICYyLmkh2E9gTMNKEVYtllRO2Sh3oczOefK+Nw1pxu8xYR0VUI+lmtpqqCj aPFOuMZgTa1hIuqT+06J9brEE0xYFBIDclmlpoldQkSnNhFqXRitWZB29TLV9bFpy1 rc69qp467B0tfc1YQEAjK8Om3czsnyhbrekA4Pu9XdPIo8J19K9A/luPL/UC1zaVsg Hw8/Hqhq3Q49w== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 46/54] selftests/mm: protection_keys: use library code for HugeTLB setup Date: Tue, 28 Apr 2026 23:42:32 +0300 Message-ID: <20260428204240.1924129-47-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" protection_keys open codes setup of HugeTLB pages. Replace it with the library functions from hugepage_setup. Replace exit() calls with _exit() to avoid restoring HugeTLB settings in the middle of test. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/protection_keys.c | 51 ++++++-------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/s= elftests/mm/protection_keys.c index d617b41dda6b..f8a5447a55b7 100644 --- a/tools/testing/selftests/mm/protection_keys.c +++ b/tools/testing/selftests/mm/protection_keys.c @@ -47,6 +47,7 @@ #include =20 #include "pkey-helpers.h" +#include "hugepage_settings.h" =20 int iteration_nr =3D 1; int test_nr; @@ -61,6 +62,7 @@ noinline int read_ptr(int *ptr) return *ptr; } =20 +#if CONTROL_TRACING > 0 static void cat_into_file(char *str, char *file) { int fd =3D open(file, O_RDWR); @@ -86,7 +88,6 @@ static void cat_into_file(char *str, char *file) close(fd); } =20 -#if CONTROL_TRACING > 0 static int warned_tracing; static int tracing_root_ok(void) { @@ -709,50 +710,28 @@ static void *malloc_pkey_anon_huge(long size, int pro= t, u16 pkey) } =20 static int hugetlb_setup_ok; -#define SYSFS_FMT_NR_HUGE_PAGES "/sys/kernel/mm/hugepages/hugepages-%ldkB/= nr_hugepages" #define GET_NR_HUGE_PAGES 10 static void setup_hugetlbfs(void) { - int err; - int fd; - char buf[256]; - long hpagesz_kb; - long hpagesz_mb; + long hpagesz_mb =3D HPAGE_SIZE / 1024 / 1024; + unsigned long free_pages; =20 if (geteuid() !=3D 0) { ksft_print_msg("WARNING: not run as root, can not do hugetlb test\n"); return; } =20 - cat_into_file(__stringify(GET_NR_HUGE_PAGES), "/proc/sys/vm/nr_hugepages"= ); - /* - * Now go make sure that we got the pages and that they + * Make sure that we got the pages and that they * are PMD-level pages. Someone might have made PUD-level * pages the default. */ - hpagesz_kb =3D HPAGE_SIZE / 1024; - hpagesz_mb =3D hpagesz_kb / 1024; - sprintf(buf, SYSFS_FMT_NR_HUGE_PAGES, hpagesz_kb); - fd =3D open(buf, O_RDONLY); - if (fd < 0) { - fprintf(stderr, "opening sysfs %ldM hugetlb config: %s\n", - hpagesz_mb, strerror(errno)); - return; - } - - /* -1 to guarantee leaving the trailing \0 */ - err =3D read(fd, buf, sizeof(buf)-1); - close(fd); - if (err <=3D 0) { - fprintf(stderr, "reading sysfs %ldM hugetlb config: %s\n", - hpagesz_mb, strerror(errno)); - return; - } - - if (atoi(buf) !=3D GET_NR_HUGE_PAGES) { - fprintf(stderr, "could not confirm %ldM pages, got: '%s' expected %d\n", - hpagesz_mb, buf, GET_NR_HUGE_PAGES); + hugetlb_save_settings(); + hugetlb_set_nr_pages(HPAGE_SIZE, GET_NR_HUGE_PAGES); + free_pages =3D hugetlb_free_pages(HPAGE_SIZE); + if (free_pages < GET_NR_HUGE_PAGES) { + ksft_print_msg("could not confirm %ldM pages, got: '%ld' expected %d\n", + hpagesz_mb, free_pages, GET_NR_HUGE_PAGES); return; } =20 @@ -1129,7 +1108,7 @@ static void become_child(void) /* in the child */ return; } - exit(0); + _exit(0); } =20 /* Assumes that all pkeys other than 'pkey' are unallocated */ @@ -1508,18 +1487,18 @@ static void test_ptrace_modifies_pkru(int *ptr, u16= pkey) * checking */ if (__read_pkey_reg() !=3D new_pkru) - exit(1); + _exit(1); =20 /* Stop and allow the tracer to clear XSTATE_BV for PKRU */ raise(SIGSTOP); =20 if (__read_pkey_reg() !=3D 0) - exit(1); + _exit(1); =20 /* Stop and allow the tracer to examine PKRU */ raise(SIGSTOP); =20 - exit(0); + _exit(0); } =20 pkey_assert(child =3D=3D waitpid(child, &status, 0)); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 356754A35; Tue, 28 Apr 2026 20:48:00 +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=1777409281; cv=none; b=ccCvCdL6wv2pMsTQ3MWyZEWPLx+1cGNSaN3afP+bmQ0AVPXRwHW105pAveitLjPsjqQaB5vncExAK5mR/ha+BIyUKfhaJd+eZ58IsTMAN2N0kFJwuh7Vd5ryX5nRIIvTN/Nk46xjytO+AOwWxN2Cf6omnelEAFH7+P4YifCGK0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409281; c=relaxed/simple; bh=pMqT3V7GrLrPKmH8KQ0+ElCx+AnALakW5vIuoVUm4lQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JUy8b5UOcDeupzDRMDH6C4vhvb738QCZUjLpvWMJWG3EJGE7PzkKriMWdsYKMUJzxeD1g4zBmzwl1FnlJQuyXSDgSXerr3VTmLX7bVwNU8dBEk8BkM8RB6NpcdZlaMo6KKdbgxTDMgFi98P/Vek6tEQR07MZdnh2S72ovxOAJWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VSulbNh2; 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="VSulbNh2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC675C2BCAF; Tue, 28 Apr 2026 20:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409280; bh=pMqT3V7GrLrPKmH8KQ0+ElCx+AnALakW5vIuoVUm4lQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VSulbNh23OPZdj6S8HoCUp9j+rWArxXYrl8I3L4Mw9cSe8I3xUPfJhuV2OBxKulWJ fdTRYQOVSovFRx+RjTrIGJ7ULDGaQxY2lz4IawLutXLUr3K9GXARZxLCxh4InlTQeO bkkIlHEkS8dQbjgMeGJBqnsjQSHMca9yi2nKXDfMIaD+/nYL+6e1lu3GVhOXyCFbz2 1rvd2YozXokylduoR9S3zjGEvb82Y3j+owTcIjX6i8N2H+kjsmCHqBlBOsl+sU67Vd f+xiz1VjZJOC9GMSLCcdaQsBQ4Bksp0GT74wMIrF60RLDHRp9taagW8bZp5a00ExRo 4uNxV4dkYQVng== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 47/54] selftests/mm: thuge-gen: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:33 +0300 Message-ID: <20260428204240.1924129-48-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" thuge-gen skips tests if there are no free huge pages prepared by a wrapper script and shm liimts in proc are too low. Replace custom detection of huge pages with the library functions and add setup of HugeTLB pages and shm limits to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/thuge-gen.c | 79 ++++---------------------- 1 file changed, 11 insertions(+), 68 deletions(-) diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftes= ts/mm/thuge-gen.c index 1007bc8aa57c..b63d87d72a7d 100644 --- a/tools/testing/selftests/mm/thuge-gen.c +++ b/tools/testing/selftests/mm/thuge-gen.c @@ -38,15 +38,6 @@ #ifndef SHM_HUGE_SHIFT #define SHM_HUGE_SHIFT 26 #endif -#ifndef SHM_HUGE_MASK -#define SHM_HUGE_MASK 0x3f -#endif -#ifndef SHM_HUGE_2MB -#define SHM_HUGE_2MB (21 << SHM_HUGE_SHIFT) -#endif -#ifndef SHM_HUGE_1GB -#define SHM_HUGE_1GB (30 << SHM_HUGE_SHIFT) -#endif =20 #define NUM_PAGESIZES 5 #define NUM_PAGES 4 @@ -64,32 +55,10 @@ int ilog2(unsigned long v) =20 void show(unsigned long ps) { - char buf[100]; - if (ps =3D=3D getpagesize()) return; =20 - ksft_print_msg("%luMB: ", ps >> 20); - - fflush(stdout); - snprintf(buf, sizeof buf, - "cat /sys/kernel/mm/hugepages/hugepages-%lukB/free_hugepages", - ps >> 10); - system(buf); -} - -unsigned long read_free(unsigned long ps) -{ - unsigned long val =3D 0; - char buf[100]; - - snprintf(buf, sizeof(buf), - "/sys/kernel/mm/hugepages/hugepages-%lukB/free_hugepages", - ps >> 10); - if (read_sysfs(buf, &val) && ps !=3D getpagesize()) - ksft_print_msg("missing %s\n", buf); - - return val; + ksft_print_msg("%luMB: %ld\n", ps >> 20, hugetlb_free_pages(ps)); } =20 void test_mmap(unsigned long size, unsigned flags) @@ -97,14 +66,14 @@ void test_mmap(unsigned long size, unsigned flags) char *map; unsigned long before, after; =20 - before =3D read_free(size); + before =3D hugetlb_free_pages(size); map =3D mmap(NULL, size*NUM_PAGES, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB|flags, -1, 0); if (map =3D=3D MAP_FAILED) ksft_exit_fail_msg("mmap: %s\n", strerror(errno)); =20 memset(map, 0xff, size*NUM_PAGES); - after =3D read_free(size); + after =3D hugetlb_free_pages(size); =20 show(size); ksft_test_result(size =3D=3D getpagesize() || (before - after) =3D=3D NUM= _PAGES, @@ -121,7 +90,7 @@ void test_shmget(unsigned long size, unsigned flags) struct shm_info i; char *map; =20 - before =3D read_free(size); + before =3D hugetlb_free_pages(size); id =3D shmget(IPC_PRIVATE, size * NUM_PAGES, IPC_CREAT|0600|flags); if (id < 0) { if (errno =3D=3D EPERM) { @@ -142,7 +111,7 @@ void test_shmget(unsigned long size, unsigned flags) shmctl(id, IPC_RMID, NULL); =20 memset(map, 0xff, size*NUM_PAGES); - after =3D read_free(size); + after =3D hugetlb_free_pages(size); =20 show(size); ksft_test_result(size =3D=3D getpagesize() || (before - after) =3D=3D NUM= _PAGES, @@ -154,43 +123,15 @@ void test_shmget(unsigned long size, unsigned flags) void find_pagesizes(void) { unsigned long largest =3D getpagesize(); - unsigned long shmmax_val =3D 0; int i; - glob_t g; =20 - glob("/sys/kernel/mm/hugepages/hugepages-*kB", 0, NULL, &g); - assert(g.gl_pathc <=3D NUM_PAGESIZES); - for (i =3D 0; (i < g.gl_pathc) && (num_page_sizes < NUM_PAGESIZES); i++) { - sscanf(g.gl_pathv[i], "/sys/kernel/mm/hugepages/hugepages-%lukB", - &page_sizes[num_page_sizes]); - page_sizes[num_page_sizes] <<=3D 10; - ksft_print_msg("Found %luMB\n", page_sizes[i] >> 20); + num_page_sizes =3D hugetlb_setup(NUM_PAGES, page_sizes, ARRAY_SIZE(page_s= izes)); =20 - if (page_sizes[num_page_sizes] > largest) + for (i =3D 0; i < num_page_sizes; i++) + if (page_sizes[i] > largest) largest =3D page_sizes[i]; =20 - if (read_free(page_sizes[num_page_sizes]) >=3D NUM_PAGES) - num_page_sizes++; - else - ksft_print_msg("SKIP for size %lu MB as not enough huge pages, need %u\= n", - page_sizes[num_page_sizes] >> 20, NUM_PAGES); - } - globfree(&g); - - read_sysfs("/proc/sys/kernel/shmmax", &shmmax_val); - if (shmmax_val < NUM_PAGES * largest) { - ksft_print_msg("WARNING: shmmax is too small to run this test.\n"); - ksft_print_msg("Please run the following command to increase shmmax:\n"); - ksft_print_msg("echo %lu > /proc/sys/kernel/shmmax\n", largest * NUM_PAG= ES); - ksft_exit_skip("Test skipped due to insufficient shmmax value.\n"); - } - -#if defined(__x86_64__) - if (largest !=3D 1U<<30) { - ksft_exit_skip("No GB pages available on x86-64\n" - "Please boot with hugepagesz=3D1G hugepages=3D%d\n", NUM_PAGES); - } -#endif + shm_limits_prepare(NUM_PAGES * largest); } =20 int main(void) @@ -233,3 +174,5 @@ int main(void) =20 ksft_finished(); } + +SHM_LIMITS_RESTORE() --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 85F404A35; Tue, 28 Apr 2026 20:48:07 +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=1777409287; cv=none; b=IS/ACt9cd/a8OECaJiGsLBxABE5FSD1BDJ9cULEp/2Mgg5AW7DHQyYsYcw6+OCB6mZt8By1w6p0tS2tQC0R50+klWCfDtGkVfwu08abAJ07TJkDU+W60hpoBQU6kHDPvPlawKB6G6923A8xX6G29WC6iTPRWSOHb5xUflFWFK9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409287; c=relaxed/simple; bh=n2KgdfeDkv6qGICkBg3Vwdx+MRmhbjeNlFxUjnQTB8E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BxcBi5kNBQ853E+SzCj8QwxY39EvPwrMoS2Vd5wk7q0220Yafp5KxOYDa8qm10x96Lr/6jaqSHTbpKLFc24lVWZFykYH/FR6wgZYK1CCuLFVSW1JRftJsvh41KANHJX/GLFr8sIK/gE6rW6z2vhIhHcqfOte6XJJKQA9Kzz4dBI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LyYmCfUT; 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="LyYmCfUT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 548C8C2BCB3; Tue, 28 Apr 2026 20:48:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409287; bh=n2KgdfeDkv6qGICkBg3Vwdx+MRmhbjeNlFxUjnQTB8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LyYmCfUTY2G4V530dknb3eO7NHTasmxoDpdVvrgwU78AtmHgRv4xF8f3uCPZ/jM14 cVswan0mmRYOHVU3VpVJosWpAoVZ1izld0PsVhUgCDUonA7gBWcjJ20emy2Z13ds0E RV2In/aOajeta7CYPc5WrEP+zpmw7j5LaaUOj/IYtlvjB9X0AqYr3dcW51oWC5ytkp KgYQ+54oL8dQ594Y/oteKma0ib+Dq/Derrz8iqbOchVmQYcn8JaMaxTA/K5YnhYnQW 9ifHzksHFVo17kV6W4wS8ub864jmzK0/kWbRu0aF7t2Y8XCHe07YkuCFetZvEIdVdP PLPrPgHSd14Yg== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 48/54] selftests/mm: uffd-stress: use hugetlb_save and alloc huge pages Date: Tue, 28 Apr 2026 23:42:34 +0300 Message-ID: <20260428204240.1924129-49-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" uffd-stress skips HugeTLB tests if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino Tested-by: Sarthak Sharma --- tools/testing/selftests/mm/uffd-stress.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-stress.c b/tools/testing/selft= ests/mm/uffd-stress.c index 7e37cf3d27f6..9693d042f16f 100644 --- a/tools/testing/selftests/mm/uffd-stress.c +++ b/tools/testing/selftests/mm/uffd-stress.c @@ -479,9 +479,12 @@ int main(int argc, char **argv) * Ensure nr_parallel - 1 hugepages on top of that to account * for racy extra reservation of hugepages. */ - if (gopts->test_type =3D=3D TEST_HUGETLB && - hugetlb_free_default_pages() < 2 * (bytes / gopts->page_size) + gopts-= >nr_parallel - 1) - ksft_exit_skip("Skipping userfaultfd... not enough hugepages\n"); + if (gopts->test_type =3D=3D TEST_HUGETLB) { + unsigned long nr =3D 2 * (bytes / gopts->page_size) + gopts->nr_parallel= - 1; + + if (!hugetlb_setup_default(nr)) + ksft_exit_skip("Skipping userfaultfd... not enough hugepages\n"); + } =20 gopts->nr_pages_per_cpu =3D bytes / gopts->page_size / gopts->nr_parallel; if (!gopts->nr_pages_per_cpu) { --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 1728D3803F8; Tue, 28 Apr 2026 20:48:14 +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=1777409294; cv=none; b=piE5DCrEP2Yc2ib1ehaRt3UILdjw71506ZNiXf8lc74E02L2P5Jt9ZSjyM+4alPBVXRe0KZrJq4vOJjsNOPfZjljoIXn+7Wo+exmrQl6KlkETZ8sFzB45Yi/D7E/eH2RVGwJxGhJ2/vItTpTvOnx2bmATG13QBQ8KWbx5sFEJN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409294; c=relaxed/simple; bh=C8Qz87BGrLBhc4P4E9wehTmUZkE5iKzjerVbkLBntAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uU0ZBQHOjiJj3tKhZdgJ2IKhbi2Q86nLIrxO8TJHUOmdXtSA0WtI7ZOmO0kdGMXGmzVlpePEoakKyUeM0c4t0SRUEqdCCNDfws+AN+f42tFT3/Qanjpe0BcxAB5WLvn0OpF2DBmC5YCzZeuUu1ZddbEKTD8nkqLLREurWu3K7tY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RR7cpHE7; 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="RR7cpHE7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0D60C2BCC4; Tue, 28 Apr 2026 20:48:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409294; bh=C8Qz87BGrLBhc4P4E9wehTmUZkE5iKzjerVbkLBntAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RR7cpHE7thWHO2+9FeEKmkFhRFBUzwIJiQBh4ygtYGyuaZQqIMQjLpWatx0lOAOwn JQsk+vM2+cwevsRrpF/sFfmtzZp8en2eiVqRRExGdlNe+oG1VJJYBPTgGYHbfGK1Ji jVZaWRywXFcJXKaK9WzReg1cQBJyjBTB0rqAJjmdU1GI1Z4TMhmzVrOwiOZ0IGD3mO sEwpK4iaUg4bXg3/DxvpM7PPOghqX3mVuZidp0+8yJj+CER2WVK3tGGQi7jfejWWNj KdHDSrJ+A9o6OLcqGM4VBhQutBlVHR6LP7Zyq93rtsKII1SoOHBiWBY8b8u5Qyyn8V le9F9rhpfuPJQ== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 49/54] selftests/mm: uffd-unit-tests: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:35 +0300 Message-ID: <20260428204240.1924129-50-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" uffd-unit-tests skips HugeTLB tests if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Replace exit() calls with _exit() to avoid restoring HugeTLB settings in the middle of test. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/uffd-unit-tests.c | 31 +++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/s= elftests/mm/uffd-unit-tests.c index 1a33db281f8a..20e1829db91f 100644 --- a/tools/testing/selftests/mm/uffd-unit-tests.c +++ b/tools/testing/selftests/mm/uffd-unit-tests.c @@ -305,7 +305,7 @@ static int pagemap_test_fork(uffd_global_test_opts_t *g= opts, bool with_event, bo if (test_pin) unpin_pages(&args); /* Succeed */ - exit(0); + _exit(0); } waitpid(child, &result, 0); =20 @@ -773,7 +773,7 @@ static void uffd_sigbus_test_common(uffd_global_test_op= ts_t *gopts, bool wp) err("fork"); =20 if (!pid) - exit(faulting_process(gopts, 2, wp)); + _exit(faulting_process(gopts, 2, wp)); =20 waitpid(pid, &err, 0); if (err) @@ -827,7 +827,7 @@ static void uffd_events_test_common(uffd_global_test_op= ts_t *gopts, bool wp) err("fork"); =20 if (!pid) - exit(faulting_process(gopts, 0, wp)); + _exit(faulting_process(gopts, 0, wp)); =20 waitpid(pid, &err, 0); if (err) @@ -1706,11 +1706,32 @@ static int uffd_count_tests(int n_tests, int n_mems= , const char *test_filter) return count; } =20 +static unsigned long uffd_setup_hugetlb(void) +{ + unsigned long nr_hugepages, hp_size; + + hugetlb_save_settings(); + hp_size =3D default_huge_page_size(); + + if (!hp_size) + return 0; + + /* need twice UFFD_TEST_MEM_SIZE, one for src area and one for dst */ + nr_hugepages =3D 2 * MAX(UFFD_TEST_MEM_SIZE, hp_size * 2) / hp_size; + hugetlb_set_nr_default_pages(nr_hugepages); + + if (hugetlb_free_default_pages() < nr_hugepages) + return 0; + + return hp_size; +} + int main(int argc, char *argv[]) { int n_tests =3D sizeof(uffd_tests) / sizeof(uffd_test_case_t); int n_mems =3D sizeof(mem_types) / sizeof(mem_type_t); const char *test_filter =3D NULL; + unsigned long hugepage_size; bool list_only =3D false; uffd_test_case_t *test; mem_type_t *mem_type; @@ -1745,6 +1766,8 @@ int main(int argc, char *argv[]) return KSFT_PASS; } =20 + hugepage_size =3D uffd_setup_hugetlb(); + ksft_print_header(); ksft_set_plan(uffd_count_tests(n_tests, n_mems, test_filter)); =20 @@ -1771,7 +1794,7 @@ int main(int argc, char *argv[]) uffd_test_case_ops =3D test->test_case_ops; =20 if (mem_type->mem_flag & (MEM_HUGETLB_PRIVATE | MEM_HUGETLB)) { - gopts.page_size =3D default_huge_page_size(); + gopts.page_size =3D hugepage_size; if (gopts.page_size =3D=3D 0) { uffd_test_skip("huge page size is 0, feature missing?"); continue; --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 F3A0B379989; Tue, 28 Apr 2026 20:48:20 +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=1777409301; cv=none; b=HaycHIfqzJPheoiDboSo0NAyeSvSmRMJmvKtF/z5nxQLbYuNEe7I+zyO/FcpTzGB3roJpMXHzImQXOwu1AnN7BUmGwWi45ivQD2ab4Fn/mU246zVvoI9EO0ga6Q+FYfDSvxTbNXRz3wCZrd11nGPPd/5fT47RCySHuPVPAPKa3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409301; c=relaxed/simple; bh=HtpaUkBbB7ijuw6rctcgEdxPGwj4VxmBP6AvOyp0uHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RBGBXlkjCnl+jVz8pTFFzjccDWPL7MxwZHbvtg5GI1xiLVFH2B2EOQ4uLXyRf9usRxtGKWadRXbwb3Et/xagFhDfl/SXF82DCi/hO2W/dyhjmlKX/Q1efYxXwieNO0NlNcoHm0EnWVWfp+rXfvbx0TTji1RE/grwKE/D9ACDTbQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MrBgAN7v; 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="MrBgAN7v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78506C2BCAF; Tue, 28 Apr 2026 20:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409300; bh=HtpaUkBbB7ijuw6rctcgEdxPGwj4VxmBP6AvOyp0uHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MrBgAN7v0Gg/6OxNrbQotAn9rKocS0ALXFItaZnMWNG1OLuQmgJy7qdzFHSbrC5QP zBQ5eDY7h59KZ3h81uYkJvJBierPcozQ7O7/7jo2eRoBfbscSY3a7+Frbk772e23k6 1xgrJx8QYXesKBPb7sy/GNogVChQtwZSsIf9nV6dNOA3wrA3BtrUVGP3hrME5j/5Hr aWU51BXDfiNs7kbgjz+C5lKiW6hJFWmE4n/J4M2drZoiOhfQMCOI49Aj+eVojI956S MvZ1g4qUF6KPNuZnHXpXa5Rqb0DksAHwCigbZI6LCPDyQTrHEcp5NbVyGbz/0pKi+E bN9Ax4BP1jjTg== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 50/54] selftests/mm: uffd-wp-mremap: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:36 +0300 Message-ID: <20260428204240.1924129-51-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" uffd-wp-remap skips HugeTLB tests if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/uffd-wp-mremap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/mm/uffd-wp-mremap.c b/tools/testing/se= lftests/mm/uffd-wp-mremap.c index 9d67b11c2f28..f63fe02f404f 100644 --- a/tools/testing/selftests/mm/uffd-wp-mremap.c +++ b/tools/testing/selftests/mm/uffd-wp-mremap.c @@ -336,14 +336,14 @@ int main(int argc, char **argv) struct thp_settings settings; int i, j, plan =3D 0; =20 + hugepage_save_settings(true, true); + pagesize =3D getpagesize(); nr_thpsizes =3D detect_thp_sizes(thpsizes, ARRAY_SIZE(thpsizes)); - nr_hugetlbsizes =3D detect_hugetlb_page_sizes(hugetlbsizes, - ARRAY_SIZE(hugetlbsizes)); + nr_hugetlbsizes =3D hugetlb_setup(1, hugetlbsizes, ARRAY_SIZE(hugetlbsize= s)); =20 /* If THP is supported, save THP settings and initially disable THP. */ if (nr_thpsizes) { - thp_save_settings(); thp_read_settings(&settings); for (i =3D 0; i < NR_ORDERS; i++) { settings.hugepages[i].enabled =3D THP_NEVER; --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 76BC937B00C; Tue, 28 Apr 2026 20:48:27 +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=1777409307; cv=none; b=g5NNfYf4Pjk3XhVQbsrZU8+fFmG4Aj6m18jaIgwKTo7ex14Z4FislrmHX/BJRdVHLgyIiW+1FQnKUdEVa5pj9jbuOOVfrB30kEOHudO5wAL2c+tXJ4zARxSj3HgZumReSQfdbbprHyPYbSJF8f2WW1ojpC+OpxaUMJAYHzY5A9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409307; c=relaxed/simple; bh=n+ynKYOhHHd3fYSwNPmEpGp3HvFkvJ4/6qKKQftdCu0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sbZKR3VVdFFhladX+hj8TsMo1e24Jd7JxvBGb8KINngwddbfbd7BkfbobogxJDwIa8KYgPX2t9z8KFRw3s3/mnuCFhfYVwwbeM9spQblTId7M20S6sH4o/ciESQ6xSAx/jqX5qX9xJ/ggcGmDspniTjo8fbIdwR5t4PTFuB7mV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fc5aWZvE; 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="fc5aWZvE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FF6EC2BCB3; Tue, 28 Apr 2026 20:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409307; bh=n+ynKYOhHHd3fYSwNPmEpGp3HvFkvJ4/6qKKQftdCu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fc5aWZvEBk/mFdR7Qscyfqp2MKP5O8O75phTbP6wzsYUc4XJeyPFoPeYDDJY/ovNH PxNoUCf8AG/OD97MlUQ9Qapk2W8FXPKjrMh9ZzMHkdqfk6wXXgPLyvByH2iOViry4M zuRKDV2hmkZuHCZE4CwaGcEcleWX79mzw/7xr+Fyj5MrOsL/X+VybscVk0ZiDeanov smGHfx38WNEPVfxCj88X8E/SV3pbjUFLo/5upRBsIGwKMScqIdvSS+S6zugAFy+nl+ 5ZnmcWMBoQVxOUhs62w+kdrXpWvJ04nm5MdbfBV38XBVB0LIHlVkJQ8h1keSX5xYxI n7NVEV3L5oQ0w== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 51/54] selftests/mm: va_high_addr_switch: add setup of HugeTLB pages Date: Tue, 28 Apr 2026 23:42:37 +0300 Message-ID: <20260428204240.1924129-52-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" va_high_addr_switch skips HugeTLB tests if there are no free huge pages prepared by a wrapper script. Add setup of HugeTLB pages to the test and make sure that the original settings are restored on the test exit. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Luiz Capitulino Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/va_high_addr_switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/mm/va_high_addr_switch.c b/tools/testi= ng/selftests/mm/va_high_addr_switch.c index 0b69bd4b901d..e24d7ba00b44 100644 --- a/tools/testing/selftests/mm/va_high_addr_switch.c +++ b/tools/testing/selftests/mm/va_high_addr_switch.c @@ -325,7 +325,7 @@ int main(int argc, char **argv) if (!supported_arch()) ksft_exit_skip("Architecture not supported\n"); =20 - if (argc =3D=3D 2 && !strcmp(argv[1], "--run-hugetlb")) + if (hugetlb_setup_default(6)) run_hugetlb =3D true; =20 testcases_init(); --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 C720633B6C9; Tue, 28 Apr 2026 20:48:33 +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=1777409313; cv=none; b=ZgC8EesKVaiGs1Q630q4I7m9oqbaLuqzN2K8JyyJQ/0P9vbFyFvCNkZvl1s7i1QBXkoxGouXuEu3WGYSAdY1/0FiOz0OOQVZH3yct0JIyfA25091/4ImUhRfABNzcfeGlJrIvg5bFcvnLsvaO7fi3lY0YPKtRG9RBdftabr0Bvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409313; c=relaxed/simple; bh=Y+6CuufKGBRmaBQ8v4yV5d9wcJCiC93SEawkGDgeJlU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UCTEQK9hjBVn8+768mBvd+ihklVRe5B7d6yNG+FQiK3fcRBkgrTExqTv04gIm5ckGx9vuwmiSVWOqLNCxq2I/yqRs8RunuLqbbWB7ncpw7WzcvPF4Hjo+wyU7M5GMsvHhwp1LqHoqbklJDaYZRiCn/42haKca/Ca7Y7ifqyrr+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W+uVDnSU; 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="W+uVDnSU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C4D7C2BCAF; Tue, 28 Apr 2026 20:48:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409313; bh=Y+6CuufKGBRmaBQ8v4yV5d9wcJCiC93SEawkGDgeJlU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W+uVDnSU0GDGxd9dYc1UPrAi61qoOsqwnWxGzKpcS+fQCXupvYkTZPohSGMiBNDiP f+cp9C8F8EEsm7aTf6gCKRx7ql5Obp58kL8u1g9nVgt6VeohkCRMfZxcvzOBLsxgC5 D8QrvdaAZtyZ79cNKZhjoo97ScLImtZyeNcm4rkAK12SbORcATSeYX3XZoZrVOOTtN 9kP7LagU9W5xXiXnpYz/Jt3Lgriq9l2tsB4gIsLIQeau7TbrkiOyddJAb9YL9DcIvi hGwBOL+/bjp7pVO/+KlXHURo6UEC3GL5t7Mls7zO8DjTrwKQ2umWFsNWK+8VfRfmps Oij28WScEgXhA== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 52/54] selftests/mm: va_high_addr_switch.sh: drop huge pages setup Date: Tue, 28 Apr 2026 23:42:38 +0300 Message-ID: <20260428204240.1924129-53-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Since va_high_addr_switch takes care of setting up huge pages, there is no need to set them up in the va_high_addr_switch.sh wrapper script. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Luiz Capitulino Tested-by: Luiz Capitulino --- .../selftests/mm/va_high_addr_switch.sh | 41 +------------------ 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/tools/testing/selftests/mm/va_high_addr_switch.sh b/tools/test= ing/selftests/mm/va_high_addr_switch.sh index 9492c2d72634..01c15fe3c799 100755 --- a/tools/testing/selftests/mm/va_high_addr_switch.sh +++ b/tools/testing/selftests/mm/va_high_addr_switch.sh @@ -9,7 +9,6 @@ =20 # Kselftest framework requirement - SKIP code is 4. ksft_skip=3D4 -orig_nr_hugepages=3D0 =20 skip() { @@ -77,43 +76,5 @@ check_test_requirements() esac } =20 -save_nr_hugepages() -{ - orig_nr_hugepages=3D$(cat /proc/sys/vm/nr_hugepages) -} - -restore_nr_hugepages() -{ - echo "$orig_nr_hugepages" > /proc/sys/vm/nr_hugepages -} - -setup_nr_hugepages() -{ - local needpgs=3D$1 - while read -r name size unit; do - if [ "$name" =3D "HugePages_Free:" ]; then - freepgs=3D"$size" - break - fi - done < /proc/meminfo - if [ "$freepgs" -ge "$needpgs" ]; then - return - fi - local hpgs=3D$((orig_nr_hugepages + needpgs)) - echo $hpgs > /proc/sys/vm/nr_hugepages - - local nr_hugepgs=3D$(cat /proc/sys/vm/nr_hugepages) - if [ "$nr_hugepgs" !=3D "$hpgs" ]; then - restore_nr_hugepages - skip "$0: no enough hugepages for testing" - fi -} - check_test_requirements -save_nr_hugepages -# The HugeTLB tests require 6 pages -setup_nr_hugepages 6 -./va_high_addr_switch --run-hugetlb -retcode=3D$? -restore_nr_hugepages -exit $retcode +./va_high_addr_switch --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 5F0F933B6C9; Tue, 28 Apr 2026 20:48:40 +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=1777409320; cv=none; b=PyhNBU9z8qnwK6Rqo/n2AalI7O1fFSbGq2zxVDFyR+vflh+fr3FvOr//JJcBku6jEzby70tu+b2fn3Z43vV26aqOajT6KIrEXEgRxuEquoNxCCBJQm/bsUcVXrxztgMrm9Lb8sk+EMEJEEWRx8UCn9iRD0eQ8S3UbfPLsRko8c4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409320; c=relaxed/simple; bh=XYoR5ykBzH9ln8CEkCcM3Jpo8h2bXIFgxUkz6fxZ/LA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R0YZWICS2rZOU+fQPDMiKJBt1wYApZtL0E7HQ3tm2nLWGiiHoTxDT8eQFMmUFYjM7fiiUyOJ7k4scJ+CGoT+XUK5q8SCCOjC5CfbZdoGdpaXdqBe3HYAMDIB+NxRtHdPMtG7DwLacOstz7emFNiRek2ysKobNiLHW2HI6/wgiEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KtqfrHTS; 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="KtqfrHTS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3441EC2BCB3; Tue, 28 Apr 2026 20:48:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409320; bh=XYoR5ykBzH9ln8CEkCcM3Jpo8h2bXIFgxUkz6fxZ/LA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KtqfrHTS9/FD20Apc6D6Tc83MdB6i2S17dvN7aBXRCPZwoTGCiyaxEQu76quQaxOH EDbLBrK09yVRuVjNG96piJu6xIptkjuo5ymsEv2ot/85tUVh0hwY57HLzsg3GTz6MH lUMOoawbdRHlF4zZO2qY7frcKff9DET5JqFZkx9Z1lm4VkFtjIl3Zz1US2j7MxBq/Z Z8hAzlo1QqTnexXK3qBvdh0BxU5BfJPvWcK/pncK9zuT2vfQjt9rEcdbAWjWNHqZbH Pjtasw+ZBZq89CI+EJYemgvjUdlBKpYoMuuUzEFJ/lWb/wVPkpa4FsWeSmKn0gpzJi mBpD7G/+Ge6Uw== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 53/54] selftests/mm: run_vmtests.sh: free memory if available memory is low Date: Tue, 28 Apr 2026 23:42:39 +0300 Message-ID: <20260428204240.1924129-54-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Currently when running THP and HugeTLB tests, if HAVE_HUGEPAGES is set run_test() drops caches, compacts memory and runs the test. But if HAVE_HUGEPAGES is not set it skips the tests entirely, even if THP tests have nothing to do with HAVE_HUGEPAGES. Replace the check if HAVE_HUGEPAGES is set with a check of how much memory is available. If there is less than 256 MB of available memory, drop caches and run compaction and then continue to run a test regardless of HAVE_HUGEPAGES value. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Sarthak Sharma Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/run_vmtests.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/self= tests/mm/run_vmtests.sh index b9e520194634..b42d19036182 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -99,6 +99,9 @@ EOF exit 0 } =20 +mem_available_kb=3D$(awk '/MemAvailable/ {print $2}' /proc/meminfo) +mem_available_Mb=3D$((mem_available_kb / 1024)) + RUN_ALL=3Dfalse RUN_DESTRUCTIVE=3Dfalse TAP_PREFIX=3D"# " @@ -239,15 +242,12 @@ run_test() { # On memory constrainted systems some tests can fail to allocate hugepag= es. # perform some cleanup before the test for a higher success rate. if [ ${CATEGORY} =3D=3D "thp" -o ${CATEGORY} =3D=3D "hugetlb" ]; then - if [ "${HAVE_HUGEPAGES}" =3D "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=3D1 - fi + if (( $mem_available_Mb < 256 )); then + echo 3 > /proc/sys/vm/drop_caches + sleep 2 + echo 1 > /proc/sys/vm/compact_memory + sleep 2 + fi fi =20 local test=3D$(pretty_name "$*") --=20 2.53.0 From nobody Wed Jun 17 01:32:58 2026 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 EAE083644CF; Tue, 28 Apr 2026 20:48:46 +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=1777409327; cv=none; b=DRO6aiwdkLxDZFvZEtyg784v1Cswmx+rXLv5V6eZePE9eRzHwZzLw4I8lPZ2Ge4soE4Cg5YkOwchscIofUUNdtUn5BeGmrkarjzDk9Uv4yK8lbnC2zfEFLXdK9dapBHfhEwlJmb3hewTvzN+uWOgFS4o1vMlrJjfNKvSnp1a290= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777409327; c=relaxed/simple; bh=sZoUbqG9CxBotaWHnOZiPFKTeBgb66YHvpq2HPRKqX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B1Z0SCOK44mYCA4U63KlBK8GGo1MW+x12lvlGnQ7eOcmTec5eW5fzAmp8fnVNjF7fZGCtHUVSqUnXwq5kihUMNzTKCCAmC7KQ9mobuDvUBz19IYIFwtEgGt37qyQbydYICq1MuH2EfQUJI1BbUA09HF2NMvZndCHe0GLh37KorE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BEwvk+c8; 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="BEwvk+c8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0401C2BCB3; Tue, 28 Apr 2026 20:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777409326; bh=sZoUbqG9CxBotaWHnOZiPFKTeBgb66YHvpq2HPRKqX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BEwvk+c89LXIHHCN4f4+Pq+EZNnwtnAEh4uQfFVWCsMySqE6CEf3Zyl21hKweLePx QTen65EdzL7a0w0B10gW3pGXeKM1OaZppOW2E1rJi6+9i6Ri394QYTTjA0KbveQ749 n+ukaoBLr/8SEUosGjg0ZiD3nTontIjbw+DDyEeQtOe31/UdT5ncNH9cRoagF0E3qN iDIqSxmz37VI8471rn/QiADf1v6JpmoBierHgdYLgEW3Ha5d/9hP2ElN0wZoFspVAE MRZc13pYZLOorECpjjSqnX7REv2Mwxt5BxDR9zjP3yNeukhpr17mQxNJF3vyFpVIg7 KcHpVou0RUFCQ== From: Mike Rapoport To: Andrew Morton , David Hildenbrand Cc: Baolin Wang , Barry Song , Dev Jain , Donet Tom , Jason Gunthorpe , John Hubbard , "Liam R. Howlett" , Lance Yang , Leon Romanovsky , Lorenzo Stoakes , Luiz Capitulino , Mark Brown , Michal Hocko , Mike Rapoport , Nico Pache , Peter Xu , Ryan Roberts , Sarthak Sharma , Shuah Khan , Suren Baghdasaryan , Vlastimil Babka , Zi Yan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 54/54] selftests/mm: run_vmtests.sh: drop detection and setup of HugeTLB Date: Tue, 28 Apr 2026 23:42:40 +0300 Message-ID: <20260428204240.1924129-55-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260428204240.1924129-1-rppt@kernel.org> References: <20260428204240.1924129-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" All the tests that use HugeTLB can detect and setup HugeTLB pages on their own. Drop detection and setup of HugeTLB from run_vmtests.sh. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Sarthak Sharma Tested-by: Luiz Capitulino --- tools/testing/selftests/mm/run_vmtests.sh | 128 ++-------------------- 1 file changed, 9 insertions(+), 119 deletions(-) diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/self= tests/mm/run_vmtests.sh index b42d19036182..7e0c379e7af4 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -157,60 +157,6 @@ run_gup_matrix() { done } =20 -# get huge pagesize and freepages from /proc/meminfo -while read -r name size unit; do - if [ "$name" =3D "HugePages_Free:" ]; then - freepgs=3D"$size" - fi - if [ "$name" =3D "Hugepagesize:" ]; then - hpgsize_KB=3D"$size" - fi -done < /proc/meminfo - -# Simple hugetlbfs tests have a hardcoded minimum requirement of -# huge pages totaling 256MB (262144KB) in size. The userfaultfd -# hugetlb test requires a minimum of 2 * nr_cpus huge pages. Take -# both of these requirements into account and attempt to increase -# number of huge pages available. -nr_cpus=3D$(nproc) -uffd_min_KB=3D$((hpgsize_KB * nr_cpus * 2)) -hugetlb_min_KB=3D$((256 * 1024)) -if [[ $uffd_min_KB -gt $hugetlb_min_KB ]]; then - needmem_KB=3D$uffd_min_KB -else - needmem_KB=3D$hugetlb_min_KB -fi - -# set proper nr_hugepages -if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then - orig_nr_hugepgs=3D$(cat /proc/sys/vm/nr_hugepages) - needpgs=3D$((needmem_KB / hpgsize_KB)) - tries=3D2 - while [ "$tries" -gt 0 ] && [ "$freepgs" -lt "$needpgs" ]; do - lackpgs=3D$((needpgs - freepgs)) - echo 3 > /proc/sys/vm/drop_caches - if ! echo $((lackpgs + orig_nr_hugepgs)) > /proc/sys/vm/nr_hugepages; th= en - echo "Please run this test as root" - exit $ksft_skip - fi - while read -r name size unit; do - if [ "$name" =3D "HugePages_Free:" ]; then - freepgs=3D$size - fi - done < /proc/meminfo - tries=3D$((tries - 1)) - done - nr_hugepgs=3D$(cat /proc/sys/vm/nr_hugepages) - if [ "$freepgs" -lt "$needpgs" ]; then - printf "Not enough huge pages available (%d < %d)\n" \ - "$freepgs" "$needpgs" - fi - HAVE_HUGEPAGES=3D1 -else - echo "no hugetlbfs support in kernel?" - HAVE_HUGEPAGES=3D0 -fi - # filter 64bit architectures ARCH64STR=3D"arm64 mips64 parisc64 ppc64 ppc64le riscv64 s390x sparc64 x86= _64" if [ -z "$ARCH" ]; then @@ -283,29 +229,13 @@ run_test() { echo "TAP version 13" | tap_output =20 CATEGORY=3D"hugetlb" run_test ./hugetlb-mmap - -shmmax=3D$(cat /proc/sys/kernel/shmmax) -shmall=3D$(cat /proc/sys/kernel/shmall) -echo 268435456 > /proc/sys/kernel/shmmax -echo 4194304 > /proc/sys/kernel/shmall CATEGORY=3D"hugetlb" run_test ./hugetlb-shm -echo "$shmmax" > /proc/sys/kernel/shmmax -echo "$shmall" > /proc/sys/kernel/shmall - CATEGORY=3D"hugetlb" run_test ./hugetlb-mremap CATEGORY=3D"hugetlb" run_test ./hugetlb-vmemmap CATEGORY=3D"hugetlb" run_test ./hugetlb-madvise CATEGORY=3D"hugetlb" run_test ./hugetlb_dio - -if [ "${HAVE_HUGEPAGES}" =3D "1" ]; then - nr_hugepages_tmp=3D$(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=3D"hugetlb" run_test ./hugetlb_fault_after_madv - CATEGORY=3D"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 +CATEGORY=3D"hugetlb" run_test ./hugetlb_fault_after_madv +CATEGORY=3D"hugetlb" run_test ./hugetlb_madv_vs_map =20 if test_selected "hugetlb"; then echo "NOTE: These hugetlb tests provide minimal coverage. Use" | tap_p= refix @@ -332,44 +262,12 @@ CATEGORY=3D"gup_test" run_test ./gup_longterm CATEGORY=3D"userfaultfd" run_test ./uffd-unit-tests uffd_stress_bin=3D./uffd-stress CATEGORY=3D"userfaultfd" run_test ${uffd_stress_bin} anon 20 16 -# Hugetlb tests require source and destination huge pages. Pass in almost = half -# the size of the free pages we have, which is used for *each*. An adjustm= ent -# of (nr_parallel - 1) is done (see nr_parallel in uffd-stress.c) to have = some -# extra hugepages - this is done to prevent the test from failing by racily -# reserving more hugepages than strictly required. -# uffd-stress expects a region expressed in MiB, so we adjust -# half_ufd_size_MB accordingly. adjustment=3D$(( (31 < (nr_cpus - 1)) ? 31 : (nr_cpus - 1) )) -half_ufd_size_MB=3D$((((freepgs - adjustment) * hpgsize_KB) / 1024 / 2)) -CATEGORY=3D"userfaultfd" run_test ${uffd_stress_bin} hugetlb "$half_ufd_si= ze_MB" 32 -CATEGORY=3D"userfaultfd" run_test ${uffd_stress_bin} hugetlb-private "$hal= f_ufd_size_MB" 32 +CATEGORY=3D"userfaultfd" run_test ${uffd_stress_bin} hugetlb 128 32 +CATEGORY=3D"userfaultfd" run_test ${uffd_stress_bin} hugetlb-private 128 32 CATEGORY=3D"userfaultfd" run_test ${uffd_stress_bin} shmem 20 16 CATEGORY=3D"userfaultfd" run_test ${uffd_stress_bin} shmem-private 20 16 -# uffd-wp-mremap requires at least one page of each size. -have_all_size_hugepgs=3Dtrue -declare -A nr_size_hugepgs -for f in /sys/kernel/mm/hugepages/**/nr_hugepages; do - old=3D$(cat $f) - nr_size_hugepgs["$f"]=3D"$old" - if [ "$old" =3D=3D 0 ]; then - echo 1 > "$f" - fi - if [ $(cat "$f") =3D=3D 0 ]; then - have_all_size_hugepgs=3Dfalse - break - fi -done -if $have_all_size_hugepgs; then - CATEGORY=3D"userfaultfd" run_test ./uffd-wp-mremap -else - echo "# SKIP ./uffd-wp-mremap" -fi - -#cleanup -for f in "${!nr_size_hugepgs[@]}"; do - echo "${nr_size_hugepgs["$f"]}" > "$f" -done -echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages +CATEGORY=3D"userfaultfd" run_test ./uffd-wp-mremap =20 CATEGORY=3D"compaction" run_test ./compaction_test =20 @@ -393,14 +291,11 @@ CATEGORY=3D"mremap" run_test ./mremap_test CATEGORY=3D"hugetlb" run_test ./thuge-gen CATEGORY=3D"hugetlb" run_test ./charge_reserved_hugetlb.sh -cgroup-v2 CATEGORY=3D"hugetlb" run_test ./hugetlb_reparenting_test.sh -cgroup-v2 + if $RUN_DESTRUCTIVE; then -nr_hugepages_tmp=3D$(cat /proc/sys/vm/nr_hugepages) -enable_soft_offline=3D$(cat /proc/sys/vm/enable_soft_offline) -echo 8 > /proc/sys/vm/nr_hugepages -CATEGORY=3D"hugetlb" run_test ./hugetlb-soft-offline -echo "$nr_hugepages_tmp" > /proc/sys/vm/nr_hugepages -echo "$enable_soft_offline" > /proc/sys/vm/enable_soft_offline -CATEGORY=3D"hugetlb" run_test ./hugetlb-read-hwpoison + CATEGORY=3D"hugetlb" run_test ./hugetlb-soft-offline + echo "$enable_soft_offline" > /proc/sys/vm/enable_soft_offline + CATEGORY=3D"hugetlb" run_test ./hugetlb-read-hwpoison fi =20 if [ $VADDR64 -ne 0 ]; then @@ -464,7 +359,6 @@ if [ -x ./protection_keys_64 ] then CATEGORY=3D"pkey" run_test ./protection_keys_64 fi -echo "$nr_hugepgs" > /proc/sys/vm/nr_hugepages =20 if [ -x ./soft-dirty ] then @@ -545,10 +439,6 @@ if [ -n "${LOADED_MOD}" ]; then modprobe -r hwpoison_inject > /dev/null 2>&1 fi =20 -if [ "${HAVE_HUGEPAGES}" =3D 1 ]; then - echo "$orig_nr_hugepgs" > /proc/sys/vm/nr_hugepages -fi - echo "SUMMARY: PASS=3D${count_pass} SKIP=3D${count_skip} FAIL=3D${count_fa= il}" | tap_prefix echo "1..${count_total}" | tap_output =20 --=20 2.53.0