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.