unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Wilco Dijkstra via Libc-alpha <libc-alpha@sourceware.org>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	"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 15:38:15 +0000	[thread overview]
Message-ID: <PAWPR08MB8982647EFF03E356D3322EA983799@PAWPR08MB8982.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <4115d7fd-d7a7-cdb1-3833-daf45186480f@linaro.org>

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.

> 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.

Cheers,
Wilco

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

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-20 17:24 [PATCH] nptl: Disable THP on thread stack if it incurs in large RSS usage Adhemerval Zanella via Libc-alpha
2023-05-03 12:42 ` Wilco Dijkstra via Libc-alpha
2023-05-15 17:57   ` Adhemerval Zanella Netto via Libc-alpha
2023-05-16 15:38     ` Wilco Dijkstra via Libc-alpha [this message]
2023-05-16 16:35       ` Adhemerval Zanella Netto via Libc-alpha
2023-05-17 12:49         ` Wilco Dijkstra via Libc-alpha
2023-05-17 13:12           ` Cupertino Miranda via Libc-alpha
2023-05-17 13:20           ` Adhemerval Zanella Netto via Libc-alpha
2023-05-17 14:22             ` Wilco Dijkstra via Libc-alpha
2023-05-17 16:50               ` Adhemerval Zanella Netto via Libc-alpha
2023-05-17 18:16                 ` Wilco Dijkstra via Libc-alpha
2023-05-18 13:04                   ` Adhemerval Zanella Netto via Libc-alpha
2023-05-23  9:48                     ` Wilco Dijkstra via Libc-alpha
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 via Libc-alpha

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

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PAWPR08MB8982647EFF03E356D3322EA983799@PAWPR08MB8982.eurprd08.prod.outlook.com \
    --to=libc-alpha@sourceware.org \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=cupertino.miranda@oracle.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).