Skip to contentSkip to conversation

mm/hotplug: Optimize clear_hwpoisoned_pages

PATCH In review Balbir Singh 3 participants 3 messages Nov 2, 2018 – Nov 6, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 mm/sparse.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
mm/sparse.c +10 -0
index 33307fc05c4d..16219c7ddb5f 100644
@@ -724,6 +724,16 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
 	if (!memmap)
 		return;
 
+	/*
+	 * A further optimization is to have per section
+	 * ref counted num_poisoned_pages, but that is going
+	 * to need more space per memmap, for now just do
+	 * a quick global check, this should 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);
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Balbir Singh

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.

Makes sense to me. It would be great to actually have some number but the optimization for the normal case is quite obvious.

Quoted 28 lines
---
 mm/sparse.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
mm/sparse.c +10 -0
index 33307fc05c4d..16219c7ddb5f 100644
@@ -724,6 +724,16 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
 	if (!memmap)
 		return;
 
+	/*
+	 * A further optimization is to have per section
+	 * ref counted num_poisoned_pages, but that is going
+	 * to need more space per memmap, for now just do
+	 * a quick global check, this should 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);
Signature · 1 line
2.17.1
Signature · 2 lines
Michal Hocko
SUSE Labs