mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "David Hildenbrand (Arm)" <david@kernel.org>,
	"Zi Yan" <ziy@nvidia.com>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Nico Pache" <nico.pache@linux.dev>,
	"Ryan Roberts" <ryan.roberts@arm.com>,
	"Dev Jain" <dev.jain@arm.com>, "Barry Song" <baohua@kernel.org>,
	"Lance Yang" <lance.yang@linux.dev>,
	"Usama Arif" <usama.arif@linux.dev>,
	"Kiryl Shutsemau" <kas@kernel.org>,
	"Peter Xu" <peterx@redhat.com>,
	"Alex Williamson" <alex@shazbot.org>,
	kvm@vger.kernel.org,
	"Loïc Molinari" <loic.molinari@collabora.com>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Shuah Khan" <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org,
	"Madhavan Srinivasan" <maddy@linux.ibm.com>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, "Jason Gunthorpe" <jgg@ziepe.ca>,
	stable@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH v5 0/4] mm/huge_memory: copy PMDs at fork like the PTE path does
Date: Fri, 6 Nov 2026 17:59:56 +0100	[thread overview]
Message-ID: <2f3e4557-f4d0-43df-bce2-c653d1de305e@virtuozzo.com> (raw)
In-Reply-To: <20261105211819.2a6a349b2edc077784ca52f9@linux-foundation.org>

On 11/6/26 06:18, Andrew Morton wrote:
> The second column assumes that the child touches all the file THPs,
> yes?  If the child touches only a small proportion of those mappings,
> or just does fork+exec, that changes the "Cost" comparison?

Yes. I measured it again on bare metal, with a fork()+exec column:
x86_64 with 4 NUMA nodes, the benchmark bound to node 0, both kernels
v7.4-rc1 with the same config, 4 GB of shmem THPs mapped MAP_PRIVATE
with an anon_vma, medians of 2000 forks, range over the rounds. The
exec is of /bin/true.

  +-----------------+------------+-----------------+--------------+
  | kernel          | fork()     | child reads all | fork()+exec  |
  +-----------------+------------+-----------------+--------------+
  | v7.4-rc1        | 135-141 us | 3820-4036 us    | 559-567 us   |
  | v7.4-rc1+series | 429-440 us | 1007-1036 us    | 1190-1226 us |
  +-----------------+------------+-----------------+--------------+

So a child that execs right away, or touches little, pays about 0.3 us
per huge PMD: the copy at fork and the teardown at exec or exit. A
child that faults a PMD in itself pays about 1.8 us for it, so the
copy wins once the child touches more than about a sixth of them.

> And on ppc64 hash-mode setups this also allocates deposited page tables
> for mappings which the child might never touch?  So a modest increase
> in memory use is to be expected?

Yes, but a small one, judging from the code (I have no ppc64 to test):
one 4 KB page table fragment per copied 16 MB PMD, 1/4096 of the
mapping. Radix and other arches deposit nothing.

It is freed when the child unmaps the range, execs or exits, and a PMD
the child faults in itself deposits the same 4 KB anyway.

> But I worry that this change is not an overall win for thp-file
> mappings, which are the common case.

Only a narrow case pays the extra cost, a file THP that is:

- mapped MAP_PRIVATE;
- in a VMA written to at least once, so it has an anon_vma;
- a PMD-sized folio in the page cache, mapped by one PMD;
- itself never written to.

For example:

- a big data file mapped MAP_PRIVATE that is mostly read and patched
  in a few places;
- a private mapping of a memfd or tmpfs file.

The common case does not get here. fork() skips a VMA without an
anon_vma and without VM_COPY_ON_FORK (vma_needs_copy()), so shared
file mappings and private ones that were never written are still left
to faults.

In these VMAs fork() already copies the PTEs of the same file folios;
only their PMDs were skipped.

> I'm not understanding why we need to mess with thp-file behavior at all
> in order to address a special-PMD bug?

It came from the review of v3: David asked to make copy_huge_pmd()
decide the way copy_present_ptes() does, instead of keeping rules of
its own for PMDs:

https://lore.kernel.org/all/973fd409-64b7-4c62-82e1-c75c784b80f7@kernel.org/

> Changelog is soooo long.  I replaced this Reproducer section with simply
>
>       - A reproducer is at the Link;

Sure, thanks. And thanks for the pmd_psize fixup.

--
Cheers,
Konstantin

      parent reply	other threads:[~2026-11-06 17:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 20:40 Konstantin Khorenko
2026-11-04 20:40 ` [PATCH v5 1/4] mm/rmap: duplicate a PMD mapping as one in folio_dup_file_rmap_pmd() Konstantin Khorenko
2026-11-04 22:57   ` Jose A. Perez de Azpillaga
2026-11-04 20:40 ` [PATCH v5 2/4] mm/huge_memory: copy file THPs at fork like copy_present_ptes() does Konstantin Khorenko
2026-11-04 23:05   ` Jose A. Perez de Azpillaga
2026-11-06  3:04   ` Zi Yan
2026-11-04 20:40 ` [PATCH v5 3/4] mm/huge_memory: read a special PMD under the lock in copy_huge_pmd() Konstantin Khorenko
2026-11-04 23:09   ` Jose A. Perez de Azpillaga
2026-11-06  3:07   ` Zi Yan
2026-11-04 20:40 ` [PATCH v5 4/4] selftests/mm: test fork of PMD-mapped shmem THPs Konstantin Khorenko
2026-11-04 23:15   ` Jose A. Perez de Azpillaga
2026-11-05 13:15     ` Konstantin Khorenko
2026-11-06  5:18 ` [PATCH v5 0/4] mm/huge_memory: copy PMDs at fork like the PTE path does Andrew Morton
2026-11-06 16:48   ` Andrew Morton
2026-11-06 16:59   ` Konstantin Khorenko [this message]

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=2f3e4557-f4d0-43df-bce2-c653d1de305e@virtuozzo.com \
    --to=khorenko@virtuozzo.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex@shazbot.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jgg@ziepe.ca \
    --cc=kas@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=ljs@kernel.org \
    --cc=loic.molinari@collabora.com \
    --cc=maddy@linux.ibm.com \
    --cc=nico.pache@linux.dev \
    --cc=peterx@redhat.com \
    --cc=ritesh.list@gmail.com \
    --cc=ryan.roberts@arm.com \
    --cc=sashiko-bot@kernel.org \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=usama.arif@linux.dev \
    --cc=ziy@nvidia.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

all inboxes | Powered by JetHome®