Add support for adding data to files
The KHO inode must be updated with a mapping of which logical "block" of
the file corresponds to which page. In addition, after kexec the pages
are inserted into the page cache lazily based on when they are first
used. This makes the assumption that a page not in page cache does not
exist false. Update shmem_get_folio_gfp() and
shmem_alloc_and_add_folio() to do this.
When a page is not found in the page cache on a KHO-enabled inode,
shmem_get_folio_gfp() now still attempts to find the page since a
reference to the page might exist in the KHO inode's block list and we
haven't inserted it in the page cache yet. Since a page taken over from
KHO is similar to a clean page allocated from buddy, this handling is
done in shmem_alloc_and_add_folio().
On a KHO-enabled inode, shmem_alloc_kho_folio() is used to do this. If
the page exists on the blocks list, it is returned and
shmem_alloc_and_add_folio() initialized it and adds it to the page
cache. Otherwise, for SGP_WRITE, a new page is allocated, added to the
block list, and returned to be initialized and added to page cache. For
SGP_READ or SGP_NOALLOC, -ENOENT is returned to indicate to caller a
page is not found and it can error or zero on hole. This way, we always
keep the blocks list up-to-date on new allocations, and allow for
restoring pre-kexec pages.
shmem_get_folio_gfp() is refactored to make this logic easier to
implement.
For truncation, add the invalidate folio callback. This along with
mapping_set_release_always() on the inode makes sure it gets called on
truncate. The callback just removes the mapping of the folio from the
blocks list, since the caller will take care of actually freeing the
folio.
NOTE: As with every patch is this series, the code here is very hacky
and quickly put together to get a proof-of-concept. So the code is full
of bugs and problems, and will be significantly improved before the
first round of patches on the list.
Signed-off-by: Pratyush Yadav <ptyadav@amazon.de>
1 file changed