ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/3] swap{on,off} fixes for page size > 4KB
@ 2024-04-18 14:13 Petr Vorel
  2024-04-18 14:13 ` [LTP] [PATCH 1/3] swapoff0[12]: Remove unneeded tst_brk() Petr Vorel
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Petr Vorel @ 2024-04-18 14:13 UTC (permalink / raw)
  To: ltp

Hi Li, Cyril,

this is supposed just to fix our swap{on,off} tests on kernel with page
size > 4KB.

NOTE: while I first wanted to also convert include/libswap.h docs to the
new format, I'll postpone it to a separate effort to speedup this fix.

This is a replacement of "libswap: Change TWARN message to TINFO":

https://lore.kernel.org/ltp/20240417090222.707302-1-pvorel@suse.cz/
https://patchwork.ozlabs.org/project/ltp/patch/20240417090222.707302-1-pvorel@suse.cz/

Kind regards,
Petr

Petr Vorel (3):
  swapoff0[12]: Remove unneeded tst_brk()
  libswap: Add {SAFE_,}MAKE_MINIMAL_SWAPFILE() macros
  libswap: Use {SAFE_,}MAKE_MINIMAL_SWAPFILE()

 include/libswap.h                             | 17 +++++++++++++++++
 libs/libltpswap/libswap.c                     |  2 +-
 testcases/kernel/syscalls/swapoff/swapoff01.c |  4 +---
 testcases/kernel/syscalls/swapoff/swapoff02.c |  4 +---
 testcases/kernel/syscalls/swapon/swapon02.c   |  4 ++--
 testcases/kernel/syscalls/swapon/swapon03.c   |  4 ++--
 6 files changed, 24 insertions(+), 11 deletions(-)

-- 
2.43.0


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 1/3] swapoff0[12]: Remove unneeded tst_brk()
  2024-04-18 14:13 [LTP] [PATCH 0/3] swap{on,off} fixes for page size > 4KB Petr Vorel
@ 2024-04-18 14:13 ` Petr Vorel
  2024-04-18 14:56   ` Cyril Hrubis
  2024-04-18 14:13 ` [LTP] [PATCH 2/3] libswap: Add {SAFE_, }MAKE_MINIMAL_SWAPFILE() macros Petr Vorel
  2024-04-18 14:13 ` [LTP] [PATCH 3/3] libswap: Use {SAFE_,}MAKE_MINIMAL_SWAPFILE() Petr Vorel
  2 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2024-04-18 14:13 UTC (permalink / raw)
  To: ltp

SAFE_MAKE_SWAPFILE_BLKS() calls make_swapfile() with safe parameter == 1,
therefore passes TST_CMD_PASS_RETVAL | TST_CMD_TCONF_ON_MISSING to
tst_cmd() and following functions, which leads to quit testing due
tst_brkm(TCONF, ...).

This is a left over from transition from tst_fill_file() which does not
have safe parameter to make_swapfile() in 6249e87b5 (swapoff01.c) and
009a407a0 (swapoff02.c).

Fixes: 6249e87b5 ("libswap: customize swapfile size")
Fixes: 009a407a0 ("swapon/off: enable all_filesystem in swap test")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/kernel/syscalls/swapoff/swapoff01.c | 4 +---
 testcases/kernel/syscalls/swapoff/swapoff02.c | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
index cf13907e7..314630267 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff01.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
@@ -43,9 +43,7 @@ static void verify_swapoff(void)
 static void setup(void)
 {
 	is_swap_supported(TEST_FILE);
-
-	if (SAFE_MAKE_SWAPFILE_BLKS(SWAP_FILE, 65536))
-		tst_brk(TBROK, "Failed to create file for swap");
+	SAFE_MAKE_SWAPFILE_BLKS(SWAP_FILE, 65536);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
index 61536dda4..5a15826e4 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff02.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
@@ -87,9 +87,7 @@ static void setup(void)
 	nobody_uid = nobody->pw_uid;
 
 	is_swap_supported(TEST_FILE);
-
-	if (SAFE_MAKE_SWAPFILE_BLKS(SWAP_FILE, 10))
-		tst_brk(TBROK, "Failed to create file for swap");
+	SAFE_MAKE_SWAPFILE_BLKS(SWAP_FILE, 10);
 }
 
 static struct tst_test test = {
-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 2/3] libswap: Add {SAFE_, }MAKE_MINIMAL_SWAPFILE() macros
  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:13 ` Petr Vorel
  2024-04-18 15:39   ` Cyril Hrubis
  2024-04-18 14:13 ` [LTP] [PATCH 3/3] libswap: Use {SAFE_,}MAKE_MINIMAL_SWAPFILE() Petr Vorel
  2 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2024-04-18 14:13 UTC (permalink / raw)
  To: ltp

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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 3/3] libswap: Use {SAFE_,}MAKE_MINIMAL_SWAPFILE()
  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:13 ` [LTP] [PATCH 2/3] libswap: Add {SAFE_, }MAKE_MINIMAL_SWAPFILE() macros Petr Vorel
@ 2024-04-18 14:13 ` Petr Vorel
  2024-04-18 15:40   ` Cyril Hrubis
  2 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2024-04-18 14:13 UTC (permalink / raw)
  To: ltp

This effectively increases the minimal used number of blocks to 256.

All {SAFE_,}MAKE_SWAPFILE_SIZE() calls which were creating swap used 10
blocks. While this is ok on 4kb page size, it's too low 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).

Obviously it would fail also on kernels with CONFIG_PAGE_SIZE_256KB.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 libs/libltpswap/libswap.c                     | 2 +-
 testcases/kernel/syscalls/swapoff/swapoff02.c | 2 +-
 testcases/kernel/syscalls/swapon/swapon02.c   | 4 ++--
 testcases/kernel/syscalls/swapon/swapon03.c   | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index aed76dfe2..92127d8cd 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -192,7 +192,7 @@ int make_swapfile(const char *file, const int lineno,
 bool is_swap_supported(const char *filename)
 {
 	int i, sw_support = 0;
-	int ret = SAFE_MAKE_SWAPFILE_BLKS(filename, 10);
+	int ret = SAFE_MAKE_MINIMAL_SWAPFILE(filename);
 	int fi_contiguous = file_is_contiguous(filename);
 	long fs_type = tst_fs_type(filename);
 	const char *fstype = tst_fs_type_name(fs_type);
diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
index 5a15826e4..676d06619 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff02.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
@@ -87,7 +87,7 @@ static void setup(void)
 	nobody_uid = nobody->pw_uid;
 
 	is_swap_supported(TEST_FILE);
-	SAFE_MAKE_SWAPFILE_BLKS(SWAP_FILE, 10);
+	SAFE_MAKE_MINIMAL_SWAPFILE(SWAP_FILE);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index e5e29b8e7..20f3cfd26 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -50,8 +50,8 @@ static void setup(void)
 	is_swap_supported(TEST_FILE);
 
 	SAFE_TOUCH(NOTSWAP_FILE, 0777, NULL);
-	MAKE_SWAPFILE_BLKS(SWAP_FILE, 10);
-	MAKE_SWAPFILE_BLKS(USED_FILE, 10);
+	MAKE_MINIMAL_SWAPFILE(SWAP_FILE);
+	MAKE_MINIMAL_SWAPFILE(USED_FILE);
 
 	if (tst_syscall(__NR_swapon, USED_FILE, 0))
 		tst_res(TWARN | TERRNO, "swapon(alreadyused) failed");
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 5295a6a73..342b5e38a 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -49,7 +49,7 @@ static int setup_swap(void)
 
 			/* Create the swapfile */
 			snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, j + 2);
-			MAKE_SWAPFILE_BLKS(filename, 10);
+			MAKE_MINIMAL_SWAPFILE(filename);
 
 			/* turn on the swap file */
 			TST_EXP_PASS_SILENT(swapon(filename, 0));
@@ -62,7 +62,7 @@ static int setup_swap(void)
 		tst_brk(TFAIL, "Failed to setup swap files");
 
 	tst_res(TINFO, "Successfully created %d swap files", swapfiles);
-	MAKE_SWAPFILE_BLKS(TEST_FILE, 10);
+	MAKE_MINIMAL_SWAPFILE(TEST_FILE);
 
 	return 0;
 }
-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH 1/3] swapoff0[12]: Remove unneeded tst_brk()
  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
  0 siblings, 1 reply; 9+ messages in thread
From: Cyril Hrubis @ 2024-04-18 14:56 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH 2/3] libswap: Add {SAFE_, }MAKE_MINIMAL_SWAPFILE() macros
  2024-04-18 14:13 ` [LTP] [PATCH 2/3] libswap: Add {SAFE_, }MAKE_MINIMAL_SWAPFILE() macros Petr Vorel
@ 2024-04-18 15:39   ` Cyril Hrubis
  2024-04-18 18:14     ` Petr Vorel
  0 siblings, 1 reply; 9+ messages in thread
From: Cyril Hrubis @ 2024-04-18 15:39 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
> 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.

I'm again, slightly againts the use of disk block size as a base measure
of size. In practice the block size will either be 4k or 64k but it's
quite confusing to justify the need for 256 blocks. With 256 blocks the
minimal size will be either 1MB or 16MB depending on the actual
filesystem. So rather than that can we just default to 1MB minimal swap
file, which makes the test a bit more predictable?

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH 3/3] libswap: Use {SAFE_,}MAKE_MINIMAL_SWAPFILE()
  2024-04-18 14:13 ` [LTP] [PATCH 3/3] libswap: Use {SAFE_,}MAKE_MINIMAL_SWAPFILE() Petr Vorel
@ 2024-04-18 15:40   ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2024-04-18 15:40 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
This part is obviously fine.

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH 1/3] swapoff0[12]: Remove unneeded tst_brk()
  2024-04-18 14:56   ` Cyril Hrubis
@ 2024-04-18 18:02     ` Petr Vorel
  0 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2024-04-18 18:02 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril,

merged this first patch, thanks!

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH 2/3] libswap: Add {SAFE_, }MAKE_MINIMAL_SWAPFILE() macros
  2024-04-18 15:39   ` Cyril Hrubis
@ 2024-04-18 18:14     ` Petr Vorel
  0 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2024-04-18 18:14 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

> Hi!
> > 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.

> I'm again, slightly againts the use of disk block size as a base measure
> of size. In practice the block size will either be 4k or 64k but it's
> quite confusing to justify the need for 256 blocks. With 256 blocks the
> minimal size will be either 1MB or 16MB depending on the actual
> filesystem. So rather than that can we just default to 1MB minimal swap
> file, which makes the test a bit more predictable?

Makes sense, I'll send v2.

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-04-18 18:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [LTP] [PATCH 2/3] libswap: Add {SAFE_, }MAKE_MINIMAL_SWAPFILE() macros Petr Vorel
2024-04-18 15:39   ` 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

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 NNTP newsgroup(s).