On Thu, 2023-03-02 at 09:47 -0800, Chris Li wrote: > On Wed, Mar 01, 2023 at 04:58:08PM -0800, Yosry Ahmed wrote: > > > The indirection layer would be essential to support it but it > > > would > > > be also great if we don't waste any memory for the user who don't > > > want the feature. > > > > I can't currently think of a way to eliminate overhead for people > > only > > using swapfiles, as a lot of the core implementation changes, > > unless > > we want to maintain considerably more code with a lot of repeated > > functionality implemented differently. Perhaps this will change as > > I > > implement this, maybe things are better (or worse) than what I > > think > > they are, I am actively working on a proof-of-concept right now. > > Maybe > > a discussion in LSF/MM/BPF will help come up with optimizations as > > well :) > > How about we just put the indirection layer into the swap device? The indirection layer needs to be higher up, in order to allow for easy movement of swap entries between different devices. For example, we could initially store something in zswap, and then later decide we want to write it out to disk swap. This could also be used to quickly free up swap space at swapin time, by freeing the backing storage (eg. in zswap, or when disk swap is starting to get full)) when placing an uncompressed copy of the data in the swap cache. We could apply per-device policies on whether or not to free swap space at swapin time, because the tradeoffs are just different between eg disk and zswap. Doing that would also allow us to turn swapoff into a simple "load everything from this device into the swap cache" operation. The pageout code can move that data from the swap cache into another swap device, without ever having to look up page tables. One possible implementation might be to have swap page table entries point to a swap address in this indirection layer, and the indirection layer can be an xarray containing the actual swap entries specifying at which position in which swap device the data can be found. That might be a net reduction in the code over what we have today, because it gets rid of some ugly corner cases. kind regards, Rik van Riel -- All Rights Reversed.