Introduce vmap_file()
Subsystems (2)
v2 cover Introduce vmap_file()
Currently, users have to call vmap() or vmap_pfn() to map pages to kernel virtual space. vmap_pfn() is for special pages (i.e. pfns without struct page). vmap() handles normal pages.
With large folios, we may want to map ranges that only span part of a folio (i.e. mapping half of a 2Mb folio). vmap_file() will allow us to do so.
Create a function, vmap_file(), to map a specified range of a given file to kernel virtual space. vmap_file() is an in-kernel equivalent to mmap(), and can be useful for filesystems.
---
v2:
- Reword cover letter to provide a clearer overview of the current vmalloc APIs, and usefulness of vmap_file()
- EXPORT_SYMBOL_GPL() instead of EXPORT_SYMBOL()
- Provide support to partially map file folios
- Demote this to RFC while we look for users
--
I don't have a user for this function right now, but it will be useful as users start converting to using large folios. I'm just putting it out here for anyone that may find a use for it.
This seems like the sensible way to implement it, but I'm open to tweaking the functions semantics.
I've Cc-ed a couple people that mentioned they might be interested in using it.
Vishal Moola (Oracle) (1):
mm/vmalloc: Introduce vmap_file()
include/linux/vmalloc.h | 2 + mm/vmalloc.c | 113 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+)
Signature · 1 line
2.48.1
RFC PATCH v2 1/1 mm/vmalloc: Introduce vmap_file()
vmap_file() is effectively an in-kernel equivalent to calling mmap() on a file. A user can pass in a file mapping, and vmap_file() will map the specified portion of that file directly to kernel virtual space.
--- include/linux/vmalloc.h | 2 + mm/vmalloc.c | 113 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+)
include/linux/vmalloc.h +2 -0
@@ -192,6 +192,8 @@ extern void vfree_atomic(const void *addr);extern void *vmap (struct page **pages,unsigned int count,unsigned long flags,pgprot_t prot); +void *vmap_file (struct address_space *mapping,loff_t start,loff_t end, +unsigned long flags,pgprot_t prot);void *vmap_pfn (unsigned long *pfns,unsigned int count,pgprot_t prot);extern void vunmap (const void *addr);
mm/vmalloc.c +113 -0
119 lines not on this page · raw message
Signature · 1 line
2.48.1
HI Vishal,
Quoted 7 lines · Vishal Moola (Oracle)
Currently, users have to call
vmap()orvmap_pfn()to map pages to kernel virtual space.vmap_pfn()is for special pages (i.e. pfns without struct page).vmap()handles normal pages.With large folios, we may want to map ranges that only span part of a folio (i.e. mapping half of a 2Mb folio).
vmap_file()will allow us to do so.
You mention vmap_file can support range folio vmap, but when I look code, I can't figure out
how to use, maybe I missed something? :)
And this API still aim to file vmap, Maybe not suitable for the problem I mentioned in:
https://lore.kernel.org/lkml/[email protected]/
Thanks,
Huan Yang
Quoted 30 lines
Create a function,
vmap_file(), to map a specified range of a given file to kernel virtual space.vmap_file()is an in-kernel equivalent tommap(), and can be useful for filesystems.---
v2:
- Reword cover letter to provide a clearer overview of the current vmalloc APIs, and usefulness ofvmap_file()
-EXPORT_SYMBOL_GPL()instead ofEXPORT_SYMBOL()
- Provide support to partially map file folios
- Demote this to RFC while we look for users
--
I don't have a user for this function right now, but it will be useful as users start converting to using large folios. I'm just putting it out here for anyone that may find a use for it.This seems like the sensible way to implement it, but I'm open to tweaking the functions semantics.
I've Cc-ed a couple people that mentioned they might be interested in using it.
Vishal Moola (Oracle) (1):
mm/vmalloc: Introducevmap_file()include/linux/vmalloc.h | 2 + mm/vmalloc.c | 113 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+)
Quoted 7 lines · Huan Yang
HI Vishal,
Quoted 4 lines · Vishal Moola (Oracle)
Currently, users have to call
vmap()orvmap_pfn()to map pages to kernel virtual space.vmap_pfn()is for special pages (i.e. pfns without struct page).vmap()handles normal pages.
Quoted 7 lines
Quoted 3 lines
With large folios, we may want to map ranges that only span part of a folio (i.e. mapping half of a 2Mb folio).
vmap_file()will allow us to do so.You mention
vmap_filecan support range folio vmap, but when I look code, I can't figure outhow to use, maybe I missed something? :)
I took a look at the udma-buf code. Rather than iterating through the folios using pfns, you can calculate the corresponding file offsets (maybe you already have them?) to map the desired folios.
Quoted 3 lines
And this API still aim to file vmap, Maybe not suitable for the problem I mentioned in:
I'm not sure which problem you're referring to, could you be more specific?
Quoted 32 lines
Thanks,
Huan YangQuoted 29 lines
Create a function,
vmap_file(), to map a specified range of a given file to kernel virtual space.vmap_file()is an in-kernel equivalent tommap(), and can be useful for filesystems.---
v2:
- Reword cover letter to provide a clearer overview of the current vmalloc APIs, and usefulness ofvmap_file()
-EXPORT_SYMBOL_GPL()instead ofEXPORT_SYMBOL()
- Provide support to partially map file folios
- Demote this to RFC while we look for users
--
I don't have a user for this function right now, but it will be useful as users start converting to using large folios. I'm just putting it out here for anyone that may find a use for it.This seems like the sensible way to implement it, but I'm open to tweaking the functions semantics.
I've Cc-ed a couple people that mentioned they might be interested in using it.
Vishal Moola (Oracle) (1):
mm/vmalloc: Introducevmap_file()include/linux/vmalloc.h | 2 + mm/vmalloc.c | 113 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+)
Quoted 11 lines · Vishal Moola (Oracle)
Quoted 10 lines · Huan Yang
HI Vishal,
Quoted 7 lines · Vishal Moola (Oracle)
Currently, users have to call
vmap()orvmap_pfn()to map pages to kernel virtual space.vmap_pfn()is for special pages (i.e. pfns without struct page).vmap()handles normal pages.With large folios, we may want to map ranges that only span part of a folio (i.e. mapping half of a 2Mb folio).
vmap_file()will allow us to do so.
Quoted 6 lines
Quoted 3 lines
You mention
vmap_filecan support range folio vmap, but when I look code, I can't figure outhow to use, maybe I missed something? :)
I took a look at the udma-buf code. Rather than iterating through the folios using pfns, you can calculate the corresponding file offsets (maybe you already have them?) to map the desired folios.
Currently udmabuf folio's not simple based on file(even each memory from memfd). User can provide
random range of memfd to udmabuf to use. For example:
We get a memfd maybe 4M, user split it into [0, 2M), [1M, 2M), [2M, 4M), so you can see 1M-2M range repeat.
This range can gathered by udmabuf_create_list, then udmabuf use it. So, udmabuf record it by folio array+offset array.
I think vmap_file based on address_space's range can't help.
Quoted 6 lines
Quoted 4 lines
And this API still aim to file vmap, Maybe not suitable for the problem I mentioned in:
I'm not sure which problem you're referring to, could you be more specific?
1. udmabuf not same to file vmap usage
2. udmabuf can't use page struct if HVO hugetlb enabled and use.
It still need pfn based vmap or folio's offset based range vmap.(Or, just simple reject HVO folio use vmap) :)
Quoted 33 lines
Quoted 33 lines
Thanks,
Huan YangQuoted 29 lines
Create a function,
vmap_file(), to map a specified range of a given file to kernel virtual space.vmap_file()is an in-kernel equivalent tommap(), and can be useful for filesystems.---
v2:
- Reword cover letter to provide a clearer overview of the current vmalloc APIs, and usefulness ofvmap_file()
-EXPORT_SYMBOL_GPL()instead ofEXPORT_SYMBOL()
- Provide support to partially map file folios
- Demote this to RFC while we look for users
--
I don't have a user for this function right now, but it will be useful as users start converting to using large folios. I'm just putting it out here for anyone that may find a use for it.This seems like the sensible way to implement it, but I'm open to tweaking the functions semantics.
I've Cc-ed a couple people that mentioned they might be interested in using it.
Vishal Moola (Oracle) (1):
mm/vmalloc: Introducevmap_file()include/linux/vmalloc.h | 2 + mm/vmalloc.c | 113 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+)
Quoted 20 lines · Huan Yang
Quoted 11 lines · Vishal Moola (Oracle)
Quoted 10 lines · Huan Yang
HI Vishal,
Quoted 7 lines · Vishal Moola (Oracle)
Currently, users have to call
vmap()orvmap_pfn()to map pages to kernel virtual space.vmap_pfn()is for special pages (i.e. pfns without struct page).vmap()handles normal pages.With large folios, we may want to map ranges that only span part of a folio (i.e. mapping half of a 2Mb folio).
vmap_file()will allow us to do so.Quoted 6 lines
Quoted 3 lines
You mention
vmap_filecan support range folio vmap, but when I look code, I can't figure outhow to use, maybe I missed something? :)
I took a look at the udma-buf code. Rather than iterating through the folios using pfns, you can calculate the corresponding file offsets (maybe you already have them?) to map the desired folios.
Quoted 7 lines
Currently udmabuf folio's not simple based on file(even each memory from memfd). User can provide
random range of memfd to udmabuf to use. For example:
We get a memfd maybe 4M, user split it into [0, 2M), [1M, 2M), [2M, 4M), so you can see 1M-2M range repeat.
This range can gathered by
udmabuf_create_list, then udmabuf use it. So, udmabuf record it by folio array+offset array.
I was thinking you could call vmap_file() on every sub-range and use those addresses. It should work, we'd have to look at making udmabuf api's support it.
Quoted 1 line
I think
vmap_filebased on address_space's range can't help.
I'm not familiar with the memfd/gup code yet, but I'm fairly confident those memfds will have associated ->f_mappings that would suffice. They are file descriptors after all.
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
And this API still aim to file vmap, Maybe not suitable for the problem I mentioned in:
I'm not sure which problem you're referring to, could you be more specific?
1. udmabuf not same to file vmap usage
2. udmabuf can't use page struct if HVO hugetlb enabled and use.
vmap_file() doesn't depend on tail page structs.
Quoted 35 lines
It still need pfn based vmap or folio's offset based range vmap.(Or, just simple reject HVO folio use vmap) :)
Quoted 33 lines
Quoted 33 lines
Thanks,
Huan YangQuoted 29 lines
Create a function,
vmap_file(), to map a specified range of a given file to kernel virtual space.vmap_file()is an in-kernel equivalent tommap(), and can be useful for filesystems.---
v2:
- Reword cover letter to provide a clearer overview of the current vmalloc APIs, and usefulness ofvmap_file()
-EXPORT_SYMBOL_GPL()instead ofEXPORT_SYMBOL()
- Provide support to partially map file folios
- Demote this to RFC while we look for users
--
I don't have a user for this function right now, but it will be useful as users start converting to using large folios. I'm just putting it out here for anyone that may find a use for it.This seems like the sensible way to implement it, but I'm open to tweaking the functions semantics.
I've Cc-ed a couple people that mentioned they might be interested in using it.
Vishal Moola (Oracle) (1):
mm/vmalloc: Introducevmap_file()include/linux/vmalloc.h | 2 + mm/vmalloc.c | 113 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+)
Quoted 21 lines · Vishal Moola (Oracle)
Quoted 20 lines · Huan Yang
Quoted 11 lines · Vishal Moola (Oracle)
Quoted 10 lines · Huan Yang
HI Vishal,
Quoted 7 lines · Vishal Moola (Oracle)
Currently, users have to call
vmap()orvmap_pfn()to map pages to kernel virtual space.vmap_pfn()is for special pages (i.e. pfns without struct page).vmap()handles normal pages.With large folios, we may want to map ranges that only span part of a folio (i.e. mapping half of a 2Mb folio).
vmap_file()will allow us to do so.Quoted 6 lines
Quoted 3 lines
You mention
vmap_filecan support range folio vmap, but when I look code, I can't figure outhow to use, maybe I missed something? :)
I took a look at the udma-buf code. Rather than iterating through the folios using pfns, you can calculate the corresponding file offsets (maybe you already have them?) to map the desired folios.
Currently udmabuf folio's not simple based on file(even each memory from memfd). User can provide
Quoted 8 lines
Quoted 5 lines
random range of memfd to udmabuf to use. For example:
We get a memfd maybe 4M, user split it into [0, 2M), [1M, 2M), [2M, 4M), so you can see 1M-2M range repeat.
This range can gathered by
udmabuf_create_list, then udmabuf use it. So, udmabuf record it by folio array+offset array.I was thinking you could call
vmap_file()on every sub-range and use those addresses. It should work, we'd have to look at making udmabuf api's support it.
Hmmm, how to get contigous virtual address? Or there are a way to merge each split vmap's return address?
IMO, user invoke vmap want to map each scatter memory into contigous virtual address, but as your suggestion,
I think can't to this. :)
Quoted 5 lines
Quoted 2 lines
I think
vmap_filebased on address_space's range can't help.I'm not familiar with the memfd/gup code yet, but I'm fairly confident those memfds will have associated ->f_mappings that would suffice. They are file descriptors after all.
Agree with this.
Quoted 45 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
And this API still aim to file vmap, Maybe not suitable for the problem I mentioned in:
I'm not sure which problem you're referring to, could you be more specific?
1. udmabuf not same to file vmap usage
2. udmabuf can't use page struct if HVO hugetlb enabled and use.
vmap_file()doesn't depend on tail page structs.Quoted 34 lines
It still need pfn based vmap or folio's offset based range vmap.(Or, just simple reject HVO folio use vmap) :)
Quoted 32 lines
Quoted 32 lines
Thanks,
Huan YangQuoted 29 lines
Create a function,
vmap_file(), to map a specified range of a given file to kernel virtual space.vmap_file()is an in-kernel equivalent tommap(), and can be useful for filesystems.---
v2:
- Reword cover letter to provide a clearer overview of the current vmalloc APIs, and usefulness ofvmap_file()
-EXPORT_SYMBOL_GPL()instead ofEXPORT_SYMBOL()
- Provide support to partially map file folios
- Demote this to RFC while we look for users
--
I don't have a user for this function right now, but it will be useful as users start converting to using large folios. I'm just putting it out here for anyone that may find a use for it.This seems like the sensible way to implement it, but I'm open to tweaking the functions semantics.
I've Cc-ed a couple people that mentioned they might be interested in using it.
Vishal Moola (Oracle) (1):
mm/vmalloc: Introducevmap_file()
include/linux/vmalloc.h| 2 +
mm/vmalloc.c| 113 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 115 insertions(+)
Uladzislau Rezki
maintainerQuoted 25 lines · Huan Yang
Quoted 23 lines · Vishal Moola (Oracle)
Quoted 22 lines · Huan Yang
Quoted 11 lines · Vishal Moola (Oracle)
Quoted 10 lines · Huan Yang
HI Vishal,
Quoted 7 lines · Vishal Moola (Oracle)
Currently, users have to call
vmap()orvmap_pfn()to map pages to kernel virtual space.vmap_pfn()is for special pages (i.e. pfns without struct page).vmap()handles normal pages.With large folios, we may want to map ranges that only span part of a folio (i.e. mapping half of a 2Mb folio).
vmap_file()will allow us to do so.Quoted 6 lines
Quoted 3 lines
You mention
vmap_filecan support range folio vmap, but when I look code, I can't figure outhow to use, maybe I missed something? :)
I took a look at the udma-buf code. Rather than iterating through the folios using pfns, you can calculate the corresponding file offsets (maybe you already have them?) to map the desired folios.
Currently udmabuf folio's not simple based on file(even each memory from memfd). User can provide
random range of memfd to udmabuf to use. For example:
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
We get a memfd maybe 4M, user split it into [0, 2M), [1M, 2M), [2M, 4M), so you can see 1M-2M range repeat.
This range can gathered by
udmabuf_create_list, then udmabuf use it. So, udmabuf record it by folio array+offset array.I was thinking you could call
vmap_file()on every sub-range and use those addresses. It should work, we'd have to look at making udmabuf api's support it.Hmmm, how to get contigous virtual address? Or there are a way to merge each split vmap's return address?
The patch in question maps whole file to continues memory as i see, but i can miss something. Partly populate technique requires to get an area and partly populate it.
As i see we have something similar:
<snip>
/**
* vm_area_map_pages - map pages inside given sparse vm_area
* @area: vm_area
* @start: start address inside vm_area
* @end: end address inside vm_area
* @pages: pages to map (always PAGE_SIZE pages)
*/
int vm_area_map_pages(struct vm_struct *area, unsigned long start,
unsigned long end, struct page **pages)
{
...
<snip>
it is used by the BPF.
--
Uladzislau Rezki
Quoted 21 lines · Uladzislau Rezki
Quoted 20 lines · Huan Yang
Quoted 19 lines · Vishal Moola (Oracle)
Quoted 18 lines · Huan Yang
Quoted 17 lines · Vishal Moola (Oracle)
Quoted 7 lines · Huan Yang
HI Vishal,
Quoted 4 lines · Vishal Moola (Oracle)
Currently, users have to call
vmap()orvmap_pfn()to map pages to kernel virtual space.vmap_pfn()is for special pages (i.e. pfns without struct page).vmap()handles normal pages.Quoted 6 lines
Quoted 3 lines
With large folios, we may want to map ranges that only span part of a folio (i.e. mapping half of a 2Mb folio).
vmap_file()will allow us to do so.You mention
vmap_filecan support range folio vmap, but when I look code, I can't figure outhow to use, maybe I missed something? :)
I took a look at the udma-buf code. Rather than iterating through the folios using pfns, you can calculate the corresponding file offsets (maybe you already have them?) to map the desired folios.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Currently udmabuf folio's not simple based on file(even each memory from memfd). User can provide
random range of memfd to udmabuf to use. For example:
We get a memfd maybe 4M, user split it into [0, 2M), [1M, 2M), [2M, 4M), so you can see 1M-2M range repeat.
This range can gathered by
udmabuf_create_list, then udmabuf use it. So, udmabuf record it by folio array+offset array.
Here, :)
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I was thinking you could call
vmap_file()on every sub-range and use those addresses. It should work, we'd have to look at making udmabuf api's support it.Hmmm, how to get contigous virtual address? Or there are a way to merge each split vmap's return address?
The patch in question maps whole file to continues memory as i see, but i can miss something. Partly populate technique requires to get an area
Hmm, maybe you missed ahead talk, I point above. :)
Quoted 22 lines
and partly populate it.
As i see we have something similar:
<snip>
/**
*vm_area_map_pages- map pages inside given sparsevm_area
* @area:vm_area
* @start: start address insidevm_area
* @end: end address insidevm_area
* @pages: pages to map (alwaysPAGE_SIZEpages)
*/
int vm_area_map_pages(structvm_struct*area, unsigned long start,
unsigned long end, struct page **pages)
{
...
<snip>it is used by the BPF.
--
Uladzislau Rezki
Uladzislau Rezki
maintainerQuoted 31 lines · Huan Yang
Quoted 21 lines · Uladzislau Rezki
Quoted 20 lines · Huan Yang
Quoted 19 lines · Vishal Moola (Oracle)
Quoted 18 lines · Huan Yang
Quoted 17 lines · Vishal Moola (Oracle)
Quoted 7 lines · Huan Yang
HI Vishal,
Quoted 4 lines · Vishal Moola (Oracle)
Currently, users have to call
vmap()orvmap_pfn()to map pages to kernel virtual space.vmap_pfn()is for special pages (i.e. pfns without struct page).vmap()handles normal pages.Quoted 6 lines
Quoted 3 lines
With large folios, we may want to map ranges that only span part of a folio (i.e. mapping half of a 2Mb folio).
vmap_file()will allow us to do so.You mention
vmap_filecan support range folio vmap, but when I look code, I can't figure outhow to use, maybe I missed something? :)
I took a look at the udma-buf code. Rather than iterating through the folios using pfns, you can calculate the corresponding file offsets (maybe you already have them?) to map the desired folios.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Currently udmabuf folio's not simple based on file(even each memory from memfd). User can provide
random range of memfd to udmabuf to use. For example:
We get a memfd maybe 4M, user split it into [0, 2M), [1M, 2M), [2M, 4M), so you can see 1M-2M range repeat.
This range can gathered by
udmabuf_create_list, then udmabuf use it. So, udmabuf record it by folio array+offset array.Here, :)
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I was thinking you could call
vmap_file()on every sub-range and use those addresses. It should work, we'd have to look at making udmabuf api's support it.Hmmm, how to get contigous virtual address? Or there are a way to merge each split vmap's return address?
The patch in question maps whole file to continues memory as i see, but i can miss something. Partly populate technique requires to get an area
Hmm, maybe you missed ahead talk, I point above. :)
I pointed to how BPF does it, probably it would just give you both some extra input.
--
Uladzislau Rezki
Quoted 25 lines · Huan Yang
Quoted 23 lines · Vishal Moola (Oracle)
Quoted 22 lines · Huan Yang
Quoted 11 lines · Vishal Moola (Oracle)
Quoted 10 lines · Huan Yang
HI Vishal,
Quoted 7 lines · Vishal Moola (Oracle)
Currently, users have to call
vmap()orvmap_pfn()to map pages to kernel virtual space.vmap_pfn()is for special pages (i.e. pfns without struct page).vmap()handles normal pages.With large folios, we may want to map ranges that only span part of a folio (i.e. mapping half of a 2Mb folio).
vmap_file()will allow us to do so.Quoted 6 lines
Quoted 3 lines
You mention
vmap_filecan support range folio vmap, but when I look code, I can't figure outhow to use, maybe I missed something? :)
I took a look at the udma-buf code. Rather than iterating through the folios using pfns, you can calculate the corresponding file offsets (maybe you already have them?) to map the desired folios.
Currently udmabuf folio's not simple based on file(even each memory from memfd). User can provide
random range of memfd to udmabuf to use. For example:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
We get a memfd maybe 4M, user split it into [0, 2M), [1M, 2M), [2M, 4M), so you can see 1M-2M range repeat.
This range can gathered by
udmabuf_create_list, then udmabuf use it. So, udmabuf record it by folio array+offset array.I was thinking you could call
vmap_file()on every sub-range and use those addresses. It should work, we'd have to look at making udmabuf api's support it.Hmmm, how to get contigous virtual address? Or there are a way to merge each split vmap's return address?
I'm not sure, I'd have to take a look at that. Maybe going into a large folio world that might be a useful expansion on the APIs?
Quoted 3 lines
IMO, user invoke vmap want to map each scatter memory into contigous virtual address, but as your suggestion,
I think can't to this. :)
We could discuss vmap_file() supporting a series of offsets to map portions of a file; I think thats a reasonable ask for the general API.
We could potentially do multiple files as well, but things start getting really complex at that point so I'd like to avoid that.
The Udma code looks to be doing some buggy stuff, so I'd prefer we look at fixing/reworking those before hacking in a 'generic' API just so they can keep doing that.