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

Li Wang liwang@redhat.com
Thu Nov 6 04:46:35 CET 2025


On Wed, Nov 5, 2025 at 11:48 PM Petr Vorel <pvorel@suse.cz> wrote:

> Previously tst_max_swapfiles() had fine tuning for a specific kernel
> version which was fragile due various backports in enterprise kernels.
>
> Let's try to create and use as many swap files until swapon() fails.
> Then check for expected EPERM.
>
> Suggested-by: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/kernel/syscalls/swapon/swapon03.c | 63 +++++++++++++--------
>  1 file changed, 40 insertions(+), 23 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/swapon/swapon03.c
> b/testcases/kernel/syscalls/swapon/swapon03.c
> index b89d853188..0027f874be 100644
> --- a/testcases/kernel/syscalls/swapon/swapon03.c
> +++ b/testcases/kernel/syscalls/swapon/swapon03.c
> @@ -1,14 +1,18 @@
>  // SPDX-License-Identifier: GPL-2.0-or-later
>  /*
> + * Copyright (c) Linux Test Project, 2009-2025
>   * Copyright (c) International Business Machines Corp., 2007
>   * Created by <rsalveti@linux.vnet.ibm.com>
> - *
>   */
>
>  /*\
> - * This test case checks whether swapon(2) system call returns:
> + * Test checks whether :man2:`swapon` system call returns EPERM when the
> maximum
> + * number of swap files are already in use.
>   *
> - *  - EPERM when there are more than MAX_SWAPFILES already in use.
> + * NOTE: test does not try to calculate MAX_SWAPFILES from the internal
> + * kernel implementation (which is currently <23, 29> depending on kernel
> + * configuration). Instead test exptect that at least 15 swap files minus
> + * currently used swap can be created.
>   */
>
>  #include <stdio.h>
> @@ -20,49 +24,54 @@
>  #include "lapi/syscalls.h"
>  #include "libswap.h"
>
> +#define NUM_SWAP_FILES 15
>

Does the number 15 have a specific meaning?

Anyway, the whole patch set looks good to me:
Reviewed-by: Li Wang <liwang@redhat.com>


-- 
Regards,
Li Wang


More information about the ltp mailing list