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

Petr Vorel pvorel@suse.cz
Thu Apr 18 16:13:11 CEST 2024


Maximum kernel page size is 256KiB (see kernel arch/Kconfig). Therefore
this is the minimum blocks allowed to be used to avoid warning on any
kernel page size setup:

    TWARN: Swapfile size is less than the system page size. Using page size
    (65536 bytes) instead of block size (4096 bytes).

Therefore define this size and add helper macros.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/libswap.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/include/libswap.h b/include/libswap.h
index 87e32328e..ea1285e4f 100644
--- a/include/libswap.h
+++ b/include/libswap.h
@@ -23,6 +23,23 @@ int make_swapfile(const char *file, const int lineno,
 			const char *swapfile, unsigned int num,
 			int safe, enum swapfile_method method);
 
+
+/* see kernel arch/Kconfig */
+#define MINIMAL_SWAP_BLOCKS 256
+
+/**
+ * Macro to create minimal swapfile.
+ */
+#define MAKE_MINIMAL_SWAPFILE(swapfile) \
+    make_swapfile(__FILE__, __LINE__, swapfile, MINIMAL_SWAP_BLOCKS, 0, SWAPFILE_BY_BLKS)
+
+/**
+ * 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_BLOCKS, 1, SWAPFILE_BY_BLKS)
+
 /**
  * Macro to create swapfile size in megabytes (MB).
  */
-- 
2.43.0



More information about the ltp mailing list