nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.82k stars 29.71k forks source link

Support memory-mapped files #41069

Closed dead-claudia closed 2 years ago

dead-claudia commented 2 years ago

Is your feature request related to a problem? Please describe. I'd like to be able to read and modify large file-based data sets without either 1. paginating them into memory explicitly (mildly inefficient and eats RAM up rapidly) or 2. doing frequent random file access (extremely inefficient for magnetic hard drives).

Describe the solution you'd like Integration of mmap/munmap/msync for Linux, and equivalent APIs in Windows in a new fs API. This API would return a memory map handle with a few pieces of functionality:

I'm omitting support for Linux's mremap as there's no direct equivalent in Windows (and the closest equivalent it has is in a part of it that's filled with various caveats).

Describe alternatives you've considered See the "without either..." part of the problem description.

Trott commented 2 years ago

@nodejs/fs

dead-claudia commented 2 years ago

Of course, there is a risk of SIGBUS-based crashes, but that can be avoided through careful management of the file system. (This would necessarily have to be warned about in the docs.)

martinheidegger commented 2 years ago

Prior work in userland.

bnoordhuis commented 2 years ago

As the author of the original mmap module: commit bnoordhuis/node-mmap@0f81e51c48 (10 years ago!) mentions why mmap is a terrible idea in an async runtime - it performs blocking I/O.

  1. paginating them into memory explicitly (mildly inefficient and eats RAM up rapidly) or 2. doing frequent random file access (extremely inefficient for magnetic hard drives).

That's no different with memory-mapped files. They're not some magic bullet.

martinheidegger commented 2 years ago

Convince me otherwise. :-)

I came to this topic by looking at n2 and faiss which both use mmap to scale for data that should be in RAM but cant because of it's size.

github-actions[bot] commented 2 years ago

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

dead-claudia commented 2 years ago

bump to not be stale

bnoordhuis commented 2 years ago

I'll go ahead and close this to avoid further content-free bumps. No maintainers spoke out in favor and I personally don't see the need for this to live in core, rather the opposite.