I think the assumption is incorrect. I think we would just check ifSo yes, with this patch I tested swap out of large zero folio, but whenpsi_memstall_enter(&pflags);We don't currently support swapping in large folios, but it is a work
}
delayacct_swapin_start();
-
- if (zswap_load(folio)) {
+ if (swap_zeromap_folio_test(folio)) {
+ folio_zero_fill(folio);
+ folio_mark_uptodate(folio);
+ folio_unlock(folio);
in progress, and this will break once we have it.
swap_zeromap_folio_test() will return false even if parts of the folio
are in fact zero-filled. Then, we will go read those from disk swap,
essentially corrupting data.
swapping in it was page by page. My assumption was that swap_read_folio
(when support is added) would only pass a large folio that was earlier
swapped out as a large folio. So if a zero filled large folio was
swapped out, the zeromap will be set for all the pages in that folio,
and at large folio swap in (when it is supported), it will see that all
the bits in the zeromap for that folio are set, and will just
folio_zero_fill.
If even a single page in large folio has non-zero data then zeromap will
not store it and it will go to either zswap or disk, and at read time as
all the bits in zeromap are not set, it will still goto either zswap or
disk, so I think this works?
Is my assumption wrong that only large folios can be swapped in only if
they were swapped out as large? I think this code works in that case.
contiguous PTEs have contiguous swap entries and swapin the folio as a
large folio in this case. It is likely that the swap entries are
contiguous because it was swapped out as a large folio, but I don't
think it's guaranteed.
For example, here is a patch that implements large swapin support for
the synchronous swapin case, and I think it just checks that the PTEs
have contiguous swap entries:
https://lore.kernel.org/linux-mm/20240304081348.197341-6-21cnbao@xxxxxxxxx/
This makes a lot of sense because otherwise you'd have to keep track
of how the folios were composed at the time of swapout, to be able to
swap the same folios back in.