From patchwork Fri Oct 30 15:57:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 11870187 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 6077B1130 for ; Fri, 30 Oct 2020 15:57:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 03D0D20A8B for ; Fri, 30 Oct 2020 15:57:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="ELu5vcLm"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kcys9TqQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03D0D20A8B 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 615A66B0075; Fri, 30 Oct 2020 11:57:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 425CA6B007E; Fri, 30 Oct 2020 11:57:33 -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 202D46B007B; Fri, 30 Oct 2020 11:57:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DEB9C6B0075 for ; Fri, 30 Oct 2020 11:57:32 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 648E2181AEF15 for ; Fri, 30 Oct 2020 15:57:32 +0000 (UTC) X-FDA: 77429046744.25.steel25_320b69327297 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 3D13B1804E3A0 for ; Fri, 30 Oct 2020 15:57:32 +0000 (UTC) X-Spam-Summary: 1,0,0,82cabbf831d5b6a1,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:30054:30064:30070,0,RBL:66.111.4.25:@sent.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yr5ciqariiuyrzgothppgkob5f4oppm7zeet6j4imnd7yopzbgoqiz634rab4.inxnwws9rx9mdrgmid9pnxsp49zpxdbfkxcbpu9nhjfh6pagmngj5e8s8wto8e9.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:160,LUA_SUMMARY:none X-HE-Tag: steel25_320b69327297 X-Filterd-Recvd-Size: 6498 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 15:57:31 +0000 (UTC) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 2BD295C02E4; Fri, 30 Oct 2020 11:57:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 30 Oct 2020 11:57:31 -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=GgFywE3sedM8p RqGb2GCUrt5KozSDzUlHAh3jMIZlYc=; b=ELu5vcLmJCPbE1orsyqdaspWVSIsY 5oksyRCGM576vzsq89hLCxIBtbLPiCCrpDaFw83NsKi3/IznqGNNbiqhpTwgQhK+ Ufls4ptpwl56aGFMNH6Df/oT3Wu+08VrHoUK+yqU72y2JeCEzoNkETULRfqFXcx3 6oCb2Asj+gmC+Y2ZZCEJtz7EXKo1eNDHHRwHn7pGhXWCxaGQE+ZD1hoG7Ju8pSvM CyYf+VwStncPVVlBqmQ7GGbCb7yAEuyid1JVD9faaPMlLpPcD4tarWsAl95+voEw 4sC0+/7hjoGctlNjU0tAZLv0Mzuo0WVb3UpYE4xYxvdHSwxv+tQslMSYg== 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=GgFywE3sedM8pRqGb2GCUrt5KozSDzUlHAh3jMIZlYc=; b=kcys9TqQ hx/6X5aclY41cAAm2+CfJLf318GOtMzVEb/zdTO0t/7En4msj8YMVxEWK5DtkKo0 p0sc/FfWfrwEvsGTXVK2R/zZhZ261K7d6pSKPJTw+H3V91x4fJxDxfo4ITgtejc7 J1vhAC2//JgIyKVxNowH5HCr2Ta1qo1s7GXVQyP+VSohKjuJryAdbiFbLaMHwEAI 9TjVqDghhW/QbkkhhJDsjd9mCJNsogaj5/ztJJR2BDoM5AsJH0QxdA03I500RqdX a4p8c2+VD+GQ1qixZkJ8OgaL9+hXQqkh4G9KUtXdLe2xaZ5MBInP2/P43rRZn6ng +KASUSrMSm1fuA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleehgdejkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofhrgggtgfesthhqredtredtjeenucfhrhhomhepkghiucgjrghn uceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepudevleffhe duuddvhfdtvdehfeekjedtleeifefhgeehjeetvdethfefvdekkeelnecukfhppeduvddr geeirddutdeirdduieegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepiihirdihrghnsehsvghnthdrtghomh X-ME-Proxy: Received: from nvrsysarch6.NVidia.COM (unknown [12.46.106.164]) by mail.messagingengine.com (Postfix) with ESMTPA id 0B8B8328005E; Fri, 30 Oct 2020 11:57:30 -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 v2 1/2] mm/compaction: count pages and stop correctly during page isolation. Date: Fri, 30 Oct 2020 11:57:15 -0400 Message-Id: <20201030155716.3614401-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. Use thp_nr_pages to count pages. 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: --- 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; } From patchwork Fri Oct 30 15:57:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 11870185 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 9F853139F for ; Fri, 30 Oct 2020 15:57:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4CDBB221EB for ; Fri, 30 Oct 2020 15:57:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="CM6maBmx"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XjsIw02X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4CDBB221EB 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 33D456B0073; Fri, 30 Oct 2020 11:57:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2ED156B0075; Fri, 30 Oct 2020 11:57:33 -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 18D906B007D; Fri, 30 Oct 2020 11:57:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id DDE916B0073 for ; Fri, 30 Oct 2020 11:57:32 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5F03C181AEF10 for ; Fri, 30 Oct 2020 15:57:32 +0000 (UTC) X-FDA: 77429046744.14.sleep80_1f1711727297 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 4076B18229835 for ; Fri, 30 Oct 2020 15:57:32 +0000 (UTC) X-Spam-Summary: 1,0,0,9202762cfc0c3400,d41d8cd98f00b204,zi.yan@sent.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1437:1513:1515:1516:1518:1521:1534:1541:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:3138:3139:3140:3141:3142:3352:3867:3868:3870:3871:4250:4321:5007:6119:6261:6653:7576:7903:10004:10400:10471:11026:11658:11914:12043:12294:12296:12438:12555:12679:12895:12986:13069:13255:13311:13357:14096:14097:14181:14394:14659:14721:21080:21451:21627:21990:30054:30064,0,RBL:66.111.4.25:@sent.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yr5xaf93psa93o5hg1r99hgxgwzyp3xt7xissh76f68mbru11t6giou15e1ke.8e6ni3z5iikgfn57rrjfo6ehdmcwehr46bo7myhjssgkffcwxm48c5rn4ucqwc9.h-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:143,LUA_SUMMARY:none X-HE-Tag: sleep80_1f1711727297 X-Filterd-Recvd-Size: 4929 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Fri, 30 Oct 2020 15:57:31 +0000 (UTC) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 2AEAA5C02E3; Fri, 30 Oct 2020 11:57:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 30 Oct 2020 11:57:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=from :to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-type:content-transfer-encoding; s=fm1; bh= a+yV5AyyQgbkAmuRGp5Grqx+CnaA6i6TKDg6E8EnuoM=; b=CM6maBmxba6MD3gN Qh3zw0M8Aodzykt7peGyp7k/hIrMRoSl4FyRsvoZgLc5iOjVDs05mgSwWSVB3RnU FHLvhGZ8QPztxZ3oWCaeIpOZPWPEHEsTHeoYk7tHY4TDF3x0XLxMUFQ2cULSYdxz on7zYvowgLYsDo6wTr3SOIKJr+0V55ya+/HxrINLLieVhkKQGEyoe3n8LemVQ3ck k76+b5mmNeYjebN9Ef6Y3sbpPgmfzDS+HiARnQnY91NWj+SduiWXEHrPsUhkVowJ so/Sxk7BtDDyHw4qi7yUjut9k5Ymb7QEhiAgjkTB5FJfFuprNPqOCAG2KQigidNZ 0qgWvw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :reply-to:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=a+yV5AyyQgbkAmuRGp5Grqx+CnaA6 i6TKDg6E8EnuoM=; b=XjsIw02X52kdwL2SI7AqkUZsB2TNMfkrvT1ZSucW8u4vP 9PKkglNpAMYJOAWnOHqUCdcHxxIYY/67DCcN3Xjpy3T35LjkN2B4z+RxS+q/C0uo +6gds5HWz1ZooDha+wUdpT/VHGI+I2LeXv+blBPL10LsEnh4Dg/+PH52HPiallui xg0D+IkHHQVbLjlS1NoldygtcJvt0pqRKpAUX8pcmCetyDlWmraPrdHsvizrrbLH DvmXnX/Z9QZtPIqoxJ7goL93hTaTSsjYilQBwYBer0J95f1B/HSDJy0Np470chnU 1SLnleKf+vrEmVlYAZwJcHLRc+1CgOZ9rYaYmgsUw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrleehgdejkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhhrgggtgfesthhqredtredtjeenucfhrhhomhepkghiucgj rghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepkefggf eljeefgeejtdethfehvdfgffdvfeefkeejtefghfetvdduffekgeeltedtnecukfhppedu vddrgeeirddutdeirdduieegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepiihirdihrghnsehsvghnthdrtghomh X-ME-Proxy: Received: from nvrsysarch6.NVidia.COM (unknown [12.46.106.164]) by mail.messagingengine.com (Postfix) with ESMTPA id 45A85328005D; Fri, 30 Oct 2020 11:57:30 -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 v2 2/2] mm/compaction: stop isolation if too many pages are isolated and we have pages to migrate. Date: Fri, 30 Oct 2020 11:57:16 -0400 Message-Id: <20201030155716.3614401-2-zi.yan@sent.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201030155716.3614401-1-zi.yan@sent.com> References: <20201030155716.3614401-1-zi.yan@sent.com> 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, if we have too many isolated pages and nr_migratepages is not zero, we should try to migrate what we have without wasting time on isolating. Fixes: 1da2f328fa64 (“mm,thp,compaction,cma: allow THP migration for CMA allocations”) Suggested-by: Vlastimil Babka Signed-off-by: Zi Yan Cc: --- mm/compaction.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 3e834ac402f1..4d237a7c3830 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -817,6 +817,10 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, * delay for some time until fewer pages are isolated */ while (unlikely(too_many_isolated(pgdat))) { + /* stop isolation if there are still pages not migrated */ + if (cc->nr_migratepages) + return 0; + /* async migration should just abort */ if (cc->mode == MIGRATE_ASYNC) return 0;