From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.3 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E6DCC4741F for ; Thu, 5 Nov 2020 20:53:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 063A320782 for ; Thu, 5 Nov 2020 20:53:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YPU4FyKS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 063A320782 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 852676B019C; Thu, 5 Nov 2020 15:53:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 802C46B019D; Thu, 5 Nov 2020 15:53:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6591F6B019E; Thu, 5 Nov 2020 15:53:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0239.hostedemail.com [216.40.44.239]) by kanga.kvack.org (Postfix) with ESMTP id 2C72E6B019C for ; Thu, 5 Nov 2020 15:53:54 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C7BF48249980 for ; Thu, 5 Nov 2020 20:53:53 +0000 (UTC) X-FDA: 77451566346.10.pull16_1b0e9f9272cc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id A44C916A0D2 for ; Thu, 5 Nov 2020 20:53:53 +0000 (UTC) X-HE-Tag: pull16_1b0e9f9272cc X-Filterd-Recvd-Size: 6708 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Nov 2020 20:53:53 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id z3so2282361pfz.6 for ; Thu, 05 Nov 2020 12:53:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y6DgJdBCW4aME83u7WdKcgwL2UHBAOIfxXW7hlUge6Q=; b=YPU4FyKSPyyWzrPeopYZ1EK1tTC0tPFrMQBZnhHGrBiI3B+NxHHytSDtGZp91BR3b1 /DGkv4vzRRiSIujXFtBmLmz/DJzGtVQPyJLr6g9XPk8xWDrKegbejuJltSSlLTVJ5ibj ic7k4rf+Hn+G0qhcDsyY0hyInVS64Ffd+Z5dHOLebRG48XGs76BhfM4zAYGcg09v2P41 gm4hrNYec0MgHSpIoCjg8AgUR82jZR7vs9cKyg8XVWVHHigPI3MxMtmWrbipNmKbW+b9 tSa/QSdZnbU7+PEnaQHrrvsLuaCdxlZIBk72MqRqN3SrbpTgESaikRIioI+IARWDInlY S7eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y6DgJdBCW4aME83u7WdKcgwL2UHBAOIfxXW7hlUge6Q=; b=soebgsNZXw4VHxWB+pNC5+ooBZ/amceCQLhPp5KtlwnZDzHPo95UPVqSPSad1XoTd/ VVj7JeLEOXGkiCYptQnTbnKM37tWfrC86JyoNbRCkbBNZnCc+X3kDvoZ1GO3RXiCFxya xpqWbSGwWIxmBsq0k1aCHzBsWLUQ6wQohXcVRhxpbwyr0NqrcBcZamRdYpwwGs+BO/h2 3In23ShgVFHPQDAtS6Tm7hlwVJzt0JRqf11LFAs5x4ZPN1AnGFmH+/nRjlp3zSnZPIcS m/ZfxWbP3bJu98CHo42R3yIgUO2W4ijLhjbkeyo97RUZZYXP5jMCnjoWROvTwdKBNfKG kaTA== X-Gm-Message-State: AOAM533/gGJ+lC5PENkuoa3thsjNFAEi98AkyOrgvOH9tt0qDMhqy6bR uYY6hb1b9JaAP5nQyfBo570= X-Google-Smtp-Source: ABdhPJzqK69VUMaA57xqokGJVipfkh3WJguLL/FDol0ji5PTkvxN+Wj3+9OZ6C2QFndraPll6u0Ukw== X-Received: by 2002:a17:90a:fb4e:: with SMTP id iq14mr4276671pjb.68.1604609632438; Thu, 05 Nov 2020 12:53:52 -0800 (PST) Received: from localhost.localdomain (c-107-3-138-210.hsd1.ca.comcast.net. [107.3.138.210]) by smtp.gmail.com with ESMTPSA id u22sm3265528pgf.24.2020.11.05.12.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 12:53:51 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] mm: migrate: return -ENOSYS if THP migration is unsupported Date: Tue, 3 Nov 2020 05:03:34 -0800 Message-Id: <20201103130334.13468-6-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103130334.13468-1-shy828301@gmail.com> References: <20201103130334.13468-1-shy828301@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In the current implementation unmap_and_move() would return -ENOMEM if THP migration is unsupported, then the THP will be split. If split is failed just exit without trying to migrate other pages. It doesn't make too much sense since there may be enough free memory to migrate other pages and there may be a lot base pages on the list. Return -ENOSYS to make consistent with hugetlb. And if THP split is failed just skip and try other pages on the list. Just skip the whole list and exit when free memory is really low. Signed-off-by: Yang Shi --- mm/migrate.c | 62 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 8f6a61c9274b..b3466d8c7f03 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1172,7 +1172,7 @@ static int unmap_and_move(new_page_t get_new_page, struct page *newpage =3D NULL; =20 if (!thp_migration_supported() && PageTransHuge(page)) - return -ENOMEM; + return -ENOSYS; =20 if (page_count(page) =3D=3D 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; } =20 +static inline int try_split_thp(struct page *page, struct page *page2, + struct list_head *from) +{ + int rc =3D 0; + + lock_page(page); + rc =3D 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 pa= ges * supplied as the target for the page migration @@ -1445,24 +1459,40 @@ int migrate_pages(struct list_head *from, new_pag= e_t get_new_page, reason, &ret_pages); =20 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 +=3D 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 =3D split_huge_page_to_list(page, from); - unlock_page(page); - if (!rc) { - list_safe_reset_next(page, page2, lru); + if (!try_split_thp(page, page2, from)) { nr_thp_split++; goto retry; } @@ -1490,7 +1520,7 @@ int migrate_pages(struct list_head *from, new_page_= t get_new_page, break; default: /* - * Permanent failure (-EBUSY, -ENOSYS, etc.): + * Permanent failure (-EBUSY, etc.): * unlike -EAGAIN case, the failed page is * removed from migration page list and not * retried in the next outer loop. --=20 2.26.2