From patchwork Fri Mar 12 08:38:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12133983 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 AC011C433DB for ; Fri, 12 Mar 2021 08:39:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5524264FA9 for ; Fri, 12 Mar 2021 08:39:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5524264FA9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EE6D68D0335; Fri, 12 Mar 2021 03:39:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E9A128D0317; Fri, 12 Mar 2021 03:39:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC5D38D0335; Fri, 12 Mar 2021 03:39:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id 9AF1E8D0317 for ; Fri, 12 Mar 2021 03:39:30 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4DD8C181B04AD for ; Fri, 12 Mar 2021 08:39:30 +0000 (UTC) X-FDA: 77910573300.19.664AA81 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2054.outbound.protection.outlook.com [40.107.223.54]) by imf22.hostedemail.com (Postfix) with ESMTP id C2FCAC0001FE for ; Fri, 12 Mar 2021 08:39:26 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KOip/FrPM1U4OEg16sLhlWvaI2B1gjBP262cxPh8xJLAGo7+cQbq4WSijhs4YIjF5lileM/KaZJm+H9nnWd1tVLCWnVOs4yRIT86+zeP+S8CgemiaJP1vIyEmQgDEF4SRwkVMxyIlWPB+u2iuaVRfWN7ZRHYkqzeZGguj7PpF8j2C2vYSBydkdmGBisrtYr4bjpdJ5FBBYpEhlTHdxPhlwI/nanzl5kHy5DpetFkK9Eqf4kGWrAKL1ltr11pIteU6vkOKxiGxURTrZIV9i5jZ7brPCk9Mx+F1htxqgrBPsY4zZ57CcR6wxFOMXiWvfYe98BhwnaxB737cstiEHj9hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ma2SIhuD2Q07N2hePYNkgTrRVySBPkOjh8cT+Sy5R8A=; b=YeIYAa34bPcvfOfLVgbKHxiKr/J9Jj8QX4MVYeuSSzDpRY845mul444HsCL2d77ZzzstdeOTZ38EAN8vZkMc27c9nm/AfKGqGyjO1dOom4KZkQNls2HRms7XTKrA9ct+uPJLFgWqDAuHB6kFowJQqwVbngk7B37f/nIPNaCLZQ9+VEUUhiaBpeXW+5MzENPj5Lblpbr/WO2oK7uydhk3mCPMmKIEJ2ZOGOqTwtr/ANcoxm6iJgT6kt+Jz23j+xbG4xtv5XCMPVE+j0icE9JczYuyq2qC2hpqqIhhuTXn3Lm5C8HVux3OAaaUXN6mFUq5o2EaUu0JIvHhaims7mIXFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ma2SIhuD2Q07N2hePYNkgTrRVySBPkOjh8cT+Sy5R8A=; b=og1dJgFjz84x7iMzvsnKpxygQaYYsLBa0n35RzxjbraxnyVfUEL1GN8lXIDdc3xqq+03MF1Ay3KxdqtsvIcWduXCBeWw4XOur4T/8Crm/1TNeEebKSgdxUrvVI1EH4ygpb5I2OYHVPjE4c/UotS6PLXqWYyb63l9uc9yHkyMmsk/vv5bIMdFk67lNWdPtxPYv2XHd5JBLpAVroljcoU+itNDiNZ7edxoxPw72rvwuriGPlEXjLSJNoOERS0oa0XpcOEKAA3PnBOfP6fEDj1/9dUc68IqUvn8V+9O8BCsuYWmc3ZFgVqxEB454Ekt+V4tKwPjy/ewVuSmjlAw9Oi7JA== Received: from DM5PR06CA0089.namprd06.prod.outlook.com (2603:10b6:3:4::27) by CH2PR12MB3957.namprd12.prod.outlook.com (2603:10b6:610:2c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17; Fri, 12 Mar 2021 08:39:25 +0000 Received: from DM6NAM11FT004.eop-nam11.prod.protection.outlook.com (2603:10b6:3:4:cafe::bb) by DM5PR06CA0089.outlook.office365.com (2603:10b6:3:4::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Fri, 12 Mar 2021 08:39:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT004.mail.protection.outlook.com (10.13.172.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.3933.31 via Frontend Transport; Fri, 12 Mar 2021 08:39:25 +0000 Received: from localhost (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 12 Mar 2021 08:39:24 +0000 From: Alistair Popple To: , , , CC: , , , , , , , , , , , Alistair Popple Subject: [PATCH v6 3/8] mm/rmap: Split try_to_munlock from try_to_unmap Date: Fri, 12 Mar 2021 19:38:46 +1100 Message-ID: <20210312083851.15981-4-apopple@nvidia.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210312083851.15981-1-apopple@nvidia.com> References: <20210312083851.15981-1-apopple@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5d1ffd88-81b4-41f1-67d7-08d8e53257ce X-MS-TrafficTypeDiagnostic: CH2PR12MB3957: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yjP7KLsmqntbmCaT2B9DzNxHoMVR8jGUnZp2BYu44nIrJGdxeYGBILS5IQESh7ulpDkW6PIMI6IkRaRjDa9FD1KUw7M0qomkns7JpgGYpt1szWlLzbg9LTBQoYuwpR6dLKujrPXSR2poLjpzxtjA5wLgYdrxook3IUzCz5WZm7D72y9obXU7WiRC/OrSjKppxpLptGoDe8VdUF0pfDsT75aRW0t2TI5FdKHVeOzxFMMxc1BgDP1zOj6Q1E3kZHKuYw2mdXtkJ+rhPSiLBNSSwirwX0ojUS9mb4BvYUOnT4fjiURyOdon5YLfuz7n/8ex72jSxpbj/pKZNkA2qlfy3NkE5mmaPHoQ3QAaWkEUy5EzsoTDvvzZOOlkmDfTEQmviTVGnMma8qjZGtUkpXnfw9+N/JTxf6Uq5LdB3OZSp2W3uoN1vtMMEc8JZhHURK03BNZleaR1F6kwJDPEVYbN5UR92YD58nayoCJiKCt5qCJHPzl2taCfv2tAdpmK/N8tqFAuSw58yJYPdQPykhg55es7ltoKI/JkI6zb1Lbnf1U8gE+zOowpQLnJlL7HztXJu2zolG3vTKTeTzsfWpy9ybTg4v24sqEkdQrdqv24Zd0qHYOj6aSNkipT3CvW2Bgw95L4D6A+djp5+Vu4qo9+PG8HCL22k57z/AEDUVq/kbNohjbpF1MHP8nvcOv3taX5 X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(136003)(396003)(346002)(376002)(39860400002)(46966006)(36840700001)(8936002)(26005)(8676002)(16526019)(70206006)(36860700001)(186003)(110136005)(54906003)(2616005)(70586007)(82740400003)(107886003)(4326008)(336012)(7636003)(47076005)(356005)(34020700004)(36756003)(7416002)(316002)(36906005)(83380400001)(86362001)(478600001)(5660300002)(426003)(2906002)(6666004)(82310400003)(1076003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2021 08:39:25.5326 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5d1ffd88-81b4-41f1-67d7-08d8e53257ce X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT004.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3957 X-Stat-Signature: moz6eiw4yg4a6ciwb63c4bedw1e99khs X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C2FCAC0001FE Received-SPF: none (nvidia.com>: No applicable sender policy available) receiver=imf22; identity=mailfrom; envelope-from=""; helo=NAM11-DM6-obe.outbound.protection.outlook.com; client-ip=40.107.223.54 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615538366-495791 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 behaviour of try_to_unmap_one() is difficult to follow because it performs different operations based on a fairly large set of flags used in different combinations. TTU_MUNLOCK is one such flag. However it is exclusively used by try_to_munlock() which specifies no other flags. Therefore rather than overload try_to_unmap_one() with unrelated behaviour split this out into it's own function and remove the flag. Signed-off-by: Alistair Popple Reviewed-by: Ralph Campbell Reviewed-by: Christoph Hellwig --- Christoph - I didn't add your Reviewed-by from v3 because removal of the extra VM_LOCKED check in v4 changed things slightly. Let me know if you're still ok for me to add it. Thanks. v4: * Removed redundant check for VM_LOCKED --- include/linux/rmap.h | 1 - mm/rmap.c | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index def5c62c93b3..e26ac2d71346 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -87,7 +87,6 @@ struct anon_vma_chain { enum ttu_flags { TTU_MIGRATION = 0x1, /* migration mode */ - TTU_MUNLOCK = 0x2, /* munlock mode */ TTU_SPLIT_HUGE_PMD = 0x4, /* split huge PMD if any */ TTU_IGNORE_MLOCK = 0x8, /* ignore mlock */ diff --git a/mm/rmap.c b/mm/rmap.c index 977e70803ed8..d02bade5245b 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1405,10 +1405,6 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, struct mmu_notifier_range range; enum ttu_flags flags = (enum ttu_flags)(long)arg; - /* munlock has nothing to gain from examining un-locked vmas */ - if ((flags & TTU_MUNLOCK) && !(vma->vm_flags & VM_LOCKED)) - return true; - if (IS_ENABLED(CONFIG_MIGRATION) && (flags & TTU_MIGRATION) && is_zone_device_page(page) && !is_device_private_page(page)) return true; @@ -1469,8 +1465,6 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, page_vma_mapped_walk_done(&pvmw); break; } - if (flags & TTU_MUNLOCK) - continue; } /* Unexpected PMD-mapped THP? */ @@ -1784,6 +1778,37 @@ bool try_to_unmap(struct page *page, enum ttu_flags flags) return !page_mapcount(page) ? true : false; } +static bool try_to_munlock_one(struct page *page, struct vm_area_struct *vma, + unsigned long address, void *arg) +{ + struct page_vma_mapped_walk pvmw = { + .page = page, + .vma = vma, + .address = address, + }; + + /* munlock has nothing to gain from examining un-locked vmas */ + if (!(vma->vm_flags & VM_LOCKED)) + return true; + + while (page_vma_mapped_walk(&pvmw)) { + /* PTE-mapped THP are never mlocked */ + if (!PageTransCompound(page)) { + /* + * Holding pte lock, we do *not* need + * mmap_lock here + */ + mlock_vma_page(page); + } + page_vma_mapped_walk_done(&pvmw); + + /* found a mlocked page, no point continuing munlock check */ + return false; + } + + return true; +} + /** * try_to_munlock - try to munlock a page * @page: the page to be munlocked @@ -1796,8 +1821,7 @@ bool try_to_unmap(struct page *page, enum ttu_flags flags) void try_to_munlock(struct page *page) { struct rmap_walk_control rwc = { - .rmap_one = try_to_unmap_one, - .arg = (void *)TTU_MUNLOCK, + .rmap_one = try_to_munlock_one, .done = page_not_mapped, .anon_lock = page_lock_anon_vma_read,