From patchwork Tue May 18 20:08:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12265593 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 34E01C43460 for ; Tue, 18 May 2021 20:08:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DFCDB6108D for ; Tue, 18 May 2021 20:08:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFCDB6108D 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 7D70A8E004C; Tue, 18 May 2021 16:08:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AF568E002F; Tue, 18 May 2021 16:08:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6532F8E004C; Tue, 18 May 2021 16:08:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id 244308E002F for ; Tue, 18 May 2021 16:08:32 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B14308249980 for ; Tue, 18 May 2021 20:08:31 +0000 (UTC) X-FDA: 78155439222.27.04A2873 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf02.hostedemail.com (Postfix) with ESMTP id 1FFA44080F55 for ; Tue, 18 May 2021 20:08:28 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id t4so5735618plc.6 for ; Tue, 18 May 2021 13:08:31 -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=Bft5/S3sIep+UIOe0wjEBCs4qeqthplQvAas8/8e+yo=; b=nHLS3OJzElgnE2B/Z8SKCricVXLIx3iJxQjJ0syYMD0st4Cu/HagKgnXREM54zswjw XMNbtKvBMaoANopTaCd8U7u2Hm86+M3RuZtminAUpNjSsKZa0ANHy7i82oYV5IUBo3y5 9as9AvR0a6Tf/pms+EH7p0fkg0BSIgxX0pHVwN8P5Wx2tzfzJWe1qn5USVLiIJCq+FuE BSJupLShAnX1rbhtkb46N4UqYZ8EQt19Oxj+xOEtlDuZCPe1a2dfSKZZsE6riRl+RTUN VZadMbE778WhVEQIFJBh5I6kdzgTgYVgZZeinQpMkA7oXwHQKhc9R+s52vZyIwRN3/vc 4HjQ== 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=Bft5/S3sIep+UIOe0wjEBCs4qeqthplQvAas8/8e+yo=; b=fLbtqtFlCmDFJ4mwcaUeBeBA7ZCbdfd4ES2I6hkqjBa/Unb9V6EU24xRknyGM1c9Rz CeizyIYHM2UVZIIAwT32w80nS2HEoQLwGVN/LN2codncQSXb7e0jxgxB8yLFdvor1RoX rHL8gqOWruIE7kWeuFD109grbzuZ8pEjfpFcK3HF3Glmim1OmR8nrJ5NcXL745Tjqfw+ 7OC0IFJCHb7yHXniBsaHPmhZKgMDuBaqLi2zobWZMXbDBRI1RFprLLhklUImjHsPGAse n0QKEscWZbjj0pjSUWkaXaOYSi4Hr5q57ZugScr9FCud/r33bXE1ubIOB0mG95K8QvQG j3ww== X-Gm-Message-State: AOAM530wynkR/sQMNMQW4PNr6BfftG+Hv+pc+VQq9vjgNbkbeYTMOcWi UYKF58AcoDPy9+zCbhZo/zw= X-Google-Smtp-Source: ABdhPJycucOy8RWBt3ZSLaK0DULZYOHapGP8SDJZBX29cfFbM7ELURa2SaI9yfmt82bS4uEWVqBwiA== X-Received: by 2002:a17:902:e007:b029:ef:9dd2:be6 with SMTP id o7-20020a170902e007b02900ef9dd20be6mr6495035plo.12.1621368510709; Tue, 18 May 2021 13:08:30 -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 r11sm13456600pgl.34.2021.05.18.13.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 13:08:29 -0700 (PDT) From: Yang Shi To: mgorman@suse.de, kirill.shutemov@linux.intel.com, ziy@nvidia.com, ying.huang@intel.com, mhocko@suse.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: [v3 PATCH 6/7] mm: migrate: check mapcount for THP instead of refcount Date: Tue, 18 May 2021 13:08:00 -0700 Message-Id: <20210518200801.7413-7-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210518200801.7413-1-shy828301@gmail.com> References: <20210518200801.7413-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1FFA44080F55 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=nHLS3OJz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf02.hostedemail.com: domain of shy828301@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspamd-Server: rspam03 X-Stat-Signature: o5mdnzr654pn7cwurb8hcefiswx85p5r X-HE-Tag: 1621368508-542250 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 035daaec1ca0..77215f28502b 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2070,6 +2070,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) && total_mapcount(page) > 1) + return 0; + /* Avoid migrating to a node that is nearly full */ if (!migrate_balanced_pgdat(pgdat, compound_nr(page))) return 0; @@ -2077,18 +2081,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));