Skip to contentSkip to conversation

mm, hugetlb: Pass fault address to no page handler

PATCH In review Huang, Ying 6 participants 12 messages May 15, 2018 – May 17, 2018

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

PATCH 1/1 mm, hugetlb: Pass fault address to no page handler

From: Huang Ying <[email protected]>

This is to take better advantage of huge page clearing optimization (c79b57e462b5d, "mm: hugetlb: clear target sub-page last when clearing huge page"). Which will clear to access sub-page last to avoid the cache lines of to access sub-page to be evicted when clearing other sub-pages. This needs to get the address of the sub-page to access, that is, the fault address inside of the huge page. So the hugetlb no page fault handler is changed to pass that information. This will benefit workloads which don't access the begin of the huge page after page fault.

With this patch, the throughput increases ~28.1% in vm-scalability anon-w-seq test case with 88 processes on a 2 socket Xeon E5 2699 v4 system (44 cores, 88 threads). The test case creates 88 processes, each process mmap a big anonymous memory area and writes to it from the end to the begin. For each process, other processes could be seen as other workload which generates heavy cache pressure. At the same time, the cache miss rate reduced from ~36.3% to ~25.6%, the IPC (instruction per cycle) increased from 0.3 to 0.37, and the time spent in user space is reduced ~19.3%

Cc Andrea Arcangeli <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Jan Kara <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Christopher Lameter <[email protected]>
Cc "Aneesh Kumar K.V" <[email protected]>
Cc Punit Agrawal <[email protected]>
Cc Anshuman Khandual <[email protected]>
---
 mm/hugetlb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/hugetlb.c +6 -6
index 129088710510..3de6326abf39 100644
@@ -3677,7 +3677,7 @@ int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
 
 static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 			   struct address_space *mapping, pgoff_t idx,
-			   unsigned long address, pte_t *ptep, unsigned int flags)
+			   unsigned long faddress, pte_t *ptep, unsigned int flags)
 {
 	struct hstate *h = hstate_vma(vma);
 	int ret = VM_FAULT_SIGBUS;
@@ -3686,6 +3686,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 	struct page *page;
 	pte_t new_pte;
 	spinlock_t *ptl;
+	unsigned long address = faddress & huge_page_mask(h);
 
 	/*
 	 * Currently, we are forced to kill the process in the event the
@@ -3749,7 +3750,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 				ret = VM_FAULT_SIGBUS;
 			goto out;
 		}
-		clear_huge_page(page, address, pages_per_huge_page(h));
+		clear_huge_page(page, faddress, pages_per_huge_page(h));
 		__SetPageUptodate(page);
 		set_page_huge_active(page);
 
@@ -3871,7 +3872,7 @@ u32 hugetlb_fault_mutex_hash(struct hstate *h, struct mm_struct *mm,
 #endif
 
 int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
-			unsigned long address, unsigned int flags)
+			unsigned long faddress, unsigned int flags)
 {
 	pte_t *ptep, entry;
 	spinlock_t *ptl;
@@ -3883,8 +3884,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 	struct hstate *h = hstate_vma(vma);
 	struct address_space *mapping;
 	int need_wait_lock = 0;
-
-	address &= huge_page_mask(h);
+	unsigned long address = faddress & huge_page_mask(h);
 
 	ptep = huge_pte_offset(mm, address, huge_page_size(h));
 	if (ptep) {
@@ -3914,7 +3914,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 
 	entry = huge_ptep_get(ptep);
 	if (huge_pte_none(entry)) {
-		ret = hugetlb_no_page(mm, vma, mapping, idx, address, ptep, flags);
+		ret = hugetlb_no_page(mm, vma, mapping, idx, faddress, ptep, flags);
 		goto out_mutex;
 	}
 
Signature · 1 line
2.16.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Ying

From: Huang Ying <[email protected]>

This is to take better advantage of huge page clearing optimization (c79b57e462b5d, "mm: hugetlb: clear target sub-page last when clearing huge page"). Which will clear to access sub-page last to avoid the cache lines of to access sub-page to be evicted when clearing other sub-pages. This needs to get the address of the sub-page to access, that is, the fault address inside of the huge page. So the hugetlb no page fault handler is changed to pass that information. This will benefit workloads which don't access the begin of the huge page after page fault.

Quoted 9 lines

With this patch, the throughput increases ~28.1% in vm-scalability anon-w-seq test case with 88 processes on a 2 socket Xeon E5 2699 v4 system (44 cores, 88 threads). The test case creates 88 processes, each process mmap a big anonymous memory area and writes to it from the end to the begin. For each process, other processes could be seen as other workload which generates heavy cache pressure. At the same time, the cache miss rate reduced from ~36.3% to ~25.6%, the IPC (instruction per cycle) increased from 0.3 to 0.37, and the time spent in user space is reduced ~19.3%

Since this patch only addresses hugetlbfs huge pages, I would suggest making that more explicit in the commit message. Other than that, the changes look fine to me.

Quoted 1 line
Signature · 1 line
Mike Kravetz
Quoted 76 lines
Cc Andrea Arcangeli <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Jan Kara <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Christopher Lameter <[email protected]>
Cc "Aneesh Kumar K.V" <[email protected]>
Cc Punit Agrawal <[email protected]>
Cc Anshuman Khandual <[email protected]>
---
 mm/hugetlb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/hugetlb.c +6 -6
index 129088710510..3de6326abf39 100644
@@ -3677,7 +3677,7 @@ int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
 
 static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 			   struct address_space *mapping, pgoff_t idx,
-			   unsigned long address, pte_t *ptep, unsigned int flags)
+			   unsigned long faddress, pte_t *ptep, unsigned int flags)
 {
 	struct hstate *h = hstate_vma(vma);
 	int ret = VM_FAULT_SIGBUS;
@@ -3686,6 +3686,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 	struct page *page;
 	pte_t new_pte;
 	spinlock_t *ptl;
+	unsigned long address = faddress & huge_page_mask(h);
 
 	/*
 	 * Currently, we are forced to kill the process in the event the
@@ -3749,7 +3750,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 				ret = VM_FAULT_SIGBUS;
 			goto out;
 		}
-		clear_huge_page(page, address, pages_per_huge_page(h));
+		clear_huge_page(page, faddress, pages_per_huge_page(h));
 		__SetPageUptodate(page);
 		set_page_huge_active(page);
 
@@ -3871,7 +3872,7 @@ u32 hugetlb_fault_mutex_hash(struct hstate *h, struct mm_struct *mm,
 #endif
 
 int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
-			unsigned long address, unsigned int flags)
+			unsigned long faddress, unsigned int flags)
 {
 	pte_t *ptep, entry;
 	spinlock_t *ptl;
@@ -3883,8 +3884,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 	struct hstate *h = hstate_vma(vma);
 	struct address_space *mapping;
 	int need_wait_lock = 0;
-
-	address &= huge_page_mask(h);
+	unsigned long address = faddress & huge_page_mask(h);
 
 	ptep = huge_pte_offset(mm, address, huge_page_size(h));
 	if (ptep) {
@@ -3914,7 +3914,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 
 	entry = huge_ptep_get(ptep);
 	if (huge_pte_none(entry)) {
-		ret = hugetlb_no_page(mm, vma, mapping, idx, address, ptep, flags);
+		ret = hugetlb_no_page(mm, vma, mapping, idx, faddress, ptep, flags);
 		goto out_mutex;
 	}
 
#2 lore raw
Quoted 23 lines · Mike Kravetz
Quoted 12 lines · Ying

From: Huang Ying <[email protected]>

This is to take better advantage of huge page clearing optimization (c79b57e462b5d, "mm: hugetlb: clear target sub-page last when clearing huge page"). Which will clear to access sub-page last to avoid the cache lines of to access sub-page to be evicted when clearing other sub-pages. This needs to get the address of the sub-page to access, that is, the fault address inside of the huge page. So the hugetlb no page fault handler is changed to pass that information. This will benefit workloads which don't access the begin of the huge page after page fault.

Quoted 9 lines

With this patch, the throughput increases ~28.1% in vm-scalability anon-w-seq test case with 88 processes on a 2 socket Xeon E5 2699 v4 system (44 cores, 88 threads). The test case creates 88 processes, each process mmap a big anonymous memory area and writes to it from the end to the begin. For each process, other processes could be seen as other workload which generates heavy cache pressure. At the same time, the cache miss rate reduced from ~36.3% to ~25.6%, the IPC (instruction per cycle) increased from 0.3 to 0.37, and the time spent in user space is reduced ~19.3%

Quoted 2 lines

Since this patch only addresses hugetlbfs huge pages, I would suggest making that more explicit in the commit message.

Sure. Will revise it!

Quoted 5 lines

Other than that, the changes look fine to me.

Quoted 1 line

Thanks!

Best Regards,
Huang, Ying

Acked-by on v1 1/1
#3 lore raw
In reply to Huang, Ying
Quoted 22 lines · Ying

From: Huang Ying <[email protected]>

This is to take better advantage of huge page clearing optimization (c79b57e462b5d, "mm: hugetlb: clear target sub-page last when clearing huge page"). Which will clear to access sub-page last to avoid the cache lines of to access sub-page to be evicted when clearing other sub-pages. This needs to get the address of the sub-page to access, that is, the fault address inside of the huge page. So the hugetlb no page fault handler is changed to pass that information. This will benefit workloads which don't access the begin of the huge page after page fault.

With this patch, the throughput increases ~28.1% in vm-scalability anon-w-seq test case with 88 processes on a 2 socket Xeon E5 2699 v4 system (44 cores, 88 threads). The test case creates 88 processes, each process mmap a big anonymous memory area and writes to it from the end to the begin. For each process, other processes could be seen as other workload which generates heavy cache pressure. At the same time, the cache miss rate reduced from ~36.3% to ~25.6%, the IPC (instruction per cycle) increased from 0.3 to 0.37, and the time spent in user space is reduced ~19.3%

Quoted 14 lines
Cc Andrea Arcangeli <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Jan Kara <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Christopher Lameter <[email protected]>
Cc "Aneesh Kumar K.V" <[email protected]>
Cc Punit Agrawal <[email protected]>
Cc Anshuman Khandual <[email protected]>
#4 lore raw
In reply to Huang, Ying
Quoted 54 lines · Ying

From: Huang Ying <[email protected]>

This is to take better advantage of huge page clearing optimization (c79b57e462b5d, "mm: hugetlb: clear target sub-page last when clearing huge page"). Which will clear to access sub-page last to avoid the cache lines of to access sub-page to be evicted when clearing other sub-pages. This needs to get the address of the sub-page to access, that is, the fault address inside of the huge page. So the hugetlb no page fault handler is changed to pass that information. This will benefit workloads which don't access the begin of the huge page after page fault.

With this patch, the throughput increases ~28.1% in vm-scalability anon-w-seq test case with 88 processes on a 2 socket Xeon E5 2699 v4 system (44 cores, 88 threads). The test case creates 88 processes, each process mmap a big anonymous memory area and writes to it from the end to the begin. For each process, other processes could be seen as other workload which generates heavy cache pressure. At the same time, the cache miss rate reduced from ~36.3% to ~25.6%, the IPC (instruction per cycle) increased from 0.3 to 0.37, and the time spent in user space is reduced ~19.3%

Cc Andrea Arcangeli <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Jan Kara <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Christopher Lameter <[email protected]>
Cc "Aneesh Kumar K.V" <[email protected]>
Cc Punit Agrawal <[email protected]>
Cc Anshuman Khandual <[email protected]>
---
 mm/hugetlb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/hugetlb.c +1 -1
index 129088710510..3de6326abf39 100644
@@ -3677,7 +3677,7 @@ int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
 
 static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 			   struct address_space *mapping, pgoff_t idx,
-			   unsigned long address, pte_t *ptep, unsigned int flags)
+			   unsigned long faddress, pte_t *ptep, unsigned int flags)
 {
 	struct hstate *h = hstate_vma(vma);
 	int ret = VM_FAULT_SIGBUS;

mm/hugetlb.c static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma, · line 3689

Quoted 4 lines
mm/hugetlb.c +1 -0
@@ -3686,6 +3686,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 	struct page *page;
 	pte_t new_pte;
 	spinlock_t *ptl;
+	unsigned long address = faddress & huge_page_mask(h);

faddress? I would rather keep it address and rename maked out variable to 'haddr'. We use 'haddr' for the cause in other places.

Signature · 1 line
 Kirill A. Shutemov
#5 lore raw
Quoted 47 lines · Kirill A. Shutemov
Quoted 46 lines · Ying

From: Huang Ying <[email protected]>

This is to take better advantage of huge page clearing optimization (c79b57e462b5d, "mm: hugetlb: clear target sub-page last when clearing huge page"). Which will clear to access sub-page last to avoid the cache lines of to access sub-page to be evicted when clearing other sub-pages. This needs to get the address of the sub-page to access, that is, the fault address inside of the huge page. So the hugetlb no page fault handler is changed to pass that information. This will benefit workloads which don't access the begin of the huge page after page fault.

With this patch, the throughput increases ~28.1% in vm-scalability anon-w-seq test case with 88 processes on a 2 socket Xeon E5 2699 v4 system (44 cores, 88 threads). The test case creates 88 processes, each process mmap a big anonymous memory area and writes to it from the end to the begin. For each process, other processes could be seen as other workload which generates heavy cache pressure. At the same time, the cache miss rate reduced from ~36.3% to ~25.6%, the IPC (instruction per cycle) increased from 0.3 to 0.37, and the time spent in user space is reduced ~19.3%

Cc Andrea Arcangeli <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Jan Kara <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Christopher Lameter <[email protected]>
Cc "Aneesh Kumar K.V" <[email protected]>
Cc Punit Agrawal <[email protected]>
Cc Anshuman Khandual <[email protected]>
---
 mm/hugetlb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/hugetlb.c +0 -0
index 129088710510..3de6326abf39 100644
@@ -3677,7 +3677,7 @@ int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
 
Quoted 15 lines

mm/hugetlb.c static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma, · line 3689

Quoted 12 lines
mm/hugetlb.c +2 -1
 static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 			   struct address_space *mapping, pgoff_t idx,
-			   unsigned long address, pte_t *ptep, unsigned int flags)
+			   unsigned long faddress, pte_t *ptep, unsigned int flags)
 {
 	struct hstate *h = hstate_vma(vma);
 	int ret = VM_FAULT_SIGBUS;
@@ -3686,6 +3686,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 	struct page *page;
 	pte_t new_pte;
 	spinlock_t *ptl;
+	unsigned long address = faddress & huge_page_mask(h);

faddress? I would rather keep it address and rename maked out variable to 'haddr'. We use 'haddr' for the cause in other places.

I found haddr is popular in huge_memory.c but not used in hugetlb.c at all. Is it desirable to start to use "haddr" in hugetlb.c?

Best Regards,
Huang, Ying

#6 lore raw
Quoted 7 lines · Ying
Quoted 4 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	unsigned long address = faddress & huge_page_mask(h);

faddress? I would rather keep it address and rename maked out variable to 'haddr'. We use 'haddr' for the cause in other places.

I found haddr is popular in huge_memory.c but not used in hugetlb.c at all. Is it desirable to start to use "haddr" in hugetlb.c?

Yes, I think so. There's no reason to limit haddr convention to THP.

Signature · 1 line
 Kirill A. Shutemov
#7 lore raw
Quoted 10 lines · Kirill A. Shutemov
Quoted 7 lines · Ying
Quoted 4 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	unsigned long address = faddress & huge_page_mask(h);

faddress? I would rather keep it address and rename maked out variable to 'haddr'. We use 'haddr' for the cause in other places.

I found haddr is popular in huge_memory.c but not used in hugetlb.c at all. Is it desirable to start to use "haddr" in hugetlb.c?

Yes, I think so. There's no reason to limit haddr convention to THP.

OK. Will do this.

Best Regards,
Huang, Ying

Acked-by on v1 1/1
#8 lore raw
In reply to Huang, Ying
Quoted 12 lines · Ying

From: Huang Ying <[email protected]>

This is to take better advantage of huge page clearing optimization (c79b57e462b5d, "mm: hugetlb: clear target sub-page last when clearing huge page"). Which will clear to access sub-page last to avoid the cache lines of to access sub-page to be evicted when clearing other sub-pages. This needs to get the address of the sub-page to access, that is, the fault address inside of the huge page. So the hugetlb no page fault handler is changed to pass that information. This will benefit workloads which don't access the begin of the huge page after page fault.

Quoted 9 lines

With this patch, the throughput increases ~28.1% in vm-scalability anon-w-seq test case with 88 processes on a 2 socket Xeon E5 2699 v4 system (44 cores, 88 threads). The test case creates 88 processes, each process mmap a big anonymous memory area and writes to it from the end to the begin. For each process, other processes could be seen as other workload which generates heavy cache pressure. At the same time, the cache miss rate reduced from ~36.3% to ~25.6%, the IPC (instruction per cycle) increased from 0.3 to 0.37, and the time spent in user space is reduced ~19.3%

This paragraph is confusing as Mike mentioned already. It would be probably more helpful to see how was the test configured to use hugetlb pages and what is the end benefit.

I do not have any real objection to the implementation so feel free to add

I am just wondering what is the usecase driving this. Or is it just a generic optimization that always makes sense to do? Indicating that in the changelog would be helpful as well.

Thanks!

Quoted 79 lines
Cc Andrea Arcangeli <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Jan Kara <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Christopher Lameter <[email protected]>
Cc "Aneesh Kumar K.V" <[email protected]>
Cc Punit Agrawal <[email protected]>
Cc Anshuman Khandual <[email protected]>
---
 mm/hugetlb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/hugetlb.c +6 -6
index 129088710510..3de6326abf39 100644
@@ -3677,7 +3677,7 @@ int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
 
 static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 			   struct address_space *mapping, pgoff_t idx,
-			   unsigned long address, pte_t *ptep, unsigned int flags)
+			   unsigned long faddress, pte_t *ptep, unsigned int flags)
 {
 	struct hstate *h = hstate_vma(vma);
 	int ret = VM_FAULT_SIGBUS;
@@ -3686,6 +3686,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 	struct page *page;
 	pte_t new_pte;
 	spinlock_t *ptl;
+	unsigned long address = faddress & huge_page_mask(h);
 
 	/*
 	 * Currently, we are forced to kill the process in the event the
@@ -3749,7 +3750,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 				ret = VM_FAULT_SIGBUS;
 			goto out;
 		}
-		clear_huge_page(page, address, pages_per_huge_page(h));
+		clear_huge_page(page, faddress, pages_per_huge_page(h));
 		__SetPageUptodate(page);
 		set_page_huge_active(page);
 
@@ -3871,7 +3872,7 @@ u32 hugetlb_fault_mutex_hash(struct hstate *h, struct mm_struct *mm,
 #endif
 
 int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
-			unsigned long address, unsigned int flags)
+			unsigned long faddress, unsigned int flags)
 {
 	pte_t *ptep, entry;
 	spinlock_t *ptl;
@@ -3883,8 +3884,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 	struct hstate *h = hstate_vma(vma);
 	struct address_space *mapping;
 	int need_wait_lock = 0;
-
-	address &= huge_page_mask(h);
+	unsigned long address = faddress & huge_page_mask(h);
 
 	ptep = huge_pte_offset(mm, address, huge_page_size(h));
 	if (ptep) {
@@ -3914,7 +3914,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 
 	entry = huge_ptep_get(ptep);
 	if (huge_pte_none(entry)) {
-		ret = hugetlb_no_page(mm, vma, mapping, idx, address, ptep, flags);
+		ret = hugetlb_no_page(mm, vma, mapping, idx, faddress, ptep, flags);
 		goto out_mutex;
 	}
 
Signature · 1 line
2.16.1
Signature · 2 lines
Michal Hocko
SUSE Labs
#9 lore raw
Quoted 27 lines · Michal Hocko
Quoted 12 lines · Ying

From: Huang Ying <[email protected]>

This is to take better advantage of huge page clearing optimization (c79b57e462b5d, "mm: hugetlb: clear target sub-page last when clearing huge page"). Which will clear to access sub-page last to avoid the cache lines of to access sub-page to be evicted when clearing other sub-pages. This needs to get the address of the sub-page to access, that is, the fault address inside of the huge page. So the hugetlb no page fault handler is changed to pass that information. This will benefit workloads which don't access the begin of the huge page after page fault.

Quoted 9 lines

With this patch, the throughput increases ~28.1% in vm-scalability anon-w-seq test case with 88 processes on a 2 socket Xeon E5 2699 v4 system (44 cores, 88 threads). The test case creates 88 processes, each process mmap a big anonymous memory area and writes to it from the end to the begin. For each process, other processes could be seen as other workload which generates heavy cache pressure. At the same time, the cache miss rate reduced from ~36.3% to ~25.6%, the IPC (instruction per cycle) increased from 0.3 to 0.37, and the time spent in user space is reduced ~19.3%

This paragraph is confusing as Mike mentioned already. It would be probably more helpful to see how was the test configured to use hugetlb pages and what is the end benefit.

Quoted 6 lines

I do not have any real objection to the implementation so feel free to add

I am just wondering what is the usecase driving this. Or is it just a generic optimization that always makes sense to do? Indicating that in the changelog would be helpful as well.

I just noticed that the optimization was not added for 'gigantic' pages. Should we consider adding support for gigantic pages as well? It may be that the cache miss cost is insignificant when added to the time required to clear a 1GB (for x86) gigantic page.

One more thing, I'm guessing the copy_huge/gigantic_page() routines would see a similar benefit. Specifically, for copies as a result of a COW. Is that another area to consider?

That gets back to Michal's question of a specific use case or generic optimization. Unless code is simple (as in this patch), seems like we should hold off on considering additional optimizations unless there is a specific use case.

I'm still OK with this change.

Signature · 1 line
Mike Kravetz
#10 lore raw
Quoted 35 lines · Mike Kravetz
Quoted 27 lines · Michal Hocko
Quoted 12 lines · Ying

From: Huang Ying <[email protected]>

This is to take better advantage of huge page clearing optimization (c79b57e462b5d, "mm: hugetlb: clear target sub-page last when clearing huge page"). Which will clear to access sub-page last to avoid the cache lines of to access sub-page to be evicted when clearing other sub-pages. This needs to get the address of the sub-page to access, that is, the fault address inside of the huge page. So the hugetlb no page fault handler is changed to pass that information. This will benefit workloads which don't access the begin of the huge page after page fault.

Quoted 9 lines

With this patch, the throughput increases ~28.1% in vm-scalability anon-w-seq test case with 88 processes on a 2 socket Xeon E5 2699 v4 system (44 cores, 88 threads). The test case creates 88 processes, each process mmap a big anonymous memory area and writes to it from the end to the begin. For each process, other processes could be seen as other workload which generates heavy cache pressure. At the same time, the cache miss rate reduced from ~36.3% to ~25.6%, the IPC (instruction per cycle) increased from 0.3 to 0.37, and the time spent in user space is reduced ~19.3%

This paragraph is confusing as Mike mentioned already. It would be probably more helpful to see how was the test configured to use hugetlb pages and what is the end benefit.

Quoted 6 lines

I do not have any real objection to the implementation so feel free to add

I am just wondering what is the usecase driving this. Or is it just a generic optimization that always makes sense to do? Indicating that in the changelog would be helpful as well.

Quoted 4 lines

I just noticed that the optimization was not added for 'gigantic' pages. Should we consider adding support for gigantic pages as well? It may be that the cache miss cost is insignificant when added to the time required to clear a 1GB (for x86) gigantic page.

Yes. I worry about that too.

Quoted 3 lines

One more thing, I'm guessing the copy_huge/gigantic_page() routines would see a similar benefit. Specifically, for copies as a result of a COW. Is that another area to consider?

Yes. I have the patch already and will send it out soon.

Quoted 6 lines

That gets back to Michal's question of a specific use case or generic optimization. Unless code is simple (as in this patch), seems like we should hold off on considering additional optimizations unless there is a specific use case.

I'm still OK with this change.

Thanks!

Best Regards,
Huang, Ying

#11 lore raw
In reply to Michal Hocko
Quoted 23 lines · Michal Hocko
Quoted 12 lines · Ying

From: Huang Ying <[email protected]>

This is to take better advantage of huge page clearing optimization (c79b57e462b5d, "mm: hugetlb: clear target sub-page last when clearing huge page"). Which will clear to access sub-page last to avoid the cache lines of to access sub-page to be evicted when clearing other sub-pages. This needs to get the address of the sub-page to access, that is, the fault address inside of the huge page. So the hugetlb no page fault handler is changed to pass that information. This will benefit workloads which don't access the begin of the huge page after page fault.

Quoted 9 lines

With this patch, the throughput increases ~28.1% in vm-scalability anon-w-seq test case with 88 processes on a 2 socket Xeon E5 2699 v4 system (44 cores, 88 threads). The test case creates 88 processes, each process mmap a big anonymous memory area and writes to it from the end to the begin. For each process, other processes could be seen as other workload which generates heavy cache pressure. At the same time, the cache miss rate reduced from ~36.3% to ~25.6%, the IPC (instruction per cycle) increased from 0.3 to 0.37, and the time spent in user space is reduced ~19.3%

Quoted 3 lines

This paragraph is confusing as Mike mentioned already. It would be probably more helpful to see how was the test configured to use hugetlb pages and what is the end benefit.

Sure. Will revise it.

Quoted 3 lines

I do not have any real objection to the implementation so feel free to add

Thanks!

Quoted 3 lines

I am just wondering what is the usecase driving this. Or is it just a generic optimization that always makes sense to do? Indicating that in the changelog would be helpful as well.

I think this is a generic optimization.

Best Regards,
Huang, Ying

Quoted 81 lines

Thanks!

Quoted 79 lines
Cc Andrea Arcangeli <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Jan Kara <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Christopher Lameter <[email protected]>
Cc "Aneesh Kumar K.V" <[email protected]>
Cc Punit Agrawal <[email protected]>
Cc Anshuman Khandual <[email protected]>
---
 mm/hugetlb.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
mm/hugetlb.c +6 -6
index 129088710510..3de6326abf39 100644
@@ -3677,7 +3677,7 @@ int huge_add_to_page_cache(struct page *page, struct address_space *mapping,
 
 static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 			   struct address_space *mapping, pgoff_t idx,
-			   unsigned long address, pte_t *ptep, unsigned int flags)
+			   unsigned long faddress, pte_t *ptep, unsigned int flags)
 {
 	struct hstate *h = hstate_vma(vma);
 	int ret = VM_FAULT_SIGBUS;
@@ -3686,6 +3686,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 	struct page *page;
 	pte_t new_pte;
 	spinlock_t *ptl;
+	unsigned long address = faddress & huge_page_mask(h);
 
 	/*
 	 * Currently, we are forced to kill the process in the event the
@@ -3749,7 +3750,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
 				ret = VM_FAULT_SIGBUS;
 			goto out;
 		}
-		clear_huge_page(page, address, pages_per_huge_page(h));
+		clear_huge_page(page, faddress, pages_per_huge_page(h));
 		__SetPageUptodate(page);
 		set_page_huge_active(page);
 
@@ -3871,7 +3872,7 @@ u32 hugetlb_fault_mutex_hash(struct hstate *h, struct mm_struct *mm,
 #endif
 
 int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
-			unsigned long address, unsigned int flags)
+			unsigned long faddress, unsigned int flags)
 {
 	pte_t *ptep, entry;
 	spinlock_t *ptl;
@@ -3883,8 +3884,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 	struct hstate *h = hstate_vma(vma);
 	struct address_space *mapping;
 	int need_wait_lock = 0;
-
-	address &= huge_page_mask(h);
+	unsigned long address = faddress & huge_page_mask(h);
 
 	ptep = huge_pte_offset(mm, address, huge_page_size(h));
 	if (ptep) {
@@ -3914,7 +3914,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 
 	entry = huge_ptep_get(ptep);
 	if (huge_pte_none(entry)) {
-		ret = hugetlb_no_page(mm, vma, mapping, idx, address, ptep, flags);
+		ret = hugetlb_no_page(mm, vma, mapping, idx, faddress, ptep, flags);
 		goto out_mutex;
 	}
 
Signature · 1 line
2.16.1