Bug 208223 - Allow setting of stack sizes for threads
Summary: Allow setting of stack sizes for threads
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Don Olmstead
URL:
Keywords: InRadar
Depends on:
Blocks: 187485 210068
  Show dependency treegraph
 
Reported: 2020-02-25 16:05 PST by Don Olmstead
Modified: 2020-04-15 09:01 PDT (History)
24 users (show)

See Also:


Attachments
WIP Patch (5.50 KB, patch)
2020-02-25 16:08 PST, Don Olmstead
no flags Details | Formatted Diff | Diff
WIP Patch (5.94 KB, patch)
2020-02-26 09:23 PST, Don Olmstead
no flags Details | Formatted Diff | Diff
Patch (16.94 KB, patch)
2020-02-26 11:27 PST, Don Olmstead
no flags Details | Formatted Diff | Diff
Patch (17.00 KB, patch)
2020-02-26 11:37 PST, Don Olmstead
mark.lam: review+
Details | Formatted Diff | Diff
Patch (17.08 KB, patch)
2020-02-26 12:41 PST, Don Olmstead
no flags Details | Formatted Diff | Diff
Patch (17.08 KB, patch)
2020-02-26 12:42 PST, Don Olmstead
no flags Details | Formatted Diff | Diff
Patch (17.04 KB, patch)
2020-02-26 13:13 PST, Don Olmstead
ysuzuki: review+
Details | Formatted Diff | Diff
Patch (16.71 KB, patch)
2020-02-26 13:23 PST, Don Olmstead
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Don Olmstead 2020-02-25 16:05:06 PST
Currently all threads use the default stack size and no attempt is made to change the size. This might not be ideal on some platforms or some thread types.
Comment 1 Don Olmstead 2020-02-25 16:08:36 PST Comment hidden (obsolete)
Comment 2 Don Olmstead 2020-02-26 09:23:52 PST Comment hidden (obsolete)
Comment 3 Don Olmstead 2020-02-26 11:27:59 PST Comment hidden (obsolete)
Comment 4 Don Olmstead 2020-02-26 11:37:48 PST
Created attachment 391762 [details]
Patch
Comment 5 Mark Lam 2020-02-26 12:03:53 PST
Comment on attachment 391762 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=391762&action=review

r=me with fixes.

> Source/WTF/ChangeLog:11
> +        based on their own observations. Additionally a default stack size can be specified
> +        during by defining DEFAULT_THREAD_STACK_SIZE_IN_KB if the default stack for a platform is

Can you clarify what you mean here by "specified during"?  I suspect you're missing some details.

> Source/WTF/wtf/Threading.cpp:53
>  
> +#if defined(DEFAULT_THREAD_STACK_SIZE_IN_KB) && DEFAULT_THREAD_STACK_SIZE_IN_KB > 0
> +static constexpr size_t defaultStackSize = DEFAULT_THREAD_STACK_SIZE_IN_KB * 1024;
> +#else
> +// Use the platform's default stack size
> +static constexpr size_t defaultStackSize = 0;
> +#endif

Just move this into Thread::create() and initialize an Optional<size_t> there.

> Source/WTF/wtf/Threading.cpp:162
> +    // If the stack size is set to 0 then use the system default. Platforms can tune the values here.

Please add a comma after '0'.

> Source/WTF/wtf/Threading.h:247
> +    bool establishHandle(NewThreadContext*, size_t);

Please use Optional<size_t> instead of size_t.  Then we don't have to worry about the convention of a size of 0 meaning something special.

> Source/WTF/wtf/posix/ThreadingPOSIX.cpp:204
> +bool Thread::establishHandle(NewThreadContext* context, size_t stackSize)

Use Optional<size_t>.

> Source/WTF/wtf/win/ThreadingWin.cpp:156
> +bool Thread::establishHandle(NewThreadContext* data, size_t stackSize)

Use Optional<size_t>.
Comment 6 Mark Lam 2020-02-26 12:05:22 PST
Comment on attachment 391762 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=391762&action=review

>> Source/WTF/wtf/Threading.cpp:53
>> +#endif
> 
> Just move this into Thread::create() and initialize an Optional<size_t> there.

On 2nd thought, let's have a static defaultStackSize() function that returns an Optional<size_t>, and have Thread::create() call that.
Comment 7 Don Olmstead 2020-02-26 12:41:20 PST Comment hidden (obsolete)
Comment 8 Don Olmstead 2020-02-26 12:42:39 PST
Created attachment 391769 [details]
Patch

Address review feedback
Comment 9 Mark Lam 2020-02-26 13:02:05 PST
Comment on attachment 391769 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=391769&action=review

> Source/WTF/wtf/Threading.cpp:48
> +static Optional<size_t> defaultStackSize() {

WebKit style requires the { to be on the next line.

> Source/WTF/wtf/Threading.cpp:173
> +#if PLATFORM(PLAYSTATION)
> +    if (threadType == ThreadType::JavaScript)
> +        stackSize = 512 * 1024;
> +#else
> +    UNUSED_PARAM(threadType);
> +#endif

Hmmm ... further improvement: let rename defaultStackSize() to stackSize() and pass it the ThreadType.  With that, you can move this logic in there, and we can have the computation of the stack size to use all in one place.

> Source/WTF/wtf/posix/ThreadingPOSIX.cpp:212
> +    if (stackSize.hasValue())

You can just say "if (stackSize)" instead.

> Source/WTF/wtf/win/ThreadingWin.cpp:159
> +    unsigned initFlag = stackSize.hasValue() ? STACK_SIZE_PARAM_IS_A_RESERVATION : 0;

Ditto: just use "staskSize ?" instead of "stackSize.hasValue() ?".
Comment 10 Don Olmstead 2020-02-26 13:13:30 PST
Created attachment 391773 [details]
Patch

More cleanup. Good idea with the stackSize function!
Comment 11 Yusuke Suzuki 2020-02-26 13:15:41 PST
Comment on attachment 391769 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=391769&action=review

>> Source/WTF/wtf/Threading.cpp:173
>> +#endif
> 
> Hmmm ... further improvement: let rename defaultStackSize() to stackSize() and pass it the ThreadType.  With that, you can move this logic in there, and we can have the computation of the stack size to use all in one place.

Sounds better.

>> Source/WTF/wtf/win/ThreadingWin.cpp:159
>> +    unsigned initFlag = stackSize.hasValue() ? STACK_SIZE_PARAM_IS_A_RESERVATION : 0;
> 
> Ditto: just use "staskSize ?" instead of "stackSize.hasValue() ?".

Or, use `stackSize.valueOr(0)`.
Comment 12 Yusuke Suzuki 2020-02-26 13:16:54 PST
Comment on attachment 391773 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=391773&action=review

r=me

> Source/WTF/wtf/Threading.cpp:174
> +

Remove this line.
Comment 13 Don Olmstead 2020-02-26 13:23:37 PST
Created attachment 391774 [details]
Patch

Patch for landing
Comment 14 WebKit Commit Bot 2020-02-26 15:27:23 PST
Comment on attachment 391774 [details]
Patch

Clearing flags on attachment: 391774

Committed r257521: <https://trac.webkit.org/changeset/257521>
Comment 15 WebKit Commit Bot 2020-02-26 15:27:26 PST
All reviewed patches have been landed.  Closing bug.
Comment 16 Radar WebKit Bug Importer 2020-02-26 15:28:13 PST
<rdar://problem/59824199>