From patchwork Tue Aug 9 22:00:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12939967 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 029D7C19F2D for ; Tue, 9 Aug 2022 22:01:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0E058E0008; Tue, 9 Aug 2022 18:01:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A094B8E0007; Tue, 9 Aug 2022 18:01:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80D738E0008; Tue, 9 Aug 2022 18:01:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 603C28E0001 for ; Tue, 9 Aug 2022 18:01:13 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1C326C12B1 for ; Tue, 9 Aug 2022 22:01:13 +0000 (UTC) X-FDA: 79781425626.20.17C2564 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id B244B20184 for ; Tue, 9 Aug 2022 22:01:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660082470; 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=KrXV1mhD8NFSPZwAf9c4FL2hL9qvLlZq2jcNtWuZzdA=; b=YWQlnY9GGa44oSDEKV+26Vjp8Ia44VGC1qVFzT6lr+WhlET05t0YRfya4RNVcyjEkSOXju bI3FY4OiuoGNUquJ13Yz/SDv2WDzL2hX0fQw/eYNcuPGnSdJMYd/XaYbYgc2M93Gc2l507 LZ9jrkmiOXE2diKDFvwZSuSDGD8FUAE= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-191-pFteTs01MJqzzbBycbxJtg-1; Tue, 09 Aug 2022 18:01:09 -0400 X-MC-Unique: pFteTs01MJqzzbBycbxJtg-1 Received: by mail-qv1-f70.google.com with SMTP id u9-20020a0cec89000000b0047498457e00so6903852qvo.3 for ; Tue, 09 Aug 2022 15:01:09 -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=KrXV1mhD8NFSPZwAf9c4FL2hL9qvLlZq2jcNtWuZzdA=; b=0XyJxXuLxtvwGZYfmZJyNilH/RfpiwPUpQHS5aXdFS/mpcY9ZJdGc6eajpK0sYA5uo x3dh/2X40FFMsC3P4lRYyBgsKCuuwcfm3sMFPvFAQPwjV1LkFDl/ZQmc1+qQk8iybECx /3SPkmb/gk14/KV4NxHxavTFzV8e7sBxufbmdH7Y/mgm9p33uhpHXvsPJAgo5NW4LJ9I lcgDf9e1U4qzuyOJ44qLuuigiEZEpAcuW1wueTEqRRfc2kNhJZANq45tdId8+7kzujzn A6A4ptyvix7SVaoPDVztqEXQM8wqeFgDOgSuXQ2l9+fBV7TGkKSFzhvcZiaYd6nXx/b/ V67Q== X-Gm-Message-State: ACgBeo35dRFERT7FdY6HhEXTD7FFwKIR8/OWapzj45AcjMo0+0ilTGdr H9SdZMoznZq4EUtXNdorKLbxof4yZrdJL4X9hjJ0hzQUw/FxQ+SM097knMy17eETDy8DNSBMQig MVBRxoaVpvZNlUp+F+P9zka9fcqGVUejs02GcTFVIMJ5UT7FQ2lhALdvrh83e X-Received: by 2002:a05:6214:f24:b0:476:72bb:2473 with SMTP id iw4-20020a0562140f2400b0047672bb2473mr21833898qvb.82.1660082468671; Tue, 09 Aug 2022 15:01:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR53TiwBc9GpPqRdwAZDQe2UaVr8TnIHRxStNg8j6qBByy+9hjyDW7m38tabiWtpuwTjDL75Bw== X-Received: by 2002:a05:6214:f24:b0:476:72bb:2473 with SMTP id iw4-20020a0562140f2400b0047672bb2473mr21833862qvb.82.1660082468439; Tue, 09 Aug 2022 15:01:08 -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 b16-20020a05622a021000b0031eddc83560sm10563383qtx.90.2022.08.09.15.01.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 09 Aug 2022 15:01:08 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Minchan Kim , David Hildenbrand , Nadav Amit , Andrew Morton , Hugh Dickins , Vlastimil Babka , Andrea Arcangeli , Andi Kleen , Huang Ying , "Kirill A . Shutemov" Subject: [PATCH v3 4/7] mm/thp: Carry over dirty bit when thp splits on pmd Date: Tue, 9 Aug 2022 18:00:57 -0400 Message-Id: <20220809220100.20033-5-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220809220100.20033-1-peterx@redhat.com> References: <20220809220100.20033-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=1660082472; a=rsa-sha256; cv=none; b=3rzBzjAfxnLoZRJaliRK/70BKN9gl9HFbtsGFCNMZIq8gopFEiq/KAH31he1HrJQjZ7zpj UxBk4CtGuf78P7PlS3OmGtffjxLNT1eNOmeq/5w1kDg2a/T+/uvptVgp7DDoQV7UmUbU/h Z2cOhGrqAhtOQhCcViymM8BqJYS1K/o= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YWQlnY9G; spf=pass (imf03.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660082472; 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=KrXV1mhD8NFSPZwAf9c4FL2hL9qvLlZq2jcNtWuZzdA=; b=eRUqXF539fcacGcBGSKDVg5BJUNgWr2zZhBpeQRcdxRiyDk2mtQDc6kOpaDZ71vwS7ZRSr o5//rVfFL8Z8KZamamLguUoT3d6qZwIM5uuk4OgOXn7yebr1hqwHZ89/T0SiDUvJokvvr4 ngLZow0lcj2/Z2Snu6A1IrC5NvSTF68= X-Rspamd-Queue-Id: B244B20184 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YWQlnY9G; spf=pass (imf03.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-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: eeux6b4bms3pqogm5hs3a36hby1rn5an X-HE-Tag: 1660082470-465105 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. Signed-off-by: Peter Xu Reviewed-by: "Huang, Ying" --- mm/huge_memory.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 0611b2fd145a..e8e78d1bac5f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2005,7 +2005,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; @@ -2098,6 +2098,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, SetPageDirty(page); write = pmd_write(old_pmd); young = pmd_young(old_pmd); + dirty = pmd_dirty(old_pmd); soft_dirty = pmd_soft_dirty(old_pmd); uffd_wp = pmd_uffd_wp(old_pmd); @@ -2161,6 +2162,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)