Welcome to the Linux Foundation Forum!

Chap 14. process.memoryUsage()

Hi,
Explanations of Chap 14 on process.memoryUsage(), suggests heapUsed is the total amount of memory (RAM+ swap), while rss is the amount of RAM. However rss is greater than heapUsed, so I think something must be missing in the explanation...
Can anyone clarify what these really are?
Thank you

Answers

  • djedje
    djedje Posts: 20

    Agree with Pablo,

    Running this simple loop the heapUsed grows, but rss don't..... (It would surprise me if the swap area is in use for this case).

     const d = [process.memoryUsage()]
    
    let i = 0
    while(i < 1000) {
        i++
        if(i === 500) d.push(process.memoryUsage())
    }
    d.push(process.memoryUsage())
    
    console.table(d)
    
    

    ┌─────────┬──────────┬───────────┬──────────┬──────────┬──────────────┐
    │ (index) │ rss │ heapTotal │ heapUsed │ external │ arrayBuffers │
    ├─────────┼──────────┼───────────┼──────────┼──────────┼──────────────┤
    │ 0 │ 31649792 │ 4730880 │ 2932488 │ 970568 │ 9402 │
    │ 1 │ 31649792 │ 4730880 │ 2936368 │ 970608 │ 9402 │
    │ 2 │ 31649792 │ 4730880 │ 2936760 │ 970608 │ 9402 │
    └─────────┴──────────┴───────────┴──────────┴──────────┴──────────────┘

  • hi @pablo.pena

    To the best I know, heap is memory area allocated through function like malloc() in C, while RSS is any allocated memory, whether through user triggered function like malloc() or implicit procedures like running executable and loading portion of the executable file into memory (code, data and so on)

    So, likely, RSS, in your case is bigger than Heap because the above reason. Hope it helps

Categories

Upcoming Training