Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The rss memory not recall after a lot of file writing #35989

Open
yunnysunny opened this issue Nov 6, 2020 · 3 comments
Open

The rss memory not recall after a lot of file writing #35989

yunnysunny opened this issue Nov 6, 2020 · 3 comments
Labels
memory Issues and PRs related to the memory management or memory footprint.

Comments

@yunnysunny
Copy link
Contributor

yunnysunny commented Nov 6, 2020

  • Version: 14.15.0
  • Platform: Linux 3.10.0-693.2.2.el7.x86_64 deps: update openssl to 1.0.1j #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem:

What steps will reproduce the bug?

const fs = require('fs');
const path = require('path');
const MAX_SIZE = 1000 * 1000;
console.time('write');
let count = 0;
console.log('pid', process.pid);
function write(stream, i) {
    stream.end(JSON.stringify({index:i}), function(err) {
        stream.destroy();
        if (err) {
            console.error('write error', err);
        }
        count++;
        if (count === MAX_SIZE) {
            console.timeEnd('write');//write: 498283.611ms
        }
    });
}
for(var i=0; i< MAX_SIZE;i++) {
    const filename = path.join(__dirname, 'files/' + i + '.json');
    const stream = fs.createWriteStream(filename);
    write(stream, i);
}
setInterval(function() {}, 1000);

After run this code, the node occupy about 800MB memory, most of that is outside the heap. I had tried the version of 12.18.4, it has the same problem. I wonder how to recall the memory.

@gireeshpunathil
Copy link
Member

how is your system memory looking like? cat /proc/meminfo

@yunnysunny
Copy link
Contributor Author

cat /proc/meminfo

MemTotal:       32729996 kB
MemFree:         9712032 kB
MemAvailable:   20127312 kB
Buffers:               0 kB
Cached:         11719040 kB
SwapCached:        23180 kB
Active:          8994680 kB
Inactive:        8406908 kB
Active(anon):    6780020 kB
Inactive(anon):  2254296 kB
Active(file):    2214660 kB
Inactive(file):  6152612 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       4194300 kB
SwapFree:        4141572 kB
Dirty:              2000 kB
Writeback:             0 kB
AnonPages:       5661068 kB
Mapped:           322496 kB
Shmem:           3351616 kB
Slab:            4010436 kB
SReclaimable:    2475428 kB
SUnreclaim:      1535008 kB
KernelStack:       41664 kB
PageTables:        65524 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    20559296 kB
Committed_AS:   21363840 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      348372 kB
VmallocChunk:   34342174716 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      367552 kB
DirectMap2M:    22654976 kB
DirectMap1G:    10485760 kB

@gireeshpunathil
Copy link
Member

thanks for the data. as pointed out in the referenced issue, a previously grown up rss DOES NOT come down automatically in response to release of memory from the process, instead in response to increased demand of memory in the system. In that sense, the rss does not reflect TRUE memory usage of the process.

You have ~10GB free memory in your system, and is low on load. So a previous growth in rss will be seen as current rss too, but you can consider it as not being actively used.

The data point that shows the active, in-use memory of an app is wss (working set size), and unfortunately there are not platform-generic way of obtaining that, so we don't have a mechanism to observe that.

Hope this clarifies.

reference: #31641

@PoojaDurgad PoojaDurgad added the memory Issues and PRs related to the memory management or memory footprint. label Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
memory Issues and PRs related to the memory management or memory footprint.
Projects
None yet
Development

No branches or pull requests

3 participants