From nobody Sat Apr 11 12:30:42 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8F64C19F2A for ; Thu, 11 Aug 2022 16:42:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238963AbiHKQmV (ORCPT ); Thu, 11 Aug 2022 12:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239210AbiHKQlC (ORCPT ); Thu, 11 Aug 2022 12:41:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E5964A5C63 for ; Thu, 11 Aug 2022 09:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660234422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3RIarNO4bl/SlYdwgU6TGCIMSMDAhYZFkoNFGsJp8ZY=; b=Ve3XDgeHzhWl1vN60y2FbtItfPts8jfi6EAA2rmqQ1gwGq9VPqMZmI6sAcqNLeHTob5pkG iDAd1LmFqFFnjYCbLAChj6sLqWTUMIwRseYb37zqxHfPOUPPyhaU6IymFMVG7/h+rLRy/E kiJNpP6QimDI6AA1Jrgf6CmF8y4C9w4= Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-28-Qg9sZUtAONSi6vCROLRXPQ-1; Thu, 11 Aug 2022 12:13:41 -0400 X-MC-Unique: Qg9sZUtAONSi6vCROLRXPQ-1 Received: by mail-io1-f69.google.com with SMTP id j8-20020a6b7948000000b0067c2923d1b8so9797860iop.6 for ; Thu, 11 Aug 2022 09:13:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=3RIarNO4bl/SlYdwgU6TGCIMSMDAhYZFkoNFGsJp8ZY=; b=iQ+q4YCOKNlVEOVMrt0qwc3oHTyKFqITFcXBgCckhFPcJlct/bmFmotRqkF4aQmW3/ shkIQNiJhonnkdWfzJR8PTOWvZ7j3ZSxvu1ILYVg4yWnKVfkdZt8xVIst8Ex+gvuqVrr noolZAnaFWajahyqz1AjiwQbnR3EryqpiR2fC+SDk1SbfRxge3ggXAL9akqhjYGVn2rB mnDXLswuYA+ehlN3nG4jbwC++V4nTe9ayNf3N/OwTUbNsSx2iWGoxeDn3TNgTg9pdsJt JkBhN/Ll9hMB6wwJXAmd6I4JkASk14AoycXaokHBRszBcklZsOzIPvKguE0DombgCmqB 5Ozg== X-Gm-Message-State: ACgBeo2IlN2qCWl7FjnF+H2ITanZL/UFOAh8Jq8YaFpGJ8ZB5MrBsmiF IC1Z8P3T7hdPpS2uGTB+AUj3gokMuoSEELz+WQhPtKR4v1e4CHg1kmyLi2WIsW7ZRxIUhT5NUGn CKgXSeu9MBVoE4oGNgufK+dft X-Received: by 2002:a6b:c343:0:b0:67c:6033:a682 with SMTP id t64-20020a6bc343000000b0067c6033a682mr25999iof.148.1660234420822; Thu, 11 Aug 2022 09:13:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR6oIBb2BB4Q/hh/sdEHHNGipMyiCcZTfi7mlLc8HUt82uGH8takFsvaPCiWYe/hV/AqCvZxHw== X-Received: by 2002:a6b:c343:0:b0:67c:6033:a682 with SMTP id t64-20020a6bc343000000b0067c6033a682mr25990iof.148.1660234420598; Thu, 11 Aug 2022 09:13:40 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id t1-20020a92ca81000000b002dd1c3c5c46sm3415429ilo.73.2022.08.11.09.13.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 11 Aug 2022 09:13:40 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , "Kirill A . Shutemov" , Alistair Popple , peterx@redhat.com, Andrea Arcangeli , Minchan Kim , Andrew Morton , David Hildenbrand , Andi Kleen , Nadav Amit , Huang Ying , Vlastimil Babka Subject: [PATCH v4 4/7] mm/thp: Carry over dirty bit when thp splits on pmd Date: Thu, 11 Aug 2022 12:13:28 -0400 Message-Id: <20220811161331.37055-5-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220811161331.37055-1-peterx@redhat.com> References: <20220811161331.37055-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Carry over the dirty bit from pmd to pte when a huge pmd splits. It shouldn't be a correctness issue since when pmd_dirty() we'll have the page marked dirty anyway, however having dirty bit carried over helps the next initial writes of split ptes on some archs like x86. Reviewed-by: Huang Ying Signed-off-by: Peter Xu --- mm/huge_memory.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 3222b40a0f6d..2f68e034ddec 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2027,7 +2027,7 @@ static void __split_huge_pmd_locked(struct vm_area_st= ruct *vma, pmd_t *pmd, pgtable_t pgtable; pmd_t old_pmd, _pmd; bool young, write, soft_dirty, pmd_migration =3D false, uffd_wp =3D false; - bool anon_exclusive =3D false; + bool anon_exclusive =3D false, dirty =3D false; unsigned long addr; int i; =20 @@ -2116,8 +2116,10 @@ static void __split_huge_pmd_locked(struct vm_area_s= truct *vma, pmd_t *pmd, uffd_wp =3D pmd_swp_uffd_wp(old_pmd); } else { page =3D pmd_page(old_pmd); - if (pmd_dirty(old_pmd)) + if (pmd_dirty(old_pmd)) { + dirty =3D true; SetPageDirty(page); + } write =3D pmd_write(old_pmd); young =3D pmd_young(old_pmd); soft_dirty =3D pmd_soft_dirty(old_pmd); @@ -2183,6 +2185,9 @@ static void __split_huge_pmd_locked(struct vm_area_st= ruct *vma, pmd_t *pmd, entry =3D pte_wrprotect(entry); if (!young) entry =3D pte_mkold(entry); + /* NOTE: this may set soft-dirty too on some archs */ + if (dirty) + entry =3D pte_mkdirty(entry); if (soft_dirty) entry =3D pte_mksoft_dirty(entry); if (uffd_wp) --=20 2.32.0