The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Alexander Gordeev <agordeev@linux.ibm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Lorenzo Stoakes <ljs@kernel.org>
Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/mm: khugepaged: skip swap tests when no swap available
Date: Thu, 6 Aug 2026 15:45:27 +0200	[thread overview]
Message-ID: <9d0d98ea-05bd-43c0-bb36-68aea62cbde8@kernel.org> (raw)
In-Reply-To: <20260804125351.1715708-1-agordeev@linux.ibm.com>

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 <agordeev@linux.ibm.com>
> ---
>  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/20260715133418.170386-1-jaeyeon.lee.dev@gmail.com/

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

      reply	other threads:[~2026-08-06 13:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04 12:53 [PATCH] selftests/mm: khugepaged: skip swap tests when no swap available Alexander Gordeev
2026-08-06 13:45 ` David Hildenbrand (Arm) [this message]

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=9d0d98ea-05bd-43c0-bb36-68aea62cbde8@kernel.org \
    --to=david@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    /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