RFR(M): 8169373: Work around linux NPTL stack guard error.

David Holmes david.holmes at oracle.com
Thu Nov 10 22:20:21 UTC 2016


Hi Goetz,

On 11/11/2016 8:00 AM, Lindenmaier, Goetz wrote:
> Hi David,
>
> This issue is different to 6675312, see also my comment in the bug.
>
> It appears running jtreg test runtime/Thread/TooSmallStackSize.java,
> with my patch below you can reproduce it on linuxx86_64. You can not
> do that with 6675312. Also, I would assume there are systems out there
> on x86 that uses 64-K pages, did you run the tests on these? I would
> assume you get hard crashes with stack overflows in the first C2
> compilation if there is only 64K usable CompilerThreadStack.
>
> My fix does not affect Java threads, which are the largest amount
> of threads used by the VM. It affects only the non-Java threads.
> It adds one page to these threads. The page does not require memory,
> as it's protected. The stack will only require more space if the thread
> ran into a stack overflow before the fix as else the pages are not mapped.
> This are stack overflows that cause hard crashes, at least on ppc the VM
> does not properly catch these stack overflows, so any setup working now
> will not run into the additional space. Altogether there should be no
> effect on running systems besides requiring one more entry in the
> page table per non-Java thread.
>
> The problem is caused by a rather recent change (8140520: segfault on solaris-amd64
> with "-XX:VMThreadStackSize=1" option) which was pushed after
> feature-close. As this was a rather recent change, it must be possible to
> fix this follow up issue. What else is this period in the project good
> for if not fixing issues?
>
> So I really think this issue should be fixed.

I only gave it a cursory look initially and had not noticed that the 
effective change was only being applied to PPC and S390 code. If this 
truly relates to the 8140520 fix and is not specifically trying to 
address the NPTL bug then we should be able to do something. But at the 
moment I'm confused by exactly what 8140520 changed that broke this, or 
why a change is only needed on PPC and only for non-Java threads. The 
special casing here actually makes things worse at the moment - but I 
will examine this in more detail.

Thanks,
David

> Best regards,
>   Goetz.
>
>
>> -----Original Message-----
>> From: David Holmes [mailto:david.holmes at oracle.com]
>> Sent: Thursday, November 10, 2016 10:02 PM
>> To: Lindenmaier, Goetz <goetz.lindenmaier at sap.com>; hotspot-runtime-
>> dev at openjdk.java.net
>> Subject: Re: RFR(M): 8169373: Work around linux NPTL stack guard error.
>>
>> Hi Goetz,
>>
>> As per the bug report, this issue was already known (6675312) and we
>> chose not to try and address it due to no reported issues at the time.
>> While I see that you have encountered an issue (is it real or
>> fabricated?) I think this change is too intrusive to be applied at this
>> stage of the JDK 9 release cycle, as it will change the stack
>> requirements of every application running on Linux.
>>
>> Thanks,
>> David
>>
>> On 11/11/2016 1:58 AM, Lindenmaier, Goetz wrote:
>>> Hi,
>>>
>>>
>>>
>>> Please review this change. I please need a sponsor:
>>>
>>> http://cr.openjdk.java.net/~goetz/wr16/8169373-ppc-stackFix/webrev.01/
>>>
>>>
>>>
>>> In the Linux NPTL pthread implementation the guard size mechanism is not
>>> implemented properly. The posix standard requires to add the size of the
>>> guard pages to the stack size, instead Linux takes the space out of
>>> 'stacksize'.
>>>
>>> The Posix standard http://pubs.opengroup.org/onlinepubs/9699919799/
>>>  says "the implementation allocates extra memory at the overflow end of
>>> the stack". The linux man page
>>> https://linux.die.net/man/3/pthread_attr_setguardsize says "As at glibc
>>> 2.8, the NPTL threading implementation includes the guard area within
>>> the stack size allocation, rather than allocating extra space at the end
>>> of the stack, as POSIX.1 requires".
>>>
>>> I encounter this problem in runtime/Thread/TooSmallStackSize.java on ppc
>>> with 64K pages. _compiler_thread_min_stack_allowed is 128K on ppc, and
>>> ppc specifies two OS guard pages. The VM crashes in pthread creation
>>> because there is no usable space in the thread stack after allocating
>>> the guard pages.
>>>
>>> But TooSmallStackSize.java requires that the VM comes up with the stack
>>> size mentioned in the error message.
>>>
>>> This fix adapts the requested stack size on Linux by the size of the
>>> guard pages to mimick proper behaviour, see change to os_linux.cpp.
>>>
>>>
>>>
>>> The change also streamlines usage of stack_guard_page on linuxppc,
>>> linuxppcle, aixppc and linuxs390.
>>>
>>>
>>>
>>> To reproduce the error on linux_x86_64, apply below patch and call the
>>> VM with -XX:CompilerThreadStackSize=64.
>>>
>>>
>>>
>>> I'm still exploring why I had to choose such big compiler stacks on ppc
>>> to get -version passing, but I wanted to send the RFR now as people
>>> obviously looked at the bug I opened (Thanks David!).
>>>
>>>
>>>
>>> Best regards,
>>>
>>>   Goetz.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> diff -r b7ae012c55c3 src/os_cpu/linux_x86/vm/os_linux_x86.cpp
>>>
>>> --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp  Mon Nov 07 12:37:28
>> 2016
>>> +0100
>>>
>>> +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp  Thu Nov 10 16:52:17
>> 2016
>>> +0100
>>>
>>> @@ -701,7 +701,7 @@
>>>
>>> size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
>>>
>>>    // Creating guard page is very expensive. Java thread has HotSpot
>>>
>>>    // guard page, only enable glibc guard page for non-Java threads.
>>>
>>> -  return (thr_type == java_thread ? 0 : page_size());
>>>
>>> +  return (thr_type == java_thread ? 0 : 64*K);
>>>
>>> }
>>>
>>>
>>>
>>> // Java thread:
>>>


More information about the hotspot-runtime-dev mailing list