Re: mm: move_pages syscall can't return ENOENT when pages are not present

From: Xiaotian Feng
Date: Wed May 09 2012 - 05:28:53 EST


On Wed, May 9, 2012 at 4:58 PM, Zhouping Liu <zliu@xxxxxxxxxx> wrote:
> hi, all
>
> Recently, I found an error in move_pages syscall:
>
> depending on move_pages(2), when page is not present,
> it should fail with ENOENT, in fact, it's ok without
> any errno.
>
> the following reproducer can easily reproduce
> the issue, suggest you get more details by strace.
> inside reproducer, I try to move a non-exist page from
> node 1 to node 0.
>
> I have tested it on the latest kernel 3.4-rc5 with 2 and 4 numa nodes.
> [zliu@ZhoupingLiu ~]$ gcc -o reproducer reproducer.c -lnuma
> [zliu@ZhoupingLiu ~]$ ./reproducer
> from_node is 1, to_node is 0
> ERROR: move_pages expected FAIL.
>

" If nodes is not NULL, move_pages returns the number of valid
migration requests which could not currently be performed. Otherwise
it returns 0."

> I'm not in mail list, please CC me.
>
> /*
> Â* Copyright (C) 2012 ÂRed Hat, Inc.
> Â*
> Â* This work is licensed under the terms of the GNU GPL, version 2. See
> Â* the COPYING file in the top-level directory.
> Â*
> Â* Compiled: gcc -o reproducer reproducer.c -lnuma
> Â* Description:
> Â* it's designed to check move_pages syscall, when
> Â* page is not present, it should fail with ENOENT.
> Â*/
>
> #include <sys/mman.h>
> #include <sys/types.h>
> #include <sys/wait.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <errno.h>
> #include <numa.h>
> #include <numaif.h>
>
> #define TEST_PAGES 4
>
> int main(int argc, char **argv)
> {
> Â Â Â Âvoid *pages[TEST_PAGES];
> Â Â Â Âint onepage;
> Â Â Â Âint nodes[TEST_PAGES];
> Â Â Â Âint status, ret;
> Â Â Â Âint i, from_node = 1, to_node = 0;
>
> Â Â Â Âonepage = getpagesize();
>
> Â Â Â Âfor (i = 0; i < TEST_PAGES - 1; i++) {
> Â Â Â Â Â Â Â Âpages[i] = numa_alloc_onnode(onepage, from_node);
> Â Â Â Â Â Â Â Ânodes[i] = to_node;
> Â Â Â Â}
>
> Â Â Â Ânodes[TEST_PAGES - 1] = to_node;
>
> Â Â Â Â/*
> Â Â Â Â * the follow page is not available, also not aligned,
> Â Â Â Â * depend on move_pages(2), it can't be moved, and should
> Â Â Â Â * return ENOENT errno.
> Â Â Â Â */
> Â Â Â Âpages[TEST_PAGES - 1] = pages[TEST_PAGES - 2] - onepage * 4 + 1;
>
> Â Â Â Âprintf("from_node is %u, to_node is %u\n", from_node, to_node);
> Â Â Â Âret = move_pages(0, TEST_PAGES, pages, nodes, &status, MPOL_MF_MOVE);
> Â Â Â Âif (ret == -1) {
> Â Â Â Â Â Â Â Âif (errno != ENOENT)
> Â Â Â Â Â Â Â Â Â Â Â Âperror("move_pages expected ENOENT errno, but it's");
> Â Â Â Â Â Â Â Âelse
> Â Â Â Â Â Â Â Â Â Â Â Âprintf("Succeed\n");
> Â Â Â Â} else {
> Â Â Â Â Â Â Â Âprintf("ERROR: move_pages expected FAIL.\n");
> Â Â Â Â}
>
> Â Â Â Âfor (i = 0; i < TEST_PAGES; i++)
> Â Â Â Â Â Â Â Ânuma_free(pages[i], onepage);
>
> Â Â Â Âreturn 0;
> }
>
> --
> Thanks,
> Zhouping
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/