Skip to content

Commit 1b8ec45

Browse files
committed
mm: selftest to verify zero-filled pages are mapped to zeropage
JIRA: https://issues.redhat.com/browse/RHEL-88165 Conflicts: * tools/testing/selftests/mm/split_huge_page_test.c: This commit drops code related to `split_pmd_zero_pages()` from split_huge_page_test.c, as it is not needed for our backport. The goal is to apply only the vm_util.[ch] changes from the upstream patch series, while avoiding dependencies on upstream commit fc4d182 ("mm: huge_memory: enable debugfs to split huge pages to any order"), which are not present in RHEL-9 and are unrelated to this backport effort. This patch is a backport of the following upstream commit: commit 391e869 Author: Alexander Zhu <alexlzhu@fb.com> Date: Fri Aug 30 11:03:37 2024 +0100 mm: selftest to verify zero-filled pages are mapped to zeropage When a THP is split, any subpage that is zero-filled will be mapped to the shared zeropage, hence saving memory. Add selftest to verify this by allocating zero-filled THP and comparing RssAnon before and after split. Link: https://lkml.kernel.org/r/20240830100438.3623486-4-usamaarif642@gmail.com Signed-off-by: Alexander Zhu <alexlzhu@fb.com> Signed-off-by: Usama Arif <usamaarif642@gmail.com> Acked-by: Rik van Riel <riel@surriel.com> Cc: Barry Song <baohua@kernel.org> Cc: David Hildenbrand <david@redhat.com> Cc: Domenico Cerasuolo <cerasuolodomenico@gmail.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Kairui Song <ryncsn@gmail.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Mike Rapoport <rppt@kernel.org> Cc: Nico Pache <npache@redhat.com> Cc: Roman Gushchin <roman.gushchin@linux.dev> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Shakeel Butt <shakeel.butt@linux.dev> Cc: Shuang Zhai <zhais@google.com> Cc: Yu Zhao <yuzhao@google.com> Cc: Shuang Zhai <szhai2@cs.rochester.edu> Cc: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Li Wang <liwang@redhat.com>
1 parent c4a0f7a commit 1b8ec45

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tools/testing/selftests/mm/vm_util.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#define PMD_SIZE_FILE_PATH "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size"
1313
#define SMAP_FILE_PATH "/proc/self/smaps"
14+
#define STATUS_FILE_PATH "/proc/self/status"
1415
#define MAX_LINE_LENGTH 500
1516

1617
unsigned int __page_size;
@@ -97,6 +98,27 @@ uint64_t read_pmd_pagesize(void)
9798
return strtoul(buf, NULL, 10);
9899
}
99100

101+
unsigned long rss_anon(void)
102+
{
103+
unsigned long rss_anon = 0;
104+
FILE *fp;
105+
char buffer[MAX_LINE_LENGTH];
106+
107+
fp = fopen(STATUS_FILE_PATH, "r");
108+
if (!fp)
109+
ksft_exit_fail_msg("%s: Failed to open file %s\n", __func__, STATUS_FILE_PATH);
110+
111+
if (!check_for_pattern(fp, "RssAnon:", buffer, sizeof(buffer)))
112+
goto err_out;
113+
114+
if (sscanf(buffer, "RssAnon:%10lu kB", &rss_anon) != 1)
115+
ksft_exit_fail_msg("Reading status error\n");
116+
117+
err_out:
118+
fclose(fp);
119+
return rss_anon;
120+
}
121+
100122
bool __check_huge(void *addr, char *pattern, int nr_hpages,
101123
uint64_t hpage_size)
102124
{

tools/testing/selftests/mm/vm_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ unsigned long pagemap_get_pfn(int fd, char *start);
3939
void clear_softdirty(void);
4040
bool check_for_pattern(FILE *fp, const char *pattern, char *buf, size_t len);
4141
uint64_t read_pmd_pagesize(void);
42+
unsigned long rss_anon(void);
4243
bool check_huge_anon(void *addr, int nr_hpages, uint64_t hpage_size);
4344
bool check_huge_file(void *addr, int nr_hpages, uint64_t hpage_size);
4445
bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size);

0 commit comments

Comments
 (0)