linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Barry Song <21cnbao@gmail.com>,
	akpm@linux-foundation.org, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, Barry Song <v-songbaohua@oppo.com>,
	Chuanhua Han <hanchuanhua@oppo.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Ryan Roberts <ryan.roberts@arm.com>, Zi Yan <ziy@nvidia.com>,
	Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>,
	Kalesh Singh <kaleshsingh@google.com>,
	Suren Baghdasaryan <surenb@google.com>
Subject: Re: [PATCH RFC] mm: entirely reuse the whole anon mTHP in do_wp_page
Date: Sat, 31 Aug 2024 11:44:20 +0200	[thread overview]
Message-ID: <d0b826c1-8577-46f8-8e4c-ca2b72554819@redhat.com> (raw)
In-Reply-To: <20240831092339.66085-1-21cnbao@gmail.com>

On 31.08.24 11:23, Barry Song wrote:
> From: Barry Song <v-songbaohua@oppo.com>
> 
> On a physical phone, it's sometimes observed that deferred_split
> mTHPs account for over 15% of the total mTHPs. Profiling by Chuanhua
> indicates that the majority of these originate from the typical fork
> scenario.
> When the child process either execs or exits, the parent process should
> ideally be able to reuse the entire mTHP. However, the current kernel
> lacks this capability and instead places the mTHP into split_deferred,
> performing a CoW (Copy-on-Write) on just a single subpage of the mTHP.
> 
>   main()
>   {
>   #define SIZE 1024 * 1024UL
>           void *p = malloc(SIZE);
>           memset(p, 0x11, SIZE);
>           if (fork() == 0)
>                   exec(....);
>          /*
>   	 * this will trigger cow one subpage from
>   	 * mTHP and put mTHP into split_deferred
>   	 * list
>   	 */
>   	*(int *)(p + 10) = 10;
>   	printf("done\n");
>   	while(1);
>   }
> 
> This leads to two significant issues:
> 
> * Memory Waste: Before the mTHP is fully split by the shrinker,
> it wastes memory. In extreme cases, such as with a 64KB mTHP,
> the memory usage could be 64KB + 60KB until the last subpage
> is written, at which point the mTHP is freed.
> 
> * Fragmentation and Performance Loss: It destroys large folios
> (negating the performance benefits of CONT-PTE) and fragments memory.
> 
> To address this, we should aim to reuse the entire mTHP in such cases.
> 
> Hi David,
> 
> I’ve renamed wp_page_reuse() to wp_folio_reuse() and added an
> entirely_reuse argument because I’m not sure if there are still cases
> where we reuse a subpage within an mTHP. For now, I’m setting
> entirely_reuse to true only for the newly supported case, while all
> other cases still get false. Please let me know if this is incorrect—if
> we don’t reuse subpages at all, we could remove the argument.

See [1] I sent out this week, that is able to reuse even without 
scanning page tables. If we find the the folio is exclusive we could try 
processing surrounding PTEs that map the same folio.

[1] https://lkml.kernel.org/r/20240829165627.2256514-1-david@redhat.com

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2024-08-31  9:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-31  9:23 Barry Song
2024-08-31  9:44 ` David Hildenbrand [this message]
2024-08-31  9:55   ` Barry Song
2024-08-31 10:07     ` David Hildenbrand
2024-08-31 10:21       ` Barry Song
2024-08-31 10:29         ` David Hildenbrand
2024-08-31 10:49           ` Barry Song
2024-08-31 11:02             ` David Hildenbrand
2024-08-31  9:59 ` David Hildenbrand
2024-08-31 10:09   ` Barry Song
2024-08-31 10:14     ` David Hildenbrand

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=d0b826c1-8577-46f8-8e4c-ca2b72554819@redhat.com \
    --to=david@redhat.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=chrisl@kernel.org \
    --cc=hanchuanhua@oppo.com \
    --cc=kaleshsingh@google.com \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryan.roberts@arm.com \
    --cc=surenb@google.com \
    --cc=v-songbaohua@oppo.com \
    --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