Extend and reorganize Highmem's documentation
Subsystems (2)
cover Extend and reorganize Highmem's documentation
This series has the purpose to extend and reorganize Highmem's documentation.
This is still a work in progress, because some information should still be moved from highmem.rst to highmem.h and highmem-internal.h. Specifically I'm talking about moving the "how to" information to the relevant headers, as it as been suggested by Ira Weiny (Intel).
This series is composed by four patches gathered from a previous series made of two, plus two more single patches. The subject of this cover has changed and the layout of the changes across the four patches has changed too. For this reason it is very hard to show a valid versions' log. Therefore, I decided to start over and drop versions (Maintainers of the previous patch have been told to drop them).
Fabio M. De Francesco (4):
mm/highmem: Fix kernel-doc warnings in highmem*.h Documentation/vm: Include kdocs from highmem*.h into highmem.rst Documentation/vm: Remove "Using kmap-atomic" from highmem.rst. Documentation/vm: Rework "Temporary Virtual Mappings" section
Documentation/vm/highmem.rst | 101 +++++++++++++++++++------------ include/linux/highmem-internal.h | 14 ++++- include/linux/highmem.h | 15 +---- 3 files changed, 75 insertions(+), 55 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 mm/highmem: Fix kernel-doc warnings in highmem*.h
scripts/kernel-doc -v -none include/linux/highmem* reports the following warnings:
include/linux/highmem.h:160: warning: expecting prototype for kunmap_atomic(). Prototype was for nr_free_highpages() instead include/linux/highmem.h:204: warning: No description found for return value of 'alloc_zeroed_user_highpage_movable' include/linux/highmem-internal.h:256: warning: Function parameter or member '__addr' not described in 'kunmap_atomic' include/linux/highmem-internal.h:256: warning: Excess function parameter 'addr' description in 'kunmap_atomic'
Fix these warnings by (1) moving the kernel-doc comments from highmem.h to highmem-internal.h (which is the file were the kunmap_atomic() macro is actually defined), (2) extending and merging it with the comment which was already in highmem-internal.h, and (3) using correct parameter names.
--- include/linux/highmem-internal.h | 14 +++++++++++--- include/linux/highmem.h | 15 +++------------ 2 files changed, 14 insertions(+), 15 deletions(-)
include/linux/highmem-internal.h +11 -3
@@ -236,9 +236,17 @@ static inline unsigned long totalhigh_pages(void) { return 0UL; }#endif /* CONFIG_HIGHMEM */ -/* -* Prevent people trying to call kunmap_atomic() as if it were kunmap() -* kunmap_atomic() should get the return value of kmap_atomic, not the page. +/** +* kunmap_atomic - Unmap the virtual address mapped by kmap_atomic() +* @__addr: Virtual address to be unmapped +* +* Unmap an address previously mapped by kmap_atomic() and re-enables +* pagefaults and preemption. Mappings should be unmapped in the reverse +* order that they were mapped. See kmap_local_page() for details. +* @__addr can be any address within the mapped page, so there is no need +* to subtract any offset that has been added. In contrast to kunmap(), +* this function takes the address returned from kmap_atomic(), not the +* page passed to it. The compiler will warn you if you pass the page. */ #define kunmap_atomic (__addr) \ do { \
include/linux/highmem.h +3 -12
@@ -37,7 +37,7 @@ static inline void *kmap(struct page *page);/** * kunmap - Unmap the virtual address mapped by kmap() -* @addr: Virtual address to be unmapped +* @page: Virtual address to be unmapped * * Counterpart to kmap(). A NOOP for CONFIG_HIGHMEM=n and for mappings of * pages in the low memory area.
@@ -145,17 +145,6 @@ static inline void *kmap_local_folio(struct folio *folio, size_t offset);*/ static inline void *kmap_atomic (struct page *page); -/** -* kunmap_atomic - Unmap the virtual address mapped by kmap_atomic() -* @addr: Virtual address to be unmapped -* -* Counterpart to kmap_atomic(). -* -* Effectively a wrapper around kunmap_local() which additionally undoes -* the side effects of kmap_atomic(), i.e. reenabling pagefaults and -* preemption. -*/ -/* Highmem related interfaces for management code */ static inline unsigned int nr_free_highpages (void );static inline unsigned long totalhigh_pages (void );
@@ -191,6 +180,8 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr)* @vma: The VMA the page is to be allocated for * @vaddr: The virtual address the page will be inserted into * +* Returns: The allocated and zeroed HIGHMEM page +* * This function will allocate a page for a VMA that the caller knows will * be able to migrate in the future using move_pages() or reclaimed *
Signature · 1 line
2.34.1
PATCH 2/4 Documentation/vm: Include kdocs from highmem*.h into highmem.rst
In reply to Fabio M. De Francescokernel-docs that are in include/linux/highmem.h and in include/linux/highmem-internal.h should be included in highmem.rst.
Use kdocs directives to include the above-mentioned comments into highmem.rst.
--- Documentation/vm/highmem.rst | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/vm/highmem.rst +7 -0
@@ -145,3 +145,10 @@ The general recommendation is that you don't use more than 8GiB on a 32-bit machine - although more might work for you and your workload, you're pretty much on your own - don't expect kernel developers to really care much if things come apart. + + +Functions +========= + +.. kernel-doc:: include/linux/highmem.h +.. kernel-doc:: include/linux/highmem-internal.h
Signature · 1 line
2.34.1
PATCH 3/4 Documentation/vm: Remove "Using kmap-atomic" from highmem.rst.
In reply to Fabio M. De FrancescoThe use of kmap_atomic() is deprecated in favor of kmap_local_page(). For this reason the "Using kmap_atomic" section in highmem.rst is obsolete and unnecessary.
Therefore, just remove it.
--- Documentation/vm/highmem.rst | 35 ----------------------------------- 1 file changed, 35 deletions(-)
Documentation/vm/highmem.rst +0 -35
@@ -72,41 +72,6 @@ The kernel contains several ways of creating temporary mappings: It may be assumed that k[un]map_atomic() won't fail. -Using kmap_atomic -================= - -When and where to use kmap_atomic() is straightforward. It is used when code -wants to access the contents of a page that might be allocated from high memory -(see __GFP_HIGHMEM), for example a page in the pagecache. The API has two -functions, and they can be used in a manner similar to the following:: - - /* Find the page of interest. */ - struct page *page = find_get_page(mapping, offset); - - /* Gain access to the contents of that page. */ - void *vaddr = kmap_atomic(page); - - /* Do something to the contents of that page. */ - memset(vaddr, 0, PAGE_SIZE); - - /* Unmap that page. */ - kunmap_atomic(vaddr); - -Note that the kunmap_atomic() call takes the result of the kmap_atomic() call -not the argument. - -If you need to map two pages because you want to copy from one page to -another you need to keep the kmap_atomic calls strictly nested, like:: - - vaddr1 = kmap_atomic(page1); - vaddr2 = kmap_atomic(page2); - - memcpy(vaddr1, vaddr2, PAGE_SIZE); - - kunmap_atomic(vaddr2); - kunmap_atomic(vaddr1); - - Cost of Temporary Mappings ==========================
Signature · 1 line
2.34.1
PATCH 4/4 Documentation/vm: Rework "Temporary Virtual Mappings"
In reply to Fabio M. De FrancescoExtend and rework the "Temporary Virtual Mappings" section of the highmem.rst documentation.
Despite the local kmaps were introduced by Thomas Gleixner in October 2020, documentation was still missing information about them. These additions rely largely on Gleixner's patches, Jonathan Corbet's LWN articles, comments by Ira Weiny and Matthew Wilcox, and in-code comments from ./include/linux/highmem.h.
1) Add a paragraph to document kmap_local_page().
2) Reorder the list of functions by decreasing order of preference of use.
3) Rework part of the kmap() entry in list.
--- Documentation/vm/highmem.rst | 71 ++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 11 deletions(-)
Documentation/vm/highmem.rst +60 -11
@@ -50,26 +50,75 @@ space when they use mm context tags. Temporary Virtual Mappings ========================== -The kernel contains several ways of creating temporary mappings: +The kernel contains several ways of creating temporary mappings. The following +list shows them in order of preference of use. -* vmap(). This can be used to make a long duration mapping of multiple - physical pages into a contiguous virtual space. It needs global - synchronization to unmap. +* kmap_local_page(). This function is used to require short term mappings. + It can be invoked from any context (including interrupts) but the mappings + can only be used in the context which acquired them. + + This function should be preferred, where feasible, over all the others. -* kmap(). This permits a short duration mapping of a single page. It needs - global synchronization, but is amortized somewhat. It is also prone to - deadlocks when using in a nested fashion, and so it is not recommended for - new code. + These mappings are per thread, CPU local (i.e., migration from one CPU to + another is disabled - this is why they are called "local"), but they don't + disable preemption. It's valid to take pagefaults in a local kmap region, + unless the context in which the local mapping is acquired does not allow + it for other reasons. + + It is assumed that kmap_local_page() always returns the virtual address + of the mapping, therefore they won't ever fail. + + If a task holding local kmaps is preempted, the maps are removed on context + switch and restored when the task comes back on the CPU. As the maps are + strictly CPU local, it is guaranteed that the task stays on the CPU and + that the CPU cannot be unplugged until the local kmaps are released. + + Nesting kmap_local_page() and kmap_atomic() mappings is allowed to a certain + extent (up to KMAP_TYPE_NR) but their invocations have to be strictly ordered + because the map implementation is stack based. * kmap_atomic(). This permits a very short duration mapping of a single page. Since the mapping is restricted to the CPU that issued it, it performs well, but the issuing task is therefore required to stay on that CPU until it has finished, lest some other task displace its mappings. - kmap_atomic() may also be used by interrupt contexts, since it is does not - sleep and the caller may not sleep until after kunmap_atomic() is called. + kmap_atomic() may also be used by interrupt contexts, since it does not + sleep and the callers too may not sleep until after kunmap_atomic() is + called. + + Each call of kmap_atomic() in the kernel creates a non-preemptible section + and disable pagefaults. This could be a source of unwanted latency, so it + should be only used if it is absolutely required, otherwise kmap_local_page() + should be used where it is feasible. - It may be assumed that k[un]map_atomic() won't fail. + It is assumed that k[un]map_atomic() won't fail. + +* kmap(). This should be used to make short duration mapping of a single + page with no restrictions on preemption or migration. It comes with an + overhead as mapping space is restricted and protected by a global lock + for synchronization. When mapping is no more needed, the address that + the page was mapped to must be released with kunmap(). + + Mapping changes must be propagated across all the CPUs. kmap() also + requires global TLB invalidation when the kmap's pool wraps and it might + block when the mapping space is fully utilized until a slot becomes + available. Therefore, kmap() is only callable from preemptible context. + + All the above work is necessary if a mapping must last for a relatively + long time but the bulk of high-memory mappings in the kernel are + short-lived and only used in one place. This means that the cost of + kmap() is mostly wasted in such cases. kmap() was not intended for long + term mappings but it has morphed in that direction and its use is + strongly discouraged in newer code and the set of the preceding functions + should be preferred. + + On 64-bit systems, calls to kmap_local_page(), kmap_atomic() and kmap() have + no real work to do because a 64-bit address space is more than sufficient to + address all the physical memory whose pages are permanently mapped. + +* vmap(). This can be used to make a long duration mapping of multiple + physical pages into a contiguous virtual space. It needs global + synchronization to unmap. Cost of Temporary Mappings
Signature · 1 line
2.34.1
Re: [PATCH 1/4] mm/highmem: Fix kernel-doc warnings in highmem*.h
In reply to Fabio M. De FrancescoQuoted 28 lines · Fabio M. De Francesco
scripts/kernel-doc -v -none include/linux/highmem*reports the following warnings:
include/linux/highmem.h:160: warning: expecting prototype forkunmap_atomic(). Prototype was fornr_free_highpages()insteadinclude/linux/highmem.h:204: warning: No description found for return value of 'alloc_zeroed_user_highpage_movable'include/linux/highmem-internal.h:256: warning: Function parameter or member '__addr' not described in 'kunmap_atomic'include/linux/highmem-internal.h:256: warning: Excess function parameter 'addr' description in 'kunmap_atomic'Fix these warnings by (1) moving the kernel-doc comments from
highmem.htohighmem-internal.h(which is the file were thekunmap_atomic()macro is actually defined), (2) extending and merging it with the comment which was already inhighmem-internal.h, and (3) using correct parameter names.Cc Mike Rapoport <[email protected]>Cc Ira Weiny <[email protected]>Suggested-by Matthew Wilcox <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- include/linux/highmem-internal.h | 14 +++++++++++--- include/linux/highmem.h | 15 +++------------ 2 files changed, 14 insertions(+), 15 deletions(-)include/linux/highmem-internal.h +0
-0@@ -236,9 +236,17 @@ static inline unsigned long totalhigh_pages(void) { return 0UL; }
include/linux/highmem-internal.h static inline unsigned long totalhigh_pages(void) { return 0UL; } · line 243
Quoted 10 lines
include/linux/highmem-internal.h +5
-3#endif /* CONFIG_HIGHMEM */ -/* -* Prevent people trying to call kunmap_atomic() as if it were kunmap() -* kunmap_atomic() should get the return value of kmap_atomic, not the page. +/** +* kunmap_atomic - Unmap the virtual address mapped by kmap_atomic() +* @__addr: Virtual address to be unmapped +* +* Unmap an address previously mapped by kmap_atomic() and re-enables
Unmap ... and re-enable
or
Unmaps ... and re-enables
Other than that
Quoted 53 lines
include/linux/highmem-internal.h +6
-0+* pagefaults and preemption. Mappings should be unmapped in the reverse +* order that they were mapped. See kmap_local_page() for details. +* @__addr can be any address within the mapped page, so there is no need +* to subtract any offset that has been added. In contrast to kunmap(), +* this function takes the address returned from kmap_atomic(), not the +* page passed to it. The compiler will warn you if you pass the page. */ #define kunmap_atomic (__addr) \ do { \include/linux/highmem.h +3
-12@@ -37,7 +37,7 @@ static inline void *kmap(struct page *page);/** * kunmap - Unmap the virtual address mapped by kmap() -* @addr: Virtual address to be unmapped +* @page: Virtual address to be unmapped * * Counterpart to kmap(). A NOOP for CONFIG_HIGHMEM=n and for mappings of * pages in the low memory area. @@ -145,17 +145,6 @@ static inline void *kmap_local_folio(struct folio *folio, size_t offset);*/ static inline void *kmap_atomic (struct page *page); -/** -* kunmap_atomic - Unmap the virtual address mapped by kmap_atomic() -* @addr: Virtual address to be unmapped -* -* Counterpart to kmap_atomic(). -* -* Effectively a wrapper around kunmap_local() which additionally undoes -* the side effects of kmap_atomic(), i.e. reenabling pagefaults and -* preemption. -*/ -/* Highmem related interfaces for management code */ static inline unsigned int nr_free_highpages (void );static inline unsigned long totalhigh_pages (void );@@ -191,6 +180,8 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr)* @vma: The VMA the page is to be allocated for * @vaddr: The virtual address the page will be inserted into * +* Returns: The allocated and zeroed HIGHMEM page +* * This function will allocate a page for a VMA that the caller knows will * be able to migrate in the future using move_pages() or reclaimed * Signature · 1 line
2.34.1
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 2/4] Documentation/vm: Include kdocs from highmem*.h into highmem.rst
In reply to Fabio M. De FrancescoQuoted 6 lines · Fabio M. De Francesco
kernel-docs that are in
include/linux/highmem.hand ininclude/linux/highmem-internal.hshould be included inhighmem.rst.Use kdocs directives to include the above-mentioned comments into
highmem.rst.
Quoted 6 lines
Cc Jonathan Corbet <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ira Weiny <[email protected]>Cc Matthew Wilcox <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>
Quoted 23 lines
--- Documentation/vm/highmem.rst | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/vm/highmem.rst +7
-0@@ -145,3 +145,10 @@ The general recommendation is that you don't use more than 8GiB on a 32-bit machine - although more might work for you and your workload, you're pretty much on your own - don't expect kernel developers to really care much if things come apart. + + +Functions +========= + +.. kernel-doc:: include/linux/highmem.h +.. kernel-doc:: include/linux/highmem-internal.hSignature · 1 line
2.34.1
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 1/4] mm/highmem: Fix kernel-doc warnings in highmem*.h
In reply to Mike RapoportQuoted 2 lines · On venerdì 22 aprile 2022 10:24:14 CEST Mike Rapoport wrote:
Quoted 1 line · Fabio M. De Francesco
scripts/kernel-doc -v -none include/linux/highmem*reports the
following
Quoted 3 lines
Quoted 3 lines
warnings:
include/linux/highmem.h:160: warning: expecting prototype for
kunmap_atomic(). Prototype was for nr_free_highpages() instead
Quoted 1 line
Quoted 1 line
include/linux/highmem.h:204: warning: No description found for return
value of 'alloc_zeroed_user_highpage_movable'
Quoted 1 line
Quoted 1 line
include/linux/highmem-internal.h:256: warning: Function parameter or
member '__addr' not described in 'kunmap_atomic'
Quoted 1 line
Quoted 1 line
include/linux/highmem-internal.h:256: warning: Excess function
parameter 'addr' description in 'kunmap_atomic'
Quoted 2 lines
Quoted 2 lines
Fix these warnings by (1) moving the kernel-doc comments from
highmem.h
to
Quoted 2 lines
Quoted 2 lines
highmem-internal.h(which is the file were thekunmap_atomic()macro is actually defined), (2) extending and merging it with the comment which
was
Quoted 13 lines
Quoted 13 lines
already in
highmem-internal.h, and (3) using correct parameter names.Cc Mike Rapoport <[email protected]>Cc Ira Weiny <[email protected]>Suggested-by Matthew Wilcox <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- include/linux/highmem-internal.h | 14 +++++++++++--- include/linux/highmem.h | 15 +++------------ 2 files changed, 14 insertions(+), 15 deletions(-)[...]
Quoted 8 lines
Quoted 2 lines
+ *
+ * Unmap an address previously mapped bykmap_atomic()and re-enablesUnmap ... and re-enable
or
Unmaps ... and re-enables
Sorry, I should have read it twice before submitting :(
This entire series has already been taken by Andrew Morton for "-mm" immediately after submission. I think that probably the better suited solution is to send a correction when they show upstream.
Do you agree with me or you prefer that I resubmit the whole series as a v2 now?
Quoted 5 lines
Other than that
Acked-by Mike Rapoport <[email protected]>
I also saw your "Acked-by" tag in patch 2/4. Thanks!
Regards,
Fabio
Mike Rapoport
reviewerRe: [PATCH 1/4] mm/highmem: Fix kernel-doc warnings in highmem*.h
Quoted 40 lines · Fabio M. De Francesco
Quoted 2 lines · On venerdì 22 aprile 2022 10:24:14 CEST Mike Rapoport wrote:
Quoted 1 line · Fabio M. De Francesco
scripts/kernel-doc -v -none include/linux/highmem*reports thefollowing
Quoted 3 lines
Quoted 3 lines
warnings:
include/linux/highmem.h:160: warning: expecting prototype for
kunmap_atomic(). Prototype was fornr_free_highpages()insteadQuoted 1 line
Quoted 1 line
include/linux/highmem.h:204: warning: No description found for returnvalue of '
alloc_zeroed_user_highpage_movable'Quoted 1 line
Quoted 1 line
include/linux/highmem-internal.h:256: warning: Function parameter ormember '
__addr' not described in 'kunmap_atomic'Quoted 1 line
Quoted 1 line
include/linux/highmem-internal.h:256: warning: Excess functionparameter 'addr' description in '
kunmap_atomic'Quoted 2 lines
Quoted 2 lines
Fix these warnings by (1) moving the kernel-doc comments from
highmem.hto
Quoted 2 lines
Quoted 2 lines
highmem-internal.h(which is the file were thekunmap_atomic()macro is actually defined), (2) extending and merging it with the comment whichwas
Quoted 20 lines
Quoted 11 lines
already in
highmem-internal.h, and (3) using correct parameter names.Cc Mike Rapoport <[email protected]>Cc Ira Weiny <[email protected]>Suggested-by Matthew Wilcox <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- include/linux/highmem-internal.h | 14 +++++++++++--- include/linux/highmem.h | 15 +++------------ 2 files changed, 14 insertions(+), 15 deletions(-)Quoted 4 lines
[...]
+ *
+ * Unmap an address previously mapped bykmap_atomic()and re-enablesUnmap ... and re-enable
or
Quoted 7 lines
Quoted 1 line
Unmaps ... and re-enables
Sorry, I should have read it twice before submitting :(
This entire series has already been taken by Andrew Morton for "-mm" immediately after submission. I think that probably the better suited solution is to send a correction when they show upstream.
You can send a correction as an incremental patch against mmotm tree that's mirrored here:
https://github.com/hnaz/linux-mm
I believe Andrew will add it to his mmotm queue.
Quoted 16 lines
Do you agree with me or you prefer that I resubmit the whole series as a v2 now?
Quoted 5 lines
Other than that
Acked-by Mike Rapoport <[email protected]>I also saw your "Acked-by" tag in patch 2/4. Thanks!
Regards,
Fabio
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 1/4] mm/highmem: Fix kernel-doc warnings in highmem*.h
In reply to Fabio M. De FrancescoQuoted 52 lines · Fabio M. De Francesco
scripts/kernel-doc -v -none include/linux/highmem*reports the following warnings:
include/linux/highmem.h:160: warning: expecting prototype forkunmap_atomic(). Prototype was fornr_free_highpages()insteadinclude/linux/highmem.h:204: warning: No description found for return value of 'alloc_zeroed_user_highpage_movable'include/linux/highmem-internal.h:256: warning: Function parameter or member '__addr' not described in 'kunmap_atomic'include/linux/highmem-internal.h:256: warning: Excess function parameter 'addr' description in 'kunmap_atomic'Fix these warnings by (1) moving the kernel-doc comments from
highmem.htohighmem-internal.h(which is the file were thekunmap_atomic()macro is actually defined), (2) extending and merging it with the comment which was already inhighmem-internal.h, and (3) using correct parameter names.Cc Mike Rapoport <[email protected]>Cc Ira Weiny <[email protected]>Suggested-by Matthew Wilcox <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- include/linux/highmem-internal.h | 14 +++++++++++--- include/linux/highmem.h | 15 +++------------ 2 files changed, 14 insertions(+), 15 deletions(-)include/linux/highmem-internal.h +11
-3@@ -236,9 +236,17 @@ static inline unsigned long totalhigh_pages(void) { return 0UL; }#endif /* CONFIG_HIGHMEM */ -/* -* Prevent people trying to call kunmap_atomic() as if it were kunmap() -* kunmap_atomic() should get the return value of kmap_atomic, not the page. +/** +* kunmap_atomic - Unmap the virtual address mapped by kmap_atomic() +* @__addr: Virtual address to be unmapped +* +* Unmap an address previously mapped by kmap_atomic() and re-enables +* pagefaults and preemption. Mappings should be unmapped in the reverse +* order that they were mapped. See kmap_local_page() for details. +* @__addr can be any address within the mapped page, so there is no need +* to subtract any offset that has been added. In contrast to kunmap(), +* this function takes the address returned from kmap_atomic(), not the +* page passed to it. The compiler will warn you if you pass the page. */ #define kunmap_atomic (__addr) \ do { \include/linux/highmem.h +0
-0
include/linux/highmem.h static inline void *kmap(struct page *page); · line 40
Quoted 5 lines
include/linux/highmem.h +1
-1@@ -37,7 +37,7 @@ static inline void *kmap(struct page *page);/** * kunmap - Unmap the virtual address mapped by kmap() -* @addr: Virtual address to be unmapped +* @page: Virtual address to be unmapped
^^^^^^^^^^^^^^^ Page
Not only was the name wrong but the description of an address is wrong.
Other than that LGTM:
Quoted 33 lines
include/linux/highmem.h +2
-11* * Counterpart to kmap(). A NOOP for CONFIG_HIGHMEM=n and for mappings of * pages in the low memory area. @@ -145,17 +145,6 @@ static inline void *kmap_local_folio(struct folio *folio, size_t offset);*/ static inline void *kmap_atomic (struct page *page); -/** -* kunmap_atomic - Unmap the virtual address mapped by kmap_atomic() -* @addr: Virtual address to be unmapped -* -* Counterpart to kmap_atomic(). -* -* Effectively a wrapper around kunmap_local() which additionally undoes -* the side effects of kmap_atomic(), i.e. reenabling pagefaults and -* preemption. -*/ -/* Highmem related interfaces for management code */ static inline unsigned int nr_free_highpages (void );static inline unsigned long totalhigh_pages (void );@@ -191,6 +180,8 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr)* @vma: The VMA the page is to be allocated for * @vaddr: The virtual address the page will be inserted into * +* Returns: The allocated and zeroed HIGHMEM page +* * This function will allocate a page for a VMA that the caller knows will * be able to migrate in the future using move_pages() or reclaimed * Signature · 1 line
2.34.1
Re: [PATCH 2/4] Documentation/vm: Include kdocs from highmem*.h into highmem.rst
In reply to Fabio M. De FrancescoQuoted 6 lines · Fabio M. De Francesco
kernel-docs that are in
include/linux/highmem.hand ininclude/linux/highmem-internal.hshould be included inhighmem.rst.Use kdocs directives to include the above-mentioned comments into
highmem.rst.
Quoted 6 lines
Cc Jonathan Corbet <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ira Weiny <[email protected]>Cc Matthew Wilcox <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>
Quoted 22 lines
--- Documentation/vm/highmem.rst | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/vm/highmem.rst +7
-0@@ -145,3 +145,10 @@ The general recommendation is that you don't use more than 8GiB on a 32-bit machine - although more might work for you and your workload, you're pretty much on your own - don't expect kernel developers to really care much if things come apart. + + +Functions +========= + +.. kernel-doc:: include/linux/highmem.h +.. kernel-doc:: include/linux/highmem-internal.hSignature · 1 line
2.34.1
Re: [PATCH 3/4] Documentation/vm: Remove "Using kmap-atomic" from highmem.rst.
In reply to Fabio M. De FrancescoQuoted 1 line · Fabio M. De Francesco
The use of
kmap_atomic()is deprecated in favor ofkmap_local_page().
I'm not sure deprecated is the right word. And I think the fact that this documentation is stale is a better reason for the patch as is.
This series should end up indicating the desire to stop growing kmap() and kmap_atomic() call sites and that their deprecation is on the horizon. I've not read the text in patch 4/4 yet.
Quoted 3 lines
For
this reason the "Usingkmap_atomic" section inhighmem.rstis obsolete and unnecessary.
A lot of the text is obsolete (and redundant) but the example code might be useful.
Why not move the example and relevant bits into the kdoc for kmap_atomic() which is then automatically picked up via patch 2/4.
Ira
Quoted 62 lines
Therefore, just remove it.
Cc Jonathan Corbet <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ira Weiny <[email protected]>Cc Matthew Wilcox <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- Documentation/vm/highmem.rst | 35 ----------------------------------- 1 file changed, 35 deletions(-)Documentation/vm/highmem.rst +0
-35@@ -72,41 +72,6 @@ The kernel contains several ways of creating temporary mappings: It may be assumed that k[un]map_atomic() won't fail. -Using kmap_atomic -================= - -When and where to use kmap_atomic() is straightforward. It is used when code -wants to access the contents of a page that might be allocated from high memory -(see __GFP_HIGHMEM), for example a page in the pagecache. The API has two -functions, and they can be used in a manner similar to the following:: - - /* Find the page of interest. */ - struct page *page = find_get_page(mapping, offset); - - /* Gain access to the contents of that page. */ - void *vaddr = kmap_atomic(page); - - /* Do something to the contents of that page. */ - memset(vaddr, 0, PAGE_SIZE); - - /* Unmap that page. */ - kunmap_atomic(vaddr); - -Note that the kunmap_atomic() call takes the result of the kmap_atomic() call -not the argument. - -If you need to map two pages because you want to copy from one page to -another you need to keep the kmap_atomic calls strictly nested, like:: - - vaddr1 = kmap_atomic(page1); - vaddr2 = kmap_atomic(page2); - - memcpy(vaddr1, vaddr2, PAGE_SIZE); - - kunmap_atomic(vaddr2); - kunmap_atomic(vaddr1); - - Cost of Temporary Mappings ==========================Signature · 1 line
2.34.1
Re: [PATCH 3/4] Documentation/vm: Remove "Using kmap-atomic" from highmem.rst.
Quoted 4 lines · On venerdì 22 aprile 2022 20:38:09 CEST Ira Weiny wrote:
Quoted 1 line · Fabio M. De Francesco
The use of
kmap_atomic()is deprecated in favor ofkmap_local_page().I'm not sure deprecated is the right word.
OK, in v2 I won't use "deprecated". Instead I'll say something about a strong preference to avoid its use. The reason why developers should avoid kmap_atomic() are explained in 4/4 (I've copy-pasted some lines here for your convenience):
+ Each call of kmap_atomic() in the kernel creates a non-preemptible section
+ and disable pagefaults. This could be a source of unwanted latency, so it
+ should be only used if it is absolutely required, otherwise kmap_local_page()
+ should be used where it is feasible.
Quoted 4 lines
And I think the fact that this
documentation is stale is a better reason for the patch as is.This series should end up indicating the desire to stop growing
kmap()
and
Quoted 1 line
kmap_atomic()call sites and that their deprecation is on the horizon.
I've
Quoted 1 line
not read the text in patch 4/4 yet.
I'll wait for your review of 4/4 before sending v2.
Quoted 3 lines
Quoted 3 lines
For
this reason the "Usingkmap_atomic" section inhighmem.rstis obsolete
and
Quoted 3 lines
Quoted 1 line
unnecessary.
A lot of the text is obsolete (and redundant) but the example code might
be
Quoted 3 lines
useful.
Why not move the example and relevant bits into the kdoc for
kmap_atomic()
Quoted 1 line
which is then automatically picked up via patch 2/4.
Yes, I agree with you. I'll take into account your suggestion for v2.
However, as I said above, I'll hold v2 until you have time to review 4/4 for the purpose to not miss any changes that you might require for that patch too.
Furthermore, while working on v2, I think that I'll extend this series with one or two patch more, in order to address other issues I noticed.
Thanks,
Fabio
Re: [PATCH 1/4] mm/highmem: Fix kernel-doc warnings in highmem*.h
In reply to Ira Weiny(I don't know why it looks like my previous reply has not been sent and it also disappeared from drafts. I apologize if for whatever reason you receive this message twice)
Quoted 10 lines · On venerdì 22 aprile 2022 20:08:46 CEST Ira Weiny wrote:
On Thu, Apr 21, 2022 at 08:01:57PM +0200, Fabio M. De Francesco wrote:
[snip]
Quoted 6 lines
include/linux/highmem.h +0
-0@@ -37,7 +37,7 @@ static inline void *kmap(struct page *page);
Quoted 8 lines
include/linux/highmem.h static inline void *kmap(struct page *page); · line 40
Quoted 4 lines
include/linux/highmem.h +1
-1/** * kunmap - Unmap the virtual address mapped by kmap() -* @addr: Virtual address to be unmapped +* @page: Virtual address to be unmapped ^^^^^^^^^^^^^^^ PageNot only was the name wrong but the description of an address is wrong.
Yes, correct. I'll rewrite this line the following way and send a v2 of this series while addressing also what it is required by your review of 3/4 (unless you have better suited suggestions):
- * @addr: Virtual address to be unmapped
+ * @page: Pointer to the page which was mapped by kmap()
Quoted 3 lines
Other than that LGTM:
Reviewed-by Ira Weiny <[email protected]>
Thanks!
Fabio
Re: [PATCH 4/4] Documentation/vm: Rework "Temporary Virtual Mappings"
In reply to Fabio M. De FrancescoQuoted 46 lines · Fabio M. De Francesco
Extend and rework the "Temporary Virtual Mappings" section of the
highmem.rstdocumentation.Despite the local kmaps were introduced by Thomas Gleixner in October 2020, documentation was still missing information about them. These additions rely largely on Gleixner's patches, Jonathan Corbet's LWN articles, comments by Ira Weiny and Matthew Wilcox, and in-code comments from
./include/linux/highmem.h.1) Add a paragraph to document
kmap_local_page().
2) Reorder the list of functions by decreasing order of preference of use.
3) Rework part of thekmap()entry in list.Cc Jonathan Corbet <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ira Weiny <[email protected]>Cc Matthew Wilcox <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- Documentation/vm/highmem.rst | 71 ++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 11 deletions(-)Documentation/vm/highmem.rst +7
-5@@ -50,26 +50,75 @@ space when they use mm context tags. Temporary Virtual Mappings ========================== -The kernel contains several ways of creating temporary mappings: +The kernel contains several ways of creating temporary mappings. The following +list shows them in order of preference of use. -* vmap(). This can be used to make a long duration mapping of multiple - physical pages into a contiguous virtual space. It needs global - synchronization to unmap. +* kmap_local_page(). This function is used to require short term mappings. + It can be invoked from any context (including interrupts) but the mappings + can only be used in the context which acquired them. + + This function should be preferred, where feasible, over all the others. -* kmap(). This permits a short duration mapping of a single page. It needs
Documentation/vm/highmem.rst space when they use mm context tags. · line 68
Quoted 10 lines
Documentation/vm/highmem.rst +7
-3- global synchronization, but is amortized somewhat. It is also prone to - deadlocks when using in a nested fashion, and so it is not recommended for - new code. + These mappings are per thread, CPU local (i.e., migration from one CPU to + another is disabled - this is why they are called "local"), but they don't + disable preemption. It's valid to take pagefaults in a local kmap region, + unless the context in which the local mapping is acquired does not allow + it for other reasons. + + It is assumed that kmap_local_page() always returns the virtual address
kmap_local_page() does return a kernel virtual address. Why 'assume' this?
Do you mean it returns an address in the direct map?
Documentation/vm/highmem.rst space when they use mm context tags. · line 69
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ of the mapping, therefore they won't ever fail.
I don't think that returning a virtual address has anything to do with the assumption they will not fail.
Why do you say this?
Documentation/vm/highmem.rst space when they use mm context tags. · line 78
Quoted 9 lines
Documentation/vm/highmem.rst +9
-0+ + If a task holding local kmaps is preempted, the maps are removed on context + switch and restored when the task comes back on the CPU. As the maps are + strictly CPU local, it is guaranteed that the task stays on the CPU and + that the CPU cannot be unplugged until the local kmaps are released. + + Nesting kmap_local_page() and kmap_atomic() mappings is allowed to a certain + extent (up to KMAP_TYPE_NR) but their invocations have to be strictly ordered + because the map implementation is stack based.
I think I would reference the kmap_local_page() for more details on the ordering because there have been some conversions I've done which were complicated by this.
Quoted 14 lines
Documentation/vm/highmem.rst +6
-2* kmap_atomic(). This permits a very short duration mapping of a single page. Since the mapping is restricted to the CPU that issued it, it performs well, but the issuing task is therefore required to stay on that CPU until it has finished, lest some other task displace its mappings. - kmap_atomic() may also be used by interrupt contexts, since it is does not - sleep and the caller may not sleep until after kunmap_atomic() is called. + kmap_atomic() may also be used by interrupt contexts, since it does not + sleep and the callers too may not sleep until after kunmap_atomic() is + called. + + Each call of kmap_atomic() in the kernel creates a non-preemptible section + and disable pagefaults. This could be a source of unwanted latency, so it
Documentation/vm/highmem.rst space when they use mm context tags. · line 99
Quoted 10 lines
Documentation/vm/highmem.rst +8
-1+ should be only used if it is absolutely required, otherwise kmap_local_page() + should be used where it is feasible. - It may be assumed that k[un]map_atomic() won't fail. + It is assumed that k[un]map_atomic() won't fail. + +* kmap(). This should be used to make short duration mapping of a single + page with no restrictions on preemption or migration. It comes with an + overhead as mapping space is restricted and protected by a global lock + for synchronization. When mapping is no more needed, the address that
^^^^^^^^ no longer
Quoted 4 lines
Documentation/vm/highmem.rst +4
-0+ the page was mapped to must be released with kunmap(). + + Mapping changes must be propagated across all the CPUs. kmap() also + requires global TLB invalidation when the kmap's pool wraps and it might
Documentation/vm/highmem.rst space when they use mm context tags. · line 113
Quoted 10 lines
Documentation/vm/highmem.rst +10
-0+ block when the mapping space is fully utilized until a slot becomes + available. Therefore, kmap() is only callable from preemptible context. + + All the above work is necessary if a mapping must last for a relatively + long time but the bulk of high-memory mappings in the kernel are + short-lived and only used in one place. This means that the cost of + kmap() is mostly wasted in such cases. kmap() was not intended for long + term mappings but it has morphed in that direction and its use is + strongly discouraged in newer code and the set of the preceding functions + should be preferred.
Nice!
Ira
Quoted 14 lines
Documentation/vm/highmem.rst +8
-0+ + On 64-bit systems, calls to kmap_local_page(), kmap_atomic() and kmap() have + no real work to do because a 64-bit address space is more than sufficient to + address all the physical memory whose pages are permanently mapped. + +* vmap(). This can be used to make a long duration mapping of multiple + physical pages into a contiguous virtual space. It needs global + synchronization to unmap. Cost of Temporary MappingsSignature · 1 line
2.34.1
Re: [PATCH 4/4] Documentation/vm: Rework "Temporary Virtual Mappings"
Quoted 2 lines · On lunedì 25 aprile 2022 02:59:48 CEST Ira Weiny wrote:
Quoted 1 line · Fabio M. De Francesco
Extend and rework the "Temporary Virtual Mappings" section of the
highmem.rst
Quoted 3 lines
Quoted 3 lines
documentation.
Despite the local kmaps were introduced by Thomas Gleixner in October
2020,
Quoted 1 line
Quoted 1 line
documentation was still missing information about them. These additions
rely
Quoted 1 line
Quoted 1 line
largely on Gleixner's patches, Jonathan Corbet's LWN articles, comments
by
Quoted 18 lines
Quoted 18 lines
Ira Weiny and Matthew Wilcox, and in-code comments from
./include/linux/highmem.h.1) Add a paragraph to document
kmap_local_page().
2) Reorder the list of functions by decreasing order of preference of use.
3) Rework part of thekmap()entry in list.Cc Jonathan Corbet <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ira Weiny <[email protected]>Cc Matthew Wilcox <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- Documentation/vm/highmem.rst | 71 ++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 11 deletions(-)
Quoted 1 line
Documentation/vm/
Quoted 1 line
Documentation/vm/ renamed from Documentation/vm/highmem.rst +0
-0
highmem.rst
Quoted 9 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 53
Quoted 9 lines
index
e05bf5524174..960f61e7a552100644Documentation/vm/highmem.rst +1
-1@@ -50,26 +50,75 @@ space when they use mm context tags. Temporary Virtual Mappings ========================== -The kernel contains several ways of creating temporary mappings: +The kernel contains several ways of creating temporary mappings. The
following
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +1
-1+list shows them in order of preference of use. -* vmap(). This can be used to make a long duration mapping of
multiple
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +1
-2- physical pages into a contiguous virtual space. It needs global - synchronization to unmap. +* kmap_local_page(). This function is used to require short term
mappings.
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 57
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ It can be invoked from any context (including interrupts) but the
mappings
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ can only be used in the context which acquired them. + + This function should be preferred, where feasible, over all the
others.
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 58
Quoted 2 lines
Documentation/vm/highmem.rst +0
-1-* kmap(). This permits a short duration mapping of a single page. It
needs
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 59
Quoted 1 line
Documentation/vm/highmem.rst +0
-1- global synchronization, but is amortized somewhat. It is also prone
to
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 60
Quoted 1 line
Documentation/vm/highmem.rst +0
-1- deadlocks when using in a nested fashion, and so it is not
recommended for
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 61
Quoted 2 lines
Documentation/vm/highmem.rst +1
-1- new code. + These mappings are per thread, CPU local (i.e., migration from one
CPU to
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 62
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ another is disabled - this is why they are called "local"), but they
don't
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 63
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ disable preemption. It's valid to take pagefaults in a local kmap
region,
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 64
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ unless the context in which the local mapping is acquired does not
allow
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ it for other reasons. + + It is assumed that kmap_local_page() always returns the virtual
address
Quoted 2 lines
kmap_local_page()does return a kernel virtual address. Why 'assume'
this?
Quoted 6 lines
Do you mean it returns an address in the direct map?
Documentation/vm/highmem.rst space when they use mm context tags. · line 69
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ of the mapping, therefore they won't ever fail.I don't think that returning a virtual address has anything to do with
the
Quoted 3 lines
assumption they will not fail.
Why do you say this?
Oh, sorry! I didn't mean to say this. What I wrote is _not_ what I meant. My intention was to say the same that you may read below about k[un]map_atomic().
This sentence should have been:
+ It always returns a valid virtual address. It is assumed that
+ k[un]map_local() won't ever fail.
Is this rewording correct?
It's not my first time I make these kinds of silly mistakes when copy- pasting lines and then rework or merge with other text that was already there. Recently I've made a couple of these kinds of mistakes.
I'd better read twice (maybe thrice) what I write before sending :(
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 70
Quoted 3 lines
Documentation/vm/highmem.rst +2
-0+ + If a task holding local kmaps is preempted, the maps are removed on
context
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 71
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ switch and restored when the task comes back on the CPU. As the maps
are
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 72
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ strictly CPU local, it is guaranteed that the task stays on the CPU
and
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ that the CPU cannot be unplugged until the local kmaps are released. + + Nesting kmap_local_page() and kmap_atomic() mappings is allowed to a
certain
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 76
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ extent (up to KMAP_TYPE_NR) but their invocations have to be
strictly ordered
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 78
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ because the map implementation is stack based.I think I would reference the
kmap_local_page()
I suppose you are talking about the kdocs comments in code. If so, please remember that the kmap_local_page() kdocs have already been included in highmem.rst.
Am I misunderstanding what you write?
Quoted 6 lines
for more details on the
ordering because there have been some conversions I've done which were complicated by this.Quoted 2 lines
Documentation/vm/highmem.rst +0
-0* kmap_atomic(). This permits a very short duration mapping of a
single
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 80
Quoted 2 lines
Documentation/vm/highmem.rst +0
-0page. Since the mapping is restricted to the CPU that issued it, it performs well, but the issuing task is therefore required to stay on
that
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 81
Quoted 1 line
Documentation/vm/highmem.rst +0
-0CPU until it has finished, lest some other task displace its
mappings.
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 66
Quoted 2 lines
Documentation/vm/highmem.rst +0
-1- kmap_atomic() may also be used by interrupt contexts, since it is
does not
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 67
Quoted 1 line
Documentation/vm/highmem.rst +0
-1- sleep and the caller may not sleep until after kunmap_atomic() is
called.
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 82
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ kmap_atomic() may also be used by interrupt contexts, since it does
not
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 83
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ sleep and the callers too may not sleep until after kunmap_atomic()
is
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ called. + + Each call of kmap_atomic() in the kernel creates a non-preemptible
section
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 87
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ and disable pagefaults. This could be a source of unwanted latency,
so it
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 88
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ should be only used if it is absolutely required, otherwise
kmap_local_page()
Quoted 6 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 6 lines
Documentation/vm/highmem.rst +4
-1+ should be used where it is feasible. - It may be assumed that k[un]map_atomic() won't fail. + It is assumed that k[un]map_atomic() won't fail. + +* kmap(). This should be used to make short duration mapping of a
single
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 94
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ page with no restrictions on preemption or migration. It comes with
an
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 95
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ overhead as mapping space is restricted and protected by a global
lock
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 96
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ for synchronization. When mapping is no more needed, the address
that
Quoted 2 lines
^^^^^^^^ no longer
Yes, correct. I'll fix it.
Quoted 4 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 4 lines
Documentation/vm/highmem.rst +4
-0+ the page was mapped to must be released with kunmap(). + + Mapping changes must be propagated across all the CPUs. kmap() also + requires global TLB invalidation when the kmap's pool wraps and it
might
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 102
Quoted 2 lines
Documentation/vm/highmem.rst +2
-0+ block when the mapping space is fully utilized until a slot becomes + available. Therefore, kmap() is only callable from preemptible
context.
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 104
Quoted 2 lines
Documentation/vm/highmem.rst +2
-0+ + All the above work is necessary if a mapping must last for a
relatively
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ long time but the bulk of high-memory mappings in the kernel are + short-lived and only used in one place. This means that the cost of + kmap() is mostly wasted in such cases. kmap() was not intended for
long
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 109
Quoted 2 lines
Documentation/vm/highmem.rst +2
-0+ term mappings but it has morphed in that direction and its use is + strongly discouraged in newer code and the set of the preceding
functions
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 113
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ should be preferred.Nice!
Now that I have your reviews for all the four patches of this series I'll send next version on Monday.
Thanks you so much,
Fabio
Quoted 5 lines
Ira
Quoted 2 lines
Documentation/vm/highmem.rst +2
-0+ + On 64-bit systems, calls to kmap_local_page(), kmap_atomic() and
kmap() have
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 113
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ no real work to do because a 64-bit address space is more than
sufficient to
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ address all the physical memory whose pages are permanently mapped. + +* vmap(). This can be used to make a long duration mapping of
multiple
Quoted 9 lines
Quoted 8 lines
Documentation/vm/highmem.rst +2
-0+ physical pages into a contiguous virtual space. It needs global + synchronization to unmap. Cost of Temporary MappingsSignature · 1 line
2.34.1
Re: [PATCH 4/4] Documentation/vm: Rework "Temporary Virtual Mappings"
Quoted 6 lines · On lunedì 25 aprile 2022 03:42:46 CEST Fabio M. De Francesco wrote:
On lunedì 25 aprile 2022 02:59:48 CEST Ira Weiny wrote:
[...]
Quoted 1 line
Why do you say this?
Quoted 8 lines
Oh, sorry! I didn't mean to say this. What I wrote is _not_ what I meant. My intention was to say the same that you may read below about k[un]map_atomic().
This sentence should have been:
+ It always returns a valid virtual address. It is assumed that
+ k[un]map_local() won't ever fail.
These two sentences should be better rephrased as the following text...
+ kmap_local_page() always returns a valid virtual address. It is assumed
+ that kunmap_local() won't fail.
Thanks,
Fabio
Re: [PATCH 4/4] Documentation/vm: Rework "Temporary Virtual Mappings"
In reply to Fabio M. De FrancescoQuoted 99 lines · Fabio M. De Francesco
Quoted 2 lines · On lunedì 25 aprile 2022 02:59:48 CEST Ira Weiny wrote:
Quoted 1 line · Fabio M. De Francesco
Extend and rework the "Temporary Virtual Mappings" section of the
highmem.rstQuoted 3 lines
Quoted 3 lines
documentation.
Despite the local kmaps were introduced by Thomas Gleixner in October
2020,
Quoted 1 line
Quoted 1 line
documentation was still missing information about them. These additions
rely
Quoted 1 line
Quoted 1 line
largely on Gleixner's patches, Jonathan Corbet's LWN articles, comments
by
Quoted 18 lines
Quoted 18 lines
Ira Weiny and Matthew Wilcox, and in-code comments from
./include/linux/highmem.h.1) Add a paragraph to document
kmap_local_page().
2) Reorder the list of functions by decreasing order of preference of use.
3) Rework part of thekmap()entry in list.Cc Jonathan Corbet <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ira Weiny <[email protected]>Cc Matthew Wilcox <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- Documentation/vm/highmem.rst | 71 ++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 11 deletions(-)Quoted 1 line
Documentation/vm/
Quoted 1 line
Documentation/vm/ renamed from Documentation/vm/highmem.rst +0
-0
highmem.rstQuoted 9 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 53
Quoted 9 lines
index
e05bf5524174..960f61e7a552100644Documentation/vm/highmem.rst +1
-1@@ -50,26 +50,75 @@ space when they use mm context tags. Temporary Virtual Mappings ========================== -The kernel contains several ways of creating temporary mappings: +The kernel contains several ways of creating temporary mappings. Thefollowing
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +1
-1+list shows them in order of preference of use. -* vmap(). This can be used to make a long duration mapping ofmultiple
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +1
-2- physical pages into a contiguous virtual space. It needs global - synchronization to unmap. +* kmap_local_page(). This function is used to require short termmappings.
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 57
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ It can be invoked from any context (including interrupts) but themappings
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ can only be used in the context which acquired them. + + This function should be preferred, where feasible, over all theothers.
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 58
Quoted 2 lines
Documentation/vm/highmem.rst +0
-1-* kmap(). This permits a short duration mapping of a single page. Itneeds
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 59
Quoted 1 line
Documentation/vm/highmem.rst +0
-1- global synchronization, but is amortized somewhat. It is also proneto
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 60
Quoted 1 line
Documentation/vm/highmem.rst +0
-1- deadlocks when using in a nested fashion, and so it is notrecommended for
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 61
Quoted 2 lines
Documentation/vm/highmem.rst +1
-1- new code. + These mappings are per thread, CPU local (i.e., migration from oneCPU to
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 62
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ another is disabled - this is why they are called "local"), but theydon't
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 63
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ disable preemption. It's valid to take pagefaults in a local kmapregion,
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 64
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ unless the context in which the local mapping is acquired does notallow
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ it for other reasons. + + It is assumed that kmap_local_page() always returns the virtualaddress
Quoted 2 lines
kmap_local_page()does return a kernel virtual address. Why 'assume'this?
Quoted 6 lines
Do you mean it returns an address in the direct map?
Documentation/vm/highmem.rst space when they use mm context tags. · line 69
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ of the mapping, therefore they won't ever fail.I don't think that returning a virtual address has anything to do with
the
Quoted 3 lines
assumption they will not fail.
Why do you say this?
Oh, sorry! I didn't mean to say this. What I wrote is _not_ what I meant. My intention was to say the same that you may read below about k[un]map_atomic().
This sentence should have been:
+ It always returns a valid virtual address. It is assumed that
+ k[un]map_local() won't ever fail.
Quoted 7 lines
Is this rewording correct?
It's not my first time I make these kinds of silly mistakes when copy- pasting lines and then rework or merge with other text that was already there. Recently I've made a couple of these kinds of mistakes.
I'd better read twice (maybe thrice) what I write before sending :(
NP That is part of the reason we have reviews.
Quoted 14 lines
Quoted 4 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 70
Quoted 4 lines
Documentation/vm/highmem.rst +2
-0+ + If a task holding local kmaps is preempted, the maps are removed oncontext
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 71
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ switch and restored when the task comes back on the CPU. As the mapsare
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 72
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ strictly CPU local, it is guaranteed that the task stays on the CPUand
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ that the CPU cannot be unplugged until the local kmaps are released. + + Nesting kmap_local_page() and kmap_atomic() mappings is allowed to acertain
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 76
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ extent (up to KMAP_TYPE_NR) but their invocations have to be
Quoted 8 lines
strictly ordered
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 78
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ because the map implementation is stack based.I think I would reference the
kmap_local_page()I suppose you are talking about the kdocs comments in code. If so, please remember that the
kmap_local_page()kdocs have already been included inhighmem.rst.
Yes exactly.
Quoted 2 lines
Am I misunderstanding what you write?
I was just suggesting that the above could add.
'See kmal_local_page() kdoc for ordering details.'
To make sure that people understand those details and you don't have to rewrite the kdoc stuff here.
Quoted 66 lines
Quoted 7 lines
for more details on the
ordering because there have been some conversions I've done which were complicated by this.Quoted 2 lines
Documentation/vm/highmem.rst +0
-0* kmap_atomic(). This permits a very short duration mapping of asingle
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 80
Quoted 2 lines
Documentation/vm/highmem.rst +0
-0page. Since the mapping is restricted to the CPU that issued it, it performs well, but the issuing task is therefore required to stay onthat
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 81
Quoted 1 line
Documentation/vm/highmem.rst +0
-0CPU until it has finished, lest some other task displace itsmappings.
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 66
Quoted 2 lines
Documentation/vm/highmem.rst +0
-1- kmap_atomic() may also be used by interrupt contexts, since it isdoes not
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 67
Quoted 1 line
Documentation/vm/highmem.rst +0
-1- sleep and the caller may not sleep until after kunmap_atomic() iscalled.
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 82
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ kmap_atomic() may also be used by interrupt contexts, since it doesnot
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 83
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ sleep and the callers too may not sleep until after kunmap_atomic()is
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ called. + + Each call of kmap_atomic() in the kernel creates a non-preemptiblesection
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 87
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ and disable pagefaults. This could be a source of unwanted latency,so it
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 88
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ should be only used if it is absolutely required, otherwise
kmap_local_page()Quoted 6 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 6 lines
Documentation/vm/highmem.rst +4
-1+ should be used where it is feasible. - It may be assumed that k[un]map_atomic() won't fail. + It is assumed that k[un]map_atomic() won't fail. + +* kmap(). This should be used to make short duration mapping of asingle
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 94
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ page with no restrictions on preemption or migration. It comes withan
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 95
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ overhead as mapping space is restricted and protected by a globallock
Quoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 96
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ for synchronization. When mapping is no more needed, the addressthat
Quoted 2 lines
^^^^^^^^ no longerYes, correct. I'll fix it.
Quoted 4 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 4 lines
Documentation/vm/highmem.rst +4
-0+ the page was mapped to must be released with kunmap(). + + Mapping changes must be propagated across all the CPUs. kmap() also + requires global TLB invalidation when the kmap's pool wraps and itmight
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 102
Quoted 2 lines
Documentation/vm/highmem.rst +2
-0+ block when the mapping space is fully utilized until a slot becomes + available. Therefore, kmap() is only callable from preemptiblecontext.
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 104
Quoted 2 lines
Documentation/vm/highmem.rst +2
-0+ + All the above work is necessary if a mapping must last for arelatively
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ long time but the bulk of high-memory mappings in the kernel are + short-lived and only used in one place. This means that the cost of + kmap() is mostly wasted in such cases. kmap() was not intended forlong
Quoted 2 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 109
Quoted 2 lines
Documentation/vm/highmem.rst +2
-0+ term mappings but it has morphed in that direction and its use is + strongly discouraged in newer code and the set of the precedingfunctions
Quoted 8 lines
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags. · line 113
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ should be preferred.Nice!
Now that I have your reviews for all the four patches of this series I'll send next version on Monday.
Thanks you so much,
Thank you!
Ira
Quoted 28 lines
Fabio
Quoted 5 lines
Ira
Quoted 2 lines
Documentation/vm/highmem.rst +2
-0+ + On 64-bit systems, calls to kmap_local_page(), kmap_atomic() and
kmap()haveQuoted 1 line
Documentation/vm/highmem.rst space when they use mm context tags. · line 113
Quoted 1 line
Documentation/vm/highmem.rst +1
-0+ no real work to do because a 64-bit address space is more thansufficient to
Quoted 3 lines
Documentation/vm/highmem.rst space when they use mm context tags.
Quoted 3 lines
Documentation/vm/highmem.rst +3
-0+ address all the physical memory whose pages are permanently mapped. + +* vmap(). This can be used to make a long duration mapping ofmultiple
Quoted 9 lines
Quoted 8 lines
Documentation/vm/highmem.rst +2
-0+ physical pages into a contiguous virtual space. It needs global + synchronization to unmap. Cost of Temporary MappingsSignature · 1 line
2.34.1