mm: mlock: elaborate mlock selftest case and fix one bug identified
Subsystems (3)
cover mm: mlock: elaborate mlock selftest case and fix one bug identified
From: Simon Guo <[email protected]>
The original mlock self tests are far from completed and David suggests to elaborate that.
The patch set expand mlock selftest case by randomly mlock/mlock2 on given memory region. It covers both under MLOCK rlimit and exceed MLOCK rlimit case.
During the testing, one bug was identified (introduced by my previous patch and sorry for that). Fix is included in this patch set.
Simon Guo (3):
mm: mlock: correct a typo in count_mm_mlocked_page_nr() for caculate
VMLOCKED pages
selftest: move seek_to_smaps_entry() out of mlock2-tests.c
selftests: expanding more mlock selftest
mm/mlock.c | 6 +- tools/testing/selftests/vm/Makefile | 4 +- tools/testing/selftests/vm/mlock-intersect-test.c | 76 ------ tools/testing/selftests/vm/mlock-random-test.c | 293 ++++++++++++++++++++++ tools/testing/selftests/vm/mlock2-tests.c | 42 ---- tools/testing/selftests/vm/mlock2.h | 43 ++++ 6 files changed, 342 insertions(+), 122 deletions(-) delete mode 100644 tools/testing/selftests/vm/mlock-intersect-test.c create mode 100644 tools/testing/selftests/vm/mlock-random-test.c
Signature · 7 lines
1.8.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/3 mm: mlock: correct a typo in count_mm_mlocked_page_nr() for caculate VMLOCKED pages
From: Simon Guo <[email protected]>
There is a typo/bug in count_mm_mlocked_page_nr() for "&" which is mistakenly used with "&&".
Also add more checks and some minor change based on Kirill's previous comment.
--- mm/mlock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/mlock.c +4 -2
@@ -641,9 +641,11 @@ static int count_mm_mlocked_page_nr(struct mm_struct *mm, vma = mm->mmap;for (; vma ; vma = vma->vm_next) { +if (start >= vma->vm_end) +continue ;if (start + len <= vma->vm_start)break ; -if (vma->vm_flags &&VM_LOCKED ) { +if (vma->vm_flags &VM_LOCKED ) {if (start > vma->vm_start) count -= (start - vma->vm_start);if (start + len < vma->vm_end) {
@@ -654,7 +656,7 @@ static int count_mm_mlocked_page_nr(struct mm_struct *mm, } } -return (PAGE_ALIGN (count) >>PAGE_SHIFT ); +return count >>PAGE_SHIFT ; }static __must_check int do_mlock (unsigned long start,size_t len,vm_flags_t flags)
Signature · 7 lines
1.8.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/3 selftest: move seek_to_smaps_entry() out of mlock2-tests.c
In reply to [email protected]From: Simon Guo <[email protected]>
Function seek_to_smaps_entry() can be useful for other selftest functionalities, so move it out to header file.
--- tools/testing/selftests/vm/mlock2-tests.c | 42 ------------------------------ tools/testing/selftests/vm/mlock2.h | 43 +++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 42 deletions(-)
tools/testing/selftests/vm/mlock2-tests.c +0 -42
@@ -1,8 +1,6 @@#define _GNU_SOURCE#include <sys/mman.h> #include <stdint.h> -#include <stdio.h> -#include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/time.h>
@@ -119,46 +117,6 @@ static uint64_t get_kpageflags(unsigned long pfn)return flags; } -static FILE *seek_to_smaps_entry (unsigned long addr) -{ -FILE *file; -char *line =NULL ; -size_t size =0 ; -unsigned long start, end; -char perms[5 ]; -unsigned long offset; -char dev[32 ]; -unsigned long inode; -char path[BUFSIZ ]; - - file =fopen ("/proc/self/smaps" ,"r" ); -if (!file) { -perror ("fopen smaps" ); -_exit (1 ); - } - -while (getline (&line, &size, file) >0 ) { -if (sscanf (line,"%lx-%lx %s %lx %s %lu %s\n" , - &start, &end, perms, &offset, dev, &inode, path) <6 ) - goto next; - -if (start <= addr && addr < end) - goto out; - -next: -free (line); - line =NULL ; - size =0 ; - } - -fclose (file); - file =NULL ; - -out: -free (line); -return file; -} -#define VMFLAGS "VmFlags:"static bool is_vmflag_set (unsigned long addr,const char *vmflag)
tools/testing/selftests/vm/mlock2.h +43 -0
51 lines not on this page · raw message
Signature · 7 lines
1.8.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/3 selftests: expanding more mlock selftest
In reply to [email protected]From: Simon Guo <[email protected]>
This patch will randomly perform mlock/mlock2 on a given memory region, and verify the RLIMIT_MEMLOCK limitation works properly.
--- tools/testing/selftests/vm/Makefile | 4 +- tools/testing/selftests/vm/mlock-intersect-test.c | 76 ------ tools/testing/selftests/vm/mlock-random-test.c | 293 ++++++++++++++++++++++ 3 files changed, 295 insertions(+), 78 deletions(-) delete mode 100644 tools/testing/selftests/vm/mlock-intersect-test.c create mode 100644 tools/testing/selftests/vm/mlock-random-test.c
tools/testing/selftests/vm/Makefile +2 -2
@@ -10,7 +10,7 @@ BINARIES += on-fault-limit BINARIES += thuge-gen BINARIES += transhuge-stress BINARIES += userfaultfd -BINARIES += mlock-intersect-test +BINARIES += mlock-random-test all: $(BINARIES) %: %.c
@@ -18,7 +18,7 @@ all: $(BINARIES) userfaultfd: userfaultfd.c ../../../../usr/include/linux/kernel.h $(CC) $(CFLAGS) -O2 -o $@ $< -lpthread -mlock-intersect-test: mlock-intersect-test.c +mlock-random-test: mlock-random-test.c $(CC) $(CFLAGS) -o $@ $< -lcap ../../../../usr/include/linux/kernel.h:
tools/testing/selftests/vm/mlock-intersect-test.c deleted +0 -76
76 lines not on this page · raw message
tools/testing/selftests/vm/mlock-random-test.c new file +293 -0
293 lines not on this page · raw message
Signature · 7 lines
1.8.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>