[LTP] [PATCH v4 1/1] swapon03: Try to swapon() as many files until it fails

Li Wang liwang@redhat.com
Sat Dec 20 05:27:25 CET 2025


On Fri, Dec 19, 2025 at 10:48 PM Petr Vorel <pvorel@suse.cz> wrote:

> > [ Removing Michal to not bother him with LTP internals ]
>
> > > Hi!
> > > >   tst_res(TINFO, "Successfully created %d swap files", swapfiles);
> > > > - MAKE_SMALL_SWAPFILE(TEST_FILE);
>
> > > This should stay here, right? I suppose that the test works even when
> we
> > > pass non-existing file in the verify_swapon() but we shouldn't bet on
> > > that.
>
> > FYI swap file is created by is_swap_supported(TEST_FILE). But sure, I can
> > also keep MAKE_SMALL_SWAPFILE(TEST_FILE) to make sure file is also
> created.
> > We talked about related cleanup, which I wanted to postpone, but should I
> > refactor is_swap_supported() to not include swapon() call. Because when
> there
> > are too many swap files already mounted, tests is skipped with:
>
> > libswap.c:224: TCONF: Permission denied for swapon()
> > due EPERM, which is actually subject of testing for swapon03.c
>
> And, as I posted in v3 [1], we can avoid this work, if we require at least
> single swap created by the test. Or, allow a corner case all swaps are
> used,
> but just verify that by counting swap in /proc/swaps.
>
> Kind regards,
> Petr
>
> [1] https://lore.kernel.org/ltp/20251219142512.GC247368@pevik/
>
> > I'm not sure about naming. Maybe have is_swap_supported() without
> swapon() call
> > (for swapon03.c) and create new function is_swapon_supported(), which
> would call
> > is_swap_supported() + swapon() and swapoff() (for all other tests).
>

I think your idea is correct, current is_swap_supported() appears to contain
two different questions:
1. Does the kernel/filesystem support swap files at all / can we create a
swapfile?
2. Can we successfully swapon() a swapfile right now?

For most tests, (2) is a reasonable prerequisite; for swapon03 it is not,
because
the test is specifically about swapon() failing with EPERM when you hit the
swapfile limit.

To summarize the discussion, the approach might be:

is_swap_supported():
  - swap syscalls present (/proc/swaps exists)
  - filesystem allows creating files (has enough space)
  - can mkswap (or whatever MAKE_SMALL_SWAPFILE does) successfully
  - possibly sanity-check that swapfiles are supported on this FS

is_swapon_supported():
  - call is_swap_supported()
  - create a temporary swapfile
  - swapon() / swapoff() it
  - clean up

Of course, the refactor work can be achieved in separate patch set.

-- 
Regards,
Li Wang


More information about the ltp mailing list