Skip to content

Commit 23e7b5c

Browse files
djbwdavejiang
authored andcommitted
mm, madvise_inject_error: Let memory_failure() optionally take a page reference
The madvise_inject_error() routine uses get_user_pages() to lookup the pfn and other information for injected error, but it does not release that pin. The assumption is that failed pages should be taken out of circulation. However, for dax mappings it is not possible to take pages out of circulation since they are 1:1 physically mapped as filesystem blocks, or device-dax capacity. They also typically represent persistent memory which has an error clearing capability. In preparation for adding a special handler for dax mappings, shift the responsibility of taking the page reference to memory_failure(). I.e. drop the page reference and do not specify MF_COUNT_INCREASED to memory_failure(). Cc: Michal Hocko <mhocko@suse.com> Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Acked-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 2fa147b commit 23e7b5c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

mm/madvise.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,13 @@ static int madvise_inject_error(int behavior,
631631

632632

633633
for (; start < end; start += PAGE_SIZE << order) {
634+
unsigned long pfn;
634635
int ret;
635636

636637
ret = get_user_pages_fast(start, 1, 0, &page);
637638
if (ret != 1)
638639
return ret;
640+
pfn = page_to_pfn(page);
639641

640642
/*
641643
* When soft offlining hugepages, after migrating the page
@@ -651,17 +653,25 @@ static int madvise_inject_error(int behavior,
651653

652654
if (behavior == MADV_SOFT_OFFLINE) {
653655
pr_info("Soft offlining pfn %#lx at process virtual address %#lx\n",
654-
page_to_pfn(page), start);
656+
pfn, start);
655657

656658
ret = soft_offline_page(page, MF_COUNT_INCREASED);
657659
if (ret)
658660
return ret;
659661
continue;
660662
}
663+
661664
pr_info("Injecting memory failure for pfn %#lx at process virtual address %#lx\n",
662-
page_to_pfn(page), start);
665+
pfn, start);
663666

664-
ret = memory_failure(page_to_pfn(page), MF_COUNT_INCREASED);
667+
/*
668+
* Drop the page reference taken by get_user_pages_fast(). In
669+
* the absence of MF_COUNT_INCREASED the memory_failure()
670+
* routine is responsible for pinning the page to prevent it
671+
* from being released back to the page allocator.
672+
*/
673+
put_page(page);
674+
ret = memory_failure(pfn, 0);
665675
if (ret)
666676
return ret;
667677
}

0 commit comments

Comments
 (0)