From 5eb570a8d9248e0c1358078a59916d0e337e695b Mon Sep 17 00:00:00 2001 From: Balbir Singh Date: Fri, 28 Dec 2018 00:33:24 -0800 Subject: [PATCH] mm/hotplug: optimize clear_hwpoisoned_pages() In hot remove, we try to clear poisoned pages, but a small optimization to check if num_poisoned_pages is 0 helps remove the iteration through nr_pages. [akpm@linux-foundation.org: tweak comment text] Link: http://lkml.kernel.org/r/20181102120001.4526-1-bsingharora@gmail.com Signed-off-by: Balbir Singh Acked-by: Michal Hocko Acked-by: Naoya Horiguchi Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- mm/sparse.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/sparse.c b/mm/sparse.c index 3abc8cc50201..691544a2814c 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -740,6 +740,15 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages) if (!memmap) return; + /* + * A further optimization is to have per section refcounted + * num_poisoned_pages. But that would need more space per memmap, so + * for now just do a quick global check to speed up this routine in the + * absence of bad pages. + */ + if (atomic_long_read(&num_poisoned_pages) == 0) + return; + for (i = 0; i < nr_pages; i++) { if (PageHWPoison(&memmap[i])) { atomic_long_sub(1, &num_poisoned_pages); -- GitLab