Skip to content

Commit e4c9eab

Browse files
xp4ns3Jonathan Corbet
authored andcommitted
Documentation/highmem: Add information about kmap_local_folio()
The differences between kmap_local_page() and kmap_local_folio() consist only in the first taking a pointer to a page and the second taking two arguments, a pointer to a folio and the byte offset within the folio which identifies the page. The two API's can be explained at the same time in the "Temporary Virtual Mappings" section of the Highmem's documentation. Add information about kmap_local_folio() in the same subsection that explains kmap_local_page(). Cc: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Mike Rapoport (IBM) <rppt@kernel.org> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Link: https://lore.kernel.org/r/20230708121719.8270-1-fmdefrancesco@gmail.com
1 parent 9e6e2ed commit e4c9eab

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

Documentation/mm/highmem.rst

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ Temporary Virtual Mappings
5151
The kernel contains several ways of creating temporary mappings. The following
5252
list shows them in order of preference of use.
5353

54-
* kmap_local_page(). This function is used to require short term mappings.
55-
It can be invoked from any context (including interrupts) but the mappings
56-
can only be used in the context which acquired them.
57-
58-
This function should always be used, whereas kmap_atomic() and kmap() have
54+
* kmap_local_page(), kmap_local_folio() - These functions are used to create
55+
short term mappings. They can be invoked from any context (including
56+
interrupts) but the mappings can only be used in the context which acquired
57+
them. The only differences between them consist in the first taking a pointer
58+
to a struct page and the second taking a pointer to struct folio and the byte
59+
offset within the folio which identifies the page.
60+
61+
These functions should always be used, whereas kmap_atomic() and kmap() have
5962
been deprecated.
6063

6164
These mappings are thread-local and CPU-local, meaning that the mapping
@@ -72,17 +75,17 @@ list shows them in order of preference of use.
7275
maps of the outgoing task are saved and those of the incoming one are
7376
restored.
7477

75-
kmap_local_page() always returns a valid virtual address and it is assumed
76-
that kunmap_local() will never fail.
78+
kmap_local_page(), as well as kmap_local_folio() always returns valid virtual
79+
kernel addresses and it is assumed that kunmap_local() will never fail.
7780

78-
On CONFIG_HIGHMEM=n kernels and for low memory pages this returns the
81+
On CONFIG_HIGHMEM=n kernels and for low memory pages they return the
7982
virtual address of the direct mapping. Only real highmem pages are
8083
temporarily mapped. Therefore, users may call a plain page_address()
8184
for pages which are known to not come from ZONE_HIGHMEM. However, it is
82-
always safe to use kmap_local_page() / kunmap_local().
85+
always safe to use kmap_local_{page,folio}() / kunmap_local().
8386

84-
While it is significantly faster than kmap(), for the highmem case it
85-
comes with restrictions about the pointers validity. Contrary to kmap()
87+
While they are significantly faster than kmap(), for the highmem case they
88+
come with restrictions about the pointers validity. Contrary to kmap()
8689
mappings, the local mappings are only valid in the context of the caller
8790
and cannot be handed to other contexts. This implies that users must
8891
be absolutely sure to keep the use of the return address local to the
@@ -91,7 +94,7 @@ list shows them in order of preference of use.
9194
Most code can be designed to use thread local mappings. User should
9295
therefore try to design their code to avoid the use of kmap() by mapping
9396
pages in the same thread the address will be used and prefer
94-
kmap_local_page().
97+
kmap_local_page() or kmap_local_folio().
9598

9699
Nesting kmap_local_page() and kmap_atomic() mappings is allowed to a certain
97100
extent (up to KMAP_TYPE_NR) but their invocations have to be strictly ordered

0 commit comments

Comments
 (0)