* [PATCH v3 1/4] mm/memory: convert do_page_mkwrite() to use folios
@ 2023-07-06 16:38 Sidhartha Kumar
2023-07-06 16:38 ` [PATCH v3 2/4] mm/memory: convert wp_page_shared() " Sidhartha Kumar
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: Sidhartha Kumar @ 2023-07-06 16:38 UTC (permalink / raw)
To: linux-kernel, linux-mm; +Cc: akpm, willy, zhangpeng362, Sidhartha Kumar
Saves one implicit call to compound_head();
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/memory.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index cf4ae87b15639..1736a130fa829 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2935,7 +2935,7 @@ static gfp_t __get_fault_gfp_mask(struct vm_area_struct *vma)
static vm_fault_t do_page_mkwrite(struct vm_fault *vmf)
{
vm_fault_t ret;
- struct page *page = vmf->page;
+ struct folio *folio = page_folio(vmf->page);
unsigned int old_flags = vmf->flags;
vmf->flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE;
@@ -2950,14 +2950,14 @@ static vm_fault_t do_page_mkwrite(struct vm_fault *vmf)
if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))
return ret;
if (unlikely(!(ret & VM_FAULT_LOCKED))) {
- lock_page(page);
- if (!page->mapping) {
- unlock_page(page);
+ folio_lock(folio);
+ if (!folio->mapping) {
+ folio_unlock(folio);
return 0; /* retry */
}
ret |= VM_FAULT_LOCKED;
} else
- VM_BUG_ON_PAGE(!PageLocked(page), page);
+ VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
return ret;
}
--
2.41.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 2/4] mm/memory: convert wp_page_shared() to use folios
2023-07-06 16:38 [PATCH v3 1/4] mm/memory: convert do_page_mkwrite() to use folios Sidhartha Kumar
@ 2023-07-06 16:38 ` Sidhartha Kumar
2023-07-06 17:48 ` Matthew Wilcox
2023-07-07 10:30 ` zhangpeng (AS)
2023-07-06 16:38 ` [PATCH v3 3/4] mm/memory: convert do_shared_fault() to folios Sidhartha Kumar
` (2 subsequent siblings)
3 siblings, 2 replies; 10+ messages in thread
From: Sidhartha Kumar @ 2023-07-06 16:38 UTC (permalink / raw)
To: linux-kernel, linux-mm; +Cc: akpm, willy, zhangpeng362, Sidhartha Kumar
Saves six implicit calls to compound_head().
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
v3:
- remove extra page_folio() by moving up folio initialization
v2:
- change function definition to pass in a folio
mm/memory.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index 1736a130fa829..673b9fa67d0d7 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3285,13 +3285,13 @@ static vm_fault_t wp_pfn_shared(struct vm_fault *vmf)
return 0;
}
-static vm_fault_t wp_page_shared(struct vm_fault *vmf)
+static vm_fault_t wp_page_shared(struct vm_fault *vmf, struct folio *folio)
__releases(vmf->ptl)
{
struct vm_area_struct *vma = vmf->vma;
vm_fault_t ret = 0;
- get_page(vmf->page);
+ folio_get(folio);
if (vma->vm_ops && vma->vm_ops->page_mkwrite) {
vm_fault_t tmp;
@@ -3300,21 +3300,21 @@ static vm_fault_t wp_page_shared(struct vm_fault *vmf)
tmp = do_page_mkwrite(vmf);
if (unlikely(!tmp || (tmp &
(VM_FAULT_ERROR | VM_FAULT_NOPAGE)))) {
- put_page(vmf->page);
+ folio_put(folio);
return tmp;
}
tmp = finish_mkwrite_fault(vmf);
if (unlikely(tmp & (VM_FAULT_ERROR | VM_FAULT_NOPAGE))) {
- unlock_page(vmf->page);
- put_page(vmf->page);
+ folio_unlock(folio);
+ folio_put(folio);
return tmp;
}
} else {
wp_page_reuse(vmf);
- lock_page(vmf->page);
+ folio_lock(folio);
}
ret |= fault_dirty_shared_page(vmf);
- put_page(vmf->page);
+ folio_put(folio);
return ret;
}
@@ -3365,6 +3365,9 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)
vmf->page = vm_normal_page(vma, vmf->address, vmf->orig_pte);
+ if (vmf->page)
+ folio = page_folio(vmf->page);
+
/*
* Shared mapping: we are guaranteed to have VM_WRITE and
* FAULT_FLAG_WRITE set at this point.
@@ -3379,12 +3382,9 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)
*/
if (!vmf->page)
return wp_pfn_shared(vmf);
- return wp_page_shared(vmf);
+ return wp_page_shared(vmf, folio);
}
- if (vmf->page)
- folio = page_folio(vmf->page);
-
/*
* Private mapping: create an exclusive anonymous page copy if reuse
* is impossible. We might miss VM_WRITE for FOLL_FORCE handling.
--
2.41.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 3/4] mm/memory: convert do_shared_fault() to folios
2023-07-06 16:38 [PATCH v3 1/4] mm/memory: convert do_page_mkwrite() to use folios Sidhartha Kumar
2023-07-06 16:38 ` [PATCH v3 2/4] mm/memory: convert wp_page_shared() " Sidhartha Kumar
@ 2023-07-06 16:38 ` Sidhartha Kumar
2023-07-07 10:30 ` zhangpeng (AS)
2023-07-06 16:38 ` [PATCH v3 4/4] mm/memory: convert do_read_fault() to use folios Sidhartha Kumar
2023-07-07 10:30 ` [PATCH v3 1/4] mm/memory: convert do_page_mkwrite() " zhangpeng (AS)
3 siblings, 1 reply; 10+ messages in thread
From: Sidhartha Kumar @ 2023-07-06 16:38 UTC (permalink / raw)
To: linux-kernel, linux-mm; +Cc: akpm, willy, zhangpeng362, Sidhartha Kumar
Saves three implicit calls to compound_head().
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
v2:
- move folio initialization after __do_fault()
mm/memory.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index 673b9fa67d0d7..a59b10e534c07 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4607,21 +4607,24 @@ static vm_fault_t do_shared_fault(struct vm_fault *vmf)
{
struct vm_area_struct *vma = vmf->vma;
vm_fault_t ret, tmp;
+ struct folio *folio;
ret = __do_fault(vmf);
if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE | VM_FAULT_RETRY)))
return ret;
+ folio = page_folio(vmf->page);
+
/*
* Check if the backing address space wants to know that the page is
* about to become writable
*/
if (vma->vm_ops->page_mkwrite) {
- unlock_page(vmf->page);
+ folio_unlock(folio);
tmp = do_page_mkwrite(vmf);
if (unlikely(!tmp ||
(tmp & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))) {
- put_page(vmf->page);
+ folio_put(folio);
return tmp;
}
}
@@ -4629,8 +4632,8 @@ static vm_fault_t do_shared_fault(struct vm_fault *vmf)
ret |= finish_fault(vmf);
if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE |
VM_FAULT_RETRY))) {
- unlock_page(vmf->page);
- put_page(vmf->page);
+ folio_unlock(folio);
+ folio_put(folio);
return ret;
}
--
2.41.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 4/4] mm/memory: convert do_read_fault() to use folios
2023-07-06 16:38 [PATCH v3 1/4] mm/memory: convert do_page_mkwrite() to use folios Sidhartha Kumar
2023-07-06 16:38 ` [PATCH v3 2/4] mm/memory: convert wp_page_shared() " Sidhartha Kumar
2023-07-06 16:38 ` [PATCH v3 3/4] mm/memory: convert do_shared_fault() to folios Sidhartha Kumar
@ 2023-07-06 16:38 ` Sidhartha Kumar
2023-07-07 10:30 ` zhangpeng (AS)
2023-07-07 10:30 ` [PATCH v3 1/4] mm/memory: convert do_page_mkwrite() " zhangpeng (AS)
3 siblings, 1 reply; 10+ messages in thread
From: Sidhartha Kumar @ 2023-07-06 16:38 UTC (permalink / raw)
To: linux-kernel, linux-mm; +Cc: akpm, willy, zhangpeng362, Sidhartha Kumar
Saves one implicit call to compound_head()
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
v3:
- move folio initialization after finish_fault()
v2
- move folio initialization after __do_fault()
mm/memory.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index a59b10e534c07..64e1eb840dec7 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4541,6 +4541,7 @@ static inline bool should_fault_around(struct vm_fault *vmf)
static vm_fault_t do_read_fault(struct vm_fault *vmf)
{
vm_fault_t ret = 0;
+ struct folio *folio;
/*
* Let's call ->map_pages() first and use ->fault() as fallback
@@ -4558,9 +4559,10 @@ static vm_fault_t do_read_fault(struct vm_fault *vmf)
return ret;
ret |= finish_fault(vmf);
- unlock_page(vmf->page);
+ folio = page_folio(vmf->page);
+ folio_unlock(folio);
if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE | VM_FAULT_RETRY)))
- put_page(vmf->page);
+ folio_put(folio);
return ret;
}
--
2.41.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 2/4] mm/memory: convert wp_page_shared() to use folios
2023-07-06 16:38 ` [PATCH v3 2/4] mm/memory: convert wp_page_shared() " Sidhartha Kumar
@ 2023-07-06 17:48 ` Matthew Wilcox
2023-07-06 18:58 ` Sidhartha Kumar
2023-07-07 10:30 ` zhangpeng (AS)
1 sibling, 1 reply; 10+ messages in thread
From: Matthew Wilcox @ 2023-07-06 17:48 UTC (permalink / raw)
To: Sidhartha Kumar; +Cc: linux-kernel, linux-mm, akpm, zhangpeng362
On Thu, Jul 06, 2023 at 09:38:45AM -0700, Sidhartha Kumar wrote:
> Saves six implicit calls to compound_head().
>
> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 2/4] mm/memory: convert wp_page_shared() to use folios
2023-07-06 17:48 ` Matthew Wilcox
@ 2023-07-06 18:58 ` Sidhartha Kumar
0 siblings, 0 replies; 10+ messages in thread
From: Sidhartha Kumar @ 2023-07-06 18:58 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: linux-kernel, linux-mm, akpm, zhangpeng362
On 7/6/23 10:48 AM, Matthew Wilcox wrote:
> On Thu, Jul 06, 2023 at 09:38:45AM -0700, Sidhartha Kumar wrote:
>> Saves six implicit calls to compound_head().
>>
>> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
>
> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Thanks for the review throughout the revisions.
Sidhartha Kumar
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 1/4] mm/memory: convert do_page_mkwrite() to use folios
2023-07-06 16:38 [PATCH v3 1/4] mm/memory: convert do_page_mkwrite() to use folios Sidhartha Kumar
` (2 preceding siblings ...)
2023-07-06 16:38 ` [PATCH v3 4/4] mm/memory: convert do_read_fault() to use folios Sidhartha Kumar
@ 2023-07-07 10:30 ` zhangpeng (AS)
3 siblings, 0 replies; 10+ messages in thread
From: zhangpeng (AS) @ 2023-07-07 10:30 UTC (permalink / raw)
To: Sidhartha Kumar, linux-kernel, linux-mm; +Cc: akpm, willy
On 2023/7/7 0:38, Sidhartha Kumar wrote:
> Saves one implicit call to compound_head();
>
> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: ZhangPeng<zhangpeng362@huawei.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 2/4] mm/memory: convert wp_page_shared() to use folios
2023-07-06 16:38 ` [PATCH v3 2/4] mm/memory: convert wp_page_shared() " Sidhartha Kumar
2023-07-06 17:48 ` Matthew Wilcox
@ 2023-07-07 10:30 ` zhangpeng (AS)
1 sibling, 0 replies; 10+ messages in thread
From: zhangpeng (AS) @ 2023-07-07 10:30 UTC (permalink / raw)
To: Sidhartha Kumar, linux-kernel, linux-mm; +Cc: akpm, willy
On 2023/7/7 0:38, Sidhartha Kumar wrote:
> Saves six implicit calls to compound_head().
>
> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: ZhangPeng<zhangpeng362@huawei.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 3/4] mm/memory: convert do_shared_fault() to folios
2023-07-06 16:38 ` [PATCH v3 3/4] mm/memory: convert do_shared_fault() to folios Sidhartha Kumar
@ 2023-07-07 10:30 ` zhangpeng (AS)
0 siblings, 0 replies; 10+ messages in thread
From: zhangpeng (AS) @ 2023-07-07 10:30 UTC (permalink / raw)
To: Sidhartha Kumar, linux-kernel, linux-mm; +Cc: akpm, willy
On 2023/7/7 0:38, Sidhartha Kumar wrote:
> Saves three implicit calls to compound_head().
>
> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: ZhangPeng<zhangpeng362@huawei.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 4/4] mm/memory: convert do_read_fault() to use folios
2023-07-06 16:38 ` [PATCH v3 4/4] mm/memory: convert do_read_fault() to use folios Sidhartha Kumar
@ 2023-07-07 10:30 ` zhangpeng (AS)
0 siblings, 0 replies; 10+ messages in thread
From: zhangpeng (AS) @ 2023-07-07 10:30 UTC (permalink / raw)
To: Sidhartha Kumar, linux-kernel, linux-mm; +Cc: akpm, willy
On 2023/7/7 0:38, Sidhartha Kumar wrote:
> Saves one implicit call to compound_head()
>
> Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: ZhangPeng<zhangpeng362@huawei.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-07-07 10:30 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-06 16:38 [PATCH v3 1/4] mm/memory: convert do_page_mkwrite() to use folios Sidhartha Kumar
2023-07-06 16:38 ` [PATCH v3 2/4] mm/memory: convert wp_page_shared() " Sidhartha Kumar
2023-07-06 17:48 ` Matthew Wilcox
2023-07-06 18:58 ` Sidhartha Kumar
2023-07-07 10:30 ` zhangpeng (AS)
2023-07-06 16:38 ` [PATCH v3 3/4] mm/memory: convert do_shared_fault() to folios Sidhartha Kumar
2023-07-07 10:30 ` zhangpeng (AS)
2023-07-06 16:38 ` [PATCH v3 4/4] mm/memory: convert do_read_fault() to use folios Sidhartha Kumar
2023-07-07 10:30 ` zhangpeng (AS)
2023-07-07 10:30 ` [PATCH v3 1/4] mm/memory: convert do_page_mkwrite() " zhangpeng (AS)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox