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 DDF35C433F5 for ; Fri, 4 Mar 2022 18:30:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77D1A8D0002; Fri, 4 Mar 2022 13:30:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7035C8D0001; Fri, 4 Mar 2022 13:30:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A58F8D0002; Fri, 4 Mar 2022 13:30:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0232.hostedemail.com [216.40.44.232]) by kanga.kvack.org (Postfix) with ESMTP id 44F3E8D0001 for ; Fri, 4 Mar 2022 13:30:49 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 024F68249980 for ; Fri, 4 Mar 2022 18:30:49 +0000 (UTC) X-FDA: 79207545018.29.2890CF4 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf21.hostedemail.com (Postfix) with ESMTP id 8DED01C0011 for ; Fri, 4 Mar 2022 18:30:48 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id ev16-20020a17090aead000b001bc3835fea8so8739832pjb.0 for ; Fri, 04 Mar 2022 10:30:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=4TXeZfUVYIjCnHQMV6GLGvwrY0CWJzDnslUJHUckzkQ=; b=JbrcThimgiaKc5S2YQMaLPzVI7b4VpmiL4LZyRwYBbYzH35zGMw49m0tLZRCurJ9QP F74959iH9i2Rkb6nxh59Zu2oQp03sindhh36rPwErHSj6CBwRTlbz740QEXrOfLk7GpE oOUJdvhK3UCpAqWFjXQiZ4vDwG5gMQUgz2H9LKLieqiMmteTFE1ZOOhVWGZIWa3NSgZC qXFk0I7pPC73+c3IqozDVhvEgAr7JgDlPGG+ZEWmN5bzWPhftUdk3B+cWpwJsKLfXgjS WCaMdevWEJGtkqmlgREDvYSdNsedckjjpxhS07+ERSFtstRzWvWwvWOt9jS0/oC7gOSP xxfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=4TXeZfUVYIjCnHQMV6GLGvwrY0CWJzDnslUJHUckzkQ=; b=GNxW9aRfX1uCDW51EjuTvZvgUgFPjZmGPU5QlCiA/xMxOAsjECls51WHEJqDy+Mm7w 9oP5Yeaz9ZQaFWSBoXv+lQ/PxpqYgxi0CfW6cvXQLGt/5eYDxYX8pXAMEP35GYvLE9eL kXksYcb7MNvREsCUbRMN+tBfUh83A9OMJ84C+el69WSBwsPfd/iWgFt5umAcKJdQCgRi v7oOVlj2lAzyPJArGqT1m2Y5CrpPO6jv6qMdpRATPZemn0RRgtf+PzeI7BTdmaIaao9Z n2azuEZ86sATu5kfAEXau3GKCIJEmQK61VNd7z3Z2NZqTvQqqGP9IP+l4hlGJmFbNHig K0AA== X-Gm-Message-State: AOAM531S6NwGVWqqnkl43Ca1FlXSZcc8kMyxvPzhl66MKseev7cbioZ9 W6T7IXFGQRdaOsPguA2LOHZrjbosQ5i0p0ZE9Mo= X-Google-Smtp-Source: ABdhPJx6A0futcYkk5JbU5g+4xbv7vqSLzojRm+OEOU8dYMdPjKY5ewTBjlJRcXONf/pStKwe/8/5CfaySChj1JsAxk= X-Received: by 2002:a17:90b:4f8f:b0:1bf:ac1:2016 with SMTP id qe15-20020a17090b4f8f00b001bf0ac12016mr10854185pjb.21.1646418647497; Fri, 04 Mar 2022 10:30:47 -0800 (PST) MIME-Version: 1.0 References: <20220303222014.517033-1-shy828301@gmail.com> In-Reply-To: From: Yang Shi Date: Fri, 4 Mar 2022 10:30:35 -0800 Message-ID: Subject: Re: [PATCH] mm: thp: don't have to lock page anymore when splitting PMD To: David Hildenbrand Cc: Andrea Arcangeli , Andrew Morton , Hugh Dickins , "Kirill A. Shutemov" , Linux Kernel Mailing List , Linux MM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 8DED01C0011 X-Stat-Signature: sxc7teg76sz7yst76p85x3n8tw9g68eo Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=JbrcThim; spf=pass (imf21.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1646418648-840691 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 Thu, Mar 3, 2022 at 9:06 PM David Hildenbrand wrote: > > Hi, > > This probably bounces on the list due to html junk from the gmail app. > > What happened to > > https://lore.kernel.org/linux-mm/20220131162940.210846-10-david@redhat.co= m/ > > Included in the very series mentioned below? > > Was this silently dropped due to folio conversion collisions? :/ I really didn't notice you already proposed this. Maybe folio conversion, maybe mlock cleanup, I can't tell. But anyway this patch needs to get rebased. I will submit v2 to solve the comment, will add your signed-off-by. > > Yang Shi schrieb am Do. 3. M=C3=A4rz 2022 um 23:20: >> >> 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@redha= t.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 =3D false; >> - pmd_t _pmd; >> >> mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->v= m_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 !=3D page_folio(pmd_page(*pmd))) >> - goto out; >> - } >> + if (folio && folio !=3D page_folio(pmd_page(*pmd))) >> + goto out; >> >> -repeat: >> - if (pmd_trans_huge(*pmd)) { >> - if (!folio) { >> - folio =3D page_folio(pmd_page(*pmd)); >> - /* >> - * An anonymous page must be locked, to ensure t= hat a >> - * concurrent reuse_swap_page() sees stable mapc= ount; >> - * 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 =3D *pmd; >> - spin_unlock(ptl); >> - folio_lock(folio); >> - spin_lock(ptl); >> - if (unlikely(!pmd_same(*pmd, _pm= d))) { >> - folio_unlock(folio); >> - folio_put(folio); >> - folio =3D NULL; >> - goto repeat; >> - } >> - folio_put(folio); >> - } >> - do_unlock_folio =3D 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() callb= ack. >> * They are 3 cases to consider inside __split_huge_pmd_locked()= : >> -- >> 2.26.3 >>