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

Avoid creating another copy when mmap-ing files on RAMFS filesystem #979

Open
wkozaczuk opened this issue Jun 10, 2018 · 1 comment
Open

Comments

@wkozaczuk
Copy link
Collaborator

Existing implementation of vfs_file::mmap() creates extra copy of file data in memory when mmap() is called on ROFS or RAMFS file. The function default_file_mmap() uses map_file_page_read page provider which calls read() on a file and ends up copying the data when page fault happens.

Ideally we would rather point to the same memory area that RAMFS or ROFS loaded the data to. Very likely it would have to be solved differently for ROFS vs RAMFS. In case of RAMFS file already resides in memory when mmap is called. With ROFS file data is loaded into cache lazily so possibly the cache memory area could be allocated using mmap() instead of malloc() and then simply pointed to the same pages when mmap is called on a file.

@nyh
Copy link
Contributor

nyh commented Aug 26, 2018

Note that RAMFS files are not necessarily aligned to 4096 byte blocks (or to any other alignment). Starting with bf73b9a they may point directly to the bootfs dump stored in memory. If we want to allow those to be mmap()ed without copy, we will need to modify the bootfs format (see scripts/mkboofs.py and fs/vfs/main.cc) to pad large files to page-sized alignment. To reduce the size impact of this padding to a minimum, we should do this only for large files, and leave small files unpadded (and requiring a copy on mmap()).

wkozaczuk added a commit to wkozaczuk/osv that referenced this issue Apr 24, 2020
This patch optimizes memory utilization by integrating with page cache.
In essence it eliminates second copy of file data in memory when mapping files using mmap().
For example simple java example need 9MB less to run.

The crux of the changes involve adding new vnops function of type VOP_CACHE -
rofs_map_cached_page() - that ensures that requested page of a file is loaded
from disk into ROFS cache (by triggering read from disk if missing) and
eventually registers the page into pagecache by calling pagecache::map_read_cached_page().

This partially addresses cloudius-systems#979

Signed-off-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com>
wkozaczuk added a commit that referenced this issue Apr 30, 2020
This patch optimizes memory utilization by integrating with page cache.
In essence it eliminates second copy of file data in memory when mapping files using mmap().
For example simple java example need 9MB less to run.

The crux of the changes involves adding new vnops function of type VOP_CACHE -
rofs_map_cached_page() - that ensures that requested page of a file is loaded
from disk into ROFS cache (by triggering read from disk if missing) and
eventually registers the page into pagecache by calling pagecache::map_read_cached_page().

This partially addresses #979

Signed-off-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com>
@wkozaczuk wkozaczuk changed the title Avoid creating another copy when mmap-ing RAMF or ROFS file Avoid creating another copy when mmap-ing files on RAMFS filesystem Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants