From patchwork Thu Aug 11 16:13:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12941585 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 AC224C25B0C for ; Thu, 11 Aug 2022 16:13:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 186278E0007; Thu, 11 Aug 2022 12:13:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EA6E8E0002; Thu, 11 Aug 2022 12:13:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2ECD8E0007; Thu, 11 Aug 2022 12:13:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C933D8E0002 for ; Thu, 11 Aug 2022 12:13:43 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A8AFCA01E5 for ; Thu, 11 Aug 2022 16:13:43 +0000 (UTC) X-FDA: 79787807526.05.A319BE4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 4CEB21C00A1 for ; Thu, 11 Aug 2022 16:13:43 +0000 (UTC) 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-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-495-fCrgAFvOO4WfZRXT-7vg0g-1; Thu, 11 Aug 2022 12:13:41 -0400 X-MC-Unique: fCrgAFvOO4WfZRXT-7vg0g-1 Received: by mail-io1-f72.google.com with SMTP id i3-20020a5d8403000000b0067bd73cc9eeso9781048ion.19 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=wD+FXJJ3FkmSliBA18+Owxfpsdi8aSpwZ3GA/08/R9APfHF8J38PNRLPtvNZYOufbf DHCQLcJMa2XNyQ/SWInvclfcGAHBGGht7BReNctC3Yl56z0/YnKbIGjrKyV99NkQ5LXx bFb71axBbCUyw8guuVswQAqcj0KHPgnLvh8QZVyw7z1SGcqqt7JxsiV0SBkt6S5TN//j LlEgYXoOIxFfrlJgi0SXlz+nyRfhSN5Y1OLZXZ0vs+3rjyXvtHUABOJIoaPItvlDMhze G6PSh1Ewu+r73IXotfvOok+I/HbNuE7bMTIs7hqZK0up2SSOMjHx1GTcatsYxI+GOMX4 TZQg== X-Gm-Message-State: ACgBeo0JbWRsb7XymeWiGOdbk7LuF9qOMmj+dJ6xl+PZH7IgbNbiRO2/ qAuSLi4+w4VJbrBtWqdbi6GnJFR1EIClh/joo43VhXb6ZpVoVGUdp6x689B3UOdlsJ1rPce7DBr Dm0xz7Y1DIk1UFEGRdXmieB6iW8akcqfWKFHEAuAO2jv0O3JM/3b4GFT/6DrC X-Received: by 2002:a6b:c343:0:b0:67c:6033:a682 with SMTP id t64-20020a6bc343000000b0067c6033a682mr26018iof.148.1660234420987; 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660234423; a=rsa-sha256; cv=none; b=oJhttAKEIyFTIMQTEFV+j+XSib32z+LT9faYSAjG5pO9o9bXQP7C1h0HCqtQOJFZF6zMxl NxwW24GOL3gscOvUdXKSTrghiHN3EZdpylUn0YtEQDXiN5NZ92llZEWHKgxOP44MKMYl2t sK3Fx3GQ/UJIavZsUalkmSw2tRSF43o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660234423; h=from:from:sender: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:dkim-signature; bh=3RIarNO4bl/SlYdwgU6TGCIMSMDAhYZFkoNFGsJp8ZY=; b=w/GmQB9+SCSXC5ekhT8UTdULptEo7wc/xsgDzuXB2njw7TKZORJq9gbAwaht5y28aVNB9m 3FTgzJcooHyC5boUSGSfK+muh4sKJXeTymXUpfLTNQlIXXicDh+lj/G9hMP7nR5hApW908 EMs1AMg6r4l+mNtEoC5cOpo7q53nDf8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ve3XDgeH; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: mseep5u6z6ujyt4xofwad818mjfe174e X-Rspamd-Queue-Id: 4CEB21C00A1 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ve3XDgeH; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1660234423-882153 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: 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_struct *vma, pmd_t *pmd, pgtable_t pgtable; pmd_t old_pmd, _pmd; bool young, write, soft_dirty, pmd_migration = false, uffd_wp = false; - bool anon_exclusive = false; + bool anon_exclusive = false, dirty = false; unsigned long addr; int i; @@ -2116,8 +2116,10 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, uffd_wp = pmd_swp_uffd_wp(old_pmd); } else { page = pmd_page(old_pmd); - if (pmd_dirty(old_pmd)) + if (pmd_dirty(old_pmd)) { + dirty = true; SetPageDirty(page); + } write = pmd_write(old_pmd); young = pmd_young(old_pmd); soft_dirty = pmd_soft_dirty(old_pmd); @@ -2183,6 +2185,9 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, entry = pte_wrprotect(entry); if (!young) entry = pte_mkold(entry); + /* NOTE: this may set soft-dirty too on some archs */ + if (dirty) + entry = pte_mkdirty(entry); if (soft_dirty) entry = pte_mksoft_dirty(entry); if (uffd_wp)