On Mon, Jun 10, 2024 at 02:56:09PM +0100, Usama Arif wrote: > I am guessing what you are suggesting is just do this? > > if (is_folio_zero_filled(folio)) { > swap_zeromap_folio_set(folio); > folio_unlock(folio); > return 0; > } Right. > This is what I did initially while developing this, but when I started > looking into why zswap_store does folio_start_writeback, folio_unlock, > folio_end_writeback I found: > > https://elixir.bootlin.com/linux/v6.9.3/source/Documentation/filesystems/locking.rst#L336 > > "If no I/O is submitted, the filesystem must run end_page_writeback() > against the page before returning from writepage." But that's advice to filesystem authors. File pages don't come this way; we only put anonyous pages into swap (except tmpfs). > If we have zswap enabled, the zero filled pages (infact any page that is > compressed), will be saved in zswap_entry and NR_WRITTEN will be wrongly > incremented. So the behaviour for NR_WRITTEN does not change in this patch > when encountering zero pages with zswap enabled (even if its wrong). We should fiz zswap too. > In order to fix NR_WRITTEN accounting for zswap, this patch series and any > other cases where no I/O is submitted but end_page_writeback is called > before returning to writepage, maybe we could add an argument to > __folio_end_writeback like below? There are a lot of calls to > folio_end_writeback and the behaviour of zeropage with regards to NR_WRITTEN > doesnt change with or without this patchseries with zswap enabled, so maybe > we could keep this independent of this series? I would be happy to submit > this as separate patch if it makes sense. It makes no sense at all.