From patchwork Tue Apr 13 21:24:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12201459 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=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,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 03CA8C43470 for ; Tue, 13 Apr 2021 21:24:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AA3DB61242 for ; Tue, 13 Apr 2021 21:24:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AA3DB61242 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 45F4A6B007B; Tue, 13 Apr 2021 17:24:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C3C36B007D; Tue, 13 Apr 2021 17:24:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C70D6B007E; Tue, 13 Apr 2021 17:24:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id 020D96B007B for ; Tue, 13 Apr 2021 17:24:42 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id BD9A0180257D3 for ; Tue, 13 Apr 2021 21:24:42 +0000 (UTC) X-FDA: 78028623204.07.2752B7A Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf22.hostedemail.com (Postfix) with ESMTP id D37BFC0007C1 for ; Tue, 13 Apr 2021 21:24:38 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id k8so12870229pgf.4 for ; Tue, 13 Apr 2021 14:24:42 -0700 (PDT) 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=pRfd+wOd4qoxNAST21yPZCThPxUu/7bAGiKFZOKY6d8=; b=lJITJut37aBTK+f9dTgHu1UjML1K+sz8l3RIQxMTDn07BEPrnJ02I5I/bwqAHPhIn5 S8tiU2O+awovLmX4VVToKSks1+jKTAinxrg9fNCaZhIKwQrgKQKT6YmsjataVgO+KN+s WC1NYW1pTKOYHTIYPYD080AF6kOsZvrjZj+grK6E1WkxAbZuVOP2V/irQEyqxdp4va8U 5XREEOrhTQwmK19x8KewOYi0qofybk5PGLbYU1bSCZtMhhc6SfmXUZjygzLhq5IjTcqL 8frdihCWj1rzB8mYWv7kn0UwefCShpU571suGRgv6KLXt9pGzjNJiaVRXpOVs4ZfoGL9 j+8Q== 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=pRfd+wOd4qoxNAST21yPZCThPxUu/7bAGiKFZOKY6d8=; b=fK3iLe8bGZhI8Ej6KCPuH9zmeYgVHOmmeFqri+KGA5CAjVGGBI//faxVshlrbalnG6 P6DnVRuy5OMRsvUiuMEOVJd2wBI5dOn6Jdd/XhFvCYXoihldkdPFp596FDRK2jtDFqqJ oS8vc3xSpxds1eC6qCI7tu9qPJMk3IRmotyLnY1YLPLTg/wL4OIU7OCfb+EPaAZk5n26 U82A5+xzHFnqvIeuCNPW1YjPipPpCaBK5BWsJuY/DJ6yQlkq/W3YNQUPpic/5ZIZT4T5 x5wo8fI3x9bJDcTS/Pve5agALpxMCQswzHYH5fuMIGWh3zE1dnRsHIGaRgJx407J7Y4f aqnw== X-Gm-Message-State: AOAM533ENIhUdL1lBSKOk0PM4kdmw/eQ7XCoSQh4Kpd/rjany7A1mYq/ AKrRhryEE+/Hwclwk4BkHmI= X-Google-Smtp-Source: ABdhPJwgpAER6R3GgfwWJo6MkscSPav2zxnCK/y1FAkldOUG8y4v39OSNPDocMiAl+h9muoqcInf6w== X-Received: by 2002:a62:e315:0:b029:243:e499:d5ba with SMTP id g21-20020a62e3150000b0290243e499d5bamr28410928pfh.75.1618349081432; Tue, 13 Apr 2021 14:24:41 -0700 (PDT) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id fw24sm3069345pjb.21.2021.04.13.14.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 14:24:40 -0700 (PDT) From: Yang Shi To: mgorman@suse.de, kirill.shutemov@linux.intel.com, ziy@nvidia.com, mhocko@suse.com, ying.huang@intel.com, hughd@google.com, gerald.schaefer@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, borntraeger@de.ibm.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v2 PATCH 6/7] mm: migrate: check mapcount for THP instead of ref count Date: Tue, 13 Apr 2021 14:24:15 -0700 Message-Id: <20210413212416.3273-7-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210413212416.3273-1-shy828301@gmail.com> References: <20210413212416.3273-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: D37BFC0007C1 X-Stat-Signature: hcmq5uzu7ssi6yqzcs357q9kbmiwxb3m Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf22; identity=mailfrom; envelope-from=""; helo=mail-pg1-f179.google.com; client-ip=209.85.215.179 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618349078-276130 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: The generic migration path will check refcount, so no need check refcount here. But the old code actually prevents from migrating shared THP (mapped by multiple processes), so bail out early if mapcount is > 1 to keep the behavior. Signed-off-by: Yang Shi --- mm/migrate.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index a72994c68ec6..dc7cc7f3a124 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2067,6 +2067,10 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) VM_BUG_ON_PAGE(compound_order(page) && !PageTransHuge(page), page); + /* Do not migrate THP mapped by multiple processes */ + if (PageTransHuge(page) && page_mapcount(page) > 1) + return 0; + /* Avoid migrating to a node that is nearly full */ if (!migrate_balanced_pgdat(pgdat, compound_nr(page))) return 0; @@ -2074,18 +2078,6 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) if (isolate_lru_page(page)) return 0; - /* - * migrate_misplaced_transhuge_page() skips page migration's usual - * check on page_count(), so we must do it here, now that the page - * has been isolated: a GUP pin, or any other pin, prevents migration. - * The expected page count is 3: 1 for page's mapcount and 1 for the - * caller's pin and 1 for the reference taken by isolate_lru_page(). - */ - if (PageTransHuge(page) && page_count(page) != 3) { - putback_lru_page(page); - return 0; - } - page_lru = page_is_file_lru(page); mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + page_lru, thp_nr_pages(page));