mm, hwpoison: use num_poisoned_pages_sub() to decrease num_poisoned_pages
authorMiaohe Lin <linmiaohe@huawei.com>
Tue, 30 Aug 2022 12:36:01 +0000 (20:36 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 27 Sep 2022 02:46:04 +0000 (19:46 -0700)
Use num_poisoned_pages_sub() to combine multiple atomic ops into one. Also
num_poisoned_pages_dec() can be killed as there's no caller now.

Link: https://lkml.kernel.org/r/20220830123604.25763-4-linmiaohe@huawei.com
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Acked-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/swapops.h
mm/memory-failure.c

index a3d435bf9f972930d1d9ebae20d000cf071623a9..88825d1785d2d6a12c1822c4c5c5f49522189dc9 100644 (file)
@@ -485,11 +485,6 @@ static inline void num_poisoned_pages_inc(void)
        atomic_long_inc(&num_poisoned_pages);
 }
 
-static inline void num_poisoned_pages_dec(void)
-{
-       atomic_long_dec(&num_poisoned_pages);
-}
-
 static inline void num_poisoned_pages_sub(long i)
 {
        atomic_long_sub(i, &num_poisoned_pages);
index e9baa9e51f0133f1c546cd101ec5c91aac0cacff..01ce87f5706aa8c66f79aadc154d9ef1a19725e0 100644 (file)
@@ -2602,7 +2602,7 @@ retry:
 
 void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
 {
-       int i;
+       int i, total = 0;
 
        /*
         * A further optimization is to have per section refcounted
@@ -2615,8 +2615,10 @@ void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
 
        for (i = 0; i < nr_pages; i++) {
                if (PageHWPoison(&memmap[i])) {
-                       num_poisoned_pages_dec();
+                       total++;
                        ClearPageHWPoison(&memmap[i]);
                }
        }
+       if (total)
+               num_poisoned_pages_sub(total);
 }