mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
tools/lib/mm: move hugepage_settings out of selftests
Move hugepage_settings.[ch] from tools/testing/selftests/mm/ to tools/lib/mm/ so the THP and HugeTLB helpers can be shared more easily between selftests and other tools. Keep the helpers exposed to mm selftests through vm_util.h where possible, and use direct <mm/hugepage_settings.h> includes for files that do not include vm_util.h. Adjust the selftests/mm build to compile the moved implementation from its new location. Remove the remaining kselftest dependency by including file_utils.h directly and using EXIT_FAILURE in the signal handler. Link: https://lore.kernel.org/20260918112234.195857-4-sarthak.sharma@arm.com Signed-off-by: Sarthak Sharma <sarthak.sharma@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Tested-by: Muhammad Usama Anjum <usama.anjum@arm.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Barry Song <baohua@kernel.org> Cc: Dev Jain <dev.jain@arm.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Lance Yang <lance.yang@linux.dev> Cc: Leon Romanovsky <leon@kernel.org> Cc: Liam R. Howlett <liam@infradead.org> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Mark Brown <broonie@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Nico Pache <npache@redhat.com> Cc: Peter Xu <peterx@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Zi Yan <ziy@nvidia.com>
This commit is contained in:
parent
1d59dd1383
commit
32449ec2cc
|
|
@ -10,11 +10,16 @@
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "vm_util.h"
|
||||
#include "file_utils.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/"
|
||||
#define MAX_SETTINGS_DEPTH 4
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
static struct thp_settings settings_stack[MAX_SETTINGS_DEPTH];
|
||||
static int settings_index;
|
||||
static struct thp_settings saved_settings;
|
||||
|
|
@ -655,8 +660,10 @@ static void hugepage_restore_settings_atexit(void)
|
|||
|
||||
static void hugepage_restore_settings_sighandler(int sig)
|
||||
{
|
||||
(void)sig;
|
||||
|
||||
/* exit() will invoke the hugepage_restore_settings_atexit handler. */
|
||||
exit(KSFT_FAIL);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void hugepage_save_settings(bool thp, bool hugetlb)
|
||||
|
|
@ -185,8 +185,10 @@ TEST_FILES += write_hugetlb_memory.sh
|
|||
|
||||
include ../lib.mk
|
||||
|
||||
$(TEST_GEN_PROGS): vm_util.c hugepage_settings.c $(top_srcdir)/tools/lib/mm/file_utils.c
|
||||
$(TEST_GEN_FILES): vm_util.c hugepage_settings.c $(top_srcdir)/tools/lib/mm/file_utils.c
|
||||
$(TEST_GEN_PROGS): vm_util.c $(top_srcdir)/tools/lib/mm/hugepage_settings.c \
|
||||
$(top_srcdir)/tools/lib/mm/file_utils.c
|
||||
$(TEST_GEN_FILES): vm_util.c $(top_srcdir)/tools/lib/mm/hugepage_settings.c \
|
||||
$(top_srcdir)/tools/lib/mm/file_utils.c
|
||||
|
||||
$(OUTPUT)/uffd-stress: uffd-common.c
|
||||
$(OUTPUT)/uffd-unit-tests: uffd-common.c
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@
|
|||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <mm/hugepage_settings.h>
|
||||
|
||||
#include "kselftest.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define MAP_SIZE_MB 100
|
||||
#define MAP_SIZE (MAP_SIZE_MB * 1024 * 1024)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@
|
|||
#include "../../../../mm/gup_test.h"
|
||||
#include "kselftest.h"
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
static size_t pagesize;
|
||||
static int pagemap_fd;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
#include <unistd.h>
|
||||
#include "vm_util.h"
|
||||
#include "kselftest.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
uint64_t page_size;
|
||||
uint64_t pmd_pagesize;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#include "../pidfd/pidfd.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@
|
|||
#include "../../../../mm/gup_test.h"
|
||||
#include "kselftest.h"
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
static size_t pagesize;
|
||||
static int nr_hugetlbsizes;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
#include <mm/gup_test.h>
|
||||
#include "kselftest.h"
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define MB (1UL << 20)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,6 @@
|
|||
* bugs.
|
||||
*/
|
||||
|
||||
#include "kselftest_harness.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -33,6 +30,9 @@
|
|||
#include <sys/eventfd.h>
|
||||
#include <linux/userfaultfd.h>
|
||||
#include <poll.h>
|
||||
#include <mm/hugepage_settings.h>
|
||||
|
||||
#include "kselftest_harness.h"
|
||||
|
||||
/*
|
||||
* This is a private UAPI to the kernel test module so it isn't exported
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
#include <fcntl.h>
|
||||
#include "vm_util.h"
|
||||
#include "kselftest.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define MIN_FREE_PAGES 20
|
||||
#define NR_HUGE_PAGES 10 /* common number of pages to map/allocate */
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@
|
|||
#include <linux/memfd.h>
|
||||
#include "vm_util.h"
|
||||
#include "kselftest.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define LENGTH (256UL*1024*1024)
|
||||
#define PROTECTION (PROT_READ | PROT_WRITE)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@
|
|||
#include <stdbool.h>
|
||||
#include "kselftest.h"
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define DEFAULT_LENGTH_MB 10UL
|
||||
#define MB_TO_BYTES(x) (x * 1024 * 1024)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@
|
|||
#include <sys/mman.h>
|
||||
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define LENGTH (256UL*1024*1024)
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,10 @@
|
|||
#include <sys/mman.h>
|
||||
#include <sys/statfs.h>
|
||||
#include <sys/types.h>
|
||||
#include <mm/hugepage_settings.h>
|
||||
|
||||
#include "kselftest.h"
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#ifndef MADV_SOFT_OFFLINE
|
||||
#define MADV_SOFT_OFFLINE 101
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
#include <sys/syscall.h>
|
||||
#include "vm_util.h"
|
||||
#include "kselftest.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#ifndef STATX_DIOALIGN
|
||||
#define STATX_DIOALIGN 0x00002000U
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#include "vm_util.h"
|
||||
#include "kselftest.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define INLOOP_ITER 100
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define INLOOP_ITER 100
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
#include "linux/magic.h"
|
||||
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define BASE_ADDR ((void *)(1UL << 30))
|
||||
static unsigned long hpage_pmd_size;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
#include "kselftest.h"
|
||||
#include <include/vdso/time64.h>
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define KSM_SYSFS_PATH "/sys/kernel/mm/ksm/"
|
||||
#define KSM_FP(s) (KSM_SYSFS_PATH s)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
|
||||
#include "kselftest_harness.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
|
@ -16,6 +15,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "vm_util.h"
|
||||
|
||||
#define TWOMEG (2<<20)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#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 | \
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
#include <sys/wait.h>
|
||||
|
||||
#include "kselftest_harness.h"
|
||||
#include "hugepage_settings.h"
|
||||
#include "vm_util.h"
|
||||
|
||||
#ifndef PR_THP_DISABLE_EXCEPT_ADVISED
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <setjmp.h>
|
||||
#include <mm/hugepage_settings.h>
|
||||
|
||||
#include "hugepage_settings.h"
|
||||
#include "pkey-helpers.h"
|
||||
|
||||
u64 shadow_pkey_reg;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include "kselftest.h"
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define PAGEMAP_FILE_PATH "/proc/self/pagemap"
|
||||
#define TEST_ITERATIONS 10000
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
#include <time.h>
|
||||
#include "vm_util.h"
|
||||
#include "kselftest.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
uint64_t pagesize;
|
||||
unsigned int pageshift;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
#include <string.h>
|
||||
#include "vm_util.h"
|
||||
#include "kselftest.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#if !defined(MAP_HUGETLB)
|
||||
#define MAP_HUGETLB 0x40000
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
#include <sys/mman.h>
|
||||
#include "vm_util.h"
|
||||
#include "kselftest.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
int backing_fd = -1;
|
||||
int mmap_flags = MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
#include "kselftest.h"
|
||||
#include "vm_util.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
#define UFFD_FLAGS (O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
#include <assert.h>
|
||||
#include <linux/mman.h>
|
||||
#include <sys/mman.h>
|
||||
#include <mm/hugepage_settings.h>
|
||||
#include "kselftest.h"
|
||||
#include "hugepage_settings.h"
|
||||
#include "uffd-common.h"
|
||||
|
||||
static int pagemap_fd;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include "vm_util.h"
|
||||
#include "kselftest.h"
|
||||
#include "hugepage_settings.h"
|
||||
|
||||
/*
|
||||
* The hint addr value is used to allocate addresses
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "kselftest.h"
|
||||
#include <linux/fs.h>
|
||||
#include <mm/file_utils.h>
|
||||
#include <mm/hugepage_settings.h>
|
||||
|
||||
#define BIT_ULL(nr) (1ULL << (nr))
|
||||
#define PM_SOFT_DIRTY BIT_ULL(55)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user