From: Fangrui Song <maskray@google.com>
To: Yang Shi <shy828301@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, Song Liu <songliubraving@fb.com>,
Miaohe Lin <linmiaohe@huawei.com>,
linux-kernel@vger.kernel.org, Zhouyi Zhou <zhouzhouyi@gmail.com>
Subject: Re: [PATCH] mm: remove VM_EXEC requirement for THP eligibility
Date: Wed, 20 Dec 2023 20:53:38 -0800 [thread overview]
Message-ID: <CAFP8O3+5fKcGS8xEY5=DHqsN0YdybEY178nM+cXRY1bbQXV4WQ@mail.gmail.com> (raw)
In-Reply-To: <CAHbLzkpZomZBHVkSpCiK-hZUoZi4x2N6MB=PtFj-cBHOVhYs7Q@mail.gmail.com>
On Wed, Dec 20, 2023 at 3:42 PM Yang Shi <shy828301@gmail.com> wrote:
>
> On Tue, Dec 19, 2023 at 9:41 PM Fangrui Song <maskray@google.com> wrote:
> >
> > Commit e6be37b2e7bd ("mm/huge_memory.c: add missing read-only THP
> > checking in transparent_hugepage_enabled()") introduced the VM_EXEC
> > requirement, which is not strictly needed.
> >
> > lld's default --rosegment option and GNU ld's -z separate-code option
> > (default on Linux/x86 since binutils 2.31) create a read-only PT_LOAD
> > segment without the PF_X flag, which should be eligible for THP.
> >
> > Certain architectures support medium and large code models, where
> > .lrodata may be placed in a separate read-only PT_LOAD segment, which
> > should be eligible for THP as well.
>
> Yeah, it doesn't have to be VM_EXEC. The original implementation was
> restricted to VM_EXEC to minimize the blast radius and the targe use
> case is for large text segments. Out of curiosity, did you see any
> noticeable improvement with this change?
Hi Yang,
Thanks for the comment. Frankly, I am not familiar with huge pages...
I noticed this VM_EXEC condition when I was writing this
hugepage-related section in
https://maskray.me/blog/2023-12-17-exploring-the-section-layout-in-linker-output#transparent-huge-pages-for-mapped-files
(Thanks to Alexander Monakov's comment about
CONFIG_READ_ONLY_THP_FOR_FS in
https://mazzo.li/posts/check-huge-page.html).
As dTLB for read-only data is also an important optimization of
file-backed THP, it seems straightforward that we should drop the
VM_EXEC condition :)
On my Arch linux machine, the r--p page gets split if I invoke
madvise(__ehdr_start, HPAGE_SIZE, MADV_HUGEPAGE) I haven't figured out
why it behaves so in the presence of the VM_EXEC check.
% g++ test.cc -o ~/tmp/test -O2 -fuse-ld=lld
-Wl,-z,max-page-size=2097152 && sudo ~/tmp/test
__ehdr_start: 0x55f3b1c00000
55f3b1c00000-55f3b1e00000 r--p 00000000 103:03 555277119
/home/ray/tmp/test
55f3b1e00000-55f3b1e01000 r--p 00200000 103:03 555277119
/home/ray/tmp/test
55f3b2000000-55f3b2002000 r-xp 00200000 103:03 555277119
/home/ray/tmp/test
55f3b2201000-55f3b2202000 r--p 00201000 103:03 555277119
/home/ray/tmp/test
55f3b2401000-55f3b2402000 rw-p 00201000 103:03 555277119
/home/ray/tmp/test
55f3b3a9a000-55f3b3abb000 rw-p 00000000 00:00 0 [heap]
It'd be greatly appreciated if someone familiar with
CONFIG_READ_ONLY_THP_FOR_FS could provide some notes on how to use
this feature:)
> >
> > Signed-off-by: Fangrui Song <maskray@google.com>
> > ---
> > include/linux/huge_mm.h | 1 -
> > 1 file changed, 1 deletion(-)
> >
> > diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> > index fa0350b0812a..4c9e67e9000f 100644
> > --- a/include/linux/huge_mm.h
> > +++ b/include/linux/huge_mm.h
> > @@ -126,7 +126,6 @@ static inline bool file_thp_enabled(struct vm_area_struct *vma)
> > inode = vma->vm_file->f_inode;
> >
> > return (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) &&
> > - (vma->vm_flags & VM_EXEC) &&
> > !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
> > }
> >
> > --
> > 2.43.0.472.g3155946c3a-goog
> >
--
宋方睿
next prev parent reply other threads:[~2023-12-21 4:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-20 5:41 Fangrui Song
2023-12-20 23:42 ` Yang Shi
2023-12-21 4:53 ` Fangrui Song [this message]
2023-12-21 19:31 ` Yang Shi
2023-12-21 19:45 ` Yang Shi
2023-12-21 19:50 ` Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFP8O3+5fKcGS8xEY5=DHqsN0YdybEY178nM+cXRY1bbQXV4WQ@mail.gmail.com' \
--to=maskray@google.com \
--cc=akpm@linux-foundation.org \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shy828301@gmail.com \
--cc=songliubraving@fb.com \
--cc=zhouzhouyi@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox