diff mbox series

hugeshmat04: don't attach at specific address

Message ID 8b4c1fad2914aee00c8a160d1f9e482574b8e5ae.1632242721.git.jstancek@redhat.com
State Changes Requested
Headers show
Series hugeshmat04: don't attach at specific address | expand

Commit Message

Jan Stancek Sept. 21, 2021, 4:45 p.m. UTC
The test intermittently fails on ppc64le, when heap
happens to overlap with segment that the test is trying
to attach at 1GB boundary.

Let the kernel find suitable address.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Li Wang Sept. 22, 2021, 6:34 a.m. UTC | #1
On Wed, Sep 22, 2021 at 12:46 AM Jan Stancek <jstancek@redhat.com> wrote:

> The test intermittently fails on ppc64le, when heap
> happens to overlap with segment that the test is trying
> to attach at 1GB boundary.
>
> Let the kernel find suitable address.
>

I'm not sure why the original way uses fixed address, but
it should be fine to cancel that limitation.

Reviewed-by: Li Wang <liwang@redhat.com>

Or, maybe we can consider doing range_is_mapped check
before using it.
Cyril Hrubis Sept. 22, 2021, 2:29 p.m. UTC | #2
Hi!
> > The test intermittently fails on ppc64le, when heap
> > happens to overlap with segment that the test is trying
> > to attach at 1GB boundary.
> >
> > Let the kernel find suitable address.
> >
> 
> I'm not sure why the original way uses fixed address, but
> it should be fine to cancel that limitation.

It seems to be regression test for:

commit c5c99429fa57dcf6e05203ebe3676db1ec646793
Author: Larry Woodman <lwoodman@redhat.com>
Date:   Thu Jan 24 05:49:25 2008 -0800

    fix hugepages leak due to pagetable page sharing

    The shared page table code for hugetlb memory on x86 and x86_64
    is causing a leak.  When a user of hugepages exits using this code
    the system leaks some of the hugepages.

    -------------------------------------------------------
    Part of /proc/meminfo just before database startup:
    HugePages_Total:  5500
    HugePages_Free:   5500
    HugePages_Rsvd:      0
    Hugepagesize:     2048 kB

    Just before shutdown:
    HugePages_Total:  5500
    HugePages_Free:   4475
    HugePages_Rsvd:      0
    Hugepagesize:     2048 kB

    After shutdown:
    HugePages_Total:  5500
    HugePages_Free:   4988
    HugePages_Rsvd:
    0 Hugepagesize:     2048 kB
    ----------------------------------------------------------

    The problem occurs durring a fork, in copy_hugetlb_page_range().  It
    locates the dst_pte using huge_pte_alloc().  Since huge_pte_alloc() calls
    huge_pmd_share() it will share the pmd page if can, yet the main loop in
    copy_hugetlb_page_range() does a get_page() on every hugepage.  This is a
    violation of the shared hugepmd pagetable protocol and creates additional
    referenced to the hugepages causing a leak when the unmap of the VMA
    occurs.  We can skip the entire replication of the ptes when the hugepage
    pagetables are shared.  The attached patch skips copying the ptes and the
    get_page() calls if the hugetlbpage pagetable is shared.


As far as I can tell there is no reason to allocate the memory on a
fixed address to trigger this bug but it should be easy enough to check
if the test fails on a kernel that has the two lines this patch adds
commented before and after the change it test.

Also can we pretty please add the commit hash to the test metadata?
Li Wang Sept. 23, 2021, 6:49 a.m. UTC | #3
> It seems to be regression test for:
>
> commit c5c99429fa57dcf6e05203ebe3676db1ec646793
> Author: Larry Woodman <lwoodman@redhat.com>
> Date:   Thu Jan 24 05:49:25 2008 -0800
>
>     fix hugepages leak due to pagetable page sharing
>


>
> As far as I can tell there is no reason to allocate the memory on a
> fixed address to trigger this bug but it should be easy enough to check
> if the test fails on a kernel that has the two lines this patch adds
> commented before and after the change it test.
>

That commit was merged in v2.6.24, it too old kernel and
changes a lot in the two lines, I guess it is not easy to test
a kernel with revert that patch.

>
> Also can we pretty please add the commit hash to the test metadata?
>

+1
diff mbox series

Patch

diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
index e9bb9fbf7b4b..75f61de066d7 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
@@ -22,7 +22,6 @@ 
 #include "hugetlb.h"
 
 #define SIZE	(1024 * 1024 * 1024)
-#define BOUNDARY (1024 * 1024 * 1024)
 
 static long huge_free;
 static long huge_free2;
@@ -54,7 +53,7 @@  static void shared_hugepage(void)
 	if (shmid < 0)
 		tst_brk(TBROK | TERRNO, "shmget");
 
-	buf = shmat(shmid, (void *)BOUNDARY, SHM_RND | 0777);
+	buf = shmat(shmid, NULL, 0777);
 	if (buf == (void *)-1) {
 		shmctl(shmid, IPC_RMID, NULL);
 		tst_brk(TBROK | TERRNO, "shmat");