From mboxrd@z Thu Jan 1 00:00:00 1970 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 B88F0C433EF for ; Fri, 4 Mar 2022 03:44:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 463CB8D0003; Thu, 3 Mar 2022 22:44:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3ED298D0001; Thu, 3 Mar 2022 22:44:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28DD58D0003; Thu, 3 Mar 2022 22:44:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 16D6A8D0001 for ; Thu, 3 Mar 2022 22:44:51 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id E1C7112081A for ; Fri, 4 Mar 2022 03:44:50 +0000 (UTC) X-FDA: 79205312340.01.0533E58 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf15.hostedemail.com (Postfix) with ESMTP id ED6F3A0857 for ; Fri, 4 Mar 2022 03:41:14 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K8s5x3gxNzZdbj; Fri, 4 Mar 2022 10:20:53 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 10:25:35 +0800 Subject: Re: [PATCH] mm: thp: don't have to lock page anymore when splitting PMD To: Yang Shi CC: , , , , , , References: <20220303222014.517033-1-shy828301@gmail.com> From: Miaohe Lin Message-ID: <78dab4e0-1d68-c54b-2463-c0a5420b07d9@huawei.com> Date: Fri, 4 Mar 2022 10:25:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20220303222014.517033-1-shy828301@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: ED6F3A0857 X-Stat-Signature: ybeo4cj7nsy5zzwki4jyrr6xsyatnbyg Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspam-User: X-HE-Tag: 1646365274-595496 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: On 2022/3/4 6:20, Yang Shi wrote: > 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. > Sounds reasonable. Since mapcount is not used to determine if we need to COW the page, PMD split doesn't have to lock the page anymore. > [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); IUUC, here should be something like below: if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd) || is_pmd_migration_entry(*pmd)) __split_huge_pmd_locked(vma, pmd, range.start, freeze); i.e. the pmd_trans_huge case is missing in the above change. Or am I miss something ? Thanks for the patch. This really simplify the code and avoid the unneeded overhead. > 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(): >