William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 1 | From 04e4999c6fa2e9810634745a07f1e380f27b8e61 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Wed, 17 Mar 2021 13:24:57 -0700 |
| 4 | Subject: [PATCH] reduce thread stack and heap usage for javascriptcore on musl |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 5 | |
| 6 | default sizes for musl are smaller compared to glibc, this matches |
| 7 | to musl defaults, avoid stack overflow crashes in jscore |
| 8 | |
| 9 | This is based on Alpine Linux's patch based on suggestion from |
| 10 | https://bugs.webkit.org/show_bug.cgi?id=187485 |
| 11 | |
| 12 | Real solution would entail more as the suggestions to increase |
| 13 | stack size via -Wl,-z,stack-size=N does not work fully and also |
| 14 | setting DEFAULT_THREAD_STACK_SIZE_IN_KB alone is not enough either |
| 15 | |
| 16 | This patch only changes behavior when using musl, the defaults for |
| 17 | glibc in OE remains same |
| 18 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 19 | Upstream-Status: Accepted |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 20 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 21 | |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 22 | --- |
| 23 | Source/JavaScriptCore/runtime/OptionsList.h | 18 +++++++++++++++--- |
| 24 | Source/WTF/wtf/Threading.h | 4 ++++ |
| 25 | 2 files changed, 19 insertions(+), 3 deletions(-) |
| 26 | |
| 27 | diff --git a/Source/JavaScriptCore/runtime/OptionsList.h b/Source/JavaScriptCore/runtime/OptionsList.h |
| 28 | index bb6d2f1d..a6209742 100644 |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 29 | --- a/Source/JavaScriptCore/runtime/OptionsList.h |
| 30 | +++ b/Source/JavaScriptCore/runtime/OptionsList.h |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 31 | @@ -71,6 +71,18 @@ JS_EXPORT_PRIVATE bool canUseJITCage(); |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 32 | // On instantiation of the first VM instance, the Options will be write protected |
| 33 | // and cannot be modified thereafter. |
| 34 | |
| 35 | +#if OS(LINUX) && !defined(__GLIBC__) |
| 36 | +// non-glibc options on linux ( musl ) |
| 37 | +constexpr unsigned jscMaxPerThreadStack = 128 * KB; |
| 38 | +constexpr unsigned jscSoftReservedZoneSize = 32 * KB; |
| 39 | +constexpr unsigned jscReservedZoneSize = 16 * KB; |
| 40 | +#else |
| 41 | +//default |
| 42 | +constexpr unsigned jscMaxPerThreadStack = 4 * MB; |
| 43 | +constexpr unsigned jscSoftReservedZoneSize = 128 * KB; |
| 44 | +constexpr unsigned jscReservedZoneSize = 64 * KB; |
| 45 | +#endif |
| 46 | + |
| 47 | #define FOR_EACH_JSC_OPTION(v) \ |
| 48 | v(Bool, useKernTCSM, defaultTCSMValue(), Normal, "Note: this needs to go before other options since they depend on this value.") \ |
| 49 | v(Bool, validateOptions, false, Normal, "crashes if mis-typed JSC options were passed to the VM") \ |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 50 | @@ -86,9 +98,9 @@ JS_EXPORT_PRIVATE bool canUseJITCage(); |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 51 | \ |
| 52 | v(Bool, reportMustSucceedExecutableAllocations, false, Normal, nullptr) \ |
| 53 | \ |
| 54 | - v(Unsigned, maxPerThreadStackUsage, 5 * MB, Normal, "Max allowed stack usage by the VM") \ |
| 55 | - v(Unsigned, softReservedZoneSize, 128 * KB, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \ |
| 56 | - v(Unsigned, reservedZoneSize, 64 * KB, Normal, "The amount of stack space we guarantee to our clients (and to interal VM code that does not call out to clients).") \ |
| 57 | + v(Unsigned, maxPerThreadStackUsage, jscMaxPerThreadStack, Normal, "Max allowed stack usage by the VM") \ |
| 58 | + v(Unsigned, softReservedZoneSize, jscSoftReservedZoneSize, Normal, "A buffer greater than reservedZoneSize that reserves space for stringifying exceptions.") \ |
| 59 | + v(Unsigned, reservedZoneSize, jscReservedZoneSize, Normal, "The amount of stack space we guarantee to our clients (and to interal VM code that does not call out to clients).") \ |
| 60 | \ |
| 61 | v(Bool, crashOnDisallowedVMEntry, ASSERT_ENABLED, Normal, "Forces a crash if we attempt to enter the VM when disallowed") \ |
| 62 | v(Bool, crashIfCantAllocateJITMemory, false, Normal, nullptr) \ |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 63 | diff --git a/Source/WTF/wtf/Threading.h b/Source/WTF/wtf/Threading.h |
| 64 | index 9495d6c1..190b3811 100644 |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 65 | --- a/Source/WTF/wtf/Threading.h |
| 66 | +++ b/Source/WTF/wtf/Threading.h |
William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 67 | @@ -60,6 +60,10 @@ |
| 68 | #include <dispatch/dispatch.h> |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 69 | #endif |
| 70 | |
| 71 | +#if OS(LINUX) && !defined(__GLIBC__) |
| 72 | +#define DEFAULT_THREAD_STACK_SIZE_IN_KB 128 |
| 73 | +#endif |
| 74 | + |
| 75 | namespace WTF { |
| 76 | |
| 77 | class AbstractLocker; |