From patchwork Fri Oct 30 18:38:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 11870543 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5132E61C for ; Fri, 30 Oct 2020 18:38:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E761A206FA for ; Fri, 30 Oct 2020 18:38:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="WL7U4SG3"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PFdhSCBI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E761A206FA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=sent.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D5C8B6B0062; Fri, 30 Oct 2020 14:38:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CBA676B006C; Fri, 30 Oct 2020 14:38:18 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA9C16B006E; Fri, 30 Oct 2020 14:38:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id 880426B0062 for ; Fri, 30 Oct 2020 14:38:18 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2DA4A3623 for ; Fri, 30 Oct 2020 18:38:18 +0000 (UTC) X-FDA: 77429451876.24.wish70_400d4aa27298 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 1129E1A4A0 for ; Fri, 30 Oct 2020 18:38:18 +0000 (UTC) X-Spam-Summary: 1,0,0,2fb092cfab5294f9,d41d8cd98f00b204,zi.yan@sent.com,,RULES_HIT:41:152:355:379:421:541:800:960:968:973:988:989:1260:1261:1277:1311:1313:1314:1345:1437:1513:1515:1516:1518:1521:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:4117:4250:4321:5007:6117:6119:6261:6630:6653:7514:7576:10004:10400:11026:11473:11658:11914:12043:12294:12296:12438:12555:12679:12895:12986:13161:13229:13255:14096:14097:14181:14394:14659:14721:21060:21080:21451:21627:30034:30054:30064:30070,0,RBL:66.111.4.26:@sent.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04ygpxg561dwwh9xyg64du9by4ebwyppm7zeet6j4imnd7yopzbgoqiz634rab4.inxnwwh5o4rycaedid9pnxsp49zpxdbfkxcoe65iq8qbx38f51mjtszs8wto8e9.o-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:428,LUA_SUMMARY:none X-HE-Tag: wish70_400d4aa27298 X-Filterd-Recvd-Size: 6531 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 18:38:16 +0000 (UTC) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id B3DF25C01B0; Fri, 30 Oct 2020 14:38:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 30 Oct 2020 14:38:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=from :to:cc:subject:date:message-id:reply-to:mime-version :content-type:content-transfer-encoding; s=fm1; bh=WHa0SDu+o/Klm eJ7jdg6c0+1vR3M09ykjvWEYKJShPk=; b=WL7U4SG3EyfKXayCNo3Wc90uaP7yR ex/cFhD399XwftJhR13NsWFiLKA28wwbzRPGShPoNFk9l3e+jkx8wMPtTOl4rapV xL1a3P/VLC0+03aFdBaHU9OsYGcjytJj1Ws9G5zEuDv/Cb/FuuWF/DKQJMI6s64/ utb4B39d7Q4apl+gux/EJy3tv9j/+M23UoZ1ztLLA3BC29K4o3BPa/I9+otoi8fu OOurMM/reUMSXotBaZcGgLa6Nw0SgIPCXbXPaFuPQJ3VEZdze7JYSEa660ODuz2C O8f4b9KKD5Lw9ZK5tOMjVUDVra1jtp7v29N6MVAMNSmxBZYqppYu8K0LQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:message-id:mime-version:reply-to:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=WHa0SDu+o/KlmeJ7jdg6c0+1vR3M09ykjvWEYKJShPk=; b=PFdhSCBI czjbLSxl1+LquOZu4uQ4k7uTfrDtBwAmoiRwmJ+rUnyB/hz1uCW559BZMWjKJz6u G0repYGim34yzi+aMrcsXr4vvtJDSEK/W2ft23A4v6BcEZ/tPwf4j0DpbwUzkZj2 s90gWU19OWAgrk3ESqR6GwISf6mXOqayecSU+ueC6g2HFU+Xu4LrSGBuntJ0sgM/ uIu9ez7YhgwNrkReyKTR+4ZmlSZOZOUmRXyJfyC9Sb8LipnUluB4cD/t4vHbBfkY 8ZUuACXgc5/9SI+gMhVRNFMT2tCF6sWH36a2artw0eQG1P3ERR3vNyM2bSZWoOit RQMRCtjqdlzOEg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleehgdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkfforhggtgfgsehtqhertdertdejnecuhfhrohhmpegkihcujggr nhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeduveelff ehudduvdfhtddvheefkeejtdelieefhfegheejtedvtefhfedvkeekleenucfkphepuddv rdegiedruddtiedrudeigeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpeiiihdrhigrnhesshgvnhhtrdgtohhm X-ME-Proxy: Received: from nvrsysarch6.NVidia.COM (unknown [12.46.106.164]) by mail.messagingengine.com (Postfix) with ESMTPA id F0D153280059; Fri, 30 Oct 2020 14:38:12 -0400 (EDT) From: Zi Yan To: Andrew Morton , linux-mm@kvack.org Cc: Yang Shi , Michal Hocko , Vlastimil Babka , Rik van Riel , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Zi Yan Subject: [PATCH v3 1/2] mm/compaction: count pages and stop correctly during page isolation. Date: Fri, 30 Oct 2020 14:38:08 -0400 Message-Id: <20201030183809.3616803-1-zi.yan@sent.com> X-Mailer: git-send-email 2.28.0 Reply-To: Zi Yan MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Zi Yan In isolate_migratepages_block, when cc->alloc_contig is true, we are able to isolate compound pages, nr_migratepages and nr_isolated did not count compound pages correctly, causing us to isolate more pages than we thought. 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. Fixes: 1da2f328fa64 (“mm,thp,compaction,cma: allow THP migration for CMA allocations”) Signed-off-by: Zi Yan Reviewed-by: Yang Shi Cc: Acked-by: Vlastimil Babka --- mm/compaction.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index ee1f8439369e..3e834ac402f1 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1012,8 +1012,8 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, 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 @@ -1021,7 +1021,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, * 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; @@ -1132,7 +1132,7 @@ isolate_migratepages_range(struct compact_control *cc, unsigned long start_pfn, if (!pfn) break; - if (cc->nr_migratepages == COMPACT_CLUSTER_MAX) + if (cc->nr_migratepages >= COMPACT_CLUSTER_MAX) break; }