From patchwork Mon Nov 11 22:09:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11237933 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 0DF1613BD for ; Mon, 11 Nov 2019 22:09:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CE1FE2173B for ; Mon, 11 Nov 2019 22:09:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE1FE2173B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 01B486B0005; Mon, 11 Nov 2019 17:09:36 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F0DFC6B0006; Mon, 11 Nov 2019 17:09:35 -0500 (EST) 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 E4AD56B0007; Mon, 11 Nov 2019 17:09:35 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0039.hostedemail.com [216.40.44.39]) by kanga.kvack.org (Postfix) with ESMTP id CF4196B0005 for ; Mon, 11 Nov 2019 17:09:35 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 79BD6180AD81A for ; Mon, 11 Nov 2019 22:09:35 +0000 (UTC) X-FDA: 76145389110.09.jewel37_196ff810f064c X-Spam-Summary: 2,0,0,5d91a3187ad8db0b,d41d8cd98f00b204,yang.shi@linux.alibaba.com,:mhocko@suse.com:mgorman@techsingularity.net:vbabka@suse.cz:akpm@linux-foundation.org:yang.shi@linux.alibaba.com::linux-kernel@vger.kernel.org,RULES_HIT:41:69:355:379:541:800:960:965:966:973:988:989:1260:1261:1345:1437:1534:1542:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2553:2559:2562:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3871:3872:4250:4321:4385:4390:4395:5007:6119:6261:7903:8957:9592:10004:11026:11658:11914:12043:12048:12296:12297:12438:12555:12895:12986:13053:14096:14181:14394:14721:21060:21067:21080:21451:21627:30012:30054:30090,0,RBL:115.124.30.45:@linux.alibaba.com:.lbl8.mailshell.net-62.20.2.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: jewel37_196ff810f064c X-Filterd-Recvd-Size: 3341 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Mon, 11 Nov 2019 22:09:34 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R831e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07417;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0Thpy97A_1573510165; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0Thpy97A_1573510165) by smtp.aliyun-inc.com(127.0.0.1); Tue, 12 Nov 2019 06:09:31 +0800 From: Yang Shi To: mhocko@suse.com, mgorman@techsingularity.net, vbabka@suse.cz, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: migrate: handle freed page at the first place Date: Tue, 12 Nov 2019 06:09:25 +0800 Message-Id: <1573510165-113395-1-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 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: When doing migration if the freed page is met, we just return without migrating it since it is pointless to migrate a freed page. But, the current code did two things before handling freed page: 1. Return -ENOMEM if the page is THP and THP migration is not supported. 2. Allocate target page unconditionally. Both makes not too much sense. If we handle freed page at the first place we don't have to worry about allocating/freeing target page and split THP at all. For example (worst case) if we are trying to migrate a freed THP without THP migration supported, the migrate_pages() would just split the THP then retry to migrate base pages one by one by pointless allocating and freeing pages, this is just waste of time. I didn't run into any actual problem with the current code (or I may just not notice it yet), it was found by visual inspection. Cc: Michal Hocko Cc: Mel Gorman Cc: Vlastimil Babka Signed-off-by: Yang Shi --- mm/migrate.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 4fe45d1..ef96997 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1170,13 +1170,6 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page, int rc = MIGRATEPAGE_SUCCESS; struct page *newpage; - if (!thp_migration_supported() && PageTransHuge(page)) - return -ENOMEM; - - newpage = get_new_page(page, private); - if (!newpage) - return -ENOMEM; - if (page_count(page) == 1) { /* page was freed from under us. So we are done. */ ClearPageActive(page); @@ -1187,13 +1180,16 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page, __ClearPageIsolated(page); unlock_page(page); } - if (put_new_page) - put_new_page(newpage, private); - else - put_page(newpage); goto out; } + if (!thp_migration_supported() && PageTransHuge(page)) + return -ENOMEM; + + newpage = get_new_page(page, private); + if (!newpage) + return -ENOMEM; + rc = __unmap_and_move(page, newpage, force, mode); if (rc == MIGRATEPAGE_SUCCESS) set_page_owner_migrate_reason(newpage, reason);