centosout-of-memorydynamic-memory-allocationswapnpm-build

npm run build does not consume swap memory on centos and errors heap out of memory


I run npm run build give memory issue like below:

# npm run build

> fuse@9.0.0 build
> ng build

93% after chunk asset optimization SourceMapDevToolPlugin main-es2015.js generate SourceMap
<--- Last few GCs --->

[6311:0x50b4290]   182740 ms: Mark-sweep (reduce) 904.3 (936.0) -> 902.4 (935.6) MB, 1689.5 / 0.1 ms  (average mu = 0.190, current mu = 0.245) allocation failure scavenge might not succeed
[6311:0x50b4290]   182856 ms: Scavenge (reduce) 903.4 (935.6) -> 902.5 (935.6) MB, 2.5 / 0.0 ms  (average mu = 0.190, current mu = 0.245) allocation failure
[6311:0x50b4290]   182906 ms: Scavenge (reduce) 903.5 (935.6) -> 902.5 (935.6) MB, 4.1 / 0.0 ms  (average mu = 0.190, current mu = 0.245) allocation failure


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb02960 node::Abort() [ng build]
 2: 0xa18149 node::FatalError(char const*, char const*) [ng build]
 3: 0xcdd22e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [ng build]
 4: 0xcdd5a7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [ng build]
 5: 0xe94c15  [ng build]
 6: 0xe956f6  [ng build]
 7: 0xea3c1e  [ng build]
 8: 0xea4660 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [ng build]
 9: 0xea75de v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [ng build]
10: 0xe68b1a v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [ng build]
11: 0x11e1886 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [ng build]
12: 0x15d54f9  [ng build]
/tmp/build-e8d9a101.sh: line 1:  6311 Aborted                 ng build

I have 2 GB of Real memory and 4 GB of SWAP memory.

I did realtime monitoring and found that the npm run build does not consume any swap memory.

How can I make npm run build utilize swap memory so I could overcome this memory issue.

Below are realtime swap memory stats while npm command was running and as u see it only eats up realtime memory and ignore swap memory:

memory Before npm build run:

[root@vultr ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1837         328        1133         101         375        1233
Swap:          4095          31        4064

memory after run right when it crashes:

[root@vultr ~]# sudo swapon --show
NAME      TYPE SIZE  USED PRIO
/swapfile file   4G 29.9M   -2
[root@vultr ~]# sudo swapon --show
NAME      TYPE SIZE  USED PRIO
/swapfile file   4G 29.9M   -2
[root@vultr ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1837        1518          73         101         245          72
Swap:          4095          29        4066
[root@vultr ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1837        1516          75         101         245          74
Swap:          4095          29        4066
[root@vultr ~]# sudo swapon --show
NAME      TYPE SIZE  USED PRIO
/swapfile file   4G 29.9M   -2
[root@vultr ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1837        1520          70         101         245          70
Swap:          4095          29        4066
[root@vultr ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1837         450        1120         101         267        1130
Swap:          4095          31        4064

Solution

  • export NODE_OPTIONS=--max-old-space-size=4096 helped resolve the issue. SWAP memory is now utilized.