Skip to content

Commit 3c5a25f

Browse files
sam-githubandrewhughes101
authored andcommitted
test: specialize OOM check for AIX
Assumption that if memory can be malloc()ed it can be used is not true on AIX. Later access of the allocated pages can trigger SIGKILL if there are insufficient VM pages. Use psdanger() to better estimate available memory. Fixes: nodejs/build#1849 More info: - https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/generalprogramming/sys_mem_alloc.html - https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/p_bostechref/psdanger.html Related to: - nodejs/build#1820 (comment) - nodejs#28469 - nodejs#28516 PR-URL: nodejs#28857 Backport-PR-URL: nodejs#29599 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Beth Griggs <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent f8b2ffd commit 3c5a25f

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

test/addons/addon.status

-14
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,3 @@ prefix addons
33
[true] # This section applies to all platforms
44

55
[$system==aix]
6-
# https://github.com/nodejs/build/issues/1820#issuecomment-505998851
7-
# https://github.com/nodejs/node/pull/28469
8-
# https://github.com/nodejs/node/pull/28516
9-
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js: SKIP
10-
11-
# https://github.com/nodejs/node/pull/28516
12-
stringbytes-external-exceed-max/test-stringbytes-external-at-max: SKIP
13-
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii: SKIP
14-
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64: SKIP
15-
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary: SKIP
16-
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex: SKIP
17-
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8: SKIP
18-
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2: SKIP
19-
stringbytes-external-exceed-max/test-stringbytes-external-exceed-max: SKIP

test/addons/stringbytes-external-exceed-max/binding.cc

+31-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,42 @@
22
#include <node.h>
33
#include <v8.h>
44

5+
#ifdef _AIX
6+
// AIX allows over-allocation, and will SIGKILL when the allocated pages are
7+
// used if there is not enough VM. Check for available space until
8+
// out-of-memory. Don't allow more then some (large) proportion of it to be
9+
// used for the test strings, so Node & V8 have some space for allocations.
10+
#include <signal.h>
11+
#include <sys/vminfo.h>
12+
13+
static void* Allowed(size_t size) {
14+
blkcnt_t allowedBlocks = psdanger(SIGKILL);
15+
16+
if (allowedBlocks < 1) {
17+
// Already OOM
18+
return nullptr;
19+
}
20+
const size_t BYTES_PER_BLOCK = 512;
21+
size_t allowed = (allowedBlocks * BYTES_PER_BLOCK * 4) / 5;
22+
if (size < allowed) {
23+
return malloc(size);
24+
}
25+
return nullptr;
26+
}
27+
#else
28+
// Other systems also allow over-allocation, but this malloc-and-free approach
29+
// seems to be working for them.
30+
static void* Allowed(size_t size) {
31+
return malloc(size);
32+
}
33+
#endif // _AIX
34+
535
void EnsureAllocation(const v8::FunctionCallbackInfo<v8::Value> &args) {
636
v8::Isolate* isolate = args.GetIsolate();
737
uintptr_t size = args[0]->IntegerValue();
838
v8::Local<v8::Boolean> success;
939

10-
void* buffer = malloc(size);
40+
void* buffer = Allowed(size);
1141
if (buffer) {
1242
success = v8::Boolean::New(isolate, true);
1343
free(buffer);

0 commit comments

Comments
 (0)