Fix GFP_THISNODE behavior for memoryless nodes GFP_THISNODE checks that the zone selected is within the pgdat (node) of the first zone of a nodelist. That only works if the node has memory. A memoryless node will have its first zone on another pgdat (node). Thus GFP_THISNODE may be returning memory on other nodes. GFP_THISNODE should fail if there is no local memory on a node. So we add a check to verify that the node specified has memory in alloc_pages_node(). If the node has no memory then return NULL. The case of alloc_pages(GFP_THISNODE) is not changed. alloc_pages() (with no memory policies in effect) is understood to prefer the current node. If a process is running on a node with no memory then its default allocations come from the next neighboring node. GFP_THISNODE will then force the memory to come from that node. Signed-off-by: Christoph Lameter Signed-off-by: Nishanth Aravamudan Index: linux-2.6.22-rc4-mm2/include/linux/gfp.h =================================================================== --- linux-2.6.22-rc4-mm2.orig/include/linux/gfp.h 2007-06-12 12:33:37.000000000 -0700 +++ linux-2.6.22-rc4-mm2/include/linux/gfp.h 2007-06-12 12:38:37.000000000 -0700 @@ -175,6 +175,13 @@ static inline struct page *alloc_pages_n if (nid < 0) nid = numa_node_id(); + /* + * Check for the special case that GFP_THISNODE is used on a + * memoryless node + */ + if ((gfp_mask & __GFP_THISNODE) && !node_memory(nid)) + return NULL; + return __alloc_pages(gfp_mask, order, NODE_DATA(nid)->node_zonelists + gfp_zone(gfp_mask)); }