[LTP] [PATCH v3 1/2] libswap: Add {SAFE_, }MAKE_SMALL_SWAPFILE() macros

Li Wang liwang@redhat.com
Fri Apr 26 04:31:56 CEST 2024


On Fri, Apr 26, 2024 at 5:26 AM Petr Vorel <pvorel@suse.cz> wrote:

> 65536 bytes triggered warning on systems with 64 kb page size (e.g. on
> aarch64 with CONFIG_ARM64_64K_PAGES=y or on ppc64le with
> CONFIG_PAGE_SIZE_64KB=y):
>
>     TWARN: Swapfile size is less than the system page size. Using page size
>     (65536 bytes) instead of block size (4096 bytes).
>
> 1 MB should be ok for most of the systems.
>
> Suggested-by: Cyril Hrubis <chrubis@suse.cz>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
>

 Reviewed-by: Li Wang <liwang@redhat.com>

---
>  include/libswap.h | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/include/libswap.h b/include/libswap.h
> index 87e32328e..f757073cc 100644
> --- a/include/libswap.h
> +++ b/include/libswap.h
> @@ -23,6 +23,24 @@ int make_swapfile(const char *file, const int lineno,
>                         const char *swapfile, unsigned int num,
>                         int safe, enum swapfile_method method);
>
> +/** 65536 bytes is minimum for 64kb page size, let's use 1 MB */
> +#define MINIMAL_SWAP_SIZE_MB 1
> +
> +/**
> + * Macro to create minimal swapfile.
> + */
> +#define MAKE_SMALL_SWAPFILE(swapfile) \
> +    make_swapfile(__FILE__, __LINE__, swapfile, MINIMAL_SWAP_SIZE_MB, 0, \
> +                 SWAPFILE_BY_SIZE)
> +
> +/**
> + * Macro to create minimal swapfile.
> + * Includes safety checks to handle potential errors.
> + */
> +#define SAFE_MAKE_SMALL_SWAPFILE(swapfile) \
> +    make_swapfile(__FILE__, __LINE__, swapfile, MINIMAL_SWAP_SIZE_MB, 1, \
> +                 SWAPFILE_BY_SIZE)
> +
>  /**
>   * Macro to create swapfile size in megabytes (MB).
>   */
> --
> 2.43.0
>
>

-- 
Regards,
Li Wang


More information about the ltp mailing list