[LTP] [PATCH v1] swapoff01.c: Adjust blocks size base on pagesize
Cyril Hrubis
chrubis@suse.cz
Thu Feb 22 14:50:38 CET 2024
Hi!
> > Isn't this more about Btrfs though? Looking at the make_swapfile() we do
> > use statvfs to get filesystem block size and if that is Btrfs with 64k
> > blocks we end up with swapfile of a size of 4GB that sounds like a bit
> > too much I guess.
> >
>
> Sorry for confusing. It should caused by block size instead of page size.
> The code change should change like following, but i suppose you will not agree
> on this solution, correct?
>
> --- a/testcases/kernel/syscalls/swapoff/swapoff01.c
> +++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
> @@ -12,6 +12,7 @@
> #include <unistd.h>
> #include <errno.h>
> #include <stdlib.h>
> +#include <sys/statvfs.h>
>
> #include "tst_test.h"
> #include "lapi/syscalls.h"
> @@ -44,8 +45,21 @@ static void setup(void)
> {
> is_swap_supported(TEST_FILE);
>
> - if (make_swapfile(SWAP_FILE, 65536, 1))
> + struct statvfs fs_info;
> + unsigned long blk_size;
> + if (statvfs(".", &fs_info) == -1)
> + tst_brk(TBROK, "Failed to get statvfs info");
> +
> + blk_size = fs_info.f_bsize;
> +
> + int blocks = 65535;
> +
> + if (blk_size > 4096)
> + blocks = 65535 * 4096 / blk_size;
> +
> + if (make_swapfile(SWAP_FILE, blocks, 1))
> tst_brk(TBROK, "Failed to create file for swap");
> +
> }
It may be easier to change the make_swapfile() function to accept
megabytes instead of working around it like this.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list