Re: [PATCH 3/3] selftests/mm: restore enable_soft_offline in hugetlb-soft-offline
Song Hu <[email protected]>
| Newsgroups | org.kernel.vger.linux-kselftest,org.kernel.vger.linux-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
在 2026/8/12 21:42, Mike Rapoport 写道: > 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(). > Will switch to them in v2 and drop both helpers. >> + >> 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. > Will rename to orig_enable_soft_offline. Also, per the error-path issue Andrew pointed out, v2 will register the restore with atexit() so it also runs when the test exits via ksft_exit_fail_msg(), like hugepage_restore_settings_atexit() in hugepage_settings.c. Thanks, Song>> + >> 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 >> >