Skip to content

Commit cc637b1

Browse files
Xie XiuQitorvalds
authored andcommitted
memory-failure: export page_type and action result
Export 'outcome' and 'action_page_type' to mm.h, so we could use this emnus outside. This patch is preparation for adding trace events for memory-failure recovery action. Signed-off-by: Xie XiuQi <xiexiuqi@huawei.com> Acked-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: Chen Gong <gong.chen@linux.intel.com> Cc: Jim Davis <jim.epost@gmail.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Tony Luck <tony.luck@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent eb3c24f commit cc637b1

2 files changed

Lines changed: 101 additions & 101 deletions

File tree

‎include/linux/mm.h‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,6 +2153,40 @@ extern void shake_page(struct page *p, int access);
21532153
extern atomic_long_t num_poisoned_pages;
21542154
extern int soft_offline_page(struct page *page, int flags);
21552155

2156+
2157+
/*
2158+
* Error handlers for various types of pages.
2159+
*/
2160+
enum mf_outcome {
2161+
MF_IGNORED, /* Error: cannot be handled */
2162+
MF_FAILED, /* Error: handling failed */
2163+
MF_DELAYED, /* Will be handled later */
2164+
MF_RECOVERED, /* Successfully recovered */
2165+
};
2166+
2167+
enum mf_action_page_type {
2168+
MF_MSG_KERNEL,
2169+
MF_MSG_KERNEL_HIGH_ORDER,
2170+
MF_MSG_SLAB,
2171+
MF_MSG_DIFFERENT_COMPOUND,
2172+
MF_MSG_POISONED_HUGE,
2173+
MF_MSG_HUGE,
2174+
MF_MSG_FREE_HUGE,
2175+
MF_MSG_UNMAP_FAILED,
2176+
MF_MSG_DIRTY_SWAPCACHE,
2177+
MF_MSG_CLEAN_SWAPCACHE,
2178+
MF_MSG_DIRTY_MLOCKED_LRU,
2179+
MF_MSG_CLEAN_MLOCKED_LRU,
2180+
MF_MSG_DIRTY_UNEVICTABLE_LRU,
2181+
MF_MSG_CLEAN_UNEVICTABLE_LRU,
2182+
MF_MSG_DIRTY_LRU,
2183+
MF_MSG_CLEAN_LRU,
2184+
MF_MSG_TRUNCATED_LRU,
2185+
MF_MSG_BUDDY,
2186+
MF_MSG_BUDDY_2ND,
2187+
MF_MSG_UNKNOWN,
2188+
};
2189+
21562190
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
21572191
extern void clear_huge_page(struct page *page,
21582192
unsigned long addr,

‎mm/memory-failure.c‎

Lines changed: 67 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -504,68 +504,34 @@ static void collect_procs(struct page *page, struct list_head *tokill,
504504
kfree(tk);
505505
}
506506

507-
/*
508-
* Error handlers for various types of pages.
509-
*/
510-
511-
enum outcome {
512-
IGNORED, /* Error: cannot be handled */
513-
FAILED, /* Error: handling failed */
514-
DELAYED, /* Will be handled later */
515-
RECOVERED, /* Successfully recovered */
516-
};
517-
518507
static const char *action_name[] = {
519-
[IGNORED] = "Ignored",
520-
[FAILED] = "Failed",
521-
[DELAYED] = "Delayed",
522-
[RECOVERED] = "Recovered",
523-
};
524-
525-
enum action_page_type {
526-
MSG_KERNEL,
527-
MSG_KERNEL_HIGH_ORDER,
528-
MSG_SLAB,
529-
MSG_DIFFERENT_COMPOUND,
530-
MSG_POISONED_HUGE,
531-
MSG_HUGE,
532-
MSG_FREE_HUGE,
533-
MSG_UNMAP_FAILED,
534-
MSG_DIRTY_SWAPCACHE,
535-
MSG_CLEAN_SWAPCACHE,
536-
MSG_DIRTY_MLOCKED_LRU,
537-
MSG_CLEAN_MLOCKED_LRU,
538-
MSG_DIRTY_UNEVICTABLE_LRU,
539-
MSG_CLEAN_UNEVICTABLE_LRU,
540-
MSG_DIRTY_LRU,
541-
MSG_CLEAN_LRU,
542-
MSG_TRUNCATED_LRU,
543-
MSG_BUDDY,
544-
MSG_BUDDY_2ND,
545-
MSG_UNKNOWN,
508+
[MF_IGNORED] = "Ignored",
509+
[MF_FAILED] = "Failed",
510+
[MF_DELAYED] = "Delayed",
511+
[MF_RECOVERED] = "Recovered",
546512
};
547513

548514
static const char * const action_page_types[] = {
549-
[MSG_KERNEL] = "reserved kernel page",
550-
[MSG_KERNEL_HIGH_ORDER] = "high-order kernel page",
551-
[MSG_SLAB] = "kernel slab page",
552-
[MSG_DIFFERENT_COMPOUND] = "different compound page after locking",
553-
[MSG_POISONED_HUGE] = "huge page already hardware poisoned",
554-
[MSG_HUGE] = "huge page",
555-
[MSG_FREE_HUGE] = "free huge page",
556-
[MSG_UNMAP_FAILED] = "unmapping failed page",
557-
[MSG_DIRTY_SWAPCACHE] = "dirty swapcache page",
558-
[MSG_CLEAN_SWAPCACHE] = "clean swapcache page",
559-
[MSG_DIRTY_MLOCKED_LRU] = "dirty mlocked LRU page",
560-
[MSG_CLEAN_MLOCKED_LRU] = "clean mlocked LRU page",
561-
[MSG_DIRTY_UNEVICTABLE_LRU] = "dirty unevictable LRU page",
562-
[MSG_CLEAN_UNEVICTABLE_LRU] = "clean unevictable LRU page",
563-
[MSG_DIRTY_LRU] = "dirty LRU page",
564-
[MSG_CLEAN_LRU] = "clean LRU page",
565-
[MSG_TRUNCATED_LRU] = "already truncated LRU page",
566-
[MSG_BUDDY] = "free buddy page",
567-
[MSG_BUDDY_2ND] = "free buddy page (2nd try)",
568-
[MSG_UNKNOWN] = "unknown page",
515+
[MF_MSG_KERNEL] = "reserved kernel page",
516+
[MF_MSG_KERNEL_HIGH_ORDER] = "high-order kernel page",
517+
[MF_MSG_SLAB] = "kernel slab page",
518+
[MF_MSG_DIFFERENT_COMPOUND] = "different compound page after locking",
519+
[MF_MSG_POISONED_HUGE] = "huge page already hardware poisoned",
520+
[MF_MSG_HUGE] = "huge page",
521+
[MF_MSG_FREE_HUGE] = "free huge page",
522+
[MF_MSG_UNMAP_FAILED] = "unmapping failed page",
523+
[MF_MSG_DIRTY_SWAPCACHE] = "dirty swapcache page",
524+
[MF_MSG_CLEAN_SWAPCACHE] = "clean swapcache page",
525+
[MF_MSG_DIRTY_MLOCKED_LRU] = "dirty mlocked LRU page",
526+
[MF_MSG_CLEAN_MLOCKED_LRU] = "clean mlocked LRU page",
527+
[MF_MSG_DIRTY_UNEVICTABLE_LRU] = "dirty unevictable LRU page",
528+
[MF_MSG_CLEAN_UNEVICTABLE_LRU] = "clean unevictable LRU page",
529+
[MF_MSG_DIRTY_LRU] = "dirty LRU page",
530+
[MF_MSG_CLEAN_LRU] = "clean LRU page",
531+
[MF_MSG_TRUNCATED_LRU] = "already truncated LRU page",
532+
[MF_MSG_BUDDY] = "free buddy page",
533+
[MF_MSG_BUDDY_2ND] = "free buddy page (2nd try)",
534+
[MF_MSG_UNKNOWN] = "unknown page",
569535
};
570536

571537
/*
@@ -599,7 +565,7 @@ static int delete_from_lru_cache(struct page *p)
599565
*/
600566
static int me_kernel(struct page *p, unsigned long pfn)
601567
{
602-
return IGNORED;
568+
return MF_IGNORED;
603569
}
604570

605571
/*
@@ -608,7 +574,7 @@ static int me_kernel(struct page *p, unsigned long pfn)
608574
static int me_unknown(struct page *p, unsigned long pfn)
609575
{
610576
printk(KERN_ERR "MCE %#lx: Unknown page state\n", pfn);
611-
return FAILED;
577+
return MF_FAILED;
612578
}
613579

614580
/*
@@ -617,7 +583,7 @@ static int me_unknown(struct page *p, unsigned long pfn)
617583
static int me_pagecache_clean(struct page *p, unsigned long pfn)
618584
{
619585
int err;
620-
int ret = FAILED;
586+
int ret = MF_FAILED;
621587
struct address_space *mapping;
622588

623589
delete_from_lru_cache(p);
@@ -627,7 +593,7 @@ static int me_pagecache_clean(struct page *p, unsigned long pfn)
627593
* should be the one m_f() holds.
628594
*/
629595
if (PageAnon(p))
630-
return RECOVERED;
596+
return MF_RECOVERED;
631597

632598
/*
633599
* Now truncate the page in the page cache. This is really
@@ -641,7 +607,7 @@ static int me_pagecache_clean(struct page *p, unsigned long pfn)
641607
/*
642608
* Page has been teared down in the meanwhile
643609
*/
644-
return FAILED;
610+
return MF_FAILED;
645611
}
646612

647613
/*
@@ -658,15 +624,15 @@ static int me_pagecache_clean(struct page *p, unsigned long pfn)
658624
!try_to_release_page(p, GFP_NOIO)) {
659625
pr_info("MCE %#lx: failed to release buffers\n", pfn);
660626
} else {
661-
ret = RECOVERED;
627+
ret = MF_RECOVERED;
662628
}
663629
} else {
664630
/*
665631
* If the file system doesn't support it just invalidate
666632
* This fails on dirty or anything with private pages
667633
*/
668634
if (invalidate_inode_page(p))
669-
ret = RECOVERED;
635+
ret = MF_RECOVERED;
670636
else
671637
printk(KERN_INFO "MCE %#lx: Failed to invalidate\n",
672638
pfn);
@@ -752,19 +718,19 @@ static int me_swapcache_dirty(struct page *p, unsigned long pfn)
752718
ClearPageUptodate(p);
753719

754720
if (!delete_from_lru_cache(p))
755-
return DELAYED;
721+
return MF_DELAYED;
756722
else
757-
return FAILED;
723+
return MF_FAILED;
758724
}
759725

760726
static int me_swapcache_clean(struct page *p, unsigned long pfn)
761727
{
762728
delete_from_swap_cache(p);
763729

764730
if (!delete_from_lru_cache(p))
765-
return RECOVERED;
731+
return MF_RECOVERED;
766732
else
767-
return FAILED;
733+
return MF_FAILED;
768734
}
769735

770736
/*
@@ -794,9 +760,9 @@ static int me_huge_page(struct page *p, unsigned long pfn)
794760
if (!(page_mapping(hpage) || PageAnon(hpage))) {
795761
res = dequeue_hwpoisoned_huge_page(hpage);
796762
if (!res)
797-
return RECOVERED;
763+
return MF_RECOVERED;
798764
}
799-
return DELAYED;
765+
return MF_DELAYED;
800766
}
801767

802768
/*
@@ -828,10 +794,10 @@ static int me_huge_page(struct page *p, unsigned long pfn)
828794
static struct page_state {
829795
unsigned long mask;
830796
unsigned long res;
831-
enum action_page_type type;
797+
enum mf_action_page_type type;
832798
int (*action)(struct page *p, unsigned long pfn);
833799
} error_states[] = {
834-
{ reserved, reserved, MSG_KERNEL, me_kernel },
800+
{ reserved, reserved, MF_MSG_KERNEL, me_kernel },
835801
/*
836802
* free pages are specially detected outside this table:
837803
* PG_buddy pages only make a small fraction of all free pages.
@@ -842,31 +808,31 @@ static struct page_state {
842808
* currently unused objects without touching them. But just
843809
* treat it as standard kernel for now.
844810
*/
845-
{ slab, slab, MSG_SLAB, me_kernel },
811+
{ slab, slab, MF_MSG_SLAB, me_kernel },
846812

847813
#ifdef CONFIG_PAGEFLAGS_EXTENDED
848-
{ head, head, MSG_HUGE, me_huge_page },
849-
{ tail, tail, MSG_HUGE, me_huge_page },
814+
{ head, head, MF_MSG_HUGE, me_huge_page },
815+
{ tail, tail, MF_MSG_HUGE, me_huge_page },
850816
#else
851-
{ compound, compound, MSG_HUGE, me_huge_page },
817+
{ compound, compound, MF_MSG_HUGE, me_huge_page },
852818
#endif
853819

854-
{ sc|dirty, sc|dirty, MSG_DIRTY_SWAPCACHE, me_swapcache_dirty },
855-
{ sc|dirty, sc, MSG_CLEAN_SWAPCACHE, me_swapcache_clean },
820+
{ sc|dirty, sc|dirty, MF_MSG_DIRTY_SWAPCACHE, me_swapcache_dirty },
821+
{ sc|dirty, sc, MF_MSG_CLEAN_SWAPCACHE, me_swapcache_clean },
856822

857-
{ mlock|dirty, mlock|dirty, MSG_DIRTY_MLOCKED_LRU, me_pagecache_dirty },
858-
{ mlock|dirty, mlock, MSG_CLEAN_MLOCKED_LRU, me_pagecache_clean },
823+
{ mlock|dirty, mlock|dirty, MF_MSG_DIRTY_MLOCKED_LRU, me_pagecache_dirty },
824+
{ mlock|dirty, mlock, MF_MSG_CLEAN_MLOCKED_LRU, me_pagecache_clean },
859825

860-
{ unevict|dirty, unevict|dirty, MSG_DIRTY_UNEVICTABLE_LRU, me_pagecache_dirty },
861-
{ unevict|dirty, unevict, MSG_CLEAN_UNEVICTABLE_LRU, me_pagecache_clean },
826+
{ unevict|dirty, unevict|dirty, MF_MSG_DIRTY_UNEVICTABLE_LRU, me_pagecache_dirty },
827+
{ unevict|dirty, unevict, MF_MSG_CLEAN_UNEVICTABLE_LRU, me_pagecache_clean },
862828

863-
{ lru|dirty, lru|dirty, MSG_DIRTY_LRU, me_pagecache_dirty },
864-
{ lru|dirty, lru, MSG_CLEAN_LRU, me_pagecache_clean },
829+
{ lru|dirty, lru|dirty, MF_MSG_DIRTY_LRU, me_pagecache_dirty },
830+
{ lru|dirty, lru, MF_MSG_CLEAN_LRU, me_pagecache_clean },
865831

866832
/*
867833
* Catchall entry: must be at end.
868834
*/
869-
{ 0, 0, MSG_UNKNOWN, me_unknown },
835+
{ 0, 0, MF_MSG_UNKNOWN, me_unknown },
870836
};
871837

872838
#undef dirty
@@ -886,7 +852,7 @@ static struct page_state {
886852
* "Dirty/Clean" indication is not 100% accurate due to the possibility of
887853
* setting PG_dirty outside page lock. See also comment above set_page_dirty().
888854
*/
889-
static void action_result(unsigned long pfn, enum action_page_type type, int result)
855+
static void action_result(unsigned long pfn, enum mf_action_page_type type, int result)
890856
{
891857
pr_err("MCE %#lx: recovery action for %s: %s\n",
892858
pfn, action_page_types[type], action_name[result]);
@@ -901,13 +867,13 @@ static int page_action(struct page_state *ps, struct page *p,
901867
result = ps->action(p, pfn);
902868

903869
count = page_count(p) - 1;
904-
if (ps->action == me_swapcache_dirty && result == DELAYED)
870+
if (ps->action == me_swapcache_dirty && result == MF_DELAYED)
905871
count--;
906872
if (count != 0) {
907873
printk(KERN_ERR
908874
"MCE %#lx: %s still referenced by %d users\n",
909875
pfn, action_page_types[ps->type], count);
910-
result = FAILED;
876+
result = MF_FAILED;
911877
}
912878
action_result(pfn, ps->type, result);
913879

@@ -916,7 +882,7 @@ static int page_action(struct page_state *ps, struct page *p,
916882
* Could adjust zone counters here to correct for the missing page.
917883
*/
918884

919-
return (result == RECOVERED || result == DELAYED) ? 0 : -EBUSY;
885+
return (result == MF_RECOVERED || result == MF_DELAYED) ? 0 : -EBUSY;
920886
}
921887

922888
/**
@@ -1136,7 +1102,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
11361102
*/
11371103
if (!(flags & MF_COUNT_INCREASED) && !get_hwpoison_page(p)) {
11381104
if (is_free_buddy_page(p)) {
1139-
action_result(pfn, MSG_BUDDY, DELAYED);
1105+
action_result(pfn, MF_MSG_BUDDY, MF_DELAYED);
11401106
return 0;
11411107
} else if (PageHuge(hpage)) {
11421108
/*
@@ -1153,12 +1119,12 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
11531119
}
11541120
set_page_hwpoison_huge_page(hpage);
11551121
res = dequeue_hwpoisoned_huge_page(hpage);
1156-
action_result(pfn, MSG_FREE_HUGE,
1157-
res ? IGNORED : DELAYED);
1122+
action_result(pfn, MF_MSG_FREE_HUGE,
1123+
res ? MF_IGNORED : MF_DELAYED);
11581124
unlock_page(hpage);
11591125
return res;
11601126
} else {
1161-
action_result(pfn, MSG_KERNEL_HIGH_ORDER, IGNORED);
1127+
action_result(pfn, MF_MSG_KERNEL_HIGH_ORDER, MF_IGNORED);
11621128
return -EBUSY;
11631129
}
11641130
}
@@ -1203,10 +1169,10 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
12031169
*/
12041170
if (is_free_buddy_page(p)) {
12051171
if (flags & MF_COUNT_INCREASED)
1206-
action_result(pfn, MSG_BUDDY, DELAYED);
1172+
action_result(pfn, MF_MSG_BUDDY, MF_DELAYED);
12071173
else
1208-
action_result(pfn, MSG_BUDDY_2ND,
1209-
DELAYED);
1174+
action_result(pfn, MF_MSG_BUDDY_2ND,
1175+
MF_DELAYED);
12101176
return 0;
12111177
}
12121178
}
@@ -1219,7 +1185,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
12191185
* If this happens just bail out.
12201186
*/
12211187
if (PageCompound(p) && compound_head(p) != orig_head) {
1222-
action_result(pfn, MSG_DIFFERENT_COMPOUND, IGNORED);
1188+
action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED);
12231189
res = -EBUSY;
12241190
goto out;
12251191
}
@@ -1259,7 +1225,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
12591225
* on the head page to show that the hugepage is hwpoisoned
12601226
*/
12611227
if (PageHuge(p) && PageTail(p) && TestSetPageHWPoison(hpage)) {
1262-
action_result(pfn, MSG_POISONED_HUGE, IGNORED);
1228+
action_result(pfn, MF_MSG_POISONED_HUGE, MF_IGNORED);
12631229
unlock_page(hpage);
12641230
put_page(hpage);
12651231
return 0;
@@ -1288,7 +1254,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
12881254
*/
12891255
if (hwpoison_user_mappings(p, pfn, trapno, flags, &hpage)
12901256
!= SWAP_SUCCESS) {
1291-
action_result(pfn, MSG_UNMAP_FAILED, IGNORED);
1257+
action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED);
12921258
res = -EBUSY;
12931259
goto out;
12941260
}
@@ -1297,7 +1263,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
12971263
* Torn down by someone else?
12981264
*/
12991265
if (PageLRU(p) && !PageSwapCache(p) && p->mapping == NULL) {
1300-
action_result(pfn, MSG_TRUNCATED_LRU, IGNORED);
1266+
action_result(pfn, MF_MSG_TRUNCATED_LRU, MF_IGNORED);
13011267
res = -EBUSY;
13021268
goto out;
13031269
}

0 commit comments

Comments
 (0)