From patchwork Tue Nov 10 18:12:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11895005 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 F24E516C1 for ; Tue, 10 Nov 2020 18:13:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AFF3920674 for ; Tue, 10 Nov 2020 18:13:06 +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="IW9ttFO9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AFF3920674 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 7850F6B005C; Tue, 10 Nov 2020 13:13:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 70ABB6B0068; Tue, 10 Nov 2020 13:13:05 -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 535696B006C; Tue, 10 Nov 2020 13:13:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0115.hostedemail.com [216.40.44.115]) by kanga.kvack.org (Postfix) with ESMTP id 235626B005C for ; Tue, 10 Nov 2020 13:13:05 -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 AE9DE181AEF09 for ; Tue, 10 Nov 2020 18:13:04 +0000 (UTC) X-FDA: 77469305088.14.head41_4004bf5272f7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 8009918229835 for ; Tue, 10 Nov 2020 18:13:04 +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.215.170:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yftfph88gkxqxtj9f16k1wb8oqxoc58agbbtkrwxaicw9cu5xeg7mfg6foh1h.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:72,LUA_SUMMARY:none X-HE-Tag: head41_4004bf5272f7 X-Filterd-Recvd-Size: 4832 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 18:13:04 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id m13so2761009pgl.7 for ; Tue, 10 Nov 2020 10:13:03 -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=IW9ttFO9e6hx5dU8vtwmKHMgFGrf2wc3Frkmon8dAAoTdHNJrxrbbKScyAWE2e0mJ1 EU8pheNXLzIIXe/ThlR0xFVbs1CRK6da4/qT1Dp0s8rh8wQxmpVlT9PArNT4BWjgIC6x NIeTwBU14tyFWpC/jpaNg9IVixusJptWjug2HO+amO8SVLsdNEvBMJBPKdChz4Av9R58 9Hh/VZi8t8dhuBOoqLw7Va3nnLdWO0Edh6Z/NP1bXUit5fXAnM+WjrXd0ndYaIsm+l32 QsyOufxigN1PzwbTcA7+7aI6RtSh6ZtemNcE1ZYen8cJ9R/rEkb2ELWHt+YNq+zvwMCA pPaQ== 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=p3clPMiB/kYBIvHJHK1MS3uQqDkro/gpvXUgtct6UgJtvOaXBx7Is5nUP8geBNFs7v JX6onBAjf5JQhIV6A9wZ8uAeQSsLTaL/Lh9Gt+zwm5KQte3oR8b+Jkyq01xaeJGlMq+T OfGGBhuagI6BcHFMv9ubZmVGDijNp+kFkLjlDHamr81F3D3KUMzj7MEd3n+S3FUn0YUz g09aB0srfFvDcIOq4GZBBraaPP4ILLfnwehKBsfZcldHs2JnbvOvivduaub1e7kaf1+y nu6BXWxnrrio0h3cqMYN41TxolqDROj4UjHPxh6INfZIK08naZFeOqS138ivlxtX3I95 FA3g== X-Gm-Message-State: AOAM531XyXqLNYYLTdY/xIZ1r7dBP0xommcbNMlZMyDfs0ie2I3mtWqw g2jeprD7i2QVG++4odTktYY= X-Google-Smtp-Source: ABdhPJzDLli+GB2R9J7uCGeYP1eOQbrUR08X6qU11SHG9RToER/J/I4Lnn3AhnuoDAntaaaywb0yOg== X-Received: by 2002:a17:90a:67c5:: with SMTP id g5mr368182pjm.13.1605031983399; Tue, 10 Nov 2020 10:13:03 -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 k5sm4157369pjj.37.2020.11.10.10.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 10:13:02 -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: [v2 PATCH 1/5] mm: truncate_complete_page is not existed anymore Date: Tue, 10 Nov 2020 10:12:46 -0800 Message-Id: <20201110181250.264394-2-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201110181250.264394-1-shy828301@gmail.com> References: <20201110181250.264394-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 Tue Nov 10 18:12:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11895007 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 8B6DA1668 for ; Tue, 10 Nov 2020 18:13:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2D1DD20674 for ; Tue, 10 Nov 2020 18:13:09 +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="NAfJXPji" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D1DD20674 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 006DE6B006C; Tue, 10 Nov 2020 13:13:08 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F20956B0070; Tue, 10 Nov 2020 13:13:07 -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 DC0346B0071; Tue, 10 Nov 2020 13:13:07 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id ACC336B006C for ; Tue, 10 Nov 2020 13:13:07 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3FE12362D for ; Tue, 10 Nov 2020 18:13:07 +0000 (UTC) X-FDA: 77469305214.23.unit79_320c98d272f7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id F396437610 for ; Tue, 10 Nov 2020 18:13:06 +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.210.194:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04y8aoc7jhce4haacoo9yks6brkqtycxmw518mamf9rkhfnixnw5son9cb9gdsy.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: unit79_320c98d272f7 X-Filterd-Recvd-Size: 9509 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 18:13:06 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id c66so6443455pfa.4 for ; Tue, 10 Nov 2020 10:13:06 -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=NAfJXPjiMWTtwfhbG9naf/w6U8KyJ/t848F3Iw4AZzgF25FMqWojzAYfNRgl/xGUvP Vy0e2dzmt51qvj7ISeTPzk/djTw0OtsDeUvuJ/FjjAqGgo75RHrMa/aDgcZIsbnOyLQy ayMyu8SRR0c9e/DBI4GaITPL9fYFSQrCI86oXXz9EeP+6ViYuwf078Pc9mSu1fP0gtz4 sHu585Amit/hGacdaRBeaxNgP/uQTuX242VUcKTwKEobSzzrZ6I1D9zBCTsHSFGdDGe2 8Lm8iyCSHzcbAXmW/vKK71mVL1ddwHn2DpTgEidkKeFqJQl1gL/urfGOPPLa/Vz0OHtT jbsg== 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=JBhgcq2benDXXn3431pnctMuO221Iyd+Q3o2Tuej4//Meyytiw04hi464MXx2ujrhW x5A4KVoO50lk0SCH/MsHMC1we6XSVJcU2xpVz2jGk72T3c8RhtHHk+dC0QUz8FdOgAza emZpHyuL+o5GeLPP2pGAPrwD8BMeyygEQdVNnjjEMAfEawj0nByyGLyGin0WkVh5wdGI bKjZdRg3wow6ILuM3YPxTLFTTAvE0tycRXsDEXDhG51LTccL+TAISaz392sk39r3ggU5 1CwTv0N+Lngfu9LMwtfexZn44/wkRK0B1oHvl07wqIgqzMrFklDeWU/Pco2TAc6YNrrq aJSA== X-Gm-Message-State: AOAM5308Tz59qL9W4el45qOQdyMI3esmHK+koRBkaXHLYJMPKUdzuc6n nxmpaZWmfNMGznIvZ8qtbN4= X-Google-Smtp-Source: ABdhPJydP5HwqAKtuGteJf/ZKsiG60bFFB9Tp0RZbC4lkxXDLuCnLD/ShKB+VaTHZbeimHfSdhuTnA== X-Received: by 2002:a17:90b:496:: with SMTP id bh22mr386015pjb.120.1605031985614; Tue, 10 Nov 2020 10:13:05 -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 k5sm4157369pjj.37.2020.11.10.10.13.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 10:13:04 -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: [v2 PATCH 2/5] mm: migrate: simplify the logic for handling permanent failure Date: Tue, 10 Nov 2020 10:12:47 -0800 Message-Id: <20201110181250.264394-3-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201110181250.264394-1-shy828301@gmail.com> References: <20201110181250.264394-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 Tue Nov 10 18:12:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11895009 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 D9AC616C1 for ; Tue, 10 Nov 2020 18:13:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 742F420674 for ; Tue, 10 Nov 2020 18:13:11 +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="rMAhKmz2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 742F420674 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 D267C6B0070; Tue, 10 Nov 2020 13:13:09 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CFEA66B0071; Tue, 10 Nov 2020 13:13:09 -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 B9C5A6B0072; Tue, 10 Nov 2020 13:13:09 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id 8ECBF6B0070 for ; Tue, 10 Nov 2020 13:13:09 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2F7FB1EE6 for ; Tue, 10 Nov 2020 18:13:09 +0000 (UTC) X-FDA: 77469305298.15.tramp01_3e0f4eb272f7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id EAFAC1814B0C9 for ; Tue, 10 Nov 2020 18:13:08 +0000 (UTC) X-Spam-Summary: 1,0,0,6c1f8cc221274ced,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:14687:14721:21060:21080:21444:21627:21666:21990:30003:30054,0,RBL:209.85.210.194:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100;04yg7tszyiqpzx9zbq7dp89krapepyczeducy9pk9kweccos78byg8pismiozuz.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:69,LUA_SUMMARY:none X-HE-Tag: tramp01_3e0f4eb272f7 X-Filterd-Recvd-Size: 4920 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 18:13:08 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id 10so12172151pfp.5 for ; Tue, 10 Nov 2020 10:13:08 -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=wzTkN8x60Q0XiW8/C8IsngN4jAgjA+AlmtZ3C3KQcFM=; b=rMAhKmz2stnt0OpVWI6QWLFxn/frb0pncgv+GV3PkKEKdC+qq81GLDHnQj6s1cISfg 7tbs7uTQ7qP5lVTVOMNcs7we8EfQ9a3knrthROKacF0iCS4pF5XeFxgbZrDpG8WuXErQ 61lolt0ZG+qJjRyqn7pVHenNxdszmg4JizQFfiYEsf3resqysh/T7Hw7BXC23CGH6PPE fD0VeNXrPG3mvJAvqsxEpTn7g3M5I+C7F5IIMgL2CPmB6XW0lSkgRzlvEh7fB0whTsLx lr0StdAwIW5GEkh49kanqDjL6T8B8amgBl+wMBHMQJpHjzLb8rdWIJaJMRL/UP4QFt+O BGiw== 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=wzTkN8x60Q0XiW8/C8IsngN4jAgjA+AlmtZ3C3KQcFM=; b=rIuIZCc+x1nl9ibiS+HVWamSJg1DiorYGrIcwfps5oGZbV+VOa5yhqiUzCCO4dvnlQ fUMo0+P5kkXA3kc7Cv2epD4LtEgl1tN/7uaadBZIJqZRmHAnBRLCfCa6/bh07wU2jqGB PllRsCMEwRNyDAwMgHkraToMZnVifBNwDDvn6zUhtKvDISDoDYE6aBU4NBzc8OqDkoFW qjOWJU/idj9HLVAEf50RwkIjjtwy4KCnpAuJKD4YAJBELSGrOBpilp0JtNQ+duzDYob4 TOfrXRBMofblW6zqRd83iraNrHjbvXyoMMZ7wSrxzjbJR1Z/8uXl0NkbMlZ2UNjVvoEj Gi6g== X-Gm-Message-State: AOAM533YVkKKkTGve+PjIjB6rMpXxoEm9oE1X2cZthBRRFuTnlbo2r5J O1xGtdqjK/RHk+DHTc6hAV4= X-Google-Smtp-Source: ABdhPJz9D38r5ZlM0UCBJXLFJsDSccwf+fHgs+pPgH8XmWGxY4AeJC3hVCEadRPQImntasuJMlolaw== X-Received: by 2002:a17:90a:df8f:: with SMTP id p15mr367490pjv.29.1605031987645; Tue, 10 Nov 2020 10:13:07 -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 k5sm4157369pjj.37.2020.11.10.10.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 10:13:06 -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: [v2 PATCH 3/5] mm: migrate: skip shared exec THP for NUMA balancing Date: Tue, 10 Nov 2020 10:12:48 -0800 Message-Id: <20201110181250.264394-4-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201110181250.264394-1-shy828301@gmail.com> References: <20201110181250.264394-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 d7167f7107bd..1b103e801fe4 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2069,6 +2069,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 @@ -2086,8 +2096,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 +2151,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); @@ -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 Tue Nov 10 18:12:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11895011 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 04B2016C1 for ; Tue, 10 Nov 2020 18:13:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B415220674 for ; Tue, 10 Nov 2020 18:13:13 +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="I1r4bpBe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B415220674 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 5D72E6B0072; Tue, 10 Nov 2020 13:13:12 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 587956B0074; Tue, 10 Nov 2020 13:13:12 -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 3FCBC6B0075; Tue, 10 Nov 2020 13:13:12 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id 135B86B0072 for ; Tue, 10 Nov 2020 13:13:12 -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 B012A824999B for ; Tue, 10 Nov 2020 18:13:11 +0000 (UTC) X-FDA: 77469305382.08.jewel34_431201f272f7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 8FD361819E764 for ; Tue, 10 Nov 2020 18:13:11 +0000 (UTC) X-Spam-Summary: 1,0,0,3c832f54ecdb5acc,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.214.193:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yrbcu7tdj6d6bix9m5marcmrtoqypeoqea4u849pr6n5q5wk4ybn677ah16gc.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:69,LUA_SUMMARY:none X-HE-Tag: jewel34_431201f272f7 X-Filterd-Recvd-Size: 5599 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 18:13:10 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id k7so6889603plk.3 for ; Tue, 10 Nov 2020 10:13:10 -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=METT62l5bl1QOeNAT1zAxW9WSJIbbi+SftVWPulzf3A=; b=I1r4bpBeciZdhrdMeQwTpQtdYv/5vYY/Lb31pwQy2h56pSZowU/JX8kxfxQ4lrfgy8 4GeJLASRCwf9/CfBBN37pB/NeapqGvnF9e2Z6JL58jYQSaIetWzu02c6HH8CwCCebg1/ u/lxKclSTnO0zibDO+sz7Mj8W0MfHjwGd3dif6mtMLo2hdIzh9fH3Y2MFDvnViubY+XB 8aK09OfEyhC57jPykdZ+so0AZJf4Xh6ZuaaKRbc+8mvvHVKH+7apZZX7W+QlCRGHrVRO Y2sVem3sDPsiPBbmKdR8VrakHmZ7Et6+DjFi9UYXxf3PTEjujv0QXBikJcUxNp/7UWyk dvNw== 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=METT62l5bl1QOeNAT1zAxW9WSJIbbi+SftVWPulzf3A=; b=Yn4hDZlz6JLaRDNx90Gn7oqd5Iby6N02HIQ/NgTwNbdZMHhI7z4Sq66X6MaDw6MfSm HC6RkWyL3QAGOIocJgkudh/Tj+U7W/Zksw7YJGyX5HrpeOH1ktNhbJWW/+OUBBQvtYKQ miAdokZ30WUn+xNo6yW/JkPnA6mCxm7dl0NjJeu7aPZPdnFfSH3DtbRFOIFDDyifd2TZ DIZh/yfhLsM+JXpIJ+Ek522GxqZysJCw/1ou1t6Kwmyp9qZfiYZOg8LBisT/jOQwoyhy rvLNGBdRqQCecPG/kmTv37oSymQmmf6dIbqjTg1ZxoPzpG3yP7iOtzWAdoVlCfZDAfUO +qoQ== X-Gm-Message-State: AOAM533q7VOjUvYqFBl7K9wAL0x5QNLiFy7hQQwhESw0ems7vKGXDojv yD5D6fwshUia/FCGDC5AYLA= X-Google-Smtp-Source: ABdhPJwo/sGFSUG1Jh6oyERIbbJeS18FFBCXGxTR+9l230LLSqNwItQ5DiwkzTpfym9jNhWf7icmjg== X-Received: by 2002:a17:902:56d:b029:d7:c927:2e51 with SMTP id 100-20020a170902056db02900d7c9272e51mr15637869plf.27.1605031990148; Tue, 10 Nov 2020 10:13:10 -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 k5sm4157369pjj.37.2020.11.10.10.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 10:13:09 -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: [v2 PATCH 4/5] mm: migrate: clean up migrate_prep{_local} Date: Tue, 10 Nov 2020 10:12:49 -0800 Message-Id: <20201110181250.264394-5-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201110181250.264394-1-shy828301@gmail.com> References: <20201110181250.264394-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 1b103e801fe4..693bf06448ad 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 10 18:12:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11895013 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 849941668 for ; Tue, 10 Nov 2020 18:13:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3EE7520797 for ; Tue, 10 Nov 2020 18:13:16 +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="ZecElvz8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EE7520797 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 115D76B0075; Tue, 10 Nov 2020 13:13:15 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0CB586B0078; Tue, 10 Nov 2020 13:13:15 -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 EF8506B007B; Tue, 10 Nov 2020 13:13:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0141.hostedemail.com [216.40.44.141]) by kanga.kvack.org (Postfix) with ESMTP id BD8786B0075 for ; Tue, 10 Nov 2020 13:13:14 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 58A6E3630 for ; Tue, 10 Nov 2020 18:13:14 +0000 (UTC) X-FDA: 77469305508.13.cars33_3206c10272f7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 38AF918140B67 for ; Tue, 10 Nov 2020 18:13:14 +0000 (UTC) X-Spam-Summary: 1,0,0,74bb2b3ddab92c88,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: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-66.100.201.100 62.50.0.100;04ygfppmn8d7prkjhwsgpbuak4fucoc5y5w97c6c51kjpi1qe6qe1a63wqujwjn.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: cars33_3206c10272f7 X-Filterd-Recvd-Size: 6718 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 18:13:13 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id c66so6443758pfa.4 for ; Tue, 10 Nov 2020 10:13: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=WbZNZfdUV+Jb/ecPWV8SHsj0cS3TmcMVN/IJ8mgWjoo=; b=ZecElvz8otZT3eF+V+Jipxwyqbrob11E7XA9qzjhlGlhadYlXS8W8PW9wGVdeswGez CxF2D9SQhatxA8z2yAvhIBDUfw34NXyDVlQHVyanlirj091JZcS8JwyJeU0qoIyFSY7E dYMCcohLw/8s4zcFX5NVO+HVNlr1N+/mvC6PFX0QvSl35tNTidvW5GWpotZHjTh5Lmxi gYTd6QhpWjqAOQjrTLoeIamqeEznAjGasRXXHnvBJ1zi0aclgzVQ6ZKGHKdC4RTXDS/v qTMYCopbRVqS4A2SIr4Ik9k0+zM3YWmqdB7rmVzDEhSh8nZPjPPIV0WBemo3+wz2n2wb OsDA== 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=WbZNZfdUV+Jb/ecPWV8SHsj0cS3TmcMVN/IJ8mgWjoo=; b=BWnj/UkyaNangEDWZB+OkiwxL725BE7E4qwm+1wu9TsVqM8aMWzBhHVQC6xr1fUZRV h3+hll5xe60bqJlihjzgVjafA5CNgnhmhygFrTpl0gbPXaXN75DC/xFXed5Mea00Rzab opLUSvqNOFoBkkb7oqsPdeKLJoUw7rO1XfCVwFgJozs0b3v50+y/EPKxIHv7IRnfGGNM V97SONtHreyFIvZtNoUcmy+GLgQ+gsRGSMxku9V8oHu/KOThGZXsV8TYDCLTgyodSiYO gXY2Z+r7HkAPc79c1MMQbbHWYMbdBa8qvXFOQUvtc5HmFHYNg4o1pN/cMzPs8+VWey2v UK7w== X-Gm-Message-State: AOAM530XNIzmHloVgOqe3G7QxubHYiLUJPNm9l0bIL8IrGIN5cJPNjSu u/uZoqfFmNAgqtYZKGCW7uU= X-Google-Smtp-Source: ABdhPJxOUAfMQOEUDeYGAxyPeDNAvEvec0OJ5dlCxusPzBkLXqu1dHgak7I+9muIvRjGfKDPBR3vCg== X-Received: by 2002:a17:90a:3f10:: with SMTP id l16mr378261pjc.110.1605031992965; Tue, 10 Nov 2020 10:13: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 k5sm4157369pjj.37.2020.11.10.10.13.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2020 10:13:11 -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: [v2 PATCH 5/5] mm: migrate: return -ENOSYS if THP migration is unsupported Date: Tue, 10 Nov 2020 10:12:50 -0800 Message-Id: <20201110181250.264394-6-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201110181250.264394-1-shy828301@gmail.com> References: <20201110181250.264394-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 693bf06448ad..d110af76fa4d 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.