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

Li Wang liwang@redhat.com
Fri Apr 19 03:50:01 CEST 2024


Hi Petr, Cyril,

The patchset generally looks good.

But I have a concern about the macro name "MINIMAL" word,
which misled people to think that is the minimal swapfile size we
can make on the system, but obviously it is not, we could even
create a smaller one, right?

Can we rename it with a better one?


On Fri, Apr 19, 2024 at 2:52 AM Petr Vorel <pvorel@suse.cz> wrote:

> 65536 bytes triggered warning on systems with 64kb 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>
> ---
> Changes v1->v2:
> * Use 1MB for minimal swap file instead of using disk block size as a
>   base measure of size (Cyril)
>
>  include/libswap.h | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/include/libswap.h b/include/libswap.h
> index 87e32328e..28ce7842d 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_MINIMAL_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_MINIMAL_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