Skip to contentSkip to conversation

selftests-mm-vm_util-add-helpers-to-set-and-restore-shm-limits.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Jun 21

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: selftests/mm: vm_util: add helpers to set and restore shm limits
has been removed from the -mm tree. Its filename was
selftests-mm-vm_util-add-helpers-to-set-and-restore-shm-limits.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: "Mike Rapoport (Microsoft)" <[email protected]>
Subject: selftests/mm: vm_util: add helpers to set and restore shm limits
Date: Mon, 11 May 2026 19:28:14 +0300

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.

Cc Baolin Wang <[email protected]>
Cc Barry Song <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Dev Jain <[email protected]>
Cc Donet Tom <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Cc John Hubbard <[email protected]>
Cc Lance Yang <[email protected]>
Cc Leon Romanovsky <[email protected]>
Cc Liam Howlett <[email protected]>
Cc Li Wang <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Mark Brown <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Nico Pache <[email protected]>
Cc Peter Xu <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Zi Yan <[email protected]>

---

 tools/testing/selftests/mm/vm_util.c |   28 +++++++++++++++++++++++++
 tools/testing/selftests/mm/vm_util.h |    9 ++++++++
 2 files changed, 37 insertions(+)
tools/testing/selftests/mm/vm_util.c renamed from tools/testing/selftests/mm/vm_util.c~selftests-mm-vm_util-add-helpers-to-set-and-restore-shm-limits +28 -0
@@ -760,3 +760,31 @@ void write_num(const char *path, unsigne
 	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 = length / psize();
+	unsigned long val;
+
+	val = read_num("/proc/sys/kernel/shmmax");
+	if (val < length) {
+		write_num("/proc/sys/kernel/shmmax", length);
+		shmmax = val;
+	}
+
+	val = read_num("/proc/sys/kernel/shmall");
+	if (val < nr) {
+		write_num("/proc/sys/kernel/shmall", nr);
+		shmall = val;
+	}
+}
tools/testing/selftests/mm/vm_util.h renamed from tools/testing/selftests/mm/vm_util.h~selftests-mm-vm_util-add-helpers-to-set-and-restore-shm-limits +9 -0
@@ -168,3 +168,12 @@ void write_file(const char *path, const
 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();						\
+}

_

Patches currently in -mm which might be from [email protected] are