From patchwork Sun Dec 1 01:57:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 11268445 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 E0E6217F0 for ; Sun, 1 Dec 2019 01:57:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AE21720873 for ; Sun, 1 Dec 2019 01:57:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="jOOcWklY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE21720873 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9EDB56B036C; Sat, 30 Nov 2019 20:57:14 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 99DC16B036E; Sat, 30 Nov 2019 20:57:14 -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 88DD46B036F; Sat, 30 Nov 2019 20:57:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0248.hostedemail.com [216.40.44.248]) by kanga.kvack.org (Postfix) with ESMTP id 6A93F6B036C for ; Sat, 30 Nov 2019 20:57:14 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 190D82C0C for ; Sun, 1 Dec 2019 01:57:14 +0000 (UTC) X-FDA: 76214909988.18.verse70_3f21308c3d228 X-Spam-Summary: 2,0,0,c215b60682a148e4,d41d8cd98f00b204,akpm@linux-foundation.org,:akpm@linux-foundation.org::mgorman@techsingularity.net:mhocko@suse.com:mm-commits@vger.kernel.org:torvalds@linux-foundation.org:vbabka@suse.cz:yang.shi@linux.alibaba.com,RULES_HIT:41:355:379:800:960:965:966:967:973:988:989:1260:1263:1345:1381:1431:1437:1534:1542:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2525:2559:2563:2682:2685:2693:2859:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:4390:4395:5007:6261:6653:7576:7903:8957:9025:9121:9545:9592:10004:10913:11026:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12783:12986:14096:14181:14721:14849:21060:21080:21433:21451:21627:21819:21939:30012:30054,0,RBL:error,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:3,LUA_SUM MARY:non X-HE-Tag: verse70_3f21308c3d228 X-Filterd-Recvd-Size: 3403 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Sun, 1 Dec 2019 01:57:13 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (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 D54D0217AB; Sun, 1 Dec 2019 01:57:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575165433; bh=/2rtnSvaqSIdsqgtXHziAl7RiYz6VlgkUwR9UcaBHYE=; h=Date:From:To:Subject:From; b=jOOcWklY9gIsFgepSNSYsQ8HUZrOpl0+ETnaXrzCH20ajpSA916iYcXWMwXbf85VX Bfd0AdeyqmGgCmil7KQ+XWKEZh7r/vJdRNVWamztnrT9ySOjIcxXcVzrLlb75PGI8h ERVlGpZRqEWqwaWsOHO6rUMuAqgJdB6CGugOPgNg= Date: Sat, 30 Nov 2019 17:57:12 -0800 From: akpm@linux-foundation.org To: akpm@linux-foundation.org, linux-mm@kvack.org, mgorman@techsingularity.net, mhocko@suse.com, mm-commits@vger.kernel.org, torvalds@linux-foundation.org, vbabka@suse.cz, yang.shi@linux.alibaba.com Subject: [patch 134/158] mm/migrate.c: handle freed page at the first place Message-ID: <20191201015712.oGwSkH_BM%akpm@linux-foundation.org> User-Agent: s-nail v14.8.16 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: Yang Shi Subject: mm/migrate.c: handle freed page at the first place 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 allocates target page unconditionally before handling freed page, if the page is freed, the newly allocated will be just freed. It doesn't make too much sense and is just a waste of time although migrating freed page is rare. So, handle freed page at the before that to avoid unnecessary page allocation and free. Link: http://lkml.kernel.org/r/1573755869-106954-1-git-send-email-yang.shi@linux.alibaba.com Signed-off-by: Yang Shi Acked-by: Michal Hocko Reviewed-by: Andrew Morton Cc: Mel Gorman Cc: Vlastimil Babka Signed-off-by: Andrew Morton --- mm/migrate.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) --- a/mm/migrate.c~mm-migrate-handle-freed-page-at-the-first-place +++ a/mm/migrate.c @@ -1168,15 +1168,11 @@ static ICE_noinline int unmap_and_move(n enum migrate_reason reason) { int rc = MIGRATEPAGE_SUCCESS; - struct page *newpage; + struct page *newpage = NULL; 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 +1183,13 @@ static ICE_noinline int unmap_and_move(n __ClearPageIsolated(page); unlock_page(page); } - if (put_new_page) - put_new_page(newpage, private); - else - put_page(newpage); goto out; } + 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);