From patchwork Tue Nov 3 13:03:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11885093 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 6D16E697 for ; Thu, 5 Nov 2020 20:53:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 19D6920719 for ; Thu, 5 Nov 2020 20:53:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nDFSc5E0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 19D6920719 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2AAEE6B0192; Thu, 5 Nov 2020 15:53:46 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 234B36B0193; Thu, 5 Nov 2020 15:53:46 -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 0ACAE6B0194; Thu, 5 Nov 2020 15:53:46 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0108.hostedemail.com [216.40.44.108]) by kanga.kvack.org (Postfix) with ESMTP id C63ED6B0192 for ; Thu, 5 Nov 2020 15:53:45 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 639E1180AD806 for ; Thu, 5 Nov 2020 20:53:45 +0000 (UTC) X-FDA: 77451566010.30.songs53_3e1627b272cc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 3EBF3180B3C8B for ; Thu, 5 Nov 2020 20:53:45 +0000 (UTC) X-Spam-Summary: 1,0,0,1a915c0e465e604f,d41d8cd98f00b204,shy828301@gmail.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1202:1260:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3872:3874:4250:4321:4385:5007:6119:6261:6653:7514:7903:7974:9413:10004:11026:11658:11914:12043:12048:12114:12296:12297:12438:12517:12519:12555:12895:12986:13069:13161:13229:13311:13357:13894:14096:14181:14384:14394:14687:14721:21060:21080:21325:21444:21451:21627:21666:21740:30003:30054,0,RBL:209.85.210.196:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yf11dgb1o6nhz7ou4kcopxuns7hoc58agbbtkrwxaicw9cu57f74r96dxah1h.4fiygb8wy8seg1oih7yyznc9qzypbofk7qycb5gxdb5geakkyiop5jhmx6fj7jo.r-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:68,LUA_SUMMARY:none X-HE-Tag: songs53_3e1627b272cc X-Filterd-Recvd-Size: 4791 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Nov 2020 20:53:44 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id 13so2288833pfy.4 for ; Thu, 05 Nov 2020 12:53:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QB12Dnq0Zqx+BHwKjUtFB3CjUxaGHX59xb2vUzz59zw=; b=nDFSc5E0ytVh5sWwE+6Z7ZN80uS6oRNCypDUlbFYAm77DAooRLVaQOVIh35SBU8tc/ DnRlZPcsuryFvi+aWJkcU4sMZO9UnOkDPh0Ju5YdzaxZOBOQs5IyT+m951zdA3Z6/8W7 rSEB5hRQGxQF8aRwKlBnixUhE5e2nKAdnGMlS2EZwOnxARgpVsA/cWXDKsz/l+QdTU1G VUNLndDxC9jB40ulu4gOTrRDJ33XYWuCCxCXl9haCnm45m5Tsx0lFaRu8zi9e4pOiGYY J2GesAbE5cLRq1osjCMJq/9aayz5A7lIMMXPoO9z6/ZuZtIeQeKKJuRSecjeR52570Ts o0bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QB12Dnq0Zqx+BHwKjUtFB3CjUxaGHX59xb2vUzz59zw=; b=KytE65dVLTxCHCiaMUMRZ1xDeCJcUDN9wdYd4viG+UhlvE5NtdSz7ny8QmyuHE1qF+ AsQtIBX1axljMgMgbtbWJDazQsXAy8NZ2/tZS37aUfjmYAUXBv4S9L7+1rKRkGzCA1iz GBj00XDEoL8GdvkPLVxPqvYKcI3OBCYuKejB3gjjLNv8+BEX1OZYigWxQLSGJhmRWQwz dEQy39pf7a59LxlsZar+I7IawpjUmTTqM7Ok9nofiBAlLxyVU3no0da8/NQaC3nt20qm W9U/um/iutuSbKcUpuyGnURJSKtqkI2vO0QCPO2Gqxp5mYhqsMzUSvMCpA2TRzpgj39o 6h5w== X-Gm-Message-State: AOAM531WrmdO6kNaN/q2dAzIXiQzjRAxxfgKXHI5JJx9/d4U52RUFAKT kY1c30MqPtN2Eb+H92rPjsU= X-Google-Smtp-Source: ABdhPJz40G2S/CGCQtwBbJtpMNoorkNydyinaIkS/Ezn6FTP4Z1u1hRFVNX+FpEDhrGeYK6RFe72sQ== X-Received: by 2002:a17:90a:a394:: with SMTP id x20mr4135807pjp.213.1604609623788; Thu, 05 Nov 2020 12:53:43 -0800 (PST) Received: from localhost.localdomain (c-107-3-138-210.hsd1.ca.comcast.net. [107.3.138.210]) by smtp.gmail.com with ESMTPSA id u22sm3265528pgf.24.2020.11.05.12.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 12:53:42 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] mm: truncate_complete_page is not existed anymore Date: Tue, 3 Nov 2020 05:03:30 -0800 Message-Id: <20201103130334.13468-2-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103130334.13468-1-shy828301@gmail.com> References: <20201103130334.13468-1-shy828301@gmail.com> 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: The commit 9f4e41f4717832e34cca153ced62b4a1d7e26c0e ("mm: refactor truncate_complete_page()") refactored truncate_complete_page(), and it is not existed anymore, correct the comment in vmscan and migrate to avoid confusion. Signed-off-by: Yang Shi Reviewed-by: Jan Kara --- mm/migrate.c | 2 +- mm/vmscan.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 5ca5842df5db..8a2e7e19e27b 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1106,7 +1106,7 @@ static int __unmap_and_move(struct page *page, struct page *newpage, * and treated as swapcache but it has no rmap yet. * Calling try_to_unmap() against a page->mapping==NULL page will * trigger a BUG. So handle it here. - * 2. An orphaned page (see truncate_complete_page) might have + * 2. An orphaned page (see truncate_cleanup_page) might have * fs-private metadata. The page can be picked up due to memory * offlining. Everywhere else except page reclaim, the page is * invisible to the vm, so the page can not be migrated. So try to diff --git a/mm/vmscan.c b/mm/vmscan.c index 1b8f0e059767..165cca87edc8 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1393,7 +1393,7 @@ static unsigned int shrink_page_list(struct list_head *page_list, * * Rarely, pages can have buffers and no ->mapping. These are * the pages which were not successfully invalidated in - * truncate_complete_page(). We try to drop those buffers here + * truncate_cleanup_page(). We try to drop those buffers here * and if that worked, and the page is no longer mapped into * process address space (page_count == 1) it can be freed. * Otherwise, leave the page on the LRU so it is swappable. From patchwork Tue Nov 3 13:03:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11885095 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 05E6714B4 for ; Thu, 5 Nov 2020 20:53:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8DA4420782 for ; Thu, 5 Nov 2020 20:53:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gaK5tfxo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8DA4420782 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 62EDB6B0194; Thu, 5 Nov 2020 15:53:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5C5DC6B0196; Thu, 5 Nov 2020 15:53:48 -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 394696B0197; Thu, 5 Nov 2020 15:53:48 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0089.hostedemail.com [216.40.44.89]) by kanga.kvack.org (Postfix) with ESMTP id 00D0A6B0194 for ; Thu, 5 Nov 2020 15:53:47 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 96FA58249980 for ; Thu, 5 Nov 2020 20:53:47 +0000 (UTC) X-FDA: 77451566094.12.shirt73_210b23d272cc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 773871801BE96 for ; Thu, 5 Nov 2020 20:53:47 +0000 (UTC) X-Spam-Summary: 1,0,0,1a64553b7eb92e2b,d41d8cd98f00b204,shy828301@gmail.com,,RULES_HIT:2:41:69:355:379:541:800:960:966:973:988:989:1202:1260:1311:1314:1345:1359:1437:1515:1535:1605:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:2899:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:4049:4120:4250:4385:4605:5007:6261:6653:7514:7903:8660:8957:9010:9121:9413:10004:11026:11473:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12683:12895:13148:13161:13172:13229:13230:13894:14096:14394:14687:21060:21080:21444:21450:21451:21627:21666:21796:21939:21987:21990:30012:30034:30036:30054:30069:30070:30091,0,RBL:209.85.215.193:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100;04yf5rdcj3nsn4oxrhpgpg1k8gzh5ycxmw518mamf9rkhfnixnw5son9cb9gdsy.fen7r88ubhd4wkqdbb6qb4d9hty8ztkdy4h3rmxwrof51s4g6yyz34bqph5coyo.q-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_ru les:0:0: X-HE-Tag: shirt73_210b23d272cc X-Filterd-Recvd-Size: 9165 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Nov 2020 20:53:46 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id r186so2204182pgr.0 for ; Thu, 05 Nov 2020 12:53:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jE4qSk2GuBQuLE3VKoSzbFTrSHhXqdRokaed5NT8Mes=; b=gaK5tfxoQSaRHHEbQMSlU8zj9YPCoi0uuimK2r5eJ7E4XnR07Ov3FH8IonVXyJdkCe v52OhSZKZom6zW8qiS10sZjo+wwutX1eZgMyfkEvFG2XdQC8EGkGJU9BkFuOsoS8Wiby /frtI43Ougmrq0bEyaMZwWv5YGk4kdAWEtoCwfQ1kS0nHu40ymqIK8Emhdz+sQ6GxgwD MnaClz+8XmCB9Qwq6M6uOF1nGux/OrJXch/pamebOBKnDbq7CtJNAZuj3J2hzedTr4AN KpmU1OyxwwNKmX2qbm2XLSnpfP3Gi0gEosHSFErb7jfhhxbI610KwLOBaJKIF+0UCzET 0jFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jE4qSk2GuBQuLE3VKoSzbFTrSHhXqdRokaed5NT8Mes=; b=av/wVGLbNlBfUFm3QdXSR19bOnvncBS5pffjfPzBRdw/MIKh4bLGYZEV0W+aSdE1sV GuVgF1gvJ8VszRHE2g2Y9XFmzpSiXAp4z4SnR2csdIplCaZfsMOk3gDGkxGhL6t9piHX aos/POzJcL0yvY5m/snZAmLpI9Zzh7HWHbxWxEYnKCgQ4AhGRtsqGk7tsS7SGejBr/Wj DBC8IvhGaWgwreu9OlcLzSAWOm45D9Fy2WVtQV0yYPY4CeVQK/Pelx4c0f0eKY65PvOP A2K8oIvfLZNZmQ84KHeeRQCStnP5yS6zGGJS3WnCJ3qT9bpiRFXgpSUGD8RDcFfBqRMY lT+A== X-Gm-Message-State: AOAM53043FFsvk/F8K8afkPxVcDYmSt7CxYlYEjvyU+G2x66PZMeJprA AdbPm9n+pregnhH4UA1uDmw= X-Google-Smtp-Source: ABdhPJx0XwY0IdRHx1Njn+CvjHuWeJssCSQR+wFpwv9Wevxik8A5BqkXfjTXCuOQhoZHB6wAvZNscw== X-Received: by 2002:a63:3c1b:: with SMTP id j27mr4077005pga.79.1604609626212; Thu, 05 Nov 2020 12:53:46 -0800 (PST) Received: from localhost.localdomain (c-107-3-138-210.hsd1.ca.comcast.net. [107.3.138.210]) by smtp.gmail.com with ESMTPSA id u22sm3265528pgf.24.2020.11.05.12.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 12:53:45 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] mm: migrate: simplify the logic for handling permanent failure Date: Tue, 3 Nov 2020 05:03:31 -0800 Message-Id: <20201103130334.13468-3-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103130334.13468-1-shy828301@gmail.com> References: <20201103130334.13468-1-shy828301@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When unmap_and_move{_huge_page}() returns !-EAGAIN and !MIGRATEPAGE_SUCCESS, the page would be put back to LRU or proper list if it is non-LRU movable page. But, the callers always call putback_movable_pages() to put the failed pages back later on, so it seems not very efficient to put every single page back immediately, and the code looks convoluted. Put the failed page on a separate list, then splice the list to migrate list when all pages are tried. It is the caller's responsibility to call putback_movable_pages() to handle failures. This also makes the code simpler and more readable. After the change the rules are: * Success: non hugetlb page will be freed, hugetlb page will be put back * -EAGAIN: stay on the from list * -ENOMEM: stay on the from list * Other errno: put on ret_pages list then splice to from list The from list would be empty iff all pages are migrated successfully, it was not so before. This has no impact to current existing callsites. Signed-off-by: Yang Shi --- mm/migrate.c | 58 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 8a2e7e19e27b..c33c92495ead 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1169,7 +1169,8 @@ static int unmap_and_move(new_page_t get_new_page, free_page_t put_new_page, unsigned long private, struct page *page, int force, enum migrate_mode mode, - enum migrate_reason reason) + enum migrate_reason reason, + struct list_head *ret) { int rc = MIGRATEPAGE_SUCCESS; struct page *newpage = NULL; @@ -1206,7 +1207,14 @@ static int unmap_and_move(new_page_t get_new_page, * migrated will have kept its references and be restored. */ list_del(&page->lru); + } + /* + * If migration is successful, releases reference grabbed during + * isolation. Otherwise, restore the page to right list unless + * we want to retry. + */ + if (rc == MIGRATEPAGE_SUCCESS) { /* * Compaction can migrate also non-LRU pages which are * not accounted to NR_ISOLATED_*. They can be recognized @@ -1215,35 +1223,16 @@ static int unmap_and_move(new_page_t get_new_page, if (likely(!__PageMovable(page))) mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + page_is_file_lru(page), -thp_nr_pages(page)); - } - /* - * If migration is successful, releases reference grabbed during - * isolation. Otherwise, restore the page to right list unless - * we want to retry. - */ - if (rc == MIGRATEPAGE_SUCCESS) { if (reason != MR_MEMORY_FAILURE) /* * We release the page in page_handle_poison. */ put_page(page); } else { - if (rc != -EAGAIN) { - if (likely(!__PageMovable(page))) { - putback_lru_page(page); - goto put_new; - } + if (rc != -EAGAIN) + list_add_tail(&page->lru, ret); - lock_page(page); - if (PageMovable(page)) - putback_movable_page(page); - else - __ClearPageIsolated(page); - unlock_page(page); - put_page(page); - } -put_new: if (put_new_page) put_new_page(newpage, private); else @@ -1274,7 +1263,8 @@ static int unmap_and_move(new_page_t get_new_page, static int unmap_and_move_huge_page(new_page_t get_new_page, free_page_t put_new_page, unsigned long private, struct page *hpage, int force, - enum migrate_mode mode, int reason) + enum migrate_mode mode, int reason, + struct list_head *ret) { int rc = -EAGAIN; int page_was_mapped = 0; @@ -1290,7 +1280,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, * kicking migration. */ if (!hugepage_migration_supported(page_hstate(hpage))) { - putback_active_hugepage(hpage); + list_move_tail(&hpage->lru, ret); return -ENOSYS; } @@ -1372,8 +1362,10 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, out_unlock: unlock_page(hpage); out: - if (rc != -EAGAIN) + if (rc == MIGRATEPAGE_SUCCESS) putback_active_hugepage(hpage); + else if (rc != -EAGAIN && rc != MIGRATEPAGE_SUCCESS) + list_move_tail(&hpage->lru, ret); /* * If migration was not successful and there's a freeing callback, use @@ -1404,8 +1396,8 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, * * The function returns after 10 attempts or if no pages are movable any more * because the list has become empty or no retryable pages exist any more. - * The caller should call putback_movable_pages() to return pages to the LRU - * or free list only if ret != 0. + * It is caller's responsibility to call putback_movable_pages() to return pages + * to the LRU or free list only if ret != 0. * * Returns the number of pages that were not migrated, or an error code. */ @@ -1426,6 +1418,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, struct page *page2; int swapwrite = current->flags & PF_SWAPWRITE; int rc, nr_subpages; + LIST_HEAD(ret_pages); if (!swapwrite) current->flags |= PF_SWAPWRITE; @@ -1448,11 +1441,12 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, if (PageHuge(page)) rc = unmap_and_move_huge_page(get_new_page, put_new_page, private, page, - pass > 2, mode, reason); + pass > 2, mode, reason, + &ret_pages); else rc = unmap_and_move(get_new_page, put_new_page, private, page, pass > 2, mode, - reason); + reason, &ret_pages); switch(rc) { case -ENOMEM: @@ -1519,6 +1513,12 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, nr_thp_failed += thp_retry; rc = nr_failed; out: + /* + * Put the permanent failure page back to migration list, they + * will be put back to the right list by the caller. + */ + list_splice(&ret_pages, from); + count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded); count_vm_events(PGMIGRATE_FAIL, nr_failed); count_vm_events(THP_MIGRATION_SUCCESS, nr_thp_succeeded); From patchwork Tue Nov 3 13:03:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11885097 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 26BC6697 for ; Thu, 5 Nov 2020 20:53:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B029020724 for ; Thu, 5 Nov 2020 20:53:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N04RTqwe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B029020724 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 67E336B0196; Thu, 5 Nov 2020 15:53:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 62CC36B0197; Thu, 5 Nov 2020 15:53:50 -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 4854C6B0198; Thu, 5 Nov 2020 15:53:50 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0074.hostedemail.com [216.40.44.74]) by kanga.kvack.org (Postfix) with ESMTP id 1588D6B0196 for ; Thu, 5 Nov 2020 15:53:50 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id AFE73180AD806 for ; Thu, 5 Nov 2020 20:53:49 +0000 (UTC) X-FDA: 77451566178.15.hole76_48122ee272cc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 88F151814B0C1 for ; Thu, 5 Nov 2020 20:53:49 +0000 (UTC) X-Spam-Summary: 1,0,0,3c31ed50dcd597fd,d41d8cd98f00b204,shy828301@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1202:1260:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3867:3870:3871:3874:4250:4321:4605:5007:6117:6120:6261:6653:7514:7901:8957:9413:10004:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12895:13069:13161:13229:13311:13357:13894:14096:14181:14384:14394:14687:14721:21060:21080:21444:21627:21666:21990:30003:30054,0,RBL:209.85.215.193:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100;04yfe96y89se14z5xhcjyk6qbr8a7oczeducy9pk9kweccos78byg8pismiozuz.njyczmjtg995eny3qxrr5rt1r8f6199c6uf4b3e5tes71pgwxb8ump99wofcthi.n-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:68,LUA_SUMMARY:none X-HE-Tag: hole76_48122ee272cc X-Filterd-Recvd-Size: 4924 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Nov 2020 20:53:49 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id h6so2188725pgk.4 for ; Thu, 05 Nov 2020 12:53:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/qtr9tzhjtOBdYsDnn5cndcKy8GoT20c7Eybegwt5Kk=; b=N04RTqweYUFrqnV9gmhke51hG75fIh7p4gQzA6MwJPqIaC2mKQ3CzsQEx5z/IzCjDz G4QkNnM1CeDqPXGZj4jywlCmDW5xVx5pMSVWwTLvQ+ZAcKxkQv9IifxUEDqB+bh6hQ3s PSTC4hO6cT2myU0l+PJTqeO9OED2FCBWf1yF5Jj9cZCvFzxUHPcqtdFwxyswwJLPmC2R 0P3Y/mVDtvDQrgA2g/rnAxnc9TKfeRmSrpuI0DC2peCMtkQk+9XI7N6fpAGKAD2gIBtk fhXl4UxagPZgmvJdhghG8XDXVhrSBIIXC6fcG4Xp4u6QGWT1bKsp8fJ56OobRzWwICvs r4gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/qtr9tzhjtOBdYsDnn5cndcKy8GoT20c7Eybegwt5Kk=; b=s7vechp8uxCk2peeZV+ZPP2XCfPl0KrQgSOEdpMJjPNA/bn0YBuZ0FbUDlFrQam04a Rubvf5Zagk7u+Bhu5/qCULy7Syf5dRN6WVwEele+fjofVUjqsQo5uELqAQh7JmsRn26q 9lYH8k/OPavd2t6RGC5a7odU+k6mV1H92nNYGBk8qbCNXJN/Mjr5POwPpIvL61IDzRpB 4DKgBw3afEsgnwXLkxwlKUGqWF1BqeBFdMlfSNRe/apmj6wH/p6THNPDVL1N0lpDcPiD SDtpRHNKfjyeZCZDrIPlHnVWrg3cOYSu8jOLJ1WlF8GEv9JwKGh79hfi6+M00C0642KZ yswA== X-Gm-Message-State: AOAM532vSSu8R/Xa8uM8VwALAV57XVaZ5xLYgHSVtsJbsAEqbWsq4zE0 o7jYChQUVk79cly2sjGBmQJgrwN0uosJlg== X-Google-Smtp-Source: ABdhPJyU8XB5H0ovDjvdw4jXwbLqGN5AhkJzXvc3653T26+Rg5FqPVlkgLslhxXhoXQoKSONpx8lxA== X-Received: by 2002:a63:4866:: with SMTP id x38mr3994157pgk.228.1604609628372; Thu, 05 Nov 2020 12:53:48 -0800 (PST) Received: from localhost.localdomain (c-107-3-138-210.hsd1.ca.comcast.net. [107.3.138.210]) by smtp.gmail.com with ESMTPSA id u22sm3265528pgf.24.2020.11.05.12.53.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 12:53:47 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] mm: migrate: skip shared exec THP for NUMA balancing Date: Tue, 3 Nov 2020 05:03:32 -0800 Message-Id: <20201103130334.13468-4-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103130334.13468-1-shy828301@gmail.com> References: <20201103130334.13468-1-shy828301@gmail.com> 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: The NUMA balancing skip shared exec base page. Since CONFIG_READ_ONLY_THP_FOR_FS was introduced, there are probably shared exec THP, so skip such THPs for NUMA balancing as well. Signed-off-by: Yang Shi --- mm/migrate.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index c33c92495ead..9a32bb128f31 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2061,6 +2061,16 @@ bool pmd_trans_migrating(pmd_t pmd) return PageLocked(page); } +static inline bool is_shared_exec_page(struct vm_area_struct *vma, + struct page *page) +{ + if (page_mapcount(page) != 1 && page_is_file_lru(page) && + (vma->vm_flags & VM_EXEC)) + return true; + + return false; +} + /* * Attempt to migrate a misplaced page to the specified destination * node. Caller is expected to have an elevated reference count on @@ -2078,8 +2088,7 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma, * Don't migrate file pages that are mapped in multiple processes * with execute permissions as they are probably shared libraries. */ - if (page_mapcount(page) != 1 && page_is_file_lru(page) && - (vma->vm_flags & VM_EXEC)) + if (is_shared_exec_page(vma, page)) goto out; /* @@ -2134,6 +2143,10 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm, int page_lru = page_is_file_lru(page); unsigned long start = address & HPAGE_PMD_MASK; + if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && + is_shared_exec_page(vma, page)) + goto out; + new_page = alloc_pages_node(node, (GFP_TRANSHUGE_LIGHT | __GFP_THISNODE), HPAGE_PMD_ORDER); @@ -2245,6 +2258,7 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm, out_unlock: unlock_page(page); +out: put_page(page); return 0; } From patchwork Tue Nov 3 13:03:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11885099 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 4BE36697 for ; Thu, 5 Nov 2020 20:53:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EFB9F20724 for ; Thu, 5 Nov 2020 20:53:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iTdqtA5C" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EFB9F20724 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9D6C46B019A; Thu, 5 Nov 2020 15:53:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 98BD06B019C; Thu, 5 Nov 2020 15:53:52 -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 7E1266B019B; Thu, 5 Nov 2020 15:53:52 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0075.hostedemail.com [216.40.44.75]) by kanga.kvack.org (Postfix) with ESMTP id 41D996B0197 for ; Thu, 5 Nov 2020 15:53:52 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C274D181AEF07 for ; Thu, 5 Nov 2020 20:53:51 +0000 (UTC) X-FDA: 77451566262.14.blade48_5e0d3ce272cc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id A1B9718229818 for ; Thu, 5 Nov 2020 20:53:51 +0000 (UTC) X-Spam-Summary: 1,0,0,4b1e580d4512a80c,d41d8cd98f00b204,shy828301@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1202:1260:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2553:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3871:3872:3874:4250:4321:4605:5007:6261:6653:7514:9413:9592:10004:11026:11473:11658:11914:12043:12048:12114:12296:12297:12438:12517:12519:12555:12895:12986:13161:13229:13894:14096:14181:14394:14687:14721:21060:21080:21444:21627:21666:21740:21990:30054:30070:30090,0,RBL:209.85.210.194:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100;04yf9ufgb3u1awokataxmisz3bb1xocwxzokux4m8pr6n5q5wkwyfanzyde16gc.s7qf4wx6txhss5i5bz15hn1ngn3arsi3tkhc93ktz71fzkjeotcit9wb5m3r83f.4-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:70,LUA_SUMMARY:none X-HE-Tag: blade48_5e0d3ce272cc X-Filterd-Recvd-Size: 5556 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Nov 2020 20:53:51 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id y7so1226696pfq.11 for ; Thu, 05 Nov 2020 12:53:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6Leqw7u0Dj1Vz2BsTHyCIMeIKX4OIeHsLYnWeVSaw6Y=; b=iTdqtA5C73Vrz3wnXMfi2ehPUNtrgAzfjSC9sbuyb4PjCLL0bzTeRuU2Ma1bqfw5+M LTLPzs3uOWNX7IhP1zl2a+iyG7Ey3kmIaxok8+vFnhm+Krd7p0wP5F9jQ7e+OVwyX4Bi I1W1/E/4pNkN34HwwDGKqFo/gEPafUvsxpwT76QX/vz0ooKmKgphWAAxGJce0w9X1Zp/ J0oTYiUh2XhPeosOm4yZNQPCm6b4Okc7xfgCrhWLHQS66AjHGI17+LpRJwGyISImBU0I DACaGmustp++exPUVtB4TgIOpY1i2QtywH5XI5kmRIcLv3PvmQV22AE6nHTy3u4KnXVQ GeRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6Leqw7u0Dj1Vz2BsTHyCIMeIKX4OIeHsLYnWeVSaw6Y=; b=PRZ1e0fXh1zNHOzmOmdQWwLm7UyJ4pmo6Fldf1UHmHGK/wQ8OqquCyW+znZKZ0gFqn rcgV71nWWks4DKFwwt85g0DN5y/rvPuh+nzaCf5zgo27tE9HykovhH55+bGy2TwLrHRZ dfln+i/W4uiOaDvrj8wGwMKWRi5+6Mqq1e8XWmul5gqzvPhXfMuzyx8Tfheq9YHSEfuX RwhGhekE7/niWQbXHQvQ3v7F13XYjzW8prR6GjhOu0dvpcETh12qCzTr+0FlFwy50NYW 9NW06CJ4iLCpB9hzGWb2KAn+/0rFMHJom7v3uaYXIroarIbi1F5mLlSjl1KpOabaqKW0 IGwQ== X-Gm-Message-State: AOAM530WZsv8DNGI22j5rvMmi8C07xqUJ8ubYlP8lfSlfVrHxYFIUIN7 jUiajittaMm0y9GP0l7fIks= X-Google-Smtp-Source: ABdhPJxUZsNTq7EX7hHHMb5GM4tGtzAlPxZWwcwNcY7v3Qei0TEfEn0WLfqFpXFSp6pHxKAj/gpXtg== X-Received: by 2002:a62:a10a:0:b029:154:fd62:ba90 with SMTP id b10-20020a62a10a0000b0290154fd62ba90mr4303657pff.62.1604609630470; Thu, 05 Nov 2020 12:53:50 -0800 (PST) Received: from localhost.localdomain (c-107-3-138-210.hsd1.ca.comcast.net. [107.3.138.210]) by smtp.gmail.com with ESMTPSA id u22sm3265528pgf.24.2020.11.05.12.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 12:53:49 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] mm: migrate: clean up migrate_prep{_local} Date: Tue, 3 Nov 2020 05:03:33 -0800 Message-Id: <20201103130334.13468-5-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103130334.13468-1-shy828301@gmail.com> References: <20201103130334.13468-1-shy828301@gmail.com> 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: The migrate_prep{_local} never fails, so it is pointless to have return value and check the return value. Signed-off-by: Yang Shi --- include/linux/migrate.h | 4 ++-- mm/mempolicy.c | 8 ++------ mm/migrate.c | 8 ++------ 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 0f8d1583fa8e..4594838a0f7c 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -45,8 +45,8 @@ extern struct page *alloc_migration_target(struct page *page, unsigned long priv extern int isolate_movable_page(struct page *page, isolate_mode_t mode); extern void putback_movable_page(struct page *page); -extern int migrate_prep(void); -extern int migrate_prep_local(void); +extern void migrate_prep(void); +extern void migrate_prep_local(void); extern void migrate_page_states(struct page *newpage, struct page *page); extern void migrate_page_copy(struct page *newpage, struct page *page); extern int migrate_huge_page_move_mapping(struct address_space *mapping, diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 3fde772ef5ef..780861312008 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1114,9 +1114,7 @@ int do_migrate_pages(struct mm_struct *mm, const nodemask_t *from, int err; nodemask_t tmp; - err = migrate_prep(); - if (err) - return err; + migrate_prep(); mmap_read_lock(mm); @@ -1315,9 +1313,7 @@ static long do_mbind(unsigned long start, unsigned long len, if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) { - err = migrate_prep(); - if (err) - goto mpol_out; + migrate_prep(); } { NODEMASK_SCRATCH(scratch); diff --git a/mm/migrate.c b/mm/migrate.c index 9a32bb128f31..8f6a61c9274b 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -62,7 +62,7 @@ * to be migrated using isolate_lru_page(). If scheduling work on other CPUs is * undesirable, use migrate_prep_local() */ -int migrate_prep(void) +void migrate_prep(void) { /* * Clear the LRU lists so pages can be isolated. @@ -71,16 +71,12 @@ int migrate_prep(void) * pages that may be busy. */ lru_add_drain_all(); - - return 0; } /* Do the necessary work of migrate_prep but not if it involves other CPUs */ -int migrate_prep_local(void) +void migrate_prep_local(void) { lru_add_drain(); - - return 0; } int isolate_movable_page(struct page *page, isolate_mode_t mode) From patchwork Tue Nov 3 13:03:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11885101 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 B8BCF697 for ; Thu, 5 Nov 2020 20:53:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 50B5E20724 for ; Thu, 5 Nov 2020 20:53:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YPU4FyKS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50B5E20724 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 852676B019C; Thu, 5 Nov 2020 15:53:54 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 802C46B019D; Thu, 5 Nov 2020 15:53:54 -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 6591F6B019E; Thu, 5 Nov 2020 15:53:54 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0239.hostedemail.com [216.40.44.239]) by kanga.kvack.org (Postfix) with ESMTP id 2C72E6B019C for ; Thu, 5 Nov 2020 15:53:54 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C7BF48249980 for ; Thu, 5 Nov 2020 20:53:53 +0000 (UTC) X-FDA: 77451566346.10.pull16_1b0e9f9272cc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id A44C916A0D2 for ; Thu, 5 Nov 2020 20:53:53 +0000 (UTC) X-Spam-Summary: 1,0,0,c8668d1138b06b4d,d41d8cd98f00b204,shy828301@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:966:968:973:988:989:1202:1260:1311:1314:1345:1359:1437:1515:1535:1543:1605:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2553:2559:2562:2693:2899:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4117:4250:4321:4385:5007:6119:6120:6261:6653:7514:7875:7901:7903:8957:9010:9413:10004:11026:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12683:12895:13894:14096:14181:14394:14687:14721:21060:21080:21444:21627:21666:21990:30054:30090:30091,0,RBL:209.85.210.193:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100;04yg161tobcgwi4mm3rzgewer4d7yoc5y5w97c6c4mk8ien7miqe1a63wqujwjn.xfg76f3ci7sws3bg19mexfnpktnwkssxbpo6c1snjju5da4zzoch4erq1x5g6xd.s-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:69,LUA_SUMMARY:none X-HE-Tag: pull16_1b0e9f9272cc X-Filterd-Recvd-Size: 6708 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Nov 2020 20:53:53 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id z3so2282361pfz.6 for ; Thu, 05 Nov 2020 12:53:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y6DgJdBCW4aME83u7WdKcgwL2UHBAOIfxXW7hlUge6Q=; b=YPU4FyKSPyyWzrPeopYZ1EK1tTC0tPFrMQBZnhHGrBiI3B+NxHHytSDtGZp91BR3b1 /DGkv4vzRRiSIujXFtBmLmz/DJzGtVQPyJLr6g9XPk8xWDrKegbejuJltSSlLTVJ5ibj ic7k4rf+Hn+G0qhcDsyY0hyInVS64Ffd+Z5dHOLebRG48XGs76BhfM4zAYGcg09v2P41 gm4hrNYec0MgHSpIoCjg8AgUR82jZR7vs9cKyg8XVWVHHigPI3MxMtmWrbipNmKbW+b9 tSa/QSdZnbU7+PEnaQHrrvsLuaCdxlZIBk72MqRqN3SrbpTgESaikRIioI+IARWDInlY S7eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y6DgJdBCW4aME83u7WdKcgwL2UHBAOIfxXW7hlUge6Q=; b=soebgsNZXw4VHxWB+pNC5+ooBZ/amceCQLhPp5KtlwnZDzHPo95UPVqSPSad1XoTd/ VVj7JeLEOXGkiCYptQnTbnKM37tWfrC86JyoNbRCkbBNZnCc+X3kDvoZ1GO3RXiCFxya xpqWbSGwWIxmBsq0k1aCHzBsWLUQ6wQohXcVRhxpbwyr0NqrcBcZamRdYpwwGs+BO/h2 3In23ShgVFHPQDAtS6Tm7hlwVJzt0JRqf11LFAs5x4ZPN1AnGFmH+/nRjlp3zSnZPIcS m/ZfxWbP3bJu98CHo42R3yIgUO2W4ijLhjbkeyo97RUZZYXP5jMCnjoWROvTwdKBNfKG kaTA== X-Gm-Message-State: AOAM533/gGJ+lC5PENkuoa3thsjNFAEi98AkyOrgvOH9tt0qDMhqy6bR uYY6hb1b9JaAP5nQyfBo570= X-Google-Smtp-Source: ABdhPJzqK69VUMaA57xqokGJVipfkh3WJguLL/FDol0ji5PTkvxN+Wj3+9OZ6C2QFndraPll6u0Ukw== X-Received: by 2002:a17:90a:fb4e:: with SMTP id iq14mr4276671pjb.68.1604609632438; Thu, 05 Nov 2020 12:53:52 -0800 (PST) Received: from localhost.localdomain (c-107-3-138-210.hsd1.ca.comcast.net. [107.3.138.210]) by smtp.gmail.com with ESMTPSA id u22sm3265528pgf.24.2020.11.05.12.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 12:53:51 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] mm: migrate: return -ENOSYS if THP migration is unsupported Date: Tue, 3 Nov 2020 05:03:34 -0800 Message-Id: <20201103130334.13468-6-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103130334.13468-1-shy828301@gmail.com> References: <20201103130334.13468-1-shy828301@gmail.com> 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: In the current implementation unmap_and_move() would return -ENOMEM if THP migration is unsupported, then the THP will be split. If split is failed just exit without trying to migrate other pages. It doesn't make too much sense since there may be enough free memory to migrate other pages and there may be a lot base pages on the list. Return -ENOSYS to make consistent with hugetlb. And if THP split is failed just skip and try other pages on the list. Just skip the whole list and exit when free memory is really low. Signed-off-by: Yang Shi --- mm/migrate.c | 62 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 8f6a61c9274b..b3466d8c7f03 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1172,7 +1172,7 @@ static int unmap_and_move(new_page_t get_new_page, struct page *newpage = NULL; if (!thp_migration_supported() && PageTransHuge(page)) - return -ENOMEM; + return -ENOSYS; if (page_count(page) == 1) { /* page was freed from under us. So we are done. */ @@ -1376,6 +1376,20 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, return rc; } +static inline int try_split_thp(struct page *page, struct page *page2, + struct list_head *from) +{ + int rc = 0; + + lock_page(page); + rc = split_huge_page_to_list(page, from); + unlock_page(page); + if (!rc) + list_safe_reset_next(page, page2, lru); + + return rc; +} + /* * migrate_pages - migrate the pages specified in a list, to the free pages * supplied as the target for the page migration @@ -1445,24 +1459,40 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, reason, &ret_pages); switch(rc) { + /* + * THP migration might be unsupported or the + * allocation could've failed so we should + * retry on the same page with the THP split + * to base pages. + * + * Head page is retried immediately and tail + * pages are added to the tail of the list so + * we encounter them after the rest of the list + * is processed. + */ + case -ENOSYS: + /* THP migration is unsupported */ + if (is_thp) { + if (!try_split_thp(page, page2, from)) { + nr_thp_split++; + goto retry; + } + + nr_thp_failed++; + nr_failed += nr_subpages; + break; + } + + /* Hugetlb migration is unsupported */ + nr_failed++; + break; case -ENOMEM: /* - * THP migration might be unsupported or the - * allocation could've failed so we should - * retry on the same page with the THP split - * to base pages. - * - * Head page is retried immediately and tail - * pages are added to the tail of the list so - * we encounter them after the rest of the list - * is processed. + * When memory is low, don't bother to try to migrate + * other pages, just exit. */ if (is_thp) { - lock_page(page); - rc = split_huge_page_to_list(page, from); - unlock_page(page); - if (!rc) { - list_safe_reset_next(page, page2, lru); + if (!try_split_thp(page, page2, from)) { nr_thp_split++; goto retry; } @@ -1490,7 +1520,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, break; default: /* - * Permanent failure (-EBUSY, -ENOSYS, etc.): + * Permanent failure (-EBUSY, etc.): * unlike -EAGAIN case, the failed page is * removed from migration page list and not * retried in the next outer loop.