From patchwork Wed Jan 13 05:22:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12015795 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 3A3C5C433E0 for ; Wed, 13 Jan 2021 05:25:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8529D23117 for ; Wed, 13 Jan 2021 05:25:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8529D23117 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 D56D56B00BE; Wed, 13 Jan 2021 00:25:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CDFD98D000F; Wed, 13 Jan 2021 00:25:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF4F18D0007; Wed, 13 Jan 2021 00:25:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0029.hostedemail.com [216.40.44.29]) by kanga.kvack.org (Postfix) with ESMTP id A354C6B00BE for ; Wed, 13 Jan 2021 00:25:37 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 73F0B8245578 for ; Wed, 13 Jan 2021 05:25:37 +0000 (UTC) X-FDA: 77699614314.16.jump91_42012d92751b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 560DF100E690B for ; Wed, 13 Jan 2021 05:25:37 +0000 (UTC) X-HE-Tag: jump91_42012d92751b X-Filterd-Recvd-Size: 4443 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 05:25:36 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id x12so417458plr.10 for ; Tue, 12 Jan 2021 21:25:36 -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=YM0v4j/Vw+PE0j0qtyYxkInLgfChRzFtd1IYXVhtaBs=; b=UMBMQFjAJ/KleNdrCLc87puq8f82M8nlP3Nlp9Htg8u8SfL+gDjlPEqAOMUsZRA/w5 QrOVLDLG5hbF1ZaqfQA/mitoaGSUq1xnqtF0D0VRy1Vy6BR6fk1y3FuHmYKD67VJTN12 g4OQbOdhAYdQQKfuUvvVRWQJqUquk/cSSyhf5/RafWb6WWGaLqAORg6SQ1PsTOpioG5A y5xY0rFuv3pZD/P4JCT39VRYlOb4zqh+i/D6m0IV4+hy8VZOnYjanvBnASOIeJggxtxv mKd/C7VH6yzziINWeIMJBpBH6nOU/SS6SL3ee5Rxy0Id2T5C2R1bemu+l06tCvPOo4Ib FqKA== 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=YM0v4j/Vw+PE0j0qtyYxkInLgfChRzFtd1IYXVhtaBs=; b=nyNtVFE2Ey6x1PwL5ovM1ayos2kHyTQ8XfMf5zQt+E8duE90wAuI0vUwrifw55hi4C PP+s9k0cG0PiXwiBhlMlms5QECCGxipDNdGpqY1Zkph72X3E3lwmEsMVmVQiTpW4dlol nTNDnhb4oJg9UDCMmSJbmJbyLQCW0HXJ3elZ9IcxOGRw0QCZ5EZE99Rg7vsU3B+eCCfV YX3qIxADFGJWWwqU8jTDrfU70R5ECAJTkhBEePIXnOgfvCKxMZZoVGrCRwLyTej4l7bs OQuOL2P6GpfvK5bs/70FayFK41wpvnQ86R6azp188wuHGXEz9gPd5XKFOy0VUBIHDhoH vkMg== X-Gm-Message-State: AOAM533T9mu0rDi2RvG++aHBZU4zr6y789lkzfemmoMlRdqKKFmL5Hy4 bU3fJy1e3b1v0YpFpv4EZ0uEag== X-Google-Smtp-Source: ABdhPJxHkGLvnYePvtJVAinVs5t2rPLGqeF5cswjO6y60ppYk2XM0JruFQuehDmZQ5o6gWa3rkMO2w== X-Received: by 2002:a17:902:848e:b029:dc:b38:98f0 with SMTP id c14-20020a170902848eb02900dc0b3898f0mr622492plo.82.1610515535725; Tue, 12 Jan 2021 21:25:35 -0800 (PST) Received: from localhost.localdomain ([139.177.225.247]) by smtp.gmail.com with ESMTPSA id x15sm893081pfa.80.2021.01.12.21.25.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jan 2021 21:25:35 -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 Subject: [PATCH v4 1/6] mm: migrate: do not migrate HugeTLB page whose refcount is one Date: Wed, 13 Jan 2021 13:22:04 +0800 Message-Id: <20210113052209.75531-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210113052209.75531-1-songmuchun@bytedance.com> References: <20210113052209.75531-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;