aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-09-21 07:25:18 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-21 07:25:18 -0700
commitd1e9b33cac65794632921045e7a851c58ef1863d (patch)
treeefca05827034d73b0481f37f7209940e266b46e6 /src/bun.js
parentabfc10afeb73f9447e47929359d37f2b488c3c81 (diff)
downloadbun-d1e9b33cac65794632921045e7a851c58ef1863d.tar.gz
bun-d1e9b33cac65794632921045e7a851c58ef1863d.tar.zst
bun-d1e9b33cac65794632921045e7a851c58ef1863d.zip
On Linux, respect memory limit from cgroups (#5849)
* Implement `process.constrainedMemory()` * Add a comment * Handle max * Missing header * We can use WTF::ramSize now * Update WebKit * Update ZigGlobalObject.cpp * WebKit * :scissors: --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js')
m---------src/bun.js/WebKit0
-rw-r--r--src/bun.js/bindings/Process.cpp11
-rw-r--r--src/bun.js/bindings/Process.lut.h114
3 files changed, 69 insertions, 56 deletions
diff --git a/src/bun.js/WebKit b/src/bun.js/WebKit
-Subproject 4d995edbc44062b251be638818edcd88d7d14dd
+Subproject e1aa0a58e282b53fc20503d6e7ec93c621bc557
diff --git a/src/bun.js/bindings/Process.cpp b/src/bun.js/bindings/Process.cpp
index e95268fb1..c952cbef2 100644
--- a/src/bun.js/bindings/Process.cpp
+++ b/src/bun.js/bindings/Process.cpp
@@ -1328,6 +1328,16 @@ static Process* getProcessObject(JSC::JSGlobalObject* lexicalGlobalObject, JSVal
return process;
}
+JSC_DEFINE_HOST_FUNCTION(Process_functionConstrainedMemory,
+ (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
+{
+#if OS(LINUX) || OS(FREEBSD)
+ return JSValue::encode(jsDoubleNumber(static_cast<double>(WTF::ramSize())));
+#else
+ return JSValue::encode(jsUndefined());
+#endif
+}
+
JSC_DEFINE_HOST_FUNCTION(Process_functionCpuUsage,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
@@ -1864,6 +1874,7 @@ extern "C" void Process__emitDisconnectEvent(Zig::GlobalObject* global)
chdir Process_functionChdir Function 1
config constructProcessConfigObject PropertyCallback
connected processConnected CustomAccessor
+ constrainedMemory Process_functionConstrainedMemory Function 0
cpuUsage Process_functionCpuUsage Function 1
cwd Process_functionCwd Function 1
debugPort processDebugPort CustomAccessor
diff --git a/src/bun.js/bindings/Process.lut.h b/src/bun.js/bindings/Process.lut.h
index 620acdb64..6016466c2 100644
--- a/src/bun.js/bindings/Process.lut.h
+++ b/src/bun.js/bindings/Process.lut.h
@@ -1,6 +1,6 @@
// File generated via `make static-hash-table` / `make cpp`
-static const struct CompactHashIndex processObjectTableIndex[267] = {
- { 47, -1 },
+static const struct CompactHashIndex processObjectTableIndex[268] = {
+ { 48, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -14,9 +14,9 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 20, -1 },
+ { 21, -1 },
{ -1, -1 },
- { 49, -1 },
+ { 50, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -41,14 +41,14 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 34, -1 },
+ { 35, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 29, -1 },
- { 13, -1 },
+ { 30, -1 },
+ { 14, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -57,11 +57,11 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 59, -1 },
+ { 60, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 55, -1 },
+ { 56, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -75,36 +75,36 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 43, -1 },
+ { 44, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 0, -1 },
- { 28, -1 },
- { 37, -1 },
- { 42, -1 },
+ { 29, -1 },
+ { 38, -1 },
+ { 43, -1 },
{ -1, -1 },
- { 25, -1 },
- { 12, -1 },
+ { 26, -1 },
+ { 13, -1 },
{ -1, -1 },
{ -1, -1 },
- { 62, -1 },
+ { 63, -1 },
{ -1, -1 },
{ -1, -1 },
- { 33, -1 },
- { 44, -1 },
+ { 34, -1 },
+ { 45, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 26, -1 },
+ { 27, -1 },
{ -1, -1 },
{ -1, -1 },
- { 22, -1 },
+ { 23, -1 },
{ -1, -1 },
{ 5, -1 },
{ -1, -1 },
- { 64, -1 },
+ { 65, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -115,19 +115,19 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 27, 261 },
+ { 28, 262 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 23, 262 },
+ { 24, 263 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 50, 265 },
+ { 51, 266 },
{ -1, -1 },
- { 19, -1 },
+ { 20, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -139,10 +139,10 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 17, 257 },
+ { 18, 257 },
{ -1, -1 },
- { 14, -1 },
- { 57, -1 },
+ { 15, -1 },
+ { 58, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -161,12 +161,12 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 3, 266 },
+ { 3, 267 },
{ 1, -1 },
{ -1, -1 },
- { 63, -1 },
+ { 64, -1 },
{ -1, -1 },
- { 11, -1 },
+ { 12, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -174,24 +174,24 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 56, -1 },
+ { 57, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 10, 256 },
{ -1, -1 },
- { 16, 263 },
+ { 17, 264 },
{ -1, -1 },
- { 39, -1 },
+ { 40, -1 },
{ -1, -1 },
- { 41, -1 },
+ { 42, -1 },
{ -1, -1 },
- { 38, -1 },
- { 6, 264 },
+ { 11, 260 },
+ { 6, 265 },
{ -1, -1 },
{ -1, -1 },
{ 4, -1 },
- { 51, -1 },
+ { 52, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -205,11 +205,11 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 31, 260 },
+ { 32, 261 },
{ -1, -1 },
{ -1, -1 },
- { 48, -1 },
- { 18, 258 },
+ { 49, -1 },
+ { 19, 258 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -219,10 +219,10 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 53, -1 },
+ { 54, -1 },
{ -1, -1 },
- { 32, -1 },
- { 24, -1 },
+ { 33, -1 },
+ { 25, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -233,12 +233,12 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 52, -1 },
+ { 53, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 15, 259 },
+ { 16, 259 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
@@ -256,20 +256,21 @@ static const struct CompactHashIndex processObjectTableIndex[267] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
- { 21, -1 },
- { 30, -1 },
- { 35, -1 },
+ { 22, -1 },
+ { 31, -1 },
{ 36, -1 },
- { 40, -1 },
- { 45, -1 },
+ { 37, -1 },
+ { 39, -1 },
+ { 41, -1 },
{ 46, -1 },
- { 54, -1 },
- { 58, -1 },
- { 60, -1 },
+ { 47, -1 },
+ { 55, -1 },
+ { 59, -1 },
{ 61, -1 },
+ { 62, -1 },
};
-static const struct HashTableValue processObjectTableValues[65] = {
+static const struct HashTableValue processObjectTableValues[66] = {
{ "abort"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionAbort, 1 } },
{ "allowedNodeEnvironmentFlags"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, Process_stubEmptySet } },
{ "arch"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructArch } },
@@ -281,6 +282,7 @@ static const struct HashTableValue processObjectTableValues[65] = {
{ "chdir"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionChdir, 1 } },
{ "config"_s, static_cast<unsigned>(PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructProcessConfigObject } },
{ "connected"_s, static_cast<unsigned>(PropertyAttribute::CustomAccessor), NoIntrinsic, { HashTableValue::GetterSetterType, processConnected, setProcessConnected } },
+ { "constrainedMemory"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionConstrainedMemory, 0 } },
{ "cpuUsage"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionCpuUsage, 1 } },
{ "cwd"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Process_functionCwd, 1 } },
{ "debugPort"_s, static_cast<unsigned>(PropertyAttribute::CustomAccessor), NoIntrinsic, { HashTableValue::GetterSetterType, processDebugPort, setProcessDebugPort } },
@@ -338,4 +340,4 @@ static const struct HashTableValue processObjectTableValues[65] = {
};
static const struct HashTable processObjectTable =
- { 65, 255, true, nullptr, processObjectTableValues, processObjectTableIndex };
+ { 66, 255, true, nullptr, processObjectTableValues, processObjectTableIndex };