unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella Netto via Libc-alpha <libc-alpha@sourceware.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: Wed, 17 May 2023 13:50:35 -0300	[thread overview]
Message-ID: <f23df62c-d13a-fbfa-0fd3-9464c983ab4d@linaro.org> (raw)
In-Reply-To: <PAWPR08MB8982071513C3D16114995178837E9@PAWPR08MB8982.eurprd08.prod.outlook.com>



On 17/05/23 11:22, Wilco Dijkstra wrote:
> Hi Adhemerval,
> 
>> AFAIU the issue is after the stack is allocated with huge pages, the
>> kernel needs to fallback to standard pages because the guard 'page'
>> will be also within the same huge page allocated for the stack.  
> 
> The stack allocation explicitly never overlaps with the guard page, ie. there
> is no such fallback. All that matters is the mapped address range of the
> stack - if this fits huge pages, you'll get them.
> 
>> My understanding is, once kernel needs to fallback to use default pages, 
>> it allocates *all* the large page range.  This is what the RSS increase
>> make me believe, I am not sure if there is technical limitation to just 
>> making the range COW (since at the time of guard protection setup, no
>> the page has not been touched yet).
> 
> That's not what happens. The RSS size increases because you actually get
> a huge page (as requested). There is no fallback to standard pages.

But the threads themselves do not end up using all the VMA region allocated
for them.  Using the test program you can see it:

$ cat /proc/meminfo  | grep AnonHugePages
AnonHugePages:     43008 kB
$ ./tststackalloc &
[...]
[statm] RSS: 1049 pages (4296704 bytes = 4 MB)
[smaps] RSS: 5033984 bytes = 4 MB
[...]
$ cat /proc/meminfo  | grep AnonHugePages
AnonHugePages:     45056 kB

So even if the stack is not aligned to default large page, THP will still
back up the thread allocation.  The issues is, if the mmap is also aligned 
to THP size, the guard setup will trigger the issue that will increase RSS.
This seems to be same conclusion OpenJVM and some kernel discussion has
reached as well [1] [2].

> 
>>> So the real question is when do huge pages make sense for stacks?
>>
>> But that's not what the patch is trying to do, it only tries tot mitigate
>> a specific corner case where THP will be ineffective.  I agree with
> 
> So far there is no evidence this corner case exists, but even ignoring that,
> the expression used is incorrect.
> 
>> Cupertino that this question is really hard to answer and it will be
>> really depended of the workload and/or runtime characteristics that we will
>> need to plug in kernel feedback to have some answer.
> 
> It should be feasible to run benchmarks to get an idea whether huge stack pages
> help or not. And similarly whether the RSS increase is worth it or not.

Another option, hinted in both discussion and brought by Florian as well is to
add a pthread extension to force huge page disabl (something like pthread_attr_setflags
to make is extensible).

[1] https://bugs.openjdk.org/browse/JDK-8303215?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel&showAll=true
[2] https://lore.kernel.org/linux-mm/278ec047-4c5d-ab71-de36-094dbed4067c@redhat.com/T/

  reply	other threads:[~2023-05-17 16:51 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
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 [this message]
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=f23df62c-d13a-fbfa-0fd3-9464c983ab4d@linaro.org \
    --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).