Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3865651pxb; Tue, 17 Nov 2020 05:44:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjWrvCnrq4q7kn5EiOzfwQGdKE5zqBdO+I2N80Xx9hMJXeL78OmWJDo/wQCjGs1S91WNK7 X-Received: by 2002:a17:906:26c7:: with SMTP id u7mr19722315ejc.494.1605620648685; Tue, 17 Nov 2020 05:44:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605620648; cv=none; d=google.com; s=arc-20160816; b=DYpcx4aRHSP/OmizYfNpyIY21FJ3OxnxKjW/8taHI2dqKslP3CkajzVvPamxU8U99v +ur4DizCGftNXFL8QOrTNq9zpaAq7lm/a8R1V5h75elwaV8fWjmHj51arKBD766Z/R6g Cn8WoGrYo3IolQ1o/IfY1xKIyQD0W9950iNO0YMB/XNZU8982PhMdvkzSyx3to6/JiIB rqY2WMPUuNY3fZ91PxhtH0lvDcGMRRPDuIUA0CWpjyhcw8XJnf1RpnvUFCc7u7nhvg4p X5FXS5DbGmBDPYMEZkxzYIF1KZt8dj4147a/jF3FXNUSf75peML4YxUHFxXaqyQnwPxg kI0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Pad2U6f8GiHKBIhkVPLzReFl6DRJ7i29I09jSOi2DSQ=; b=rSDEyYGZXPUaNBBToI6y4n7XViOO22iG/MsB5UwG7apsrmiy+sUxwh1ehKT1IYe7qq mqMrVMvq4jXEFrf2qUQ8rEIdn3hYZ+js9FcpZgHLBg5pHGqF+7dPb3HvhhzXZqeeXMbh zxFOKPOW6pVxKQm2tFUg3rU5TpzBoNWiB4gFEmbpTY/o6NUVxFcBjHLo0k+pziCqumHE BNvyU0JU3NLjQBjyi7QKjk5z9qa2oCpFzj0bj1hPSGlskPpcoGdiWjnz0EsuPA39lZIP YL845SeUHMhJqk2p59LyLhzpNviLxQS43X4F1lK1Xhm6mfrF5cE5xSlWRGM8hS4gL4mu 6P/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hpTZM7UH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u21si13806789ejb.17.2020.11.17.05.43.45; Tue, 17 Nov 2020 05:44:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hpTZM7UH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732851AbgKQNkU (ORCPT + 99 others); Tue, 17 Nov 2020 08:40:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:52024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732826AbgKQNkM (ORCPT ); Tue, 17 Nov 2020 08:40:12 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0A7B020870; Tue, 17 Nov 2020 13:40:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605620411; bh=E9Io8XLxHspcMQcCzOCAH/XkfAhwNHImE3ViluL+oiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hpTZM7UHNLSu19VGR4+DsiMtCkF2He6KDcKivOKCysyi7SSp+1u6N8LRgtMSoKoyi OU6e8F+xl1zkBpJrJ+Eyck5CQTSULQoAshkjDc0I9yNrxoamBVnRRBG4ktrzVwOQJr NqmvPYDj4tI6Tbs4wSRLitgysaowvd4eIrzWpL7s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zi Yan , Andrew Morton , Yang Shi , Vlastimil Babka , Rik van Riel , Michal Hocko , Mel Gorman , Linus Torvalds Subject: [PATCH 5.9 209/255] mm/compaction: count pages and stop correctly during page isolation Date: Tue, 17 Nov 2020 14:05:49 +0100 Message-Id: <20201117122149.104711341@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zi Yan commit 38935861d85a4d9a353d1dd5a156c97700e2765d upstream. In isolate_migratepages_block, when cc->alloc_contig is true, we are able to isolate compound pages. But nr_migratepages and nr_isolated did not count compound pages correctly, causing us to isolate more pages than we thought. So count compound pages as the number of base pages they contain. Otherwise, we might be trapped in too_many_isolated while loop, since the actual isolated pages can go up to COMPACT_CLUSTER_MAX*512=16384, where COMPACT_CLUSTER_MAX is 32, since we stop isolation after cc->nr_migratepages reaches to COMPACT_CLUSTER_MAX. In addition, after we fix the issue above, cc->nr_migratepages could never be equal to COMPACT_CLUSTER_MAX if compound pages are isolated, thus page isolation could not stop as we intended. Change the isolation stop condition to '>='. The issue can be triggered as follows: In a system with 16GB memory and an 8GB CMA region reserved by hugetlb_cma, if we first allocate 10GB THPs and mlock them (so some THPs are allocated in the CMA region and mlocked), reserving 6 1GB hugetlb pages via /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages will get stuck (looping in too_many_isolated function) until we kill either task. With the patch applied, oom will kill the application with 10GB THPs and let hugetlb page reservation finish. [ziy@nvidia.com: v3] Link: https://lkml.kernel.org/r/20201030183809.3616803-1-zi.yan@sent.com Fixes: 1da2f328fa64 ("cmm,thp,compaction,cma: allow THP migration for CMA allocations") Signed-off-by: Zi Yan Signed-off-by: Andrew Morton Reviewed-by: Yang Shi Acked-by: Vlastimil Babka Cc: Rik van Riel Cc: Michal Hocko Cc: Mel Gorman Cc: Link: https://lkml.kernel.org/r/20201029200435.3386066-1-zi.yan@sent.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/compaction.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1013,8 +1013,8 @@ isolate_migratepages_block(struct compac isolate_success: list_add(&page->lru, &cc->migratepages); - cc->nr_migratepages++; - nr_isolated++; + cc->nr_migratepages += compound_nr(page); + nr_isolated += compound_nr(page); /* * Avoid isolating too much unless this block is being @@ -1022,7 +1022,7 @@ isolate_success: * or a lock is contended. For contention, isolate quickly to * potentially remove one source of contention. */ - if (cc->nr_migratepages == COMPACT_CLUSTER_MAX && + if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX && !cc->rescan && !cc->contended) { ++low_pfn; break; @@ -1133,7 +1133,7 @@ isolate_migratepages_range(struct compac if (!pfn) break; - if (cc->nr_migratepages == COMPACT_CLUSTER_MAX) + if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX) break; }