Re: [PATCH] selftests/mm: khugepaged: skip swap tests when no swap available

"David Hildenbrand (Arm)" <[email protected]>
Newsgroups org.kernel.vger.linux-kselftest,org.kernel.vger.linux-kernel,org.kvack.linux-mm
Message-ID <[email protected]>
On 8/4/26 14:53, Alexander Gordeev wrote:
> When no swap is configured, swap-related tests fail because
> madvise(MADV_PAGEOUT) does not swap out pages. Add a helper
> function to detect swap availability and skip these tests.

You should mention what the effect of that is.

> 
> Signed-off-by: Alexander Gordeev <[email protected]>
> ---
>  tools/testing/selftests/mm/khugepaged.c | 33 +++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c
> index 10e8dedcb087..b254baf9e0b7 100644
> --- a/tools/testing/selftests/mm/khugepaged.c
> +++ b/tools/testing/selftests/mm/khugepaged.c
> @@ -216,6 +216,25 @@ static bool check_swap(void *addr, unsigned long size)
>  	return swap;
>  }
>  
> +static bool is_swap_available(unsigned long size)
> +{
> +	unsigned long swap_total = 0;
> +	char buffer[256];
> +	FILE *fp;
> +
> +	fp = fopen("/proc/meminfo", "r");
> +	if (!fp)
> +		return false;
> +
> +	while (fgets(buffer, sizeof(buffer), fp)) {
> +		if (sscanf(buffer, "SwapTotal: %lu kB", &swap_total) == 1)
> +			break;
> +	}
> +	fclose(fp);
> +
> +	return swap_total >= (size / 1024);
> +}
> +
>  static void *alloc_mapping(int nr)
>  {
>  	void *p;
> @@ -734,6 +753,13 @@ static void collapse_swapin_single_pte(struct collapse_context *c, struct mem_op
>  {
>  	void *p;
>  
> +	if (!is_swap_available(page_size)) {
> +		ksft_print_msg("No swap available...");
> +		skip("Skip");
> +		ksft_test_result_skip("%s\n", __func__);
> +		return;
> +	}
> +
>  	p = ops->setup_area(1);
>  	ops->fault(p, 0, hpage_pmd_size);
>  
> @@ -760,6 +786,13 @@ static void collapse_max_ptes_swap(struct collapse_context *c, struct mem_ops *o
>  	int max_ptes_swap = thp_read_num("khugepaged/max_ptes_swap");
>  	void *p;
>  
> +	if (!is_swap_available((max_ptes_swap + 1) * page_size)) {
> +		ksft_print_msg("No swap available...");
> +		skip("Skip");
> +		ksft_test_result_skip("%s\n", __func__);
> +		return;
> +	}
> +
>  	p = ops->setup_area(1);
>  	ops->fault(p, 0, hpage_pmd_size);
>  

See

https://lore.kernel.org/all/[email protected]/

where I raise that we should rather handle the actual MADV_PAGEOUT errors,
because there can be other reasons why MADV_PAGEOUT just fails.

-- 
Cheers,

David
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.