public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Wilco Dijkstra <Wilco.Dijkstra@arm.com>,
	"libc-alpha@sourceware.org" <libc-alpha@sourceware.org>,
	Cupertino Miranda <cupertino.miranda@oracle.com>
Subject: Re: [PATCH] nptl: Disable THP on thread stack if it incurs in large RSS usage
Date: Tue, 16 May 2023 13:35:12 -0300	[thread overview]
Message-ID: <f0b2fca5-f21d-b538-329f-7795e85ad4f1@linaro.org> (raw)
In-Reply-To: <PAWPR08MB8982647EFF03E356D3322EA983799@PAWPR08MB8982.eurprd08.prod.outlook.com>



On 16/05/23 12:38, Wilco Dijkstra wrote:
> Hi Adhemerval,
> 
>>> This still doesn't make sense since if _STACK_GROWS_DOWN, mem == guard, so
>>> this will always execute the madvise. 
> 
> And if !_STACK_GROWS_DOWN, we never execute the madvise. So I don't believe
> this is correct, even if it behaves like a nop in some cases.
> 
>> Yes, if THP is set to always this is exactly the idea of this patch since
>> afaiu the kernel might still back up the stack with large pages if the 
>> request a size is smaller than the default THP. 
> 
> If a mmap start/end range does not align to a huge page, you get small pages
> at the ends because a huge page does not fit.

Yeap, this is why Curpertino original testcase adds a way to force mmap
filling the VMA to triggers the THP allocated stack.

> 
>> It is only an issue if
>> the guard page address is not aligned to THP default size, which will
>> potentially trigger issues Cupertino has brought (since we do not prior
>> hand which is the mapping flags used on page used to fulfill the allocation). 
> 
> I don't see the claimed issue happen. What happens is that if you request
> huge pages, you get them. And that is what increases the RSS size.
> 
>>> As I mentioned, I couldn't find evidence that
>>> the claimed scenario of a huge page allocated, written to and then split due to the
>>> mprotect exists.
>>
>> I adapted Cupertino original test to allow specify both the thread stack
>> and guard size by command line.  Just:
> 
> The RSS size difference is not evidence of an issue - you asked for huge pages
> and you got them! I verified they are definitely huge pages by counting the TLB
> misses when accessing the stack.
> 
>>> So the real issue is that the current stack allocation code randomly (based on
>>> alignment from previous mmap calls) uses huge pages even for small stacks.
>>
>> Keep in mind this heuristic is only enabled if THP is set to 'always', meaning
>> the kernel will try to back *all* the stack with large pages.  The issue is
>> when the *guard* page is within a large page.
> 
> Why would that be an issue? In that case you can't get a large page.
> 
> The question is, under what circumstances are huge pages in stacks beneficial and
> in which cases are they not? If have a good answer to that, then we can automatically
> do the right thing without needing a tuning.
> 

Afaiu the issue is not whether huge page in stacks is beneficial, but rather 
when kernel will fall back to default pages anyway which will be just waste 
cycles.  Another option would be tune the default stack and guard size
to avoid this issue, but this might require some more heuristics to find a 
good spot to avoid too much VMA waste.

  reply	other threads:[~2023-05-16 16:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-20 17:24 Adhemerval Zanella
2023-05-03 12:42 ` Wilco Dijkstra
2023-05-15 17:57   ` Adhemerval Zanella Netto
2023-05-16 15:38     ` Wilco Dijkstra
2023-05-16 16:35       ` Adhemerval Zanella Netto [this message]
2023-05-17 12:49         ` Wilco Dijkstra
2023-05-17 13:12           ` Cupertino Miranda
2023-05-17 13:20           ` Adhemerval Zanella Netto
2023-05-17 14:22             ` Wilco Dijkstra
2023-05-17 16:50               ` Adhemerval Zanella Netto
2023-05-17 18:16                 ` Wilco Dijkstra
2023-05-18 13:04                   ` Adhemerval Zanella Netto
2023-05-23  9:48                     ` Wilco Dijkstra
2024-01-31  2:03                       ` Cristian Rodríguez
2024-01-31  7:54                         ` Florian Weimer
2024-01-31 11:30                           ` Adhemerval Zanella Netto
2024-01-31 11:43                             ` Florian Weimer
2024-03-12  0:55                               ` Cristian Rodríguez
2024-01-31 15:18                             ` Cristian Rodríguez
2024-02-01  1:26                               ` Cristian Rodríguez
2023-05-16 14:30 ` Cupertino Miranda

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=f0b2fca5-f21d-b538-329f-7795e85ad4f1@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=cupertino.miranda@oracle.com \
    --cc=libc-alpha@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).