From patchwork Thu Jan 14 10:35:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12019189 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,URIBL_BLOCKED,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 01602C433DB for ; Thu, 14 Jan 2021 10:38:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 36D0123A3B for ; Thu, 14 Jan 2021 10:38:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 36D0123A3B 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 AA33C8D00CF; Thu, 14 Jan 2021 05:38:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A547A8D008E; Thu, 14 Jan 2021 05:38:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 969C38D00CF; Thu, 14 Jan 2021 05:38:31 -0500 (EST) 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 7F0108D008E for ; Thu, 14 Jan 2021 05:38:31 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4D4281EE6 for ; Thu, 14 Jan 2021 10:38:31 +0000 (UTC) X-FDA: 77704031622.23.brush45_3f03a7827526 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 2F78C3760C for ; Thu, 14 Jan 2021 10:38:31 +0000 (UTC) X-HE-Tag: brush45_3f03a7827526 X-Filterd-Recvd-Size: 4571 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Thu, 14 Jan 2021 10:38:30 +0000 (UTC) Received: by mail-pj1-f51.google.com with SMTP id y12so2861980pji.1 for ; Thu, 14 Jan 2021 02:38:30 -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=wusSjLYakm6+Z6kCpNRodcZYujbXCjpbVczSV3qSR3o=; b=TeiTKCMIOIJRw17QVnoSIfYza5zvzuJdQpuxOI/464cijUjiNyu9mYgydAdL2B4UTe iQsMS6mFYA/efN+W5hnMZNG8aMj4JvuHTV7zw6AQKNhNvs0V4QgCd2+KxV625KInYCvg sav6A4SdKh+/IXh4Rr0xQlxguGV5TgalxHSfo1UKCd/mt4Y7kPluOLu2gC/6KBSu9ApL S5w6wcKuli5Jq3UOCcpxq8d2jeKdawel/SjY9qoL8gnZVy9R03OXV5Atof1m2f/Grey+ crisfJEUxwDLr5TjQ2mNuvgbbRKT1TnEkyPaxMMF9HlTXV63JXWnd0Ci+vemx6gbqoME 27Bg== 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=wusSjLYakm6+Z6kCpNRodcZYujbXCjpbVczSV3qSR3o=; b=Jx2eb3kzEuoO9jkS1Wn7rSYJdx6ZonTt1xdtX35KCFc7XxOHuUIPM0IvM4G0u2Ufr2 KsxVOFBaLJied2vrYztZq+l/kPjS+FqnfRYXHnDU6t54XQMvprXrAJjWe9MeSllqXiFq /YkPHjgJA8hDRJ20HJnNpk9z4C+xRFDNdhK14ND9lteDzaRuEJXYBcDCxSinc7pyIRlT tshEtSt/J+FXED1ObXUxrgHcZYmrKrVgogUgW5gS+VKXEx4AqtM/aPSKev58cIDB7gKF ONWnSay4FVbElHpfeOr6xql3B8oSZH2qQnknQJnyst3In2WyROMKpb7MyUMVIujIuDye iVJQ== X-Gm-Message-State: AOAM533EK28T80aXuzcDu7olPv7T5BTzVNiCNv4zh3LSFvYBosAXNIps tmQDQ3qII1MAsNBLXo/oSTy4oA== X-Google-Smtp-Source: ABdhPJxZ8FcQdJ5BlixmjzNl7BHRg+e95EAUD1OOhclQznhvVWpOnMMnx+m4cvx0MnAtDvcX89YDGQ== X-Received: by 2002:a17:90a:6c22:: with SMTP id x31mr1617999pjj.196.1610620709633; Thu, 14 Jan 2021 02:38:29 -0800 (PST) Received: from localhost.localdomain ([139.177.225.247]) by smtp.gmail.com with ESMTPSA id l12sm4970112pjq.7.2021.01.14.02.38.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jan 2021 02:38:29 -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 , Michal Hocko , David Hildenbrand , Oscar Salvador Subject: [PATCH v5 1/5] mm: migrate: do not migrate HugeTLB page whose refcount is one Date: Thu, 14 Jan 2021 18:35:11 +0800 Message-Id: <20210114103515.12955-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210114103515.12955-1-songmuchun@bytedance.com> References: <20210114103515.12955-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: All pages isolated for the migration have an elevated reference count and therefore seeing a reference count equal to 1 means that the last user of the page has dropped the reference and the page has became unused and there doesn't make much sense to migrate it anymore. This has been done for regular pages and this patch does the same for hugetlb pages. Although the likelyhood of the race is rather small for hugetlb pages it makes sense the two code paths in sync. Signed-off-by: Muchun Song Reviewed-by: Mike Kravetz Acked-by: Yang Shi Acked-by: Michal Hocko Reviewed-by: David Hildenbrand Reviewed-by: Oscar Salvador --- 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;