KOSAKI Motohiro
9d8cebd4bc
mm: fix mbind vma merge problem
Strangely, current mbind() doesn't merge vma with neighbor vma although it's possible.
Unfortunately, many vma can reduce performance...
This patch fixes it.
reproduced program
----------------------------------------------------------------
#include <numaif.h>
#include <numa.h>
#include <sys/mman.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
static unsigned long pagesize;
int main(int argc, char** argv)
{
void* addr;
int ch;
int node;
struct bitmask *nmask = numa_allocate_nodemask();
int err;
int node_set = 0;
char buf[128];
while ((ch = getopt(argc, argv, "n:")) != -1){
switch (ch){
case 'n':
node = strtol(optarg, NULL, 0);
numa_bitmask_setbit(nmask, node);
node_set = 1;
break;
default:
;
}
}
argc -= optind;
argv += optind;
if (!node_set)
numa_bitmask_setbit(nmask, 0);
pagesize = getpagesize();
addr = mmap(NULL, pagesize*3, PROT_READ|PROT_WRITE,
MAP_ANON|MAP_PRIVATE, 0, 0);
if (addr == MAP_FAILED)
perror("mmap "), exit(1);
fprintf(stderr, "pid = %d \n" "addr = %p\n", getpid(), addr);
/* make page populate */
memset(addr, 0, pagesize*3);
/* first mbind */
err = mbind(addr+pagesize, pagesize, MPOL_BIND, nmask->maskp,
nmask->size, MPOL_MF_MOVE_ALL);
if (err)
error("mbind1 ");
/* second mbind */
err = mbind(addr, pagesize*3, MPOL_DEFAULT, NULL, 0, 0);
if (err)
error("mbind2 ");
sprintf(buf, "cat /proc/%d/maps", getpid());
system(buf);
return 0;
}
----------------------------------------------------------------
result without this patch
addr = 0x7fe26ef09000
[snip]
7fe26ef09000-7fe26ef0a000 rw-p 00000000 00:00 0
7fe26ef0a000-7fe26ef0b000 rw-p 00000000 00:00 0
7fe26ef0b000-7fe26ef0c000 rw-p 00000000 00:00 0
7fe26ef0c000-7fe26ef0d000 rw-p 00000000 00:00 0
=> 0x7fe26ef09000-0x7fe26ef0c000 have three vmas.
result with this patch
addr = 0x7fc9ebc76000
[snip]
7fc9ebc76000-7fc9ebc7a000 rw-p 00000000 00:00 0
7fffbe690000-7fffbe6a5000 rw-p 00000000 00:00 0 [stack]
=> 0x7fc9ebc76000-0x7fc9ebc7a000 have only one vma.
[minchan.kim@gmail.com: fix file offset passed to vma_merge()]
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reviewed-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
Signed-off-by: Minchan Kim <minchan.kim@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-03-06 11:26:25 -08:00
..
2009-12-03 13:49:43 +01:00
2010-02-12 09:41:59 -08:00
2010-02-26 19:19:39 +02:00
2010-03-06 11:26:23 -08:00
2010-03-06 11:26:24 -08:00
2010-03-06 11:26:23 -08:00
2009-11-10 04:15:47 +01:00
2010-03-01 09:15:15 -08:00
2009-12-16 12:20:01 +01:00
2009-12-16 12:19:59 +01:00
2010-03-03 08:15:05 -08:00
2009-09-21 15:14:57 +02:00
2009-12-17 16:00:19 -08:00
2009-12-15 08:53:20 -08:00
2010-01-07 11:58:36 -06:00
2009-12-16 12:20:00 +01:00
2009-12-16 12:16:49 -05:00
2010-01-16 12:15:39 -08:00
2009-12-15 08:53:20 -08:00
2009-12-21 19:56:42 +01:00
2010-03-06 11:26:24 -08:00
2010-03-06 11:26:25 -08:00
2009-09-22 07:17:35 -07:00
2010-03-01 09:15:15 -08:00
2009-12-15 08:53:24 -08:00
2010-03-06 11:26:24 -08:00
2010-03-06 11:26:24 -08:00
2010-01-15 01:43:28 -08:00
2009-09-22 07:17:31 -07:00
2009-09-21 14:28:04 +02:00
2010-03-06 11:26:24 -08:00
2010-01-16 12:15:40 -08:00
2010-03-06 11:26:23 -08:00
2010-03-06 11:26:25 -08:00
2009-09-22 07:17:26 -07:00
2009-12-15 08:53:16 -08:00
2009-12-03 13:54:25 +01:00
2009-12-15 08:53:24 -08:00
2010-02-26 08:25:35 +01:00
2009-09-24 09:34:52 +09:30
2009-12-17 15:45:32 -08:00
2010-03-06 11:26:24 -08:00
2009-12-16 19:48:48 -05:00
2010-03-04 12:07:50 +02:00
2010-03-04 12:09:43 +02:00
2010-02-12 09:42:38 -08:00
2010-03-01 17:59:24 -08:00
2009-09-22 07:17:35 -07:00
2010-03-06 11:26:25 -08:00
2010-03-06 11:26:24 -08:00
2010-01-13 16:09:33 -08:00
2010-01-16 12:15:40 -08:00
2010-02-02 12:50:47 -08:00
2010-03-06 11:26:25 -08:00
2010-03-06 11:26:25 -08:00