On Wed, Sep 25, 2024 at 7:21 AM Nhat Pham <nphamcs@xxxxxxxxx> wrote: > > > I'm only supporting the case nr > 1, when there is no need to add swap > continuations :) That's the only current use case right now (shmem) :) Sorry, I forgot to say - but to fully support a batched variant, we can do something like this: > > 1. Keep the non-batched variant: > > int swap_duplicate(swp_entry_t entry) > { > int err = 0; > > while (!err && __swap_duplicate(entry, 1, 1) == -ENOMEM) > err = add_swap_count_continuation(entry, GFP_ATOMIC); > return err; > } > > 2. Implement the batched variant: > > int swap_duplicate_nr(swp_entry_t entry, int nr) > { > swp_entry_t cur_entry; > int i, err; > > if (nr == 1) > return swap_duplicate(entry); > > err = __swap_duplicate(entry, 1, nr); > if (err == -ENOMEM) { > /* fallback to non-batched version */ > for (i = 0; i < nr; i++) { > cur_entry = (swp_entry_t){entry.val + i}; > if (swap_duplicate(cur_entry)) { > /* rollback */ > while (--i >= 0) { > cur_entry = (swp_entry_t){entry.val + i}; > swap_free(cur_entry); > } missing a "return err;" here. Not my best idea to write (pseudo) code before caffeine in the morning :) > } > } > } > return err; > } > > How does this look? My concern is that there is not really a use for > the fallback logic. Basically dead code. > > I can keep it in if you guys have a use for it soon, but otherwise I > lean towards just adding a WARN etc. there, or return -ENOMEM, and > WARN at shmem's callsite (because it cannot get -ENOMEM).