Back to index

numactl  2.0.8~rc4
migratepages.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005 Christoph Lameter, Silicon Graphics, Incorporated.
00003  * based on Andi Kleen's numactl.c.
00004  *
00005  * Manual process migration
00006  *
00007  * migratepages is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public
00009  * License as published by the Free Software Foundation; version 2.
00010  *
00011  * migratepages is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  *
00016  * You should find a copy of v2 of the GNU General Public License somewhere
00017  * on your Linux system; if not, write to the Free Software Foundation,
00018  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019  */
00020 
00021 #define _GNU_SOURCE
00022 #include <getopt.h>
00023 #include <errno.h>
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027 #include <unistd.h>
00028 #include <stdarg.h>
00029 #include "numa.h"
00030 #include "numaif.h"
00031 #include "numaint.h"
00032 #include "util.h"
00033 
00034 struct option opts[] = {
00035        {"help", 0, 0, 'h' },
00036        { 0 }
00037 };
00038 
00039 void usage(void)
00040 {
00041        fprintf(stderr,
00042               "usage: migratepages pid from-nodes to-nodes\n"
00043               "\n"
00044               "nodes is a comma delimited list of node numbers or A-B ranges or all.\n"
00045 );
00046        exit(1);
00047 }
00048 
00049 void checknuma(void)
00050 {
00051        static int numa = -1;
00052        if (numa < 0) {
00053               if (numa_available() < 0)
00054                      complain("This system does not support NUMA functionality");
00055        }
00056        numa = 0;
00057 }
00058 
00059 int main(int argc, char *argv[])
00060 {
00061        int c;
00062        char *end;
00063        int rc;
00064        int pid;
00065        struct bitmask *fromnodes;
00066        struct bitmask *tonodes;
00067 
00068        while ((c = getopt_long(argc,argv,"h", opts, NULL)) != -1) {
00069               switch (c) {
00070               default:
00071                      usage();
00072               }
00073        }
00074 
00075        argv += optind;
00076        argc -= optind;
00077 
00078        if (argc != 3)
00079               usage();
00080 
00081        checknuma();
00082 
00083        pid = strtoul(argv[0], &end, 0);
00084        if (*end || end == argv[0])
00085               usage();
00086 
00087        fromnodes = numa_parse_nodestring(argv[1]);
00088        if (!fromnodes) {
00089               printf ("<%s> is invalid\n", argv[1]);
00090               exit(1);
00091        }
00092        tonodes = numa_parse_nodestring(argv[2]);
00093        if (!tonodes) {
00094               printf ("<%s> is invalid\n", argv[2]);
00095               exit(1);
00096        }
00097 
00098        rc = numa_migrate_pages(pid, fromnodes, tonodes);
00099 
00100        if (rc < 0) {
00101               perror("migrate_pages");
00102               return 1;
00103        }
00104        return 0;
00105 }