mirror of
https://github.com/torvalds/linux.git
synced 2026-05-30 18:13:41 +02:00
selftests/mm: merge default_huge_page_size() into one
There're already 3 same definitions of the three functions. Move it into vm_util.[ch]. Link: https://lkml.kernel.org/r/20230412164223.328134-1-peterx@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Axel Rasmussen <axelrasmussen@google.com> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org> Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: Zach O'Keefe <zokeefe@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
4b54f5a758
commit
bd4d67e76f
|
|
@ -18,6 +18,7 @@
|
|||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include "vm_util.h"
|
||||
|
||||
#define MIN_FREE_PAGES 20
|
||||
#define NR_HUGE_PAGES 10 /* common number of pages to map/allocate */
|
||||
|
|
@ -35,30 +36,6 @@
|
|||
unsigned long huge_page_size;
|
||||
unsigned long base_page_size;
|
||||
|
||||
/*
|
||||
* default_huge_page_size copied from mlock2-tests.c
|
||||
*/
|
||||
unsigned long default_huge_page_size(void)
|
||||
{
|
||||
unsigned long hps = 0;
|
||||
char *line = NULL;
|
||||
size_t linelen = 0;
|
||||
FILE *f = fopen("/proc/meminfo", "r");
|
||||
|
||||
if (!f)
|
||||
return 0;
|
||||
while (getline(&line, &linelen, f) > 0) {
|
||||
if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) {
|
||||
hps <<= 10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(line);
|
||||
fclose(f);
|
||||
return hps;
|
||||
}
|
||||
|
||||
unsigned long get_free_hugepages(void)
|
||||
{
|
||||
unsigned long fhp = 0;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "vm_util.h"
|
||||
|
||||
#define err(x) perror(x), exit(1)
|
||||
|
||||
|
|
@ -74,24 +75,6 @@ void find_pagesizes(void)
|
|||
globfree(&g);
|
||||
}
|
||||
|
||||
unsigned long default_huge_page_size(void)
|
||||
{
|
||||
unsigned long hps = 0;
|
||||
char *line = NULL;
|
||||
size_t linelen = 0;
|
||||
FILE *f = fopen("/proc/meminfo", "r");
|
||||
if (!f)
|
||||
return 0;
|
||||
while (getline(&line, &linelen, f) > 0) {
|
||||
if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) {
|
||||
hps <<= 10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(line);
|
||||
return hps;
|
||||
}
|
||||
|
||||
void show(unsigned long ps)
|
||||
{
|
||||
char buf[100];
|
||||
|
|
|
|||
|
|
@ -1703,30 +1703,6 @@ static int userfaultfd_stress(void)
|
|||
|| userfaultfd_events_test() || userfaultfd_minor_test();
|
||||
}
|
||||
|
||||
/*
|
||||
* Copied from mlock2-tests.c
|
||||
*/
|
||||
unsigned long default_huge_page_size(void)
|
||||
{
|
||||
unsigned long hps = 0;
|
||||
char *line = NULL;
|
||||
size_t linelen = 0;
|
||||
FILE *f = fopen("/proc/meminfo", "r");
|
||||
|
||||
if (!f)
|
||||
return 0;
|
||||
while (getline(&line, &linelen, f) > 0) {
|
||||
if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) {
|
||||
hps <<= 10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(line);
|
||||
fclose(f);
|
||||
return hps;
|
||||
}
|
||||
|
||||
static void set_test_type(const char *type)
|
||||
{
|
||||
if (!strcmp(type, "anon")) {
|
||||
|
|
|
|||
|
|
@ -180,3 +180,24 @@ int64_t allocate_transhuge(void *ptr, int pagemap_fd)
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned long default_huge_page_size(void)
|
||||
{
|
||||
unsigned long hps = 0;
|
||||
char *line = NULL;
|
||||
size_t linelen = 0;
|
||||
FILE *f = fopen("/proc/meminfo", "r");
|
||||
|
||||
if (!f)
|
||||
return 0;
|
||||
while (getline(&line, &linelen, f) > 0) {
|
||||
if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) {
|
||||
hps <<= 10;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(line);
|
||||
fclose(f);
|
||||
return hps;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ 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);
|
||||
|
||||
/*
|
||||
* On ppc64 this will only work with radix 2M hugepage size
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user