mm/hotplug: optimize clear_hwpoisoned_pages()
authorBalbir Singh <[email protected]>
Fri, 28 Dec 2018 08:33:24 +0000 (00:33 -0800)
committerLinus Torvalds <[email protected]>
Fri, 28 Dec 2018 20:11:46 +0000 (12:11 -0800)
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.

[[email protected]: tweak comment text]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Balbir Singh <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Acked-by: Naoya Horiguchi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/sparse.c

index 3abc8cc5020120a3bbeb7c3429d19472fc96d051..691544a2814cd5a664516e6058df2d7b161965f7 100644 (file)
@@ -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);