Re: [PATCH 3/3] selftests/mm: restore enable_soft_offline in hugetlb-soft-offline

Mike Rapoport <[email protected]>
Newsgroups org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest,org.kvack.linux-mm
Message-ID <[email protected]>
Hi,

On Wed, Aug 12, 2026 at 08:08:21PM +0800, Song Hu wrote:
> hugetlb-soft-offline toggles /proc/sys/vm/enable_soft_offline between 1 and
> 0 (test_soft_offline_common(1) then (0)) and leaves it at 0 when it
> finishes, silently disabling soft offlining for the whole system after the
> run.  Read the original value before the test and restore it before
> ksft_finished().
> 
> Signed-off-by: Song Hu <[email protected]>
> ---
>  .../selftests/mm/hugetlb-soft-offline.c       | 24 +++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb-soft-offline.c b/tools/testing/selftests/mm/hugetlb-soft-offline.c
> index bc202e4ed2bd..35dcf661b091 100644
> --- a/tools/testing/selftests/mm/hugetlb-soft-offline.c
> +++ b/tools/testing/selftests/mm/hugetlb-soft-offline.c
> @@ -99,6 +99,23 @@ static int set_enable_soft_offline(int value)
>  	return 0;
>  }
>  
> +static int get_enable_soft_offline(void)
> +{
> +	FILE *fp = fopen("/proc/sys/vm/enable_soft_offline", "r");
> +	int value = -1;
> +
> +	if (!fp) {
> +		ksft_perror(EPREFIX "failed to read enable_soft_offline");
> +		return -1;
> +	}
> +	if (fscanf(fp, "%d", &value) != 1) {
> +		ksft_perror(EPREFIX "failed to parse enable_soft_offline");
> +		value = -1;
> +	}
> +	fclose(fp);
> +	return value;
> +}

We have read_num() in vm_util and write_num() that can replace
set_enable_soft_offline().

> +
>  static int create_hugetlbfs_file(struct statfs *file_stat)
>  {
>  	int fd;
> @@ -185,6 +202,8 @@ static void test_soft_offline_common(int enable_soft_offline)
>  
>  int main(int argc, char **argv)
>  {
> +	int orig;

Please spell out what orig is this.

> +
>  	ksft_print_header();
>  
>  	if (!hugetlb_setup_default(8))
> @@ -192,8 +211,13 @@ int main(int argc, char **argv)
>  
>  	ksft_set_plan(2);
>  
> +	orig = get_enable_soft_offline();
> +
>  	test_soft_offline_common(1);
>  	test_soft_offline_common(0);
>  
> +	if (orig >= 0)
> +		set_enable_soft_offline(orig);
> +
>  	ksft_finished();
>  }
> -- 
> 2.43.0
> 

-- 
Sincerely yours,
Mike.
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.