* [PATCH 1/2] mm,hugetlb: make unmap_ref_private() return void
@ 2014-07-01 20:21 Davidlohr Bueso
2014-07-01 20:21 ` [PATCH 2/2] mm,hugetlb: simplify error handling in hugetlb_cow() Davidlohr Bueso
2014-07-01 22:09 ` [PATCH 1/2] mm,hugetlb: make unmap_ref_private() return void David Rientjes
0 siblings, 2 replies; 4+ messages in thread
From: Davidlohr Bueso @ 2014-07-01 20:21 UTC (permalink / raw)
To: akpm; +Cc: davidlohr, aswin, linux-mm, linux-kernel
This function always returns 1, thus no need to check return value
in hugetlb_cow(). By doing so, we can get rid of the unnecessary WARN_ON
call. While this logic perhaps existed as a way of identifying future
unmap_ref_private() mishandling, reality is it serves no apparent purpose.
Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
---
mm/hugetlb.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 2024bbd..3c4d535 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2753,8 +2753,8 @@ void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start,
* from other VMAs and let the children be SIGKILLed if they are faulting the
* same region.
*/
-static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
- struct page *page, unsigned long address)
+static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
+ struct page *page, unsigned long address)
{
struct hstate *h = hstate_vma(vma);
struct vm_area_struct *iter_vma;
@@ -2793,8 +2793,6 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
address + huge_page_size(h), page);
}
mutex_unlock(&mapping->i_mmap_mutex);
-
- return 1;
}
/*
@@ -2856,20 +2854,18 @@ retry_avoidcopy:
*/
if (outside_reserve) {
BUG_ON(huge_pte_none(pte));
- if (unmap_ref_private(mm, vma, old_page, address)) {
- BUG_ON(huge_pte_none(pte));
- spin_lock(ptl);
- ptep = huge_pte_offset(mm, address & huge_page_mask(h));
- if (likely(ptep &&
- pte_same(huge_ptep_get(ptep), pte)))
- goto retry_avoidcopy;
- /*
- * race occurs while re-acquiring page table
- * lock, and our job is done.
- */
- return 0;
- }
- WARN_ON_ONCE(1);
+ unmap_ref_private(mm, vma, old_page, address);
+ BUG_ON(huge_pte_none(pte));
+ spin_lock(ptl);
+ ptep = huge_pte_offset(mm, address & huge_page_mask(h));
+ if (likely(ptep &&
+ pte_same(huge_ptep_get(ptep), pte)))
+ goto retry_avoidcopy;
+ /*
+ * race occurs while re-acquiring page table
+ * lock, and our job is done.
+ */
+ return 0;
}
/* Caller expects lock to be held */
--
1.8.1.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] mm,hugetlb: simplify error handling in hugetlb_cow()
2014-07-01 20:21 [PATCH 1/2] mm,hugetlb: make unmap_ref_private() return void Davidlohr Bueso
@ 2014-07-01 20:21 ` Davidlohr Bueso
2014-07-01 22:13 ` David Rientjes
2014-07-01 22:09 ` [PATCH 1/2] mm,hugetlb: make unmap_ref_private() return void David Rientjes
1 sibling, 1 reply; 4+ messages in thread
From: Davidlohr Bueso @ 2014-07-01 20:21 UTC (permalink / raw)
To: akpm; +Cc: davidlohr, aswin, linux-mm, linux-kernel
When returning from hugetlb_cow(), we always (1) put back the refcount
for each referenced page -- always 'old', and 'new' if allocation was
successful. And (2) retake the page table lock right before returning,
as the callers expects. This logic can be simplified and encapsulated,
as proposed in this patch. In addition to cleaner code, we also shave
a few bytes off in instruction text:
text data bss dec hex filename
28399 462 41328 70189 1122d mm/hugetlb.o-baseline
28367 462 41328 70157 1120d mm/hugetlb.o-patched
Passes libhugetlbfs testcases.
Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
---
mm/hugetlb.c | 35 ++++++++++++++++-------------------
1 file changed, 16 insertions(+), 19 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 3c4d535..172bc1d 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2807,7 +2807,7 @@ static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
{
struct hstate *h = hstate_vma(vma);
struct page *old_page, *new_page;
- int outside_reserve = 0;
+ int ret = 0, outside_reserve = 0;
unsigned long mmun_start; /* For mmu_notifiers */
unsigned long mmun_end; /* For mmu_notifiers */
@@ -2837,14 +2837,14 @@ retry_avoidcopy:
page_cache_get(old_page);
- /* Drop page table lock as buddy allocator may be called */
+ /*
+ * Drop page table lock as buddy allocator may be called. It will
+ * be acquired again before returning to the caller, as expected.
+ */
spin_unlock(ptl);
new_page = alloc_huge_page(vma, address, outside_reserve);
if (IS_ERR(new_page)) {
- long err = PTR_ERR(new_page);
- page_cache_release(old_page);
-
/*
* If a process owning a MAP_PRIVATE mapping fails to COW,
* it is due to references held by a child and an insufficient
@@ -2853,6 +2853,7 @@ retry_avoidcopy:
* may get SIGKILLed if it later faults.
*/
if (outside_reserve) {
+ page_cache_release(old_page);
BUG_ON(huge_pte_none(pte));
unmap_ref_private(mm, vma, old_page, address);
BUG_ON(huge_pte_none(pte));
@@ -2868,12 +2869,9 @@ retry_avoidcopy:
return 0;
}
- /* Caller expects lock to be held */
- spin_lock(ptl);
- if (err == -ENOMEM)
- return VM_FAULT_OOM;
- else
- return VM_FAULT_SIGBUS;
+ ret = (PTR_ERR(new_page) == -ENOMEM) ?
+ VM_FAULT_OOM : VM_FAULT_SIGBUS;
+ goto out_release_old;
}
/*
@@ -2881,11 +2879,8 @@ retry_avoidcopy:
* anon_vma prepared.
*/
if (unlikely(anon_vma_prepare(vma))) {
- page_cache_release(new_page);
- page_cache_release(old_page);
- /* Caller expects lock to be held */
- spin_lock(ptl);
- return VM_FAULT_OOM;
+ ret = VM_FAULT_OOM;
+ goto out_release_all;
}
copy_user_huge_page(new_page, old_page, address, vma,
@@ -2895,6 +2890,7 @@ retry_avoidcopy:
mmun_start = address & huge_page_mask(h);
mmun_end = mmun_start + huge_page_size(h);
mmu_notifier_invalidate_range_start(mm, mmun_start, mmun_end);
+
/*
* Retake the page table lock to check for racing updates
* before the page tables are altered
@@ -2915,12 +2911,13 @@ retry_avoidcopy:
}
spin_unlock(ptl);
mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end);
+out_release_all:
page_cache_release(new_page);
+out_release_old:
page_cache_release(old_page);
- /* Caller expects lock to be held */
- spin_lock(ptl);
- return 0;
+ spin_lock(ptl); /* Caller expects lock to be held */
+ return ret;
}
/* Return the pagecache page at a given address within a VMA */
--
1.8.1.4
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] mm,hugetlb: make unmap_ref_private() return void
2014-07-01 20:21 [PATCH 1/2] mm,hugetlb: make unmap_ref_private() return void Davidlohr Bueso
2014-07-01 20:21 ` [PATCH 2/2] mm,hugetlb: simplify error handling in hugetlb_cow() Davidlohr Bueso
@ 2014-07-01 22:09 ` David Rientjes
1 sibling, 0 replies; 4+ messages in thread
From: David Rientjes @ 2014-07-01 22:09 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: akpm, aswin, linux-mm, linux-kernel
On Tue, 1 Jul 2014, Davidlohr Bueso wrote:
> This function always returns 1, thus no need to check return value
> in hugetlb_cow(). By doing so, we can get rid of the unnecessary WARN_ON
> call. While this logic perhaps existed as a way of identifying future
> unmap_ref_private() mishandling, reality is it serves no apparent purpose.
>
> Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
Acked-by: David Rientjes <rientjes@google.com>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] mm,hugetlb: simplify error handling in hugetlb_cow()
2014-07-01 20:21 ` [PATCH 2/2] mm,hugetlb: simplify error handling in hugetlb_cow() Davidlohr Bueso
@ 2014-07-01 22:13 ` David Rientjes
0 siblings, 0 replies; 4+ messages in thread
From: David Rientjes @ 2014-07-01 22:13 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: akpm, aswin, linux-mm, linux-kernel
On Tue, 1 Jul 2014, Davidlohr Bueso wrote:
> When returning from hugetlb_cow(), we always (1) put back the refcount
> for each referenced page -- always 'old', and 'new' if allocation was
> successful. And (2) retake the page table lock right before returning,
> as the callers expects. This logic can be simplified and encapsulated,
> as proposed in this patch. In addition to cleaner code, we also shave
> a few bytes off in instruction text:
>
> text data bss dec hex filename
> 28399 462 41328 70189 1122d mm/hugetlb.o-baseline
> 28367 462 41328 70157 1120d mm/hugetlb.o-patched
>
> Passes libhugetlbfs testcases.
>
> Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
Acked-by: David Rientjes <rientjes@google.com>
Not sure the extra indirection is clearer code, but I can't argue with the
difference in object size.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-01 22:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-01 20:21 [PATCH 1/2] mm,hugetlb: make unmap_ref_private() return void Davidlohr Bueso
2014-07-01 20:21 ` [PATCH 2/2] mm,hugetlb: simplify error handling in hugetlb_cow() Davidlohr Bueso
2014-07-01 22:13 ` David Rientjes
2014-07-01 22:09 ` [PATCH 1/2] mm,hugetlb: make unmap_ref_private() return void David Rientjes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).