On 09/09/2024 00:21, Barry Song wrote: > From: Barry Song <v-songbaohua@xxxxxxxx> > > There could be a corner case where the first entry is non-zeromap, > but a subsequent entry is zeromap. In this case, we should not > let swap_read_folio_zeromap() return false since we will still > read corrupted data. > > Additionally, the iteration of test_bit() is unnecessary and > can be replaced with bitmap operations, which are more efficient. > > We can adopt the style of swap_pte_batch() and folio_pte_batch() to > introduce swap_zeromap_batch() which seems to provide the greatest > flexibility for the caller. This approach allows the caller to either > check if the zeromap status of all entries is consistent or determine > the number of contiguous entries with the same status. > > Since swap_read_folio() can't handle reading a large folio that's > partially zeromap and partially non-zeromap, we've moved the code > to mm/swap.h so that others, like those working on swap-in, can > access it. > > Fixes: 0ca0c24e3211 ("mm: store zero pages to be swapped out in a bitmap") > Cc: Usama Arif <usamaarif642@xxxxxxxxx> > Reviewed-by: Yosry Ahmed <yosryahmed@xxxxxxxxxx> > Signed-off-by: Barry Song <v-songbaohua@xxxxxxxx> Reviewed-by: Usama Arif <usamaarif642@xxxxxxxxx>