[rh7] mm/page_alloc: fix allocation failure of zone-restricted allocation

Submitted by Andrey Ryabinin on March 27, 2019, 3:17 p.m.


Message ID 20190327151750.23415-1-aryabinin@virtuozzo.com
State New
Series "mm/page_alloc: fix allocation failure of zone-restricted allocation"
Headers show

Commit Message

Andrey Ryabinin March 27, 2019, 3:17 p.m.
The following command sequence fails:
	mkdir -p /sys/fs/cgroup/cpuset/test
	echo 1 >  /sys/fs/cgroup/cpuset/test/cpuset.mems
	echo 1 >  /sys/fs/cgroup/cpuset/test/cpuset.cpus
	echo $$ > /sys/fs/cgroup/cpuset/test/tasks
	/usr/libexec/qemu-kvm -enable-kvm
	kvm_init_vcpu failed: Cannot allocate memory

kvm_init_vcpu() calls KVM_CREATE_VCPU ioctl() which fails with
ENOMEM because it calls __alloc_page(GFP_KERNEL|__GFP_DMA32)
and DMA32 zone present only on NUMA node 0 while process is bound
to the 1 NUMA node. However such allocation should fail, because
there is no __GFP_HARDWALL flag, thus it allowed to fallback
to the 0 NUMA node.

Allocation fails because on the fast-path we try to find zone
withing cpuset_current_mems_allowed nodemask and don't fallback
to default nodemask if zone not found.

Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
 mm/page_alloc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Patch hide | download patch | download mbox

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 5dc48331242a..45da030d8da2 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3576,6 +3576,14 @@  __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
 	first_zones_zonelist(zonelist, high_zoneidx,
 				nodemask ? : &cpuset_current_mems_allowed,
+	/*
+	 * No zone within cpuset_current_mems_allowed nodemask?
+	 * Fallback to default nodemask.
+	 */
+	if (!preferred_zone && !nodemask)
+		first_zones_zonelist(zonelist, high_zoneidx,
+				nodemask, &preferred_zone);
 	if (!preferred_zone)
 		goto out;