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 X-Spam-Level: X-Spam-Status: No, score=-24.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFB27C433B4 for ; Sat, 17 Apr 2021 04:31:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 82D3B611AB for ; Sat, 17 Apr 2021 04:31:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229944AbhDQEbv (ORCPT ); Sat, 17 Apr 2021 00:31:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbhDQEbt (ORCPT ); Sat, 17 Apr 2021 00:31:49 -0400 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41181C061574 for ; Fri, 16 Apr 2021 21:31:24 -0700 (PDT) Received: by mail-ot1-x32c.google.com with SMTP id 92-20020a9d02e50000b029028fcc3d2c9eso5131840otl.0 for ; Fri, 16 Apr 2021 21:31:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=W6o2ooVTP+MnLQxjkPC27j4YkCmKuP7UZ0yTK+5vziU=; b=MYCnjeWCAOCBV2A5whTNGk1N7PjQZqQz5hw/cEWj0es8Lvi9HCoB/jo9UZl/iNHCZE mGlFBQZ3fCaE0zl2Dg2RFIG24iLMfOZyUXPjwwJwJfoMNjjKWhGErq//y7K35Y3ZjRZw 0vq2XlJ0hQTSXW5SJVCkm95TrCP3SteqD8zvUGeveXpUxK2ozBn9IPcSTeuWu4PQNAPc lIoWUCQlgAUdRZnbhR9SI9fkKdhb0VCZU9cGAG0cjlJpEIyIHYtEd9asKEpyy0HE4siX SuZcgHO0c5DjIRbDGOcI5QPD3Wn57i9ClJSuAQMREGjGWXU73hd4OECPj7PffJQM63fA 3wcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=W6o2ooVTP+MnLQxjkPC27j4YkCmKuP7UZ0yTK+5vziU=; b=UNSRyT3YkTRn4s30FxhyFBCRq2owXa+l6quRajayfAyxllV/Xvyj8RRQHKcNzwRpmu hdrOr72Lr8KMqJA2PchfCG/wmcTx2XdxIbbVbNBWbuNYXkHZ2sjYZWuJ542XSs9n9+aq U3oTk8fKRL8mfCy0IXGtzzQx1GV1y09FxyNEZmWS6/o/VBYXe5m6ZxhV5z5oOqXUo3Yx XwPsX8mJuOR0jDPK4AyioogQ/ZWQRktx5LZF2kn+/tOfU0bHYKVsoKikYGCEPa+Qs2Qc wcNTBxQkSGjBlOx7ffJ2FBt5FZUvNDqaBPvqaErDmfqkT9TYbuS+sJ8P8EE3fWm67jD7 VaUg== X-Gm-Message-State: AOAM533A+RvoRcEjz/qYF85ZzIrwKhJxMdE/V6tsEN7DbozCwT8r2hmr 9ALQ3eg9mchStF64unysjTcrEA== X-Google-Smtp-Source: ABdhPJyvYn8ZCtwckfRxXZNQrcGUemWroaDuXExJiCBU2JDLDPKzl1qtAgjmrur/IxHHTlF9XIhBhg== X-Received: by 2002:a9d:5a1a:: with SMTP id v26mr5902631oth.50.1618633882669; Fri, 16 Apr 2021 21:31:22 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id t25sm574797otp.4.2021.04.16.21.31.21 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Fri, 16 Apr 2021 21:31:22 -0700 (PDT) Date: Fri, 16 Apr 2021 21:31:08 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Collin Fijalkovich cc: Andrew Morton , songliubraving@fb.com, surenb@google.com, hridya@google.com, kaleshsingh@google.com, hughd@google.com, timmurray@google.com, william.kucharski@oracle.com, willy@infradead.org, Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2] mm, thp: Relax the VM_DENYWRITE constraint on file-backed THPs In-Reply-To: <20210406000930.3455850-1-cfijalkovich@google.com> Message-ID: References: <20210406000930.3455850-1-cfijalkovich@google.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 5 Apr 2021, Collin Fijalkovich wrote: > Transparent huge pages are supported for read-only non-shmem files, > but are only used for vmas with VM_DENYWRITE. This condition ensures that > file THPs are protected from writes while an application is running > (ETXTBSY). Any existing file THPs are then dropped from the page cache > when a file is opened for write in do_dentry_open(). Since sys_mmap > ignores MAP_DENYWRITE, this constrains the use of file THPs to vmas > produced by execve(). > > Systems that make heavy use of shared libraries (e.g. Android) are unable > to apply VM_DENYWRITE through the dynamic linker, preventing them from > benefiting from the resultant reduced contention on the TLB. > > This patch reduces the constraint on file THPs allowing use with any > executable mapping from a file not opened for write (see > inode_is_open_for_write()). It also introduces additional conditions to > ensure that files opened for write will never be backed by file THPs. > > Restricting the use of THPs to executable mappings eliminates the risk that > a read-only file later opened for write would encounter significant > latencies due to page cache truncation. > > The ld linker flag '-z max-page-size=(hugepage size)' can be used to > produce executables with the necessary layout. The dynamic linker must > map these file's segments at a hugepage size aligned vma for the mapping to > be backed with THPs. > > Comparison of the performance characteristics of 4KB and 2MB-backed > libraries follows; the Android dex2oat tool was used to AOT compile an > example application on a single ARM core. > > 4KB Pages: > ========== > > count event_name # count / runtime > 598,995,035,942 cpu-cycles # 1.800861 GHz > 81,195,620,851 raw-stall-frontend # 244.112 M/sec > 347,754,466,597 iTLB-loads # 1.046 G/sec > 2,970,248,900 iTLB-load-misses # 0.854122% miss rate > > Total test time: 332.854998 seconds. > > 2MB Pages: > ========== > > count event_name # count / runtime > 592,872,663,047 cpu-cycles # 1.800358 GHz > 76,485,624,143 raw-stall-frontend # 232.261 M/sec > 350,478,413,710 iTLB-loads # 1.064 G/sec > 803,233,322 iTLB-load-misses # 0.229182% miss rate > > Total test time: 329.826087 seconds > > A check of /proc/$(pidof dex2oat64)/smaps shows THPs in use: > > /apex/com.android.art/lib64/libart.so > FilePmdMapped: 4096 kB > > /apex/com.android.art/lib64/libart-compiler.so > FilePmdMapped: 2048 kB > > Signed-off-by: Collin Fijalkovich Acked-by: Hugh Dickins and you also won Reviewed-by: William Kucharski in the v1 thread. I had hoped to see a more dramatic difference in the numbers above, but I'm a performance naif, and presume other loads and other libraries may show further benefit. > --- > Changes v1 -> v2: > * commit message 'non-shmem filesystems' -> 'non-shmem files' > * Add performance testing data to commit message > > fs/open.c | 13 +++++++++++-- > mm/khugepaged.c | 16 +++++++++++++++- > 2 files changed, 26 insertions(+), 3 deletions(-) > > diff --git a/fs/open.c b/fs/open.c > index e53af13b5835..f76e960d10ea 100644 > --- a/fs/open.c > +++ b/fs/open.c > @@ -852,8 +852,17 @@ static int do_dentry_open(struct file *f, > * XXX: Huge page cache doesn't support writing yet. Drop all page > * cache for this file before processing writes. > */ > - if ((f->f_mode & FMODE_WRITE) && filemap_nr_thps(inode->i_mapping)) > - truncate_pagecache(inode, 0); > + if (f->f_mode & FMODE_WRITE) { > + /* > + * Paired with smp_mb() in collapse_file() to ensure nr_thps > + * is up to date and the update to i_writecount by > + * get_write_access() is visible. Ensures subsequent insertion > + * of THPs into the page cache will fail. > + */ > + smp_mb(); > + if (filemap_nr_thps(inode->i_mapping)) > + truncate_pagecache(inode, 0); > + } > > return 0; > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index a7d6cb912b05..4c7cc877d5e3 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -459,7 +459,8 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, > > /* Read-only file mappings need to be aligned for THP to work. */ > if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file && > - (vm_flags & VM_DENYWRITE)) { > + !inode_is_open_for_write(vma->vm_file->f_inode) && > + (vm_flags & VM_EXEC)) { > return IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, > HPAGE_PMD_NR); > } > @@ -1872,6 +1873,19 @@ static void collapse_file(struct mm_struct *mm, > else { > __mod_lruvec_page_state(new_page, NR_FILE_THPS, nr); > filemap_nr_thps_inc(mapping); > + /* > + * Paired with smp_mb() in do_dentry_open() to ensure > + * i_writecount is up to date and the update to nr_thps is > + * visible. Ensures the page cache will be truncated if the > + * file is opened writable. > + */ > + smp_mb(); > + if (inode_is_open_for_write(mapping->host)) { > + result = SCAN_FAIL; > + __mod_lruvec_page_state(new_page, NR_FILE_THPS, -nr); > + filemap_nr_thps_dec(mapping); > + goto xa_locked; > + } > } > > if (nr_none) { > -- > 2.31.0.208.g409f899ff0-goog 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 X-Spam-Level: X-Spam-Status: No, score=-24.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4189C433B4 for ; Sat, 17 Apr 2021 04:31:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 51E7660FF1 for ; Sat, 17 Apr 2021 04:31:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51E7660FF1 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 79E516B006C; Sat, 17 Apr 2021 00:31:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74E276B006E; Sat, 17 Apr 2021 00:31:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C7DB6B0070; Sat, 17 Apr 2021 00:31:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0147.hostedemail.com [216.40.44.147]) by kanga.kvack.org (Postfix) with ESMTP id 3E3A56B006C for ; Sat, 17 Apr 2021 00:31:24 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DC01E180AD838 for ; Sat, 17 Apr 2021 04:31:23 +0000 (UTC) X-FDA: 78040584846.19.C739D58 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) by imf02.hostedemail.com (Postfix) with ESMTP id C5CD340002C1 for ; Sat, 17 Apr 2021 04:31:04 +0000 (UTC) Received: by mail-ot1-f44.google.com with SMTP id e89-20020a9d01e20000b0290294134181aeso1831781ote.5 for ; Fri, 16 Apr 2021 21:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=W6o2ooVTP+MnLQxjkPC27j4YkCmKuP7UZ0yTK+5vziU=; b=MYCnjeWCAOCBV2A5whTNGk1N7PjQZqQz5hw/cEWj0es8Lvi9HCoB/jo9UZl/iNHCZE mGlFBQZ3fCaE0zl2Dg2RFIG24iLMfOZyUXPjwwJwJfoMNjjKWhGErq//y7K35Y3ZjRZw 0vq2XlJ0hQTSXW5SJVCkm95TrCP3SteqD8zvUGeveXpUxK2ozBn9IPcSTeuWu4PQNAPc lIoWUCQlgAUdRZnbhR9SI9fkKdhb0VCZU9cGAG0cjlJpEIyIHYtEd9asKEpyy0HE4siX SuZcgHO0c5DjIRbDGOcI5QPD3Wn57i9ClJSuAQMREGjGWXU73hd4OECPj7PffJQM63fA 3wcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=W6o2ooVTP+MnLQxjkPC27j4YkCmKuP7UZ0yTK+5vziU=; b=lPGT1aT9j2KFRPyFKKlLZ6Te0TRx7SeT8RqCWc18szwafp6pztBEwzXfyeEi0qP7am M8uSb0Ykz/k3Cq2EB2hUnsBNxOE1KxxTwrH0iJwaMRaESMGHAh4dvK9OSbEk4t1ApKlD lN1zCH1fz+JQGlaoZHqaboQ1JQfXr3Q5KqXTsQnmV3PlPKZsbNnBYt4YL8/mHWTEOLbg iu9s/JxwveE6pTbo+3xfVCL0SfjAY9dCgDpth8tp27fD+3IZvoIcrexb7ddiBKzEaW03 3Sya7Bb7DiLo3kIMglwsFXHUN/ytTB0gARAu6TkiQDIAPIk4v2C7/RyNEHMrm4aVrJ1u 88Jg== X-Gm-Message-State: AOAM531gCe1tOEXX7he4MU5kn/dqEtoxidWIPZXiMPWjO2DCKWVE89b1 JeDWddjvgJo8fwGipr50ES5ijw== X-Google-Smtp-Source: ABdhPJyvYn8ZCtwckfRxXZNQrcGUemWroaDuXExJiCBU2JDLDPKzl1qtAgjmrur/IxHHTlF9XIhBhg== X-Received: by 2002:a9d:5a1a:: with SMTP id v26mr5902631oth.50.1618633882669; Fri, 16 Apr 2021 21:31:22 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id t25sm574797otp.4.2021.04.16.21.31.21 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Fri, 16 Apr 2021 21:31:22 -0700 (PDT) Date: Fri, 16 Apr 2021 21:31:08 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Collin Fijalkovich cc: Andrew Morton , songliubraving@fb.com, surenb@google.com, hridya@google.com, kaleshsingh@google.com, hughd@google.com, timmurray@google.com, william.kucharski@oracle.com, willy@infradead.org, Alexander Viro , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2] mm, thp: Relax the VM_DENYWRITE constraint on file-backed THPs In-Reply-To: <20210406000930.3455850-1-cfijalkovich@google.com> Message-ID: References: <20210406000930.3455850-1-cfijalkovich@google.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Stat-Signature: jpfj9qbkccu9t4zknk7nphtqrbb8snbg X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C5CD340002C1 Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from=""; helo=mail-ot1-f44.google.com; client-ip=209.85.210.44 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618633864-663662 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 Mon, 5 Apr 2021, Collin Fijalkovich wrote: > Transparent huge pages are supported for read-only non-shmem files, > but are only used for vmas with VM_DENYWRITE. This condition ensures that > file THPs are protected from writes while an application is running > (ETXTBSY). Any existing file THPs are then dropped from the page cache > when a file is opened for write in do_dentry_open(). Since sys_mmap > ignores MAP_DENYWRITE, this constrains the use of file THPs to vmas > produced by execve(). > > Systems that make heavy use of shared libraries (e.g. Android) are unable > to apply VM_DENYWRITE through the dynamic linker, preventing them from > benefiting from the resultant reduced contention on the TLB. > > This patch reduces the constraint on file THPs allowing use with any > executable mapping from a file not opened for write (see > inode_is_open_for_write()). It also introduces additional conditions to > ensure that files opened for write will never be backed by file THPs. > > Restricting the use of THPs to executable mappings eliminates the risk that > a read-only file later opened for write would encounter significant > latencies due to page cache truncation. > > The ld linker flag '-z max-page-size=(hugepage size)' can be used to > produce executables with the necessary layout. The dynamic linker must > map these file's segments at a hugepage size aligned vma for the mapping to > be backed with THPs. > > Comparison of the performance characteristics of 4KB and 2MB-backed > libraries follows; the Android dex2oat tool was used to AOT compile an > example application on a single ARM core. > > 4KB Pages: > ========== > > count event_name # count / runtime > 598,995,035,942 cpu-cycles # 1.800861 GHz > 81,195,620,851 raw-stall-frontend # 244.112 M/sec > 347,754,466,597 iTLB-loads # 1.046 G/sec > 2,970,248,900 iTLB-load-misses # 0.854122% miss rate > > Total test time: 332.854998 seconds. > > 2MB Pages: > ========== > > count event_name # count / runtime > 592,872,663,047 cpu-cycles # 1.800358 GHz > 76,485,624,143 raw-stall-frontend # 232.261 M/sec > 350,478,413,710 iTLB-loads # 1.064 G/sec > 803,233,322 iTLB-load-misses # 0.229182% miss rate > > Total test time: 329.826087 seconds > > A check of /proc/$(pidof dex2oat64)/smaps shows THPs in use: > > /apex/com.android.art/lib64/libart.so > FilePmdMapped: 4096 kB > > /apex/com.android.art/lib64/libart-compiler.so > FilePmdMapped: 2048 kB > > Signed-off-by: Collin Fijalkovich Acked-by: Hugh Dickins and you also won Reviewed-by: William Kucharski in the v1 thread. I had hoped to see a more dramatic difference in the numbers above, but I'm a performance naif, and presume other loads and other libraries may show further benefit. > --- > Changes v1 -> v2: > * commit message 'non-shmem filesystems' -> 'non-shmem files' > * Add performance testing data to commit message > > fs/open.c | 13 +++++++++++-- > mm/khugepaged.c | 16 +++++++++++++++- > 2 files changed, 26 insertions(+), 3 deletions(-) > > diff --git a/fs/open.c b/fs/open.c > index e53af13b5835..f76e960d10ea 100644 > --- a/fs/open.c > +++ b/fs/open.c > @@ -852,8 +852,17 @@ static int do_dentry_open(struct file *f, > * XXX: Huge page cache doesn't support writing yet. Drop all page > * cache for this file before processing writes. > */ > - if ((f->f_mode & FMODE_WRITE) && filemap_nr_thps(inode->i_mapping)) > - truncate_pagecache(inode, 0); > + if (f->f_mode & FMODE_WRITE) { > + /* > + * Paired with smp_mb() in collapse_file() to ensure nr_thps > + * is up to date and the update to i_writecount by > + * get_write_access() is visible. Ensures subsequent insertion > + * of THPs into the page cache will fail. > + */ > + smp_mb(); > + if (filemap_nr_thps(inode->i_mapping)) > + truncate_pagecache(inode, 0); > + } > > return 0; > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index a7d6cb912b05..4c7cc877d5e3 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -459,7 +459,8 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, > > /* Read-only file mappings need to be aligned for THP to work. */ > if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file && > - (vm_flags & VM_DENYWRITE)) { > + !inode_is_open_for_write(vma->vm_file->f_inode) && > + (vm_flags & VM_EXEC)) { > return IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, > HPAGE_PMD_NR); > } > @@ -1872,6 +1873,19 @@ static void collapse_file(struct mm_struct *mm, > else { > __mod_lruvec_page_state(new_page, NR_FILE_THPS, nr); > filemap_nr_thps_inc(mapping); > + /* > + * Paired with smp_mb() in do_dentry_open() to ensure > + * i_writecount is up to date and the update to nr_thps is > + * visible. Ensures the page cache will be truncated if the > + * file is opened writable. > + */ > + smp_mb(); > + if (inode_is_open_for_write(mapping->host)) { > + result = SCAN_FAIL; > + __mod_lruvec_page_state(new_page, NR_FILE_THPS, -nr); > + filemap_nr_thps_dec(mapping); > + goto xa_locked; > + } > } > > if (nr_none) { > -- > 2.31.0.208.g409f899ff0-goog