* [PATCH 0/3] Remove unmap_and_put_page()
@ 2025-07-09 19:40 Vishal Moola (Oracle)
2025-07-09 19:40 ` [PATCH 1/3] mm/memory.c: Use folios in __copy_remote_vm_str() Vishal Moola (Oracle)
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Vishal Moola (Oracle) @ 2025-07-09 19:40 UTC (permalink / raw)
To: linux-mm
Cc: linux-kernel, Matthew Wilcox (Oracle), David Hildenbrand,
Jordan Rome, Andrew Morton, Vishal Moola (Oracle)
This patchset uses folios in both the callers of
unmap_and_put_page(), saving a couple calls to compound_head() wrappers.
----
The initial rfc[1] attempted to provide large folio support for the
caller functions. Trying to do this without the relevant "struct page"
is excessive and unnecessary right now.
[1] https://lore.kernel.org/linux-mm/20250625174841.1094510-1-vishal.moola@gmail.com/
Vishal Moola (Oracle) (3):
mm/memory.c: Use folios in __copy_remote_vm_str()
mm/memory.c: Use folios in __access_remote_vm()
mm: Remove unmap_and_put_page()
include/linux/highmem.h | 6 ------
mm/memory.c | 16 ++++++++++------
2 files changed, 10 insertions(+), 12 deletions(-)
--
2.50.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] mm/memory.c: Use folios in __copy_remote_vm_str()
2025-07-09 19:40 [PATCH 0/3] Remove unmap_and_put_page() Vishal Moola (Oracle)
@ 2025-07-09 19:40 ` Vishal Moola (Oracle)
2025-07-11 10:49 ` David Hildenbrand
2025-07-09 19:40 ` [PATCH 2/3] mm/memory.c: Use folios in __access_remote_vm() Vishal Moola (Oracle)
2025-07-09 19:40 ` [PATCH 3/3] mm: Remove unmap_and_put_page() Vishal Moola (Oracle)
2 siblings, 1 reply; 7+ messages in thread
From: Vishal Moola (Oracle) @ 2025-07-09 19:40 UTC (permalink / raw)
To: linux-mm
Cc: linux-kernel, Matthew Wilcox (Oracle), David Hildenbrand,
Jordan Rome, Andrew Morton, Vishal Moola (Oracle)
Use kmap_local_folio() instead of kmap_local_page().
Replaces 2 calls to compound_head() from unmap_and_put_page() with one.
This prepares us for the removal of unmap_and_put_page().
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
---
mm/memory.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index 1174f3001307..d63f0d5abcc9 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -6815,6 +6815,7 @@ static int __copy_remote_vm_str(struct mm_struct *mm, unsigned long addr,
while (len) {
int bytes, offset, retval;
void *maddr;
+ struct folio *folio;
struct page *page;
struct vm_area_struct *vma = NULL;
@@ -6830,17 +6831,18 @@ static int __copy_remote_vm_str(struct mm_struct *mm, unsigned long addr,
goto out;
}
+ folio = page_folio(page);
bytes = len;
offset = addr & (PAGE_SIZE - 1);
if (bytes > PAGE_SIZE - offset)
bytes = PAGE_SIZE - offset;
- maddr = kmap_local_page(page);
+ maddr = kmap_local_folio(folio, folio_page_idx(folio, page) * PAGE_SIZE);
retval = strscpy(buf, maddr + offset, bytes);
if (retval >= 0) {
/* Found the end of the string */
buf += retval;
- unmap_and_put_page(page, maddr);
+ folio_release_kmap(folio, maddr);
break;
}
@@ -6858,7 +6860,7 @@ static int __copy_remote_vm_str(struct mm_struct *mm, unsigned long addr,
}
len -= bytes;
- unmap_and_put_page(page, maddr);
+ folio_release_kmap(folio, maddr);
}
out:
--
2.50.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] mm/memory.c: Use folios in __access_remote_vm()
2025-07-09 19:40 [PATCH 0/3] Remove unmap_and_put_page() Vishal Moola (Oracle)
2025-07-09 19:40 ` [PATCH 1/3] mm/memory.c: Use folios in __copy_remote_vm_str() Vishal Moola (Oracle)
@ 2025-07-09 19:40 ` Vishal Moola (Oracle)
2025-07-11 10:50 ` David Hildenbrand
2025-07-09 19:40 ` [PATCH 3/3] mm: Remove unmap_and_put_page() Vishal Moola (Oracle)
2 siblings, 1 reply; 7+ messages in thread
From: Vishal Moola (Oracle) @ 2025-07-09 19:40 UTC (permalink / raw)
To: linux-mm
Cc: linux-kernel, Matthew Wilcox (Oracle), David Hildenbrand,
Jordan Rome, Andrew Morton, Vishal Moola (Oracle)
Use kmap_local_folio() instead of kmap_local_page().
Replaces 2 calls to compound_head() with one.
This prepares us for the removal of unmap_and_put_page().
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
---
mm/memory.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/mm/memory.c b/mm/memory.c
index d63f0d5abcc9..3dd6c57e6511 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -6691,6 +6691,7 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr,
while (len) {
int bytes, offset;
void *maddr;
+ struct folio *folio;
struct vm_area_struct *vma = NULL;
struct page *page = get_user_page_vma_remote(mm, addr,
gup_flags, &vma);
@@ -6722,21 +6723,22 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr,
if (bytes <= 0)
break;
} else {
+ folio = page_folio(page);
bytes = len;
offset = addr & (PAGE_SIZE-1);
if (bytes > PAGE_SIZE-offset)
bytes = PAGE_SIZE-offset;
- maddr = kmap_local_page(page);
+ maddr = kmap_local_folio(folio, folio_page_idx(folio, page) * PAGE_SIZE);
if (write) {
copy_to_user_page(vma, page, addr,
maddr + offset, buf, bytes);
- set_page_dirty_lock(page);
+ folio_mark_dirty_lock(folio);
} else {
copy_from_user_page(vma, page, addr,
buf, maddr + offset, bytes);
}
- unmap_and_put_page(page, maddr);
+ folio_release_kmap(folio, maddr);
}
len -= bytes;
buf += bytes;
--
2.50.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] mm: Remove unmap_and_put_page()
2025-07-09 19:40 [PATCH 0/3] Remove unmap_and_put_page() Vishal Moola (Oracle)
2025-07-09 19:40 ` [PATCH 1/3] mm/memory.c: Use folios in __copy_remote_vm_str() Vishal Moola (Oracle)
2025-07-09 19:40 ` [PATCH 2/3] mm/memory.c: Use folios in __access_remote_vm() Vishal Moola (Oracle)
@ 2025-07-09 19:40 ` Vishal Moola (Oracle)
2025-07-11 10:51 ` David Hildenbrand
2 siblings, 1 reply; 7+ messages in thread
From: Vishal Moola (Oracle) @ 2025-07-09 19:40 UTC (permalink / raw)
To: linux-mm
Cc: linux-kernel, Matthew Wilcox (Oracle), David Hildenbrand,
Jordan Rome, Andrew Morton, Vishal Moola (Oracle)
There are no callers of unmap_and_put_page() left. Remove it.
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
---
include/linux/highmem.h | 6 ------
1 file changed, 6 deletions(-)
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index a30526cc53a7..6234f316468c 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -682,10 +682,4 @@ static inline void folio_release_kmap(struct folio *folio, void *addr)
kunmap_local(addr);
folio_put(folio);
}
-
-static inline void unmap_and_put_page(struct page *page, void *addr)
-{
- folio_release_kmap(page_folio(page), addr);
-}
-
#endif /* _LINUX_HIGHMEM_H */
--
2.50.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] mm/memory.c: Use folios in __copy_remote_vm_str()
2025-07-09 19:40 ` [PATCH 1/3] mm/memory.c: Use folios in __copy_remote_vm_str() Vishal Moola (Oracle)
@ 2025-07-11 10:49 ` David Hildenbrand
0 siblings, 0 replies; 7+ messages in thread
From: David Hildenbrand @ 2025-07-11 10:49 UTC (permalink / raw)
To: Vishal Moola (Oracle), linux-mm
Cc: linux-kernel, Matthew Wilcox (Oracle), Jordan Rome, Andrew Morton
On 09.07.25 21:40, Vishal Moola (Oracle) wrote:
> Use kmap_local_folio() instead of kmap_local_page().
> Replaces 2 calls to compound_head() from unmap_and_put_page() with one.
>
> This prepares us for the removal of unmap_and_put_page().
>
> Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
> ---
> mm/memory.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index 1174f3001307..d63f0d5abcc9 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -6815,6 +6815,7 @@ static int __copy_remote_vm_str(struct mm_struct *mm, unsigned long addr,
> while (len) {
> int bytes, offset, retval;
> void *maddr;
> + struct folio *folio;
> struct page *page;
> struct vm_area_struct *vma = NULL;
>
> @@ -6830,17 +6831,18 @@ static int __copy_remote_vm_str(struct mm_struct *mm, unsigned long addr,
> goto out;
> }
>
> + folio = page_folio(page);
> bytes = len;
> offset = addr & (PAGE_SIZE - 1);
> if (bytes > PAGE_SIZE - offset)
> bytes = PAGE_SIZE - offset;
>
> - maddr = kmap_local_page(page);
> + maddr = kmap_local_folio(folio, folio_page_idx(folio, page) * PAGE_SIZE);
It's weird to go page -> folio -> page ... but maybe that's just the way
it's supposed to work here ...
:)
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] mm/memory.c: Use folios in __access_remote_vm()
2025-07-09 19:40 ` [PATCH 2/3] mm/memory.c: Use folios in __access_remote_vm() Vishal Moola (Oracle)
@ 2025-07-11 10:50 ` David Hildenbrand
0 siblings, 0 replies; 7+ messages in thread
From: David Hildenbrand @ 2025-07-11 10:50 UTC (permalink / raw)
To: Vishal Moola (Oracle), linux-mm
Cc: linux-kernel, Matthew Wilcox (Oracle), Jordan Rome, Andrew Morton
On 09.07.25 21:40, Vishal Moola (Oracle) wrote:
> Use kmap_local_folio() instead of kmap_local_page().
> Replaces 2 calls to compound_head() with one.
>
> This prepares us for the removal of unmap_and_put_page().
>
> Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
> ---
> mm/memory.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index d63f0d5abcc9..3dd6c57e6511 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -6691,6 +6691,7 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr,
> while (len) {
> int bytes, offset;
> void *maddr;
> + struct folio *folio;
> struct vm_area_struct *vma = NULL;
> struct page *page = get_user_page_vma_remote(mm, addr,
> gup_flags, &vma);
> @@ -6722,21 +6723,22 @@ static int __access_remote_vm(struct mm_struct *mm, unsigned long addr,
> if (bytes <= 0)
> break;
> } else {
> + folio = page_folio(page);
> bytes = len;
> offset = addr & (PAGE_SIZE-1);
> if (bytes > PAGE_SIZE-offset)
> bytes = PAGE_SIZE-offset;
>
> - maddr = kmap_local_page(page);
> + maddr = kmap_local_folio(folio, folio_page_idx(folio, page) * PAGE_SIZE);
> if (write) {
> copy_to_user_page(vma, page, addr,
> maddr + offset, buf, bytes);
> - set_page_dirty_lock(page);
> + folio_mark_dirty_lock(folio);
> } else {
> copy_from_user_page(vma, page, addr,
> buf, maddr + offset, bytes);
> }
> - unmap_and_put_page(page, maddr);
> + folio_release_kmap(folio, maddr);
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] mm: Remove unmap_and_put_page()
2025-07-09 19:40 ` [PATCH 3/3] mm: Remove unmap_and_put_page() Vishal Moola (Oracle)
@ 2025-07-11 10:51 ` David Hildenbrand
0 siblings, 0 replies; 7+ messages in thread
From: David Hildenbrand @ 2025-07-11 10:51 UTC (permalink / raw)
To: Vishal Moola (Oracle), linux-mm
Cc: linux-kernel, Matthew Wilcox (Oracle), Jordan Rome, Andrew Morton
On 09.07.25 21:40, Vishal Moola (Oracle) wrote:
> There are no callers of unmap_and_put_page() left. Remove it.
>
> Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
> ---
> include/linux/highmem.h | 6 ------
> 1 file changed, 6 deletions(-)
>
> diff --git a/include/linux/highmem.h b/include/linux/highmem.h
> index a30526cc53a7..6234f316468c 100644
> --- a/include/linux/highmem.h
> +++ b/include/linux/highmem.h
> @@ -682,10 +682,4 @@ static inline void folio_release_kmap(struct folio *folio, void *addr)
> kunmap_local(addr);
> folio_put(folio);
> }
> -
> -static inline void unmap_and_put_page(struct page *page, void *addr)
> -{
> - folio_release_kmap(page_folio(page), addr);
> -}
> -
> #endif /* _LINUX_HIGHMEM_H */
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-07-11 10:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-09 19:40 [PATCH 0/3] Remove unmap_and_put_page() Vishal Moola (Oracle)
2025-07-09 19:40 ` [PATCH 1/3] mm/memory.c: Use folios in __copy_remote_vm_str() Vishal Moola (Oracle)
2025-07-11 10:49 ` David Hildenbrand
2025-07-09 19:40 ` [PATCH 2/3] mm/memory.c: Use folios in __access_remote_vm() Vishal Moola (Oracle)
2025-07-11 10:50 ` David Hildenbrand
2025-07-09 19:40 ` [PATCH 3/3] mm: Remove unmap_and_put_page() Vishal Moola (Oracle)
2025-07-11 10:51 ` David Hildenbrand
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).