Commit af605d26 authored by Peter Xu's avatar Peter Xu Committed by Andrew Morton
Browse files

selftests/mm: merge util.h into vm_util.h

There're two util headers under mm/ kselftest.  Merge one with another. 
It turns out util.h is the easy one to move.

When merging, drop PAGE_SIZE / PAGE_SHIFT because they're unnecessary
wrappers to page_size() / page_shift(), meanwhile rename them to psize()
and pshift() so as to not conflict with some existing definitions in some
test files that includes vm_util.h.

Link: https://lkml.kernel.org/r/20230412164120.327731-1-peterx@redhat.com


Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
Reviewed-by: default avatarAxel Rasmussen <axelrasmussen@google.com>
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarMike Rapoport (IBM) <rppt@kernel.org>
Cc: Dmitry Safonov <0x7f454c46@gmail.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Zach O'Keefe <zokeefe@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent c7c55fc4
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -113,6 +113,10 @@ $(OUTPUT)/mkdirty: vm_util.c
$(OUTPUT)/soft-dirty: vm_util.c
$(OUTPUT)/split_huge_page_test: vm_util.c
$(OUTPUT)/userfaultfd: vm_util.c
$(OUTPUT)/gup_test: vm_util.c
$(OUTPUT)/mrelease_test: vm_util.c
$(OUTPUT)/transhuge-stress: vm_util.c
$(OUTPUT)/ksm_tests: vm_util.c

ifeq ($(MACHINE),x86_64)
BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
+2 −3
Original line number Diff line number Diff line
@@ -12,8 +12,7 @@
#include <assert.h>
#include <mm/gup_test.h>
#include "../kselftest.h"

#include "util.h"
#include "vm_util.h"

#define MB (1UL << 20)

@@ -251,7 +250,7 @@ int main(int argc, char **argv)
	if (touch) {
		gup.gup_flags |= FOLL_TOUCH;
	} else {
		for (; (unsigned long)p < gup.addr + size; p += PAGE_SIZE)
		for (; (unsigned long)p < gup.addr + size; p += psize())
			p[0] = 0;
	}

+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@

#include "../kselftest.h"
#include <include/vdso/time64.h>
#include "util.h"
#include "vm_util.h"

#define KSM_SYSFS_PATH "/sys/kernel/mm/ksm/"
#define KSM_FP(s) (KSM_SYSFS_PATH s)
+5 −6
Original line number Diff line number Diff line
@@ -9,8 +9,7 @@
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>

#include "util.h"
#include "vm_util.h"

#include "../kselftest.h"

@@ -32,7 +31,7 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd)
	unsigned long i;
	char *buf;

	buf = (char *)mmap(NULL, nr_pages * PAGE_SIZE, PROT_READ | PROT_WRITE,
	buf = (char *)mmap(NULL, nr_pages * psize(), PROT_READ | PROT_WRITE,
			   MAP_PRIVATE | MAP_ANON, 0, 0);
	if (buf == MAP_FAILED) {
		perror("mmap failed, halting the test");
@@ -40,7 +39,7 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd)
	}

	for (i = 0; i < nr_pages; i++)
		*((unsigned long *)(buf + (i * PAGE_SIZE))) = i;
		*((unsigned long *)(buf + (i * psize()))) = i;

	/* Signal the parent that the child is ready */
	if (write(pipefd, "", 1) < 0) {
@@ -54,7 +53,7 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd)
		timeout--;
	}

	munmap(buf, nr_pages * PAGE_SIZE);
	munmap(buf, nr_pages * psize());

	return (timeout > 0) ? KSFT_PASS : KSFT_FAIL;
}
@@ -87,7 +86,7 @@ static int child_main(int pipefd[], size_t size)

	/* Allocate and fault-in memory and wait to be killed */
	close(pipefd[0]);
	res = alloc_noexit(MB(size) / PAGE_SIZE, pipefd[1]);
	res = alloc_noexit(MB(size) / psize(), pipefd[1]);
	close(pipefd[1]);
	return res;
}
+6 −6
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include "util.h"
#include "vm_util.h"

int backing_fd = -1;
int mmap_flags = MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE;
@@ -34,10 +34,10 @@ int main(int argc, char **argv)
	int pagemap_fd;

	ram = sysconf(_SC_PHYS_PAGES);
	if (ram > SIZE_MAX / sysconf(_SC_PAGESIZE) / 4)
	if (ram > SIZE_MAX / psize() / 4)
		ram = SIZE_MAX / 4;
	else
		ram *= sysconf(_SC_PAGESIZE);
		ram *= psize();
	len = ram;

	while (++i < argc) {
@@ -58,7 +58,7 @@ int main(int argc, char **argv)

	warnx("allocate %zd transhuge pages, using %zd MiB virtual memory"
	      " and %zd MiB of ram", len >> HPAGE_SHIFT, len >> 20,
	      ram >> (20 + HPAGE_SHIFT - PAGE_SHIFT - 1));
	      ram >> (20 + HPAGE_SHIFT - pshift() - 1));

	pagemap_fd = open("/proc/self/pagemap", O_RDONLY);
	if (pagemap_fd < 0)
@@ -92,7 +92,7 @@ int main(int argc, char **argv)
			if (pfn < 0) {
				nr_failed++;
			} else {
				size_t idx = pfn >> (HPAGE_SHIFT - PAGE_SHIFT);
				size_t idx = pfn >> (HPAGE_SHIFT - pshift());

				nr_succeed++;
				if (idx >= map_len) {
@@ -108,7 +108,7 @@ int main(int argc, char **argv)
			}

			/* split transhuge page, keep last page */
			if (madvise(p, HPAGE_SIZE - PAGE_SIZE, MADV_DONTNEED))
			if (madvise(p, HPAGE_SIZE - psize(), MADV_DONTNEED))
				err(2, "MADV_DONTNEED");
		}
		clock_gettime(CLOCK_MONOTONIC, &b);
Loading