From patchwork Fri Nov 13 20:53:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11904559 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 CD1DF14C0 for ; Fri, 13 Nov 2020 20:54:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8687C2224D for ; Fri, 13 Nov 2020 20:54:15 +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="Xr05ke3t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8687C2224D 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 978846B006E; Fri, 13 Nov 2020 15:54:14 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9268D6B0070; Fri, 13 Nov 2020 15:54: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 83CA96B0071; Fri, 13 Nov 2020 15:54:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0209.hostedemail.com [216.40.44.209]) by kanga.kvack.org (Postfix) with ESMTP id 5214C6B006E for ; Fri, 13 Nov 2020 15:54:14 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E220B181AEF07 for ; Fri, 13 Nov 2020 20:54:13 +0000 (UTC) X-FDA: 77480597586.22.gun11_220de3427312 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id BBD7818038E68 for ; Fri, 13 Nov 2020 20:54:13 +0000 (UTC) X-Spam-Summary: 1,0,0,bbebf55aec3d1c53,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:2553: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:14687:14721:21060:21080:21325:21444:21451:21627:21666:21740:30003:30054:30090,0,RBL:209.85.210.195:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yfnw7tyonsiwawut8srhxdt8zjdyc58agbbtkrwxaicw9cu5xeg7mfg6foh1h.4fiygb8wy8seg1oih7yyznc9qzypbofk7qycb5gxdb5gjbz8mobqdchmx6fj7jo.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:69,LUA_SUMMARY:none X-HE-Tag: gun11_220de3427312 X-Filterd-Recvd-Size: 4860 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Nov 2020 20:54:13 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id q10so8671028pfn.0 for ; Fri, 13 Nov 2020 12:54:13 -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=L/nTuHNenKI3mByfAmKMfGl5XsKGSrafuSBjeTgSoyg=; b=Xr05ke3tOLLPVl+BARViF3JhHDLwIb2OSdP08973SloTne2Xdl9b6A/CEO2/0PtwjY QfC+jBjv9t8T6d/GMJkQKwZoCWsVG++8MfuKIKDEr4QabdG3bIVs3roI57YNjGuKvjYF eonqGSJzOkPTgHMFl5JsrVgiE8E2JWnJ7TruDimoJf50MxhE0TZntcotn3022aXm0beI /KN/+F4e1fuuHRk/M2yMf96VINJs+pKIe4Xilxk2pXtf6xRhSrc7z4g9nuz6RBccoq8d Qv6fVGIy64mUGkrpxGYhyYXmFPjsFULgi3wpol3+S2ajz4X7PLE/XhSfP7JiTBIiMyUM ZJ0A== 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=L/nTuHNenKI3mByfAmKMfGl5XsKGSrafuSBjeTgSoyg=; b=NU4DYKzp7Xk5dtaAzhorfPLF3muFNTCXsB4t2M0rVAtsGb7JMscKdlDAaoS4jjcedr PDKsNqfmqghBRLDt7A04BmiWhnvSSpjLxglfNGe2ZV7ZQsXszBbcIAQmSv+CU2LYyLsO 2INEROuSyaQXnrThi57+37prj5y2UhMPRbT1Qbf5Wwagd4jSWPRxNq/61aZdUmGoIezP H92V7bBlA4lH76qYLIVtmJqbTnlCbt4DjtUX/iJD5TazmJtcz4HMDiUVLF712GRnaFpo VNXVrpdBmOI6evuJO7CwmPKJVNcmae9QBt/grezrIkTYjEfdjt7t2d9Qu40dUY4x/Mhl PkBg== X-Gm-Message-State: AOAM531vMAziHlXe2s0tAoGbPaiNCZ8sSMA0CXpK2GcuUyHSFNL5bsl8 DMZoGoWRq8UCuM61BbsLo4M= X-Google-Smtp-Source: ABdhPJyMe77z4yunKaYCWv6Bp8CSJ31Rk1HAnMM/wc13YFGNMjfkEwpOonLXqdLdp3hzCGklAA8p9g== X-Received: by 2002:a17:90b:3512:: with SMTP id ls18mr5167558pjb.70.1605300852525; Fri, 13 Nov 2020 12:54:12 -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 a18sm3780234pfa.151.2020.11.13.12.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 12:54:11 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, willy@infradead.org, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 1/5] mm: truncate_complete_page is not existed anymore Date: Fri, 13 Nov 2020 12:53:55 -0800 Message-Id: <20201113205359.556831-2-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201113205359.556831-1-shy828301@gmail.com> References: <20201113205359.556831-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. Reviewed-by: Jan Kara Signed-off-by: Yang Shi --- 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 Fri Nov 13 20:53:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11904561 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 00AA814C0 for ; Fri, 13 Nov 2020 20:54:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 980802224D for ; Fri, 13 Nov 2020 20:54:19 +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="YeqnpYRM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 980802224D 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 B4B316B0072; Fri, 13 Nov 2020 15:54:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AFBB96B0073; Fri, 13 Nov 2020 15:54:18 -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 9C3ED6B0074; Fri, 13 Nov 2020 15:54:18 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0139.hostedemail.com [216.40.44.139]) by kanga.kvack.org (Postfix) with ESMTP id 63DBE6B0072 for ; Fri, 13 Nov 2020 15:54:18 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F0C618249980 for ; Fri, 13 Nov 2020 20:54:17 +0000 (UTC) X-FDA: 77480597754.08.knife25_4e0d7d327312 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id CD33E1819E766 for ; Fri, 13 Nov 2020 20:54:17 +0000 (UTC) X-Spam-Summary: 1,0,0,a34f0bcfd8c19ff0,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:9592:10004:11026:11473:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12683:12895:13148:13161:13172:13229:13230:13894:14096:14687:21060:21080:21444:21450:21451:21627:21666:21796:21939:21987:21990:30012:30034:30036:30054:30064:30069:30070:30091,0,RBL:209.85.214.194:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04y8td4fptzpim3un4fa9wzwpapeoocxmw518mamf9rkhfnixnw5son9cb9gdsy.fen7r88ubhd4wkqdbb6qb4d9h1ha3xhnm4nwgeof6uu8qs4g6yyz34bqph5coyo.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,Cust om_rules X-HE-Tag: knife25_4e0d7d327312 X-Filterd-Recvd-Size: 9580 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Nov 2020 20:54:17 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id 35so946619ple.12 for ; Fri, 13 Nov 2020 12:54:17 -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=w/5/DKL41ubRzJ/0MsKC6N7liZIas0t4NHg8fh0y8+o=; b=YeqnpYRMJECYlwJ2i2oiA/xvCtR71OaGKOOko2ziHP5enygvVDKINEAYl3KzCWQTCg j5Hwb/UzoOLZbM0FsvhCySODKxX7xgnnKdKGWuBjlRp6VhzJmzfcXPIyzsLdMjj+RUB6 mpmybMms5QxRkuimg5U9e4vWQtwGK4Jqkx/UgqXZbKNe06TGdTayYItf3L7ldmkov48d abciVBnfgr3V8Zt2HMCThmnixCAcElVFDluYTczvoHo4z4QqTg2dyzOOTjWG3cF62QS7 GjYuqNrPR+5QWwEasRwSBA6FJntVNs9thSrSoi6lov+wXpaaSk0xpO8NAKyuNp4FYCrX jzxw== 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=w/5/DKL41ubRzJ/0MsKC6N7liZIas0t4NHg8fh0y8+o=; b=PrsRZa6+rN3AoibPgJGaFPY7P6gU7WxxVKshF9+/66fqKnm0O3UVtAyKebyIig2Bw2 lNt2+ZoXaKHbkqMDmMlU8iHFj4fiqa+BdWHpTZvtS6AAVzWuuxcxHwZUVzSvY3Rjr9q8 HTr4A5X1KeVPkOakpbf7zZ68aBndCEtOCi1/JT5EPifYtQhDGPE/1C7XG7W6Mi1pux0u 3ibDXRD3ArTOmFVtywF5h/C/0irml93HebBTogz9zAV8/ux82rFt0PYrtg0OaPSrHdWo eH6nUxwlTt03tacrNjrEffD1oPW2+MEEGK+H3WwWm3c7rPUH//40SaX0Qh0Lkj3VJkXh 79DA== X-Gm-Message-State: AOAM530nZMhQDvVUwXn+BQ8/yXpApEVrtkLPx95mCYysE4sBueOjzMpa v0oYtGLwjYJOtwLLjQCm/wk= X-Google-Smtp-Source: ABdhPJxCL1PoHkAHZw7It17Cn2Zpv/9MQm4Qe6DPRylh0kRI3D6xZbD/NPTSe83+1CWb81oYDl9Zaw== X-Received: by 2002:a17:902:d204:b029:d8:d024:e67 with SMTP id t4-20020a170902d204b02900d8d0240e67mr3700949ply.25.1605300856285; Fri, 13 Nov 2020 12:54:16 -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 a18sm3780234pfa.151.2020.11.13.12.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 12:54:15 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, willy@infradead.org, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 2/5] mm: migrate: simplify the logic for handling permanent failure Date: Fri, 13 Nov 2020 12:53:56 -0800 Message-Id: <20201113205359.556831-3-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201113205359.556831-1-shy828301@gmail.com> References: <20201113205359.556831-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: 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. Reviewed-by: Zi Yan Signed-off-by: Yang Shi --- mm/migrate.c | 68 +++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 8a2e7e19e27b..d7167f7107bd 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,12 +1441,21 @@ 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); + /* + * 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 + */ switch(rc) { case -ENOMEM: /* @@ -1519,6 +1521,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 Fri Nov 13 20:53:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11904563 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 4BA44697 for ; Fri, 13 Nov 2020 20:54:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EA2232224D for ; Fri, 13 Nov 2020 20:54:22 +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="hNK0lFKC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA2232224D 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 EF7B26B0073; Fri, 13 Nov 2020 15:54:21 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EA4E16B0074; Fri, 13 Nov 2020 15:54:21 -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 D200E6B0075; Fri, 13 Nov 2020 15:54:21 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0091.hostedemail.com [216.40.44.91]) by kanga.kvack.org (Postfix) with ESMTP id 9D83A6B0073 for ; Fri, 13 Nov 2020 15:54:21 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 47482181AEF07 for ; Fri, 13 Nov 2020 20:54:21 +0000 (UTC) X-FDA: 77480597922.07.mouth58_0013dd127312 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 2F3C31803F9A9 for ; Fri, 13 Nov 2020 20:54:21 +0000 (UTC) X-Spam-Summary: 1,0,0,d21dc6d18fbb8844,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:2198:2199:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3872:3874:4037:4250:4321:4605:5007:6117:6119:6120:6261:6653:7514:7901:7903:7974:8957:9413:10004:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12895:12986:13161:13229:13894:14096:14181:14687:14721:21060:21080:21444:21627:21666:21990:30003:30054,0,RBL:209.85.210.195:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100;04yftwwbk3uans1j5hsjgw1paiap1ycqbpr9u4d4opxyt1zb5eiowcpzrbpkunm.79go73ot1k8aft3wxgqgoeu3d1ohundfbk86tiy5wuht7r64aak1moadozrcymw.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:68,LUA_SUMMARY:none X-HE-Tag: mouth58_0013dd127312 X-Filterd-Recvd-Size: 5327 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Nov 2020 20:54:20 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id w14so8638132pfd.7 for ; Fri, 13 Nov 2020 12:54:20 -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=J1P7rD6yvIgCZ2SrjtB9V6g8Qq2F/GDvh/5dKEAS9Os=; b=hNK0lFKC6nrx+tBMO9lk+1vmT9F08322YNvttvN+TBDGtouldHpOscthUXqKDNVHVr 39ysPpyqSm1lDQ93/cayV8KFIA+qKqhyRdhhTSxcUqi8co2gH/vwOPdp/zXd2QHwYUgH S/V1npOa1IuvYQLFjzpZ273DTPRBdw7njr6pv0MHUYyehwq9mgKYnoQFqPg8kEhX5z2f xYbo+wrPYW2GVrqIk4tv9pWoWTsDomBKvMFjQCEPZM+uRCPoXQizEPEPZxwIDl9lMzsO zu/3yGs1KR+vLxypceipMjRyW3flcp1OT4yC+sNZZGJtXwA6o9df/yUtjibB2CuSvKsC cugQ== 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=J1P7rD6yvIgCZ2SrjtB9V6g8Qq2F/GDvh/5dKEAS9Os=; b=X6M3W9wMVpz4sTVEeOVIzn6otJzKtYMHnbi8eWP1F8GzhyLYEIbf+TEkJER7LusfGJ tgsLNyzoNVrlOSbzOD8XSQ3Hgv0sxTADtGE2GMP9/Fc/YauYCiVV/DajjkC43zCWDUhJ taZqgV19n3RX3nNiGX1DDAS6b1DHFiGf4183zDmL6GH/M68hI5ZmyiJn4+47G/HY4UYJ 08CLEhvMuA/eK01PqIv0fmRODzsZ5SO8p4l73XFKcvq6PP6djmRxPdcjSLDpUrVKkbA7 qcMVkZuKtjoKp1fDLbTcqmb3QI/xcfebS0xj3xhCJCHuitfr9maBBeutZC34tMWKGXj7 c7zg== X-Gm-Message-State: AOAM530ujQmh5Y9UK0RRs1m2h0oEbDp9OYpdkQX5N+NQY9xe3a2L5hOv TpAMHsNpqv/Of9eC3WFHgFg= X-Google-Smtp-Source: ABdhPJyvFIGq1ULa6iDB24RGSIbicOzPOjE2He5AGIoNQnd8H5VxYQovwey2oBqWJlwIH2HJQi6RZw== X-Received: by 2002:a63:f951:: with SMTP id q17mr3208392pgk.199.1605300860028; Fri, 13 Nov 2020 12:54:20 -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 a18sm3780234pfa.151.2020.11.13.12.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 12:54:18 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, willy@infradead.org, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 3/5] mm: migrate: skip shared exec THP for NUMA balancing Date: Fri, 13 Nov 2020 12:53:57 -0800 Message-Id: <20201113205359.556831-4-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201113205359.556831-1-shy828301@gmail.com> References: <20201113205359.556831-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. And Willy's regular filesystem THP support patches could create shared exec THP wven without that config. In addition, the page_is_file_lru() is used to tell if the page is file cache or not, but it filters out shmem page. It sounds like a typical usecase by putting executables in shmem to achieve performance gain via using shmem-THP, so it sounds worth skipping migration for such case too. 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 d7167f7107bd..18cc1ef0e447 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2069,6 +2069,17 @@ 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_is_shmem(vma)) && + (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 @@ -2086,8 +2097,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; /* @@ -2142,6 +2152,9 @@ 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_shared_exec_page(vma, page)) + goto out; + new_page = alloc_pages_node(node, (GFP_TRANSHUGE_LIGHT | __GFP_THISNODE), HPAGE_PMD_ORDER); @@ -2253,6 +2266,7 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm, out_unlock: unlock_page(page); +out: put_page(page); return 0; } From patchwork Fri Nov 13 20:53:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11904565 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 585B8697 for ; Fri, 13 Nov 2020 20:54:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1A6D822255 for ; Fri, 13 Nov 2020 20:54:25 +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="FWbOftTw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A6D822255 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 112376B0075; Fri, 13 Nov 2020 15:54:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0C2E96B0078; Fri, 13 Nov 2020 15:54:25 -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 E56766B007B; Fri, 13 Nov 2020 15:54:24 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0052.hostedemail.com [216.40.44.52]) by kanga.kvack.org (Postfix) with ESMTP id B68506B0075 for ; Fri, 13 Nov 2020 15:54:24 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4A2908249980 for ; Fri, 13 Nov 2020 20:54:24 +0000 (UTC) X-FDA: 77480598048.22.rock58_110dbb227312 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 2A9BD18038E67 for ; Fri, 13 Nov 2020 20:54:24 +0000 (UTC) X-Spam-Summary: 1,0,0,bdf4af87ac5c836c,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:14687:14721:21060:21080:21444:21627:21666:21740:21990:30054:30064:30070:30090,0,RBL:209.85.215.194:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yft4aw9epy48dkuw9asy869s87dypeoqea4u849pr6n5q5wk4ybn677ah16gc.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:71,LUA_SUMMARY:none X-HE-Tag: rock58_110dbb227312 X-Filterd-Recvd-Size: 5575 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Nov 2020 20:54:23 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id h6so8071505pgk.4 for ; Fri, 13 Nov 2020 12:54:23 -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=NlCySaarQuBRqx4ZarxGkk5wyOoOIoY4LEnvGt+q/V8=; b=FWbOftTweAh9DsE1ejLx5Hj3jf3rfjvcSWPSDIPv0iHC9LP3BmDaa0znpjQG0Nuynu APq3xUhBOA52WhIlJuoBeDVb5kRULJS097Yh1I1K8OQc88hAcDET1v2MR2JrEkj4MmKc 6/EZwRmqUA6QebJmH9dg+pwDo9vufW81WRuy/BW+G/QzFlWCmL4e7c1n6wpVZPp2nz+y qoyvjxWFLR3BQpvRZzZKkwxT45OIDLWaMiWEIkUMGu5mSr9JjuMCV5fDUnSNyruRxuA8 gBfms96UIGgIdYGDpuEe5+4JWsqdXvU6VVSnovz8kwPLuuvxt3YrdcaIBthenUBQOLnZ vBsw== 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=NlCySaarQuBRqx4ZarxGkk5wyOoOIoY4LEnvGt+q/V8=; b=sO37lYW4TLWp1ujeT5bo9dCWwOMbwc7arlBxRgDWByXjXyqd8VaOYP4AX573VU2KNh 0PbeIFm8SR868kGEE84KUgbR+bFCgKoX8izCezWBoY8dUdOk45jF3Wkk2Xa3jgZsFH6G qTRkyQBgWipny8c1WvOgxvap8b00VTcxe7QWHXjLG0MNaPhcehvYAC5JKrqTVcfVEiPF mWkex+3KjtpScc5p1gpUnPCGkXXci3K37J4QNb/raZgFaD1YhaDe676JJsQj3u9oY2HI 6STXROSIY6+JYZ2wNnBs7L5MDfZ+nSHI99bUm71H7Qb41Hl3Iu0vzQetnknNbUf8675H 2JsA== X-Gm-Message-State: AOAM531GTWtyh6YG+aH/5q0OxS1Kdlzmp7A1QEDIk3idwY/xHP9Hrtcj UWijDQOqzwCdmZFiRX/Co78= X-Google-Smtp-Source: ABdhPJxnzIuqoEzeSjtKEmms0/Rel0ToY3PHomWAvPB4LIt6hlhlCX+b1+j14OZ/MnPJDvulD+LRkw== X-Received: by 2002:a17:90a:1696:: with SMTP id o22mr4768923pja.44.1605300862975; Fri, 13 Nov 2020 12:54:22 -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 a18sm3780234pfa.151.2020.11.13.12.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 12:54:21 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, willy@infradead.org, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 4/5] mm: migrate: clean up migrate_prep{_local} Date: Fri, 13 Nov 2020 12:53:58 -0800 Message-Id: <20201113205359.556831-5-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201113205359.556831-1-shy828301@gmail.com> References: <20201113205359.556831-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. Reviewed-by: Zi Yan 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 3ca4898f3f24..8cf96bd21341 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 18cc1ef0e447..4d3d173a1706 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 Fri Nov 13 20:53:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11904567 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 2D90E697 for ; Fri, 13 Nov 2020 20:54:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DB1732224D for ; Fri, 13 Nov 2020 20:54:28 +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="r5dzGtWN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB1732224D 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 C35AD6B0078; Fri, 13 Nov 2020 15:54:27 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BE6B46B007B; Fri, 13 Nov 2020 15:54:27 -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 AFDCE6B007D; Fri, 13 Nov 2020 15:54:27 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id 7D01E6B0078 for ; Fri, 13 Nov 2020 15:54:27 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2C49F181AEF07 for ; Fri, 13 Nov 2020 20:54:27 +0000 (UTC) X-FDA: 77480598174.16.anger30_490950c27312 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 07A78100E690C for ; Fri, 13 Nov 2020 20:54:27 +0000 (UTC) X-Spam-Summary: 1,0,0,8bb02ee962ed1090,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:14687:14721:21060:21080:21444:21627:21666:21990:30054:30090:30091,0,RBL:209.85.210.196:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yfeoojd68mcmtn79gsitimspprsoc5y5w97c6c51kjpi1qe6qe1a63wqujwjn.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:68,LUA_SUMMARY:none X-HE-Tag: anger30_490950c27312 X-Filterd-Recvd-Size: 6744 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Nov 2020 20:54:26 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id z3so8626903pfb.10 for ; Fri, 13 Nov 2020 12:54:26 -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=CvuRYtIWP4UHd11OQXH+00CGziU0NWit5UcWJl2Apfg=; b=r5dzGtWNg/mpS+L45R1MXt6/lO/QS8/uCWBMj9w+ktEc6Vo4B6Xy/hw9X+YldMpWTs xWxC9Voa3j4Sb9Qub0oSKf+FkyY3Gcy79pIs9LxmFd2jqO7Ps7bZkYUsSqZDC5Q1kQoE DaHdfmxCFedkfeQNjiqmfqIOjDluCRIbOALCHAC02vlJ2PX6180hiGgIIQZpt1rCssgU x+1usfjyOgW2VBG0tSCcvWhGtXCMlSBcNemYfmyuLcIABPsAFBAYUYrWP37ZJaGRDcCb 7ohZSp10JeohHQDWp9xpyrEuFIO+va2Z8lV3xqPAxHn4xsGLS9l/f2J+lZxoCl5iC9fc 0ssA== 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=CvuRYtIWP4UHd11OQXH+00CGziU0NWit5UcWJl2Apfg=; b=TOrTrdZ7ECDxHO1ULZCLrja17CuaDvovvuP/nIO8d6uA8XeXS+2uXMz08HbuSG36Qb ZZA1lTCgFM5AIIOXAFwjCQDKI6UFMzJwQmrf7cNEVhVWL12tqH+mTm8sYI48FuybeH1b 8HODBTehCJise8XSTbg7/UBF8c9Z5IY24yImnT5SlyWkSvNpUUMIgqQqUIMTAZWGxW/q 453p3oTJJv1Pxv5wTNDnu2cdxg2ayI6CF5lUer5c5gtHZh5NuyiL7XIl9bILdYtqg0rk 640nv4JeTD2F53HNyH9UpKvOUIC37BMIE5LQmJ2crhq4vLXKESv+1p4Av1Ti33BEWCuG KSNQ== X-Gm-Message-State: AOAM530ZviNY0FTVZC55OHrkP9kB/v+nXw0PXlfacLSr8EhaDxlOuOcv DY7nQU7lj2+25vcFZxFvOFY= X-Google-Smtp-Source: ABdhPJxEE6lvaPdy3hU36wODc6jVPrBk45SRVqFfz1PSofo7RMf8IJilOgQVBbS0DqU5EH76cSxAHQ== X-Received: by 2002:a17:90a:b790:: with SMTP id m16mr4666099pjr.149.1605300865815; Fri, 13 Nov 2020 12:54:25 -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 a18sm3780234pfa.151.2020.11.13.12.54.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 12:54:24 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, willy@infradead.org, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 5/5] mm: migrate: return -ENOSYS if THP migration is unsupported Date: Fri, 13 Nov 2020 12:53:59 -0800 Message-Id: <20201113205359.556831-6-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201113205359.556831-1-shy828301@gmail.com> References: <20201113205359.556831-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 4d3d173a1706..344ac645c1f1 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 @@ -1453,24 +1467,40 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, * from list */ 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; } @@ -1498,7 +1528,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.