From: Petr Vorel <pvorel@suse.cz>
To: Yang Xu <xuyang2018.jy@fujitsu.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4 1/7] libltpswap: Add tst_max_swapfiles api
Date: Fri, 23 Feb 2024 10:04:16 +0100 [thread overview]
Message-ID: <20240223090416.GC1423688@pevik> (raw)
In-Reply-To: <20240220074218.13487-1-xuyang2018.jy@fujitsu.com>
Hi Yang Xu,
Reviewed-by: Petr Vorel <pvorel@suse.cz>
generally LGTM, just minor things below.
nit in subject: s/api/API/
> Current, the kernel constant MAX_SWAPFILES value is calculated as below
nit: I'm not a native speaker, but:
s/Current/Currently/
> ------------------------------------
> //#ifdef CONFIG_DEVICE_PRIVATE
> //#define SWP_DEVICE_NUM 4
> //#else
> //#define SWP_DEVICE_NUM 0
> //#endif
> //#ifdef CONFIG_MIGRATION
> //#define SWP_MIGRATION_NUM 3
> //#else
> //#define SWP_MIGRATION_NUM 0
> //#ifdef CONFIG_MEMORY_FAILURE
> //#define SWP_HWPOISON_NUM 1
> //#else
> //#define SWP_HWPOISON_NUM 0
> //#endif
> //#define SWP_PTE_MARKER_NUM 1
> //#define MAX_SWAPFILES_SHIFT 5
> //#define MAX_SWAPFILES \
> // ((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \
> // SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - \
> // SWP_PTE_MARKER_NUM)
nit: if you indent this code with space or tab it will be visible without //.
Using // makes text harder to read.
> ------------------------------------
> Also, man-pages missed something after 5.14 kernel. I have sent two patches[1][2] to
> add it. The kernel patches modify this kernel constant in[3][4][5][6]. Also, after kernel 6.2.0
> [7],kernel always compile in pte markers.
> [1]https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=26f3ec74e
> [2]https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=6bf3937fc
> [3]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=5042db43cc
> [4]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=b756a3b5e
> [5]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=679d10331
> [6]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=6c287605f
> [7]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=ca92ea3dc5
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> include/libswap.h | 6 +++++
> libs/libltpswap/libswap.c | 48 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 54 insertions(+)
> diff --git a/include/libswap.h b/include/libswap.h
> index bdc5aacc6..361d73175 100644
> --- a/include/libswap.h
> +++ b/include/libswap.h
> @@ -21,4 +21,10 @@ int make_swapfile(const char *swapfile, int blocks, int safe);
> * we are testing on.
> */
> bool is_swap_supported(const char *filename);
> +
> +/*
> + * Get kernel constant MAX_SWAPFILES value
nit: . at the end.
> + */
> +int tst_max_swapfiles(void);
> +
> #endif /* __LIBSWAP_H__ */
> diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> index c79de19d7..a404a4ada 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -16,6 +16,8 @@
> #include "tst_test.h"
> #include "libswap.h"
> #include "lapi/syscalls.h"
> +#include "tst_kconfig.h"
> +#include "tst_safe_stdio.h"
> static const char *const swap_supported_fs[] = {
> "btrfs",
> @@ -217,3 +219,49 @@ bool is_swap_supported(const char *filename)
> return true;
> }
> +
> +/*
> + * Get kernel constant MAX_SWAPFILES value
nit: . at the end.
> + */
> +int tst_max_swapfiles(void)
> +{
> + unsigned int max_swapfile = 32;
nit never change, maybe
#define DEFAULT_MAX_SWAPFILE 32
> + unsigned int swp_migration_num = 0, swp_hwpoison_num = 0, swp_device_num = 0, swp_pte_marker_num = 0;
nit: very long line maybe split (readability):
unsigned int swp_migration_num = 0, swp_hwpoison_num = 0,
swp_device_num = 0, swp_pte_marker_num = 0;
But file is full of ugly lines, feel free to ignore.
> + struct tst_kconfig_var migration_kconfig = TST_KCONFIG_INIT("CONFIG_MIGRATION");
> + struct tst_kconfig_var memory_kconfig = TST_KCONFIG_INIT("CONFIG_MEMORY_FAILURE");
> + struct tst_kconfig_var device_kconfig = TST_KCONFIG_INIT("CONFIG_DEVICE_PRIVATE");
> + struct tst_kconfig_var marker_kconfig = TST_KCONFIG_INIT("CONFIG_PTE_MARKER");
Maybe shorten variable - remove "_kconfig" (obvious from use by .choice member).
> +
> + tst_kconfig_read(&migration_kconfig, 1);
> + tst_kconfig_read(&memory_kconfig, 1);
> + tst_kconfig_read(&device_kconfig, 1);
> + tst_kconfig_read(&marker_kconfig, 1);
> +
> + if (migration_kconfig.choice == 'y') {
> + if (tst_kvercmp(5, 19, 0) < 0)
> + swp_migration_num = 2;
> + else
> + swp_migration_num = 3;
> + }
> +
> + if (memory_kconfig.choice == 'y')
> + swp_hwpoison_num = 1;
> +
> + if (device_kconfig.choice == 'y') {
> + if (tst_kvercmp(4, 14, 0) >= 0)
> + swp_device_num = 2;
> + if (tst_kvercmp(5, 14, 0) >= 0)
> + swp_device_num = 4;
> + }
> +
> + if (tst_kvercmp(6, 2, 0) >= 0) {
> + swp_pte_marker_num = 1;
> + } else {
> + if (marker_kconfig.choice == 'y') {
> + if (tst_kvercmp(5, 19, 0) >= 0)
> + swp_pte_marker_num = 1;
> + }
Maybe just:
if ((marker_kconfig.choice == 'y' && tst_kvercmp(5, 19, 0) >= 0) ||
tst_kvercmp(6, 2, 0) >= 0) {
swp_pte_marker_num = 1;
}
> + }
> +
> + return max_swapfile - swp_migration_num - swp_hwpoison_num - swp_device_num - swp_pte_marker_num;
> +}
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-02-23 9:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-20 7:42 [LTP] [PATCH v4 1/7] libltpswap: Add tst_max_swapfiles api Yang Xu via ltp
2024-02-20 7:42 ` [LTP] [PATCH v4 2/7] libltpswap: alter tst_count_swaps api Yang Xu via ltp
2024-02-23 9:37 ` Petr Vorel
2024-02-20 7:42 ` [LTP] [PATCH v4 3/7] syscalls/swapon03: use tst_max_swapfiles() and GET_USED_SWAPFILES() api Yang Xu via ltp
2024-02-21 9:37 ` Petr Vorel
2024-02-22 1:27 ` Yang Xu (Fujitsu) via ltp
2024-02-23 9:48 ` Petr Vorel
2024-02-20 7:42 ` [LTP] [PATCH v4 4/7] swaponoff.h: Remove useless header Yang Xu via ltp
2024-02-23 10:15 ` Petr Vorel
2024-02-20 7:42 ` [LTP] [PATCH v4 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES Yang Xu via ltp
2024-02-23 10:48 ` Petr Vorel
2024-02-20 7:42 ` [LTP] [PATCH v4 6/7] syscalls/swapon03: Simply this case Yang Xu via ltp
2024-02-23 11:48 ` Petr Vorel
2024-02-20 7:42 ` [LTP] [PATCH v4 7/7] Add fallback for RHEL9 Yang Xu via ltp
2024-02-23 11:54 ` Petr Vorel
2024-02-23 9:04 ` Petr Vorel [this message]
2024-02-23 11:56 ` [LTP] [PATCH v4 1/7] libltpswap: Add tst_max_swapfiles api Petr Vorel
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=20240223090416.GC1423688@pevik \
--to=pvorel@suse.cz \
--cc=ltp@lists.linux.it \
--cc=xuyang2018.jy@fujitsu.com \
/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