From patchwork Thu Mar 3 22:20:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12768195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71C62C433EF for ; Thu, 3 Mar 2022 22:20:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B4268D0002; Thu, 3 Mar 2022 17:20:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 863B18D0001; Thu, 3 Mar 2022 17:20:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72BE58D0002; Thu, 3 Mar 2022 17:20:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 664A68D0001 for ; Thu, 3 Mar 2022 17:20:19 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 228FE20A5 for ; Thu, 3 Mar 2022 22:20:19 +0000 (UTC) X-FDA: 79204494558.05.FA14C72 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf27.hostedemail.com (Postfix) with ESMTP id 981EB4000A for ; Thu, 3 Mar 2022 22:20:18 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id 9so6039994pll.6 for ; Thu, 03 Mar 2022 14:20:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=i+jhSHjqTSR2b7tP60Q6oAqpuTejuyJKZJEpX0NApkc=; b=XyAJUTQ4WSbV0ZyMFvjiRuolDwAoBCGZtPOcZOv7DEcHXHhJ299eb8alyt7lrHlu59 CbD3DKrch2N1D3gLJ/bGZE2r5qBFdEiXN7AFlrNeumYPduVhNF6RzWVDmrr1vUjuBJJX N3mhBWlPcKo/qIUnGACQl+mA3ssd1t/Dj/jODZNjNWLv6IWIS/N4ZNTIOCmY1LEHWG5F jB2s9TqRRwLl0ETtLcCEV8fM3IieaSAvH0gxWxn4ATX1kEcbuRwbi/UuA8LnpoSwLHoE O3z1/cByBoQlobWc0WOqoEhtSwwl6cTpNmkGxcVOaN5hBT2rpO63LFIHvjlu0bbXxdxj OuJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=i+jhSHjqTSR2b7tP60Q6oAqpuTejuyJKZJEpX0NApkc=; b=RGUWvtPNZkSAH6jCWAfr2sgcwPuZLs0nLwrPkvBnvBhMxEnyt4x8ENKMaf0uNUhr/l d6/orXQcLu2wfJ8BZGDrVe2llTWpy7xm9qr6kk2fVg3O2cKnAYuFMdyR4P6DPYLhVNiC 77ulYWFslDAhasJ45fbQpKTsyEfd0IUTp6mACUFOLqFlSLa+a3lC8wP8BlQde7fhoWsP rpxDmLuAdjF2pZhiTvNVnMyVeq0aSn3J9eOGB1HZpzQdKMz4DkHLP5RLP1z0D6hU9guY 9++prZKRelixTNZcAT5gwE48jUZvxRNwgeAKxO8ZUE1/N3ly2VPFWI+oi1gyVmoeT+C0 oAJg== X-Gm-Message-State: AOAM530Oqfl5uTPRKcgk/n9y1DWplNtR53I8WGiMfIS63GU0Z3THNPur kTbizRM8eUs3AQO4Jkgyo7g= X-Google-Smtp-Source: ABdhPJwRrG9E7twGHq/irRPt/iu4Nnxg+Oyd48nX0497BwVHi+gDwkd77MOdUbrwvBTRn4gCGupj9A== X-Received: by 2002:a17:903:2342:b0:14f:dec2:9849 with SMTP id c2-20020a170903234200b0014fdec29849mr28439484plh.74.1646346017514; Thu, 03 Mar 2022 14:20:17 -0800 (PST) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id lx7-20020a17090b4b0700b001b7d5b6d10asm2862172pjb.48.2022.03.03.14.20.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 14:20:16 -0800 (PST) From: Yang Shi To: david@redhat.com, aarcange@redhat.com, hughd@google.com, kirill.shutemov@linux.intel.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: thp: don't have to lock page anymore when splitting PMD Date: Thu, 3 Mar 2022 14:20:14 -0800 Message-Id: <20220303222014.517033-1-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: bitw8dmy6wgimmnkqbquhxfp11pon1q5 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=XyAJUTQ4; spf=pass (imf27.hostedemail.com: domain of shy828301@gmail.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Queue-Id: 981EB4000A X-HE-Tag: 1646346018-363788 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 commit c444eb564fb1 ("mm: thp: make the THP mapcount atomic against __split_huge_pmd_locked()") locked the page for PMD split to make mapcount stable for reuse_swap_page(), then commit 1c2f67308af4 ("mm: thp: fix MADV_REMOVE deadlock on shmem THP") reduce the scope to anonymous page only. However COW has not used mapcount to determine if the page is shared or not anymore due to the COW fixes [1] from David Hildenbrand and the reuse_swap_page() was removed as well. So PMD split doesn't have to lock the page anymore. This patch basically reverted the above two commits. [1] https://lore.kernel.org/linux-mm/20220131162940.210846-1-david@redhat.com/ Cc: David Hildenbrand Cc: Andrea Arcangeli Cc: Hugh Dickins Cc: "Kirill A . Shutemov" Signed-off-by: Yang Shi --- mm/huge_memory.c | 44 +++++--------------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index b49e1a11df2e..daaa698bd273 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2134,8 +2134,6 @@ void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, { spinlock_t *ptl; struct mmu_notifier_range range; - bool do_unlock_folio = false; - pmd_t _pmd; mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm, address & HPAGE_PMD_MASK, @@ -2148,48 +2146,16 @@ void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, * pmd against. Otherwise we can end up replacing wrong folio. */ VM_BUG_ON(freeze && !folio); - if (folio) { - VM_WARN_ON_ONCE(!folio_test_locked(folio)); - if (folio != page_folio(pmd_page(*pmd))) - goto out; - } + if (folio && folio != page_folio(pmd_page(*pmd))) + goto out; -repeat: - if (pmd_trans_huge(*pmd)) { - if (!folio) { - folio = page_folio(pmd_page(*pmd)); - /* - * An anonymous page must be locked, to ensure that a - * concurrent reuse_swap_page() sees stable mapcount; - * but reuse_swap_page() is not used on shmem or file, - * and page lock must not be taken when zap_pmd_range() - * calls __split_huge_pmd() while i_mmap_lock is held. - */ - if (folio_test_anon(folio)) { - if (unlikely(!folio_trylock(folio))) { - folio_get(folio); - _pmd = *pmd; - spin_unlock(ptl); - folio_lock(folio); - spin_lock(ptl); - if (unlikely(!pmd_same(*pmd, _pmd))) { - folio_unlock(folio); - folio_put(folio); - folio = NULL; - goto repeat; - } - folio_put(folio); - } - do_unlock_folio = true; - } - } - } else if (!(pmd_devmap(*pmd) || is_pmd_migration_entry(*pmd))) + if (!(pmd_devmap(*pmd) || is_pmd_migration_entry(*pmd))) goto out; + __split_huge_pmd_locked(vma, pmd, range.start, freeze); out: spin_unlock(ptl); - if (do_unlock_folio) - folio_unlock(folio); + /* * No need to double call mmu_notifier->invalidate_range() callback. * They are 3 cases to consider inside __split_huge_pmd_locked():