Skip to contentSkip to conversation

mm/khugepaged: Cleanup memcg uncharge for failure path

PATCH Applied Peter Xu 3 participants 3 messages Mar 3, 2023

Subsystems (2)
lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH 1/1 mm/khugepaged: Cleanup memcg uncharge for failure path

Explicit memcg uncharging is not needed when the memcg accounting has the same lifespan of the page/folio. That becomes the case for khugepaged after Yang & Zach's recent rework so the hpage will be allocated for each collapse rather than being cached.

Cleanup the explicit memcg uncharge in khugepaged failure path and leave that for put_page().

---
 mm/khugepaged.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
mm/khugepaged.c +2 -6
index 941d1c7ea910..dd5a7d9bc593 100644
@@ -1230,10 +1230,8 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address,
 out_up_write:
 	mmap_write_unlock(mm);
 out_nolock:
-	if (hpage) {
-		mem_cgroup_uncharge(page_folio(hpage));
+	if (hpage)
 		put_page(hpage);
-	}
 	trace_mm_collapse_huge_page(mm, result == SCAN_SUCCEED, result);
 	return result;
 }
@@ -2250,10 +2248,8 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
 		unlock_page(hpage);
 out:
 	VM_BUG_ON(!list_empty(&pagelist));
-	if (hpage) {
-		mem_cgroup_uncharge(page_folio(hpage));
+	if (hpage)
 		put_page(hpage);
-	}
 
 	trace_mm_khugepaged_collapse_file(mm, hpage, index, is_shmem, addr, file, nr, result);
 	return result;
Signature · 1 line
2.39.1
Reviewed-by on v1 1/1
#1 lore raw

Thanks Peter!

Quoted 10 lines · Peter Xu

Explicit memcg uncharging is not needed when the memcg accounting has the same lifespan of the page/folio. That becomes the case for khugepaged after Yang & Zach's recent rework so the hpage will be allocated for each collapse rather than being cached.

Cleanup the explicit memcg uncharge in khugepaged failure path and leave that for put_page().

Quoted 35 lines
---
 mm/khugepaged.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
mm/khugepaged.c +2 -6
index 941d1c7ea910..dd5a7d9bc593 100644
@@ -1230,10 +1230,8 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address,
 out_up_write:
 	mmap_write_unlock(mm);
 out_nolock:
-	if (hpage) {
-		mem_cgroup_uncharge(page_folio(hpage));
+	if (hpage)
 		put_page(hpage);
-	}
 	trace_mm_collapse_huge_page(mm, result == SCAN_SUCCEED, result);
 	return result;
 }
@@ -2250,10 +2248,8 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
 		unlock_page(hpage);
 out:
 	VM_BUG_ON(!list_empty(&pagelist));
-	if (hpage) {
-		mem_cgroup_uncharge(page_folio(hpage));
+	if (hpage)
 		put_page(hpage);
-	}
 
 	trace_mm_khugepaged_collapse_file(mm, hpage, index, is_shmem, addr, file, nr, result);
 	return result;
Signature · 1 line
2.39.1
#2 lore raw
In reply to Peter Xu
Quoted 8 lines · Peter Xu

Explicit memcg uncharging is not needed when the memcg accounting has the same lifespan of the page/folio. That becomes the case for khugepaged after Yang & Zach's recent rework so the hpage will be allocated for each collapse rather than being cached.

Cleanup the explicit memcg uncharge in khugepaged failure path and leave that for put_page().

Thanks for the cleanup. Reviewed-by: Yang Shi <[email protected]>

Quoted 38 lines
---
 mm/khugepaged.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
mm/khugepaged.c +2 -7
index 941d1c7ea910..dd5a7d9bc593 100644
@@ -1230,10 +1230,8 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address,
 out_up_write:
        mmap_write_unlock(mm);
 out_nolock:
-       if (hpage) {
-               mem_cgroup_uncharge(page_folio(hpage));
+       if (hpage)
                put_page(hpage);
-       }
        trace_mm_collapse_huge_page(mm, result == SCAN_SUCCEED, result);
        return result;
 }
@@ -2250,10 +2248,8 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
                unlock_page(hpage);
 out:
        VM_BUG_ON(!list_empty(&pagelist));
-       if (hpage) {
-               mem_cgroup_uncharge(page_folio(hpage));
+       if (hpage)
                put_page(hpage);
-       }
 
        trace_mm_khugepaged_collapse_file(mm, hpage, index, is_shmem, addr, file, nr, result);
        return result;
--

2.39.1