($INBOX_DIR/description missing)
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 2/3] libswap: Add {SAFE_, }MAKE_MINIMAL_SWAPFILE() macros
Date: Thu, 18 Apr 2024 16:13:11 +0200	[thread overview]
Message-ID: <20240418141312.99794-3-pvorel@suse.cz> (raw)
In-Reply-To: <20240418141312.99794-1-pvorel@suse.cz>

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


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2024-04-18 14:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18 14:13 [LTP] [PATCH 0/3] swap{on,off} fixes for page size > 4KB Petr Vorel
2024-04-18 14:13 ` [LTP] [PATCH 1/3] swapoff0[12]: Remove unneeded tst_brk() Petr Vorel
2024-04-18 14:56   ` Cyril Hrubis
2024-04-18 18:02     ` Petr Vorel
2024-04-18 14:13 ` Petr Vorel [this message]
2024-04-18 15:39   ` [LTP] [PATCH 2/3] libswap: Add {SAFE_, }MAKE_MINIMAL_SWAPFILE() macros Cyril Hrubis
2024-04-18 18:14     ` Petr Vorel
2024-04-18 14:13 ` [LTP] [PATCH 3/3] libswap: Use {SAFE_,}MAKE_MINIMAL_SWAPFILE() Petr Vorel
2024-04-18 15:40   ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240418141312.99794-3-pvorel@suse.cz \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).