Userspace controls soft-offline pages
Subsystems (6)
v5 cover Userspace controls soft-offline pages
Correctable memory errors are very common on servers with large amount of memory, and are corrected by ECC, but with two pain points to users:
1. Correction usually happens on the fly and adds latency overhead
2. Not-fully-proved theory states excessive correctable memory errors can develop into uncorrectable memory error.
Soft offline is kernel's additional solution for memory pages having (excessive) corrected memory errors. Impacted page is migrated to healthy page if it is in use, then the original page is discarded for any future use.
The actual policy on whether (and when) to soft offline should be maintained by userspace, especially in case of an 1G HugeTLB page. Soft-offline dissolves the HugeTLB page, either in-use or free, into chunks of 4K pages, reducing HugeTLB pool capacity by 1 hugepage. If userspace has not acknowledged such behavior, it may be surprised when later mmap hugepages MAP_FAILED due to lack of hugepages. In case of a transparent hugepage, it will be split into 4K pages as well; userspace will stop enjoying the transparent performance.
In addition, discarding the entire 1G HugeTLB page only because of corrected memory errors sounds very costly and kernel better not doing under the hood. But today there are at least 2 such cases:
1. GHES driver sees both GHES_SEV_CORRECTED and CPER_SEC_ERROR_THRESHOLD_EXCEEDED after parsing CPER.
2. RAS Correctable Errors Collector counts correctable errors per PFN and when the counter for a PFN reaches threshold
In both cases, userspace has no control of the soft offline performed by kernel's memory failure recovery.
This patch series give userspace the control of softofflining any page:
kernel only soft offlines raw page / transparent hugepage / HugeTLB hugepage if userspace has agreed to. The interface to userspace is a new sysctl called enable_soft_offline under /proc/sys/vm. By default enable_soft_line is 1 to preserve existing behavior in kernel.
Changelog
v4 => v5:
* incorportate feedbacks from Muhammad Usama Anjum <[email protected]>
* refactor selftest to use what available in kselftest.h.
* update a comment in soft_offline_page.
v3 => v4:
* incorporate feedbacks from Miaohe Lin <[email protected]>, Andrew Morton <[email protected]>, and
Oscar Salvador <[email protected]>.
* insert a refactor commit to unify soft offline's logs to follow "Soft offline: 0x${pfn}: ${message}" format.
* some rewords in document: fail => will not perform.
* v4 is still based on commit 83a7eefedc9b ("Linux 6.10-rc3"), akpm/mm-stable.
v2 => v3:
* incorporate feedbacks from Miaohe Lin <[email protected]>, Lance Yang <[email protected]>, Oscar Salvador <[email protected]>, and David Rientjes <[email protected]>.
* release potential refcount if enable_soft_offline is 0.
* soft_offline_page() returns EOPNOTSUPP if enable_soft_offline is 0.
* refactor hugetlb-soft-offline.c, for example, introduce test_soft_offline_common to reduce repeated code.
* rewrite enable_soft_offline's documentation, adds more details about the cost of soft-offline for transparent and hugetlb hugepages, and components that are impacted when enable_soft_offline becomes 0.
* fix typos in commit messages.
* v3 is still based on commit 83a7eefedc9b ("Linux 6.10-rc3").
v1 => v2:
* incorporate feedbacks from both Miaohe Lin <[email protected]> and Jane Chu <[email protected]>.
* make the switch to control all pages, instead of HugeTLB specific.
* change the API from /sys/kernel/mm/hugepages/hugepages-${size}kB/softoffline_corrected_errors to /proc/sys/vm/enable_soft_offline.
* minor update to test code.
* update documentation of the user control API.
* v2 is based on commit 83a7eefedc9b ("Linux 6.10-rc3").
Jiaqi Yan (4):
mm/memory-failure: refactor log format in soft offline code mm/memory-failure: userspace controls soft-offlining pages selftest/mm: test enable_soft_offline behaviors
docs: mm: add enable_soft_offline sysctl
Documentation/admin-guide/sysctl/vm.rst | 32 +++ mm/memory-failure.c | 38 ++- tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + .../selftests/mm/hugetlb-soft-offline.c | 227 ++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 4 + 6 files changed, 295 insertions(+), 8 deletions(-) create mode 100644 tools/testing/selftests/mm/hugetlb-soft-offline.c
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
PATCH v5 1/4 mm/memory-failure: refactor log format in soft offline code
Logs from soft_offline_page and soft_offline_in_use_page have different formats than majority of the memory failure code:
"Memory failure: 0x${pfn}: ${lower_case_message}"Convert them to the following format:
"Soft offline: 0x${pfn}: ${lower_case_message}"No functional change in this commit.
--- mm/memory-failure.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
mm/memory-failure.c +9 -6
@@ -2631,6 +2631,9 @@ int unpoison_memory(unsigned long pfn) }EXPORT_SYMBOL (unpoison_memory); +#undef pr_fmt +#define pr_fmt (fmt) "Soft offline: " fmt +static bool mf_isolate_folio (struct folio *folio,struct list_head *pagelist) {bool isolated = false;
@@ -2686,7 +2689,7 @@ static int soft_offline_in_use_page(struct page *page)if (!huge &&folio_test_large (folio)) {if (try_to_split_thp_page (page)) { -pr_info ("soft offline: %#lx: thp split failed\n" , pfn); +pr_info ("%#lx: thp split failed\n" , pfn);return -EBUSY ; } folio =page_folio (page);
@@ -2698,7 +2701,7 @@ static int soft_offline_in_use_page(struct page *page)if (PageHWPoison (page)) {folio_unlock (folio);folio_put (folio); -pr_info ("soft offline: %#lx page already poisoned\n" , pfn); +pr_info ("%#lx page already poisoned\n" , pfn);return 0 ; }
@@ -2711,7 +2714,7 @@ static int soft_offline_in_use_page(struct page *page)folio_unlock (folio);if (ret) { -pr_info ("soft_offline: %#lx: invalidated\n" , pfn); +pr_info ("%#lx: invalidated\n" , pfn);page_handle_poison (page, false, true);return 0 ; }
@@ -2728,13 +2731,13 @@ static int soft_offline_in_use_page(struct page *page)if (!list_empty (&pagelist))putback_movable_pages (&pagelist); -pr_info ("soft offline: %#lx: %s migration failed %ld, type %pGp\n" , +pr_info ("%#lx: %s migration failed %ld, type %pGp\n" , pfn, msg_page[huge], ret, &page->flags);if (ret >0 ) ret = -EBUSY ; } }else { -pr_info ("soft offline: %#lx: %s isolation failed, page count %d, type %pGp\n" , +pr_info ("%#lx: %s isolation failed, page count %d, type %pGp\n" , pfn, msg_page[huge],page_count (page), &page->flags); ret = -EBUSY ; }
@@ -2786,7 +2789,7 @@ int soft_offline_page(unsigned long pfn, int flags)mutex_lock (&mf_mutex);if (PageHWPoison (page)) { -pr_info ("%s: %#lx page already poisoned\n" , __func__, pfn); +pr_info ("%#lx: page already poisoned\n" , pfn);put_ref_page (pfn, flags);mutex_unlock (&mf_mutex);return 0 ;
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Miaohe Lin
maintainerRe: [PATCH v5 1/4] mm/memory-failure: refactor log format in soft offline code
Quoted 40 lines · Jiaqi Yan
Logs from
soft_offline_pageandsoft_offline_in_use_pagehave different formats than majority of the memory failure code:"Memory failure: 0x${pfn}: ${lower_case_message}"Convert them to the following format:
"Soft offline: 0x${pfn}: ${lower_case_message}"No functional change in this commit.
Signed-off-by Jiaqi Yan <[email protected]>--- mm/memory-failure.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)mm/memory-failure.c +4
-1@@ -2631,6 +2631,9 @@ int unpoison_memory(unsigned long pfn) }EXPORT_SYMBOL (unpoison_memory); +#undef pr_fmt +#define pr_fmt (fmt) "Soft offline: " fmt +static bool mf_isolate_folio (struct folio *folio,struct list_head *pagelist) {bool isolated = false;@@ -2686,7 +2689,7 @@ static int soft_offline_in_use_page(struct page *page)if (!huge &&folio_test_large (folio)) {if (try_to_split_thp_page (page)) { -pr_info ("soft offline: %#lx: thp split failed\n" , pfn); +pr_info ("%#lx: thp split failed\n" , pfn);return -EBUSY ; } folio =page_folio (page);
mm/memory-failure.c static int soft_offline_in_use_page(struct page *page) · line 2704
Quoted 5 lines
mm/memory-failure.c +1
-1@@ -2698,7 +2701,7 @@ static int soft_offline_in_use_page(struct page *page)if (PageHWPoison (page)) {folio_unlock (folio);folio_put (folio); -pr_info ("soft offline: %#lx page already poisoned\n" , pfn); +pr_info ("%#lx page already poisoned\n" , pfn);
Again, it's better to be "%#lx: page" to make log format consistent. Thanks.
.
Re: [PATCH v5 1/4] mm/memory-failure: refactor log format in soft offline code
Quoted 34 lines · Miaohe Lin
Quoted 32 lines · Jiaqi Yan
Logs from
soft_offline_pageandsoft_offline_in_use_pagehave different formats than majority of the memory failure code:"Memory failure: 0x${pfn}: ${lower_case_message}"Convert them to the following format:
"Soft offline: 0x${pfn}: ${lower_case_message}"No functional change in this commit.
Signed-off-by Jiaqi Yan <[email protected]>--- mm/memory-failure.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)mm/memory-failure.c +3
-0@@ -2631,6 +2631,9 @@ int unpoison_memory(unsigned long pfn) }EXPORT_SYMBOL (unpoison_memory); +#undef pr_fmt +#define pr_fmt (fmt) "Soft offline: " fmt +static bool mf_isolate_folio (struct folio *folio,struct list_head *pagelist) {bool isolated = false;@@ -2686,7 +2689,7 @@ static int soft_offline_in_use_page(struct page *page)
Quoted 15 lines
mm/memory-failure.c static int soft_offline_in_use_page(struct page *page) · line 2704
Quoted 13 lines
mm/memory-failure.c +2
-2if (!huge &&folio_test_large (folio)) {if (try_to_split_thp_page (page)) { -pr_info ("soft offline: %#lx: thp split failed\n" , pfn); +pr_info ("%#lx: thp split failed\n" , pfn);return -EBUSY ; } folio =page_folio (page);@@ -2698,7 +2701,7 @@ static int soft_offline_in_use_page(struct page *page)if (PageHWPoison (page)) {folio_unlock (folio);folio_put (folio); -pr_info ("soft offline: %#lx page already poisoned\n" , pfn); +pr_info ("%#lx page already poisoned\n" , pfn);Again, it's better to be "%#lx: page" to make log format consistent.
Ah, I missed a ":", thanks for catching this!
Quoted 2 lines
Thanks.
.
PATCH v5 2/4 mm/memory-failure: userspace controls soft-offlining pages
In reply to Jiaqi YanCorrectable memory errors are very common on servers with large amount of memory, and are corrected by ECC. Soft offline is kernel's additional recovery handling for memory pages having (excessive) corrected memory errors. Impacted page is migrated to a healthy page if inuse; the original page is discarded for any future use.
The actual policy on whether (and when) to soft offline should be maintained by userspace, especially in case of an 1G HugeTLB page. Soft-offline dissolves the HugeTLB page, either in-use or free, into chunks of 4K pages, reducing HugeTLB pool capacity by 1 hugepage. If userspace has not acknowledged such behavior, it may be surprised when later failed to mmap hugepages due to lack of hugepages. In case of a transparent hugepage, it will be split into 4K pages as well; userspace will stop enjoying the transparent performance.
In addition, discarding the entire 1G HugeTLB page only because of corrected memory errors sounds very costly and kernel better not doing under the hood. But today there are at least 2 such cases doing so:
1. when GHES driver sees both GHES_SEV_CORRECTED and CPER_SEC_ERROR_THRESHOLD_EXCEEDED after parsing CPER.
2. RAS Correctable Errors Collector counts correctable errors per PFN and when the counter for a PFN reaches threshold
In both cases, userspace has no control of the soft offline performed by kernel's memory failure recovery.
This commit gives userspace the control of softofflining any page:
kernel only soft offlines raw page / transparent hugepage / HugeTLB hugepage if userspace has agreed to. The interface to userspace is a new sysctl at /proc/sys/vm/enable_soft_offline. By default its value is set to 1 to preserve existing behavior in kernel. When set to 0, soft-offline (e.g. MADV_SOFT_OFFLINE) will fail with EOPNOTSUPP.
--- mm/memory-failure.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
mm/memory-failure.c +21 -2
@@ -68,6 +68,8 @@ static int sysctl_memory_failure_early_kill __read_mostly;static int sysctl_memory_failure_recovery__read_mostly =1 ; +static int sysctl_enable_soft_offline__read_mostly =1 ; +atomic_long_t num_poisoned_pages__read_mostly =ATOMIC_LONG_INIT (0 );static bool hw_memory_failure__read_mostly = false;
@@ -141,6 +143,15 @@ static struct ctl_table memory_failure_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, }, + { + .procname = "enable_soft_offline", + .data = &sysctl_enable_soft_offline, + .maxlen = sizeof(sysctl_enable_soft_offline), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + } };/*
@@ -2749,8 +2760,9 @@ static int soft_offline_in_use_page(struct page *page)* @pfn: pfn to soft-offline * @flags: flags. Same as memory_failure(). * -* Returns 0 on success -* -EOPNOTSUPP for hwpoison_filter() filtered the error event +* Returns 0 on success, +* -EOPNOTSUPP for hwpoison_filter() filtered the error event, or +* disabled by /proc/sys/vm/enable_soft_offline, * < 0 otherwise negated errno. * * Soft offline a page, by migration or invalidation,
@@ -2786,6 +2798,13 @@ int soft_offline_page(unsigned long pfn, int flags)return -EIO ; } +if (!sysctl_enable_soft_offline) { +pr_info_once ("%#lx: disabled by /proc/sys/vm/enable_soft_offline\n" , + pfn); +put_ref_page (pfn, flags); +return -EOPNOTSUPP ; + } +mutex_lock (&mf_mutex);if (PageHWPoison (page)) {
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
PATCH v5 3/4 selftest/mm: test enable_soft_offline behaviors
In reply to Jiaqi YanAdd regression and new tests when hugepage has correctable memory errors, and how userspace wants to deal with it:
* if enable_soft_offline=1, mapped hugepage is soft offlined
* if enable_soft_offline=0, mapped hugepage is intact
Free hugepages case is not explicitly covered by the tests.
Hugepage having corrected memory errors is emulated with MADV_SOFT_OFFLINE.
--- tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + .../selftests/mm/hugetlb-soft-offline.c | 227 ++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 4 + 4 files changed, 233 insertions(+) create mode 100644 tools/testing/selftests/mm/hugetlb-soft-offline.c
tools/testing/selftests/mm/.gitignore +1 -0
@@ -6,6 +6,7 @@ hugepage-shm hugepage-vmemmap hugetlb-madvise hugetlb-read-hwpoison +hugetlb-soft-offline khugepaged map_hugetlb map_populate
tools/testing/selftests/mm/Makefile +1 -0
@@ -42,6 +42,7 @@ TEST_GEN_FILES += gup_test TEST_GEN_FILES += hmm-tests TEST_GEN_FILES += hugetlb-madvise TEST_GEN_FILES += hugetlb-read-hwpoison +TEST_GEN_FILES += hugetlb-soft-offline TEST_GEN_FILES += hugepage-mmap TEST_GEN_FILES += hugepage-mremap TEST_GEN_FILES += hugepage-shm
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +227 -0
227 lines not on this page · raw message
tools/testing/selftests/mm/run_vmtests.sh +4 -0
@@ -331,6 +331,10 @@ CATEGORY="hugetlb" run_test ./thuge-gen CATEGORY="hugetlb" run_test ./charge_reserved_hugetlb.sh -cgroup-v2 CATEGORY="hugetlb" run_test ./hugetlb_reparenting_test.sh -cgroup-v2 if $RUN_DESTRUCTIVE; then +nr_hugepages_tmp=$(cat /proc/sys/vm/nr_hugepages) +echo 8 > /proc/sys/vm/nr_hugepages +CATEGORY="hugetlb" run_test ./hugetlb-soft-offline +echo "$nr_hugepages_tmp" > /proc/sys/vm/nr_hugepages CATEGORY="hugetlb" run_test ./hugetlb-read-hwpoison fi
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Miaohe Lin
maintainerRe: [PATCH v5 3/4] selftest/mm: test enable_soft_offline behaviors
Quoted 1 line · Jiaqi Yan
Add regression and new tests when hugepage has correctable memory
...
tools/testing/selftests/mm/hugetlb-soft-offline.c line 5
Quoted 11 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +5
-0@@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Test soft offline behavior for HugeTLB pages: +* - if enable_soft_offline = 0, hugepages should stay intact and soft +* offlining failed with EINVAL.
s/failed with EINVAL/failed with EOPNOTSUPP/g
Quoted 8 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +8
-0+* - if enable_soft_offline = 1, a hugepage should be dissolved and +* nr_hugepages/free_hugepages should be reduced by 1. +* +* Before running, make sure more than 2 hugepages of default_hugepagesz +* are allocated. For example, if /proc/meminfo/Hugepagesize is 2048kB: +* echo 8 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages +*/ +
...
Quoted 14 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +14
-0+static void test_soft_offline_common (int enable_soft_offline) +{ +int fd; +int expect_errno = enable_soft_offline ?0 :EOPNOTSUPP ; +struct statfs file_stat; +unsigned long hugepagesize_kb =0 ; +unsigned long nr_hugepages_before =0 ; +unsigned long nr_hugepages_after =0 ; +int ret; + +ksft_print_msg ("Test soft-offline when enabled_soft_offline=%d\n" , + enable_soft_offline); + + fd =create_hugetlbfs_file (&file_stat);
tools/testing/selftests/mm/hugetlb-soft-offline.c line 178
Quoted 10 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +10
-0+if (fd <0 ) { +ksft_exit_fail_msg ("Failed to create hugetlbfs file\n" ); +return ; + } + + hugepagesize_kb = file_stat.f_bsize /1024 ; +ksft_print_msg ("Hugepagesize is %ldkB\n" , hugepagesize_kb); + +if (set_enable_soft_offline (enable_soft_offline)) { +ksft_exit_fail_msg ("Failed to set enable_soft_offline\n" );
Call destroy_hugetlbfs_file() in error path?
Quoted 27 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +27
-0+return ; + } + +if (read_nr_hugepages (hugepagesize_kb, &nr_hugepages_before) !=0 ) { +ksft_exit_fail_msg ("Failed to read nr_hugepages\n" ); +return ; + } + +ksft_print_msg ("Before MADV_SOFT_OFFLINE nr_hugepages=%ld\n" , + nr_hugepages_before); + + ret =do_soft_offline (fd,2 * file_stat.f_bsize, expect_errno); + +if (read_nr_hugepages (hugepagesize_kb, &nr_hugepages_after) !=0 ) { +ksft_exit_fail_msg ("Failed to read nr_hugepages\n" ); +return ; + } + +ksft_print_msg ("After MADV_SOFT_OFFLINE nr_hugepages=%ld\n" , + nr_hugepages_after); + +if (enable_soft_offline) { +if (nr_hugepages_before != nr_hugepages_after +1 ) { +ksft_test_result_fail ("MADV_SOFT_OFFLINE should reduced 1 hugepage\n" ); +return ; + } + }else {
tools/testing/selftests/mm/hugetlb-soft-offline.c line 215
Quoted 10 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +10
-0+if (nr_hugepages_before != nr_hugepages_after) { +ksft_test_result_fail ("MADV_SOFT_OFFLINE reduced %lu hugepages\n" , + nr_hugepages_before - nr_hugepages_after); +return ; + } + } + +ksft_test_result (ret ==0 , +"Test soft-offline when enabled_soft_offline=%d\n" , + enable_soft_offline);
Call destroy_hugetlbfs_file() when test finished ?
Thanks.
.
Re: [PATCH v5 3/4] selftest/mm: test enable_soft_offline behaviors
Quoted 4 lines · Miaohe Lin
Quoted 1 line · Jiaqi Yan
Add regression and new tests when hugepage has correctable memory
...
Quoted 13 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c line 5
Quoted 11 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +5
-0@@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Test soft offline behavior for HugeTLB pages: +* - if enable_soft_offline = 0, hugepages should stay intact and soft +* offlining failed with EINVAL. s/failed with EINVAL/failed with EOPNOTSUPP/g
To be fixed in v6.
Quoted 28 lines
Quoted 9 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +8
-0+* - if enable_soft_offline = 1, a hugepage should be dissolved and +* nr_hugepages/free_hugepages should be reduced by 1. +* +* Before running, make sure more than 2 hugepages of default_hugepagesz +* are allocated. For example, if /proc/meminfo/Hugepagesize is 2048kB: +* echo 8 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages +*/ +...
Quoted 18 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +18
-0+static void test_soft_offline_common (int enable_soft_offline) +{ +int fd; +int expect_errno = enable_soft_offline ?0 :EOPNOTSUPP ; +struct statfs file_stat; +unsigned long hugepagesize_kb =0 ; +unsigned long nr_hugepages_before =0 ; +unsigned long nr_hugepages_after =0 ; +int ret; + +ksft_print_msg ("Test soft-offline when enabled_soft_offline=%d\n" , + enable_soft_offline); + + fd =create_hugetlbfs_file (&file_stat); +if (fd <0 ) { +ksft_exit_fail_msg ("Failed to create hugetlbfs file\n" ); +return ; + }
Quoted 8 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c line 178
Quoted 6 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +6
-0+ + hugepagesize_kb = file_stat.f_bsize /1024 ; +ksft_print_msg ("Hugepagesize is %ldkB\n" , hugepagesize_kb); + +if (set_enable_soft_offline (enable_soft_offline)) { +ksft_exit_fail_msg ("Failed to set enable_soft_offline\n" );Call
destroy_hugetlbfs_file()in error path?
As the counterpart of destroy_hugetlbfs_file, I think the test only needs to close(fd). Will add it in v6.
Quoted 32 lines
Quoted 32 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +31
-0+return ; + } + +if (read_nr_hugepages (hugepagesize_kb, &nr_hugepages_before) !=0 ) { +ksft_exit_fail_msg ("Failed to read nr_hugepages\n" ); +return ; + } + +ksft_print_msg ("Before MADV_SOFT_OFFLINE nr_hugepages=%ld\n" , + nr_hugepages_before); + + ret =do_soft_offline (fd,2 * file_stat.f_bsize, expect_errno); + +if (read_nr_hugepages (hugepagesize_kb, &nr_hugepages_after) !=0 ) { +ksft_exit_fail_msg ("Failed to read nr_hugepages\n" ); +return ; + } + +ksft_print_msg ("After MADV_SOFT_OFFLINE nr_hugepages=%ld\n" , + nr_hugepages_after); + +if (enable_soft_offline) { +if (nr_hugepages_before != nr_hugepages_after +1 ) { +ksft_test_result_fail ("MADV_SOFT_OFFLINE should reduced 1 hugepage\n" ); +return ; + } + }else { +if (nr_hugepages_before != nr_hugepages_after) { +ksft_test_result_fail ("MADV_SOFT_OFFLINE reduced %lu hugepages\n" , + nr_hugepages_before - nr_hugepages_after); +return ;
Quoted 8 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c line 215
Quoted 6 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +6
-0+ } + } + +ksft_test_result (ret ==0 , +"Test soft-offline when enabled_soft_offline=%d\n" , + enable_soft_offline);Call
destroy_hugetlbfs_file()when test finished ?
Test can just close(fd) once nr_hugepages_after is read.
Quoted 6 lines
Thanks.
.
Miaohe Lin
maintainerRe: [PATCH v5 3/4] selftest/mm: test enable_soft_offline behaviors
Quoted 102 lines · Jiaqi Yan
Quoted 4 lines · Miaohe Lin
Quoted 1 line · Jiaqi Yan
Add regression and new tests when hugepage has correctable memory
...
Quoted 13 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c line 5
Quoted 11 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +5
-0@@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Test soft offline behavior for HugeTLB pages: +* - if enable_soft_offline = 0, hugepages should stay intact and soft +* offlining failed with EINVAL. s/failed with EINVAL/failed with EOPNOTSUPP/g
To be fixed in v6.
Quoted 28 lines
Quoted 9 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +8
-0+* - if enable_soft_offline = 1, a hugepage should be dissolved and +* nr_hugepages/free_hugepages should be reduced by 1. +* +* Before running, make sure more than 2 hugepages of default_hugepagesz +* are allocated. For example, if /proc/meminfo/Hugepagesize is 2048kB: +* echo 8 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages +*/ +...
Quoted 18 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +18
-0+static void test_soft_offline_common (int enable_soft_offline) +{ +int fd; +int expect_errno = enable_soft_offline ?0 :EOPNOTSUPP ; +struct statfs file_stat; +unsigned long hugepagesize_kb =0 ; +unsigned long nr_hugepages_before =0 ; +unsigned long nr_hugepages_after =0 ; +int ret; + +ksft_print_msg ("Test soft-offline when enabled_soft_offline=%d\n" , + enable_soft_offline); + + fd =create_hugetlbfs_file (&file_stat); +if (fd <0 ) { +ksft_exit_fail_msg ("Failed to create hugetlbfs file\n" ); +return ; + }Quoted 8 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c line 178
Quoted 6 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +6
-0+ + hugepagesize_kb = file_stat.f_bsize /1024 ; +ksft_print_msg ("Hugepagesize is %ldkB\n" , hugepagesize_kb); + +if (set_enable_soft_offline (enable_soft_offline)) { +ksft_exit_fail_msg ("Failed to set enable_soft_offline\n" );Call
destroy_hugetlbfs_file()in error path?As the counterpart of
destroy_hugetlbfs_file, I think the test only needs to close(fd). Will add it in v6.Quoted 32 lines
Quoted 32 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +31
-0+return ; + } + +if (read_nr_hugepages (hugepagesize_kb, &nr_hugepages_before) !=0 ) { +ksft_exit_fail_msg ("Failed to read nr_hugepages\n" ); +return ; + } + +ksft_print_msg ("Before MADV_SOFT_OFFLINE nr_hugepages=%ld\n" , + nr_hugepages_before); + + ret =do_soft_offline (fd,2 * file_stat.f_bsize, expect_errno); + +if (read_nr_hugepages (hugepagesize_kb, &nr_hugepages_after) !=0 ) { +ksft_exit_fail_msg ("Failed to read nr_hugepages\n" ); +return ; + } + +ksft_print_msg ("After MADV_SOFT_OFFLINE nr_hugepages=%ld\n" , + nr_hugepages_after); + +if (enable_soft_offline) { +if (nr_hugepages_before != nr_hugepages_after +1 ) { +ksft_test_result_fail ("MADV_SOFT_OFFLINE should reduced 1 hugepage\n" ); +return ; + } + }else { +if (nr_hugepages_before != nr_hugepages_after) { +ksft_test_result_fail ("MADV_SOFT_OFFLINE reduced %lu hugepages\n" , + nr_hugepages_before - nr_hugepages_after); +return ;Quoted 8 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c line 215
Quoted 6 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +6
-0+ } + } + +ksft_test_result (ret ==0 , +"Test soft-offline when enabled_soft_offline=%d\n" , + enable_soft_offline);Call
destroy_hugetlbfs_file()when test finished ?
Quoted 1 line
Test can just close(fd) once
nr_hugepages_afteris read.
I'm sorry but I can't find the code to call close(fd) after nr_hugepages_after is read. IMO create_hugetlbfs_file() would fail to create a new hugetlb file later if close(fd) is not called when testing previous enable_soft_offline = 1 testcase. Because a hugetlb file with same name is already there. But I might miss something.
Thanks.
.
Re: [PATCH v5 3/4] selftest/mm: test enable_soft_offline behaviors
Quoted 104 lines · Miaohe Lin
Quoted 102 lines · Jiaqi Yan
Quoted 4 lines · Miaohe Lin
Quoted 1 line · Jiaqi Yan
Add regression and new tests when hugepage has correctable memory
...
Quoted 13 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c line 5
Quoted 11 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +5
-0@@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Test soft offline behavior for HugeTLB pages: +* - if enable_soft_offline = 0, hugepages should stay intact and soft +* offlining failed with EINVAL. s/failed with EINVAL/failed with EOPNOTSUPP/g
To be fixed in v6.
Quoted 28 lines
Quoted 9 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +8
-0+* - if enable_soft_offline = 1, a hugepage should be dissolved and +* nr_hugepages/free_hugepages should be reduced by 1. +* +* Before running, make sure more than 2 hugepages of default_hugepagesz +* are allocated. For example, if /proc/meminfo/Hugepagesize is 2048kB: +* echo 8 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages +*/ +...
Quoted 18 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +18
-0+static void test_soft_offline_common (int enable_soft_offline) +{ +int fd; +int expect_errno = enable_soft_offline ?0 :EOPNOTSUPP ; +struct statfs file_stat; +unsigned long hugepagesize_kb =0 ; +unsigned long nr_hugepages_before =0 ; +unsigned long nr_hugepages_after =0 ; +int ret; + +ksft_print_msg ("Test soft-offline when enabled_soft_offline=%d\n" , + enable_soft_offline); + + fd =create_hugetlbfs_file (&file_stat); +if (fd <0 ) { +ksft_exit_fail_msg ("Failed to create hugetlbfs file\n" ); +return ; + }Quoted 8 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c line 178
Quoted 6 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +6
-0+ + hugepagesize_kb = file_stat.f_bsize /1024 ; +ksft_print_msg ("Hugepagesize is %ldkB\n" , hugepagesize_kb); + +if (set_enable_soft_offline (enable_soft_offline)) { +ksft_exit_fail_msg ("Failed to set enable_soft_offline\n" );Call
destroy_hugetlbfs_file()in error path?As the counterpart of
destroy_hugetlbfs_file, I think the test only needs to close(fd). Will add it in v6.Quoted 40 lines
Quoted 28 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +27
-0+return ; + } + +if (read_nr_hugepages (hugepagesize_kb, &nr_hugepages_before) !=0 ) { +ksft_exit_fail_msg ("Failed to read nr_hugepages\n" ); +return ; + } + +ksft_print_msg ("Before MADV_SOFT_OFFLINE nr_hugepages=%ld\n" , + nr_hugepages_before); + + ret =do_soft_offline (fd,2 * file_stat.f_bsize, expect_errno); + +if (read_nr_hugepages (hugepagesize_kb, &nr_hugepages_after) !=0 ) { +ksft_exit_fail_msg ("Failed to read nr_hugepages\n" ); +return ; + } + +ksft_print_msg ("After MADV_SOFT_OFFLINE nr_hugepages=%ld\n" , + nr_hugepages_after); + +if (enable_soft_offline) { +if (nr_hugepages_before != nr_hugepages_after +1 ) { +ksft_test_result_fail ("MADV_SOFT_OFFLINE should reduced 1 hugepage\n" ); +return ; + } + }else {tools/testing/selftests/mm/hugetlb-soft-offline.c line 215
Quoted 10 lines
tools/testing/selftests/mm/hugetlb-soft-offline.c new file +10
-0+if (nr_hugepages_before != nr_hugepages_after) { +ksft_test_result_fail ("MADV_SOFT_OFFLINE reduced %lu hugepages\n" , + nr_hugepages_before - nr_hugepages_after); +return ; + } + } + +ksft_test_result (ret ==0 , +"Test soft-offline when enabled_soft_offline=%d\n" , + enable_soft_offline);Call
destroy_hugetlbfs_file()when test finished ?
Quoted 3 lines
Quoted 1 line
Test can just close(fd) once
nr_hugepages_afteris read.I'm sorry but I can't find the code to call close(fd) after
nr_hugepages_afteris read.
Sorry, I meant in v6 I will add close(fd) after nr_hugepages_after.
Quoted 3 lines
IMO
create_hugetlbfs_file()would fail to create a new hugetlb file later if close(fd) is not called when testing previousenable_soft_offline= 1 testcase. Because a hugetlb file with same name is already there. But I might miss something.
Yes, this is an absolutely valid concern, and should be address in v6 by adding close(fd) after nr_hugepages_after.
Quoted 4 lines
Thanks.
.
PATCH v5 4/4 docs: mm: add enable_soft_offline sysctl
In reply to Jiaqi YanAdd the documentation for soft offline behaviors / costs, and what the new enable_soft_offline sysctl is for.
--- Documentation/admin-guide/sysctl/vm.rst | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
Documentation/admin-guide/sysctl/vm.rst +32 -0
@@ -36,6 +36,7 @@ Currently, these files are in /proc/sys/vm: - dirtytime_expire_seconds - dirty_writeback_centisecs - drop_caches +- enable_soft_offline - extfrag_threshold - highmem_is_dirtyable - hugetlb_shm_group
@@ -267,6 +268,37 @@ used:: These are informational only. They do not mean that anything is wrong with your system. To disable them, echo 4 (bit 2) into drop_caches. +enable_soft_offline +=================== +Correctable memory errors are very common on servers. Soft-offline is kernel's +solution for memory pages having (excessive) corrected memory errors. + +For different types of page, soft-offline has different behaviors / costs. +- For a raw error page, soft-offline migrates the in-use page's content to + a new raw page. +- For a page that is part of a transparent hugepage, soft-offline splits the + transparent hugepage into raw pages, then migrates only the raw error page. + As a result, user is transparently backed by 1 less hugepage, impacting + memory access performance. +- For a page that is part of a HugeTLB hugepage, soft-offline first migrates + the entire HugeTLB hugepage, during which a free hugepage will be consumed + as migration target. Then the original hugepage is dissolved into raw + pages without compensation, reducing the capacity of the HugeTLB pool by 1. + +It is user's call to choose between reliability (staying away from fragile +physical memory) vs performance / capacity implications in transparent and +HugeTLB cases. + +For all architectures, enable_soft_offline controls whether to soft offline +memory pages. When setting to 1, kernel attempts to soft offline the pages +whenever it thinks needed. When setting to 0, kernel returns EOPNOTSUPP to +the request to soft offline the pages. Its default value is 1. + +It is worth mentioning that after setting enable_soft_offline to 0, the +following requests to soft offline pages will not be performed: +- Request to soft offline pages from RAS Correctable Errors Collector. +- On ARM, the request to soft offline pages from GHES driver. +- On PARISC, the request to soft offline pages from Page Deallocation Table. extfrag_threshold =================
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Re: [PATCH v5 4/4] docs: mm: add enable_soft_offline sysctl
Quoted 9 lines · Jiaqi Yan
Add the documentation for soft offline behaviors / costs, and what the new
enable_soft_offlinesysctl is for.Acked-by Oscar Salvador <[email protected]>Signed-off-by Jiaqi Yan <[email protected]>--- Documentation/admin-guide/sysctl/vm.rst | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
LGTM. Thanks.
Thanks.
.
Randy Dunlap
reviewerRe: [PATCH v5 4/4] docs: mm: add enable_soft_offline sysctl
In reply to Jiaqi YanHi--
Quoted 17 lines · Jiaqi Yan
Add the documentation for soft offline behaviors / costs, and what the new
enable_soft_offlinesysctl is for.Acked-by Oscar Salvador <[email protected]>Signed-off-by Jiaqi Yan <[email protected]>--- Documentation/admin-guide/sysctl/vm.rst | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+)Documentation/admin-guide/sysctl/vm.rst +0
-0@@ -267,6 +268,37 @@ used:: These are informational only. They do not mean that anything is wrong with your system. To disable them, echo 4 (bit 2) into drop_caches.
Documentation/admin-guide/sysctl/vm.rst used:: · line 279
Quoted 10 lines
Documentation/admin-guide/sysctl/vm.rst +9
-0+enable_soft_offline +=================== +Correctable memory errors are very common on servers. Soft-offline is kernel's +solution for memory pages having (excessive) corrected memory errors. + +For different types of page, soft-offline has different behaviors / costs. +- For a raw error page, soft-offline migrates the in-use page's content to + a new raw page. +- For a page that is part of a transparent hugepage, soft-offline splits the
Use only one space after the comma ...................^
Quoted 4 lines
Documentation/admin-guide/sysctl/vm.rst +4
-0+ transparent hugepage into raw pages, then migrates only the raw error page. + As a result, user is transparently backed by 1 less hugepage, impacting + memory access performance. +- For a page that is part of a HugeTLB hugepage, soft-offline first migrates
Documentation/admin-guide/sysctl/vm.rst used:: · line 293
Quoted 10 lines
Documentation/admin-guide/sysctl/vm.rst +10
-0+ the entire HugeTLB hugepage, during which a free hugepage will be consumed + as migration target. Then the original hugepage is dissolved into raw + pages without compensation, reducing the capacity of the HugeTLB pool by 1. + +It is user's call to choose between reliability (staying away from fragile +physical memory) vs performance / capacity implications in transparent and +HugeTLB cases. + +For all architectures, enable_soft_offline controls whether to soft offline +memory pages. When setting to 1, kernel attempts to soft offline the pages
When set to 1,
Documentation/admin-guide/sysctl/vm.rst used:: · line 294
Quoted 1 line
Documentation/admin-guide/sysctl/vm.rst +1
-0+whenever it thinks needed. When setting to 0, kernel returns EOPNOTSUPP to
When set to 0,
Quoted 10 lines
Documentation/admin-guide/sysctl/vm.rst +7
-0+the request to soft offline the pages. Its default value is 1. + +It is worth mentioning that after setting enable_soft_offline to 0, the +following requests to soft offline pages will not be performed: +- Request to soft offline pages from RAS Correctable Errors Collector. +- On ARM, the request to soft offline pages from GHES driver. +- On PARISC, the request to soft offline pages from Page Deallocation Table. extfrag_threshold =================
Signature · 1 line
~Randy
Re: [PATCH v5 4/4] docs: mm: add enable_soft_offline sysctl
Quoted 51 lines · Randy Dunlap
Hi--
Quoted 17 lines · Jiaqi Yan
Add the documentation for soft offline behaviors / costs, and what the new
enable_soft_offlinesysctl is for.Acked-by Oscar Salvador <[email protected]>Signed-off-by Jiaqi Yan <[email protected]>--- Documentation/admin-guide/sysctl/vm.rst | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+)Documentation/admin-guide/sysctl/vm.rst +0
-0@@ -267,6 +268,37 @@ used:: These are informational only. They do not mean that anything is wrong with your system. To disable them, echo 4 (bit 2) into drop_caches.Documentation/admin-guide/sysctl/vm.rst used:: · line 279
Quoted 10 lines
Documentation/admin-guide/sysctl/vm.rst +9
-0+enable_soft_offline +=================== +Correctable memory errors are very common on servers. Soft-offline is kernel's +solution for memory pages having (excessive) corrected memory errors. + +For different types of page, soft-offline has different behaviors / costs. +- For a raw error page, soft-offline migrates the in-use page's content to + a new raw page. +- For a page that is part of a transparent hugepage, soft-offline splits theUse only one space after the comma ...................^
Quoted 4 lines
Documentation/admin-guide/sysctl/vm.rst +4
-0+ transparent hugepage into raw pages, then migrates only the raw error page. + As a result, user is transparently backed by 1 less hugepage, impacting + memory access performance. +- For a page that is part of a HugeTLB hugepage, soft-offline first migratesDocumentation/admin-guide/sysctl/vm.rst used:: · line 293
Quoted 10 lines
Documentation/admin-guide/sysctl/vm.rst +10
-0+ the entire HugeTLB hugepage, during which a free hugepage will be consumed + as migration target. Then the original hugepage is dissolved into raw + pages without compensation, reducing the capacity of the HugeTLB pool by 1. + +It is user's call to choose between reliability (staying away from fragile +physical memory) vs performance / capacity implications in transparent and +HugeTLB cases. + +For all architectures, enable_soft_offline controls whether to soft offline +memory pages. When setting to 1, kernel attempts to soft offline the pagesWhen set to 1,
Quoted 3 lines
Documentation/admin-guide/sysctl/vm.rst used:: · line 294
Quoted 1 line
Documentation/admin-guide/sysctl/vm.rst +1
-0+whenever it thinks needed. When setting to 0, kernel returns EOPNOTSUPP toWhen set to 0,
Thanks Randy! I will fix these 3 nits in v6.
Quoted 14 lines
Documentation/admin-guide/sysctl/vm.rst used:: · line 304
Quoted 11 lines
Documentation/admin-guide/sysctl/vm.rst +7
-0+the request to soft offline the pages. Its default value is 1. + +It is worth mentioning that after setting enable_soft_offline to 0, the +following requests to soft offline pages will not be performed: +- Request to soft offline pages from RAS Correctable Errors Collector. +- On ARM, the request to soft offline pages from GHES driver. +- On PARISC, the request to soft offline pages from Page Deallocation Table. extfrag_threshold =================--
~Randy