From patchwork Sun Jan 10 12:40:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12009091 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 28CE3C433DB for ; Sun, 10 Jan 2021 12:41:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ABC7C22B45 for ; Sun, 10 Jan 2021 12:41:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ABC7C22B45 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3A00A8D001A; Sun, 10 Jan 2021 07:41:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 34E8D8D0019; Sun, 10 Jan 2021 07:41:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2663E8D001A; Sun, 10 Jan 2021 07:41:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 0970D8D0019 for ; Sun, 10 Jan 2021 07:41:30 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C269D824556B for ; Sun, 10 Jan 2021 12:41:29 +0000 (UTC) X-FDA: 77689826298.11.bird80_0d1296b27504 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id A5C8E180F8B80 for ; Sun, 10 Jan 2021 12:41:29 +0000 (UTC) X-HE-Tag: bird80_0d1296b27504 X-Filterd-Recvd-Size: 4074 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Sun, 10 Jan 2021 12:41:29 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id l23so8788013pjg.1 for ; Sun, 10 Jan 2021 04:41:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KaGXltvZsrp8CrKlla29akS0Y9Nr6dS/klR3W0Q0I3k=; b=mhH1+ONodj1jrEp44EgwTPMDpRYALjgkxKo7IAU4FLxQhOx+cQ7xJTKK4ST4aKUFRL ImjG14r00vwqLOEq1LtuX0K3jAyJxt+FAGBLG6xSPQWaEb0GzCchNO2AFzctpgzZ0w0N iCF6uzYn00XWOQ9HPQS5RLFG3MaGJRTQXR4N3ALAiP6H3G+3D749HLAXv0a7tultO+Cg 4fhgUb1bXnGmov2qI8bEo52OmWqtCnADVZxxeSBaOD0zWwREBMFTumxjJSj63Z+nx5VD CtruF9wExES4ZgYpMBfxycWgp6K8d8TV0GUOwyVxdCxHSqmPeCO5CAdI1K8YLaUE/FJ4 b3aQ== 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=KaGXltvZsrp8CrKlla29akS0Y9Nr6dS/klR3W0Q0I3k=; b=CmYNjQ7cYXyZcbis0GMpsbPUDBs46ZeI9t0fycYOp3UjKuzFdSpiOtsRhUbYF93klo nJUVjriGDYnK/9mBov842llEBi+ABMtS4b2xcvZlGRSQxPKjLoPgGQItTrEiUT05V7hL DR7NRfbrRLKSy1F6fOjB5/64P4ZwnvVImvf2dmp1Yeof25H3s9/jMXYqZahA08tg++6W kNYisuOCSf60Icn+KLtx7v2HoIhnx8iavbCoUFXErU5/u8tBviu/DQp8g0Ors+m8InEZ bCMn61e2xq3jdGQ2ZugRDSd5HHpu9RMqGhOD49MEQf38QmcID1/l+Yf/IHfqKZpFgbEP Ft8A== X-Gm-Message-State: AOAM5331tGG0Ep/EMrWdxBjN2OB27ZxQYB1VmLrEwWfe4lEe1KQo6XJo pyo86HDkmoPiZ9egp3gczoFcmQ== X-Google-Smtp-Source: ABdhPJwhzqxNy3uyJAZp111LPgXCrGrRbpbuCwkaaygJaHeHyHHUUioTRzwIzRdKi5SsZNGm87Hxhw== X-Received: by 2002:a17:90a:b395:: with SMTP id e21mr12896195pjr.197.1610282488011; Sun, 10 Jan 2021 04:41:28 -0800 (PST) Received: from localhost.localdomain ([139.177.225.247]) by smtp.gmail.com with ESMTPSA id p9sm16176960pfq.136.2021.01.10.04.41.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Jan 2021 04:41:27 -0800 (PST) From: Muchun Song To: mike.kravetz@oracle.com, akpm@linux-foundation.org Cc: n-horiguchi@ah.jp.nec.com, ak@linux.intel.com, mhocko@suse.cz, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Yang Shi Subject: [PATCH v3 1/6] mm: migrate: do not migrate HugeTLB page whose refcount is one Date: Sun, 10 Jan 2021 20:40:12 +0800 Message-Id: <20210110124017.86750-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210110124017.86750-1-songmuchun@bytedance.com> References: <20210110124017.86750-1-songmuchun@bytedance.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: If the refcount is one when it is migrated, it means that the page was freed from under us. So we are done and do not need to migrate. This optimization is consistent with the regular pages, just like unmap_and_move() does. Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Yang Shi Acked-by: Michal Hocko --- mm/migrate.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index 4385f2fb5d18..a6631c4eb6a6 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1279,6 +1279,12 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, return -ENOSYS; } + if (page_count(hpage) == 1) { + /* page was freed from under us. So we are done. */ + putback_active_hugepage(hpage); + return MIGRATEPAGE_SUCCESS; + } + new_hpage = get_new_page(hpage, private); if (!new_hpage) return -ENOMEM;