Skip to content

Commit 85a85e7

Browse files
xp4ns3akpm00
authored andcommitted
Documentation/vm: move "Using kmap-atomic" to highmem.h
The use of kmap_atomic() is new code is being deprecated in favor of kmap_local_page(). For this reason the "Using kmap_atomic" section in highmem.rst is obsolete and unnecessary, but it can still help developers if it were moved to kdocs in highmem.h. Therefore, move the relevant parts of this section from highmem.rst and merge them with the kdocs in highmem.h. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Fabio M. De Francesco <[email protected]> Suggested-by: Ira Weiny <[email protected]> Reviewed-by: Sebastian Andrzej Siewior <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Peter Collingbourne <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Will Deacon <[email protected]> Cc: Jonathan Corbet <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 174270c commit 85a85e7

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

Documentation/vm/highmem.rst

-35
Original file line numberDiff line numberDiff line change
@@ -72,41 +72,6 @@ The kernel contains several ways of creating temporary mappings:
7272
It may be assumed that k[un]map_atomic() won't fail.
7373

7474

75-
Using kmap_atomic
76-
=================
77-
78-
When and where to use kmap_atomic() is straightforward. It is used when code
79-
wants to access the contents of a page that might be allocated from high memory
80-
(see __GFP_HIGHMEM), for example a page in the pagecache. The API has two
81-
functions, and they can be used in a manner similar to the following::
82-
83-
/* Find the page of interest. */
84-
struct page *page = find_get_page(mapping, offset);
85-
86-
/* Gain access to the contents of that page. */
87-
void *vaddr = kmap_atomic(page);
88-
89-
/* Do something to the contents of that page. */
90-
memset(vaddr, 0, PAGE_SIZE);
91-
92-
/* Unmap that page. */
93-
kunmap_atomic(vaddr);
94-
95-
Note that the kunmap_atomic() call takes the result of the kmap_atomic() call
96-
not the argument.
97-
98-
If you need to map two pages because you want to copy from one page to
99-
another you need to keep the kmap_atomic calls strictly nested, like::
100-
101-
vaddr1 = kmap_atomic(page1);
102-
vaddr2 = kmap_atomic(page2);
103-
104-
memcpy(vaddr1, vaddr2, PAGE_SIZE);
105-
106-
kunmap_atomic(vaddr2);
107-
kunmap_atomic(vaddr1);
108-
109-
11075
Cost of Temporary Mappings
11176
==========================
11277

include/linux/highmem.h

+31
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,37 @@ static inline void *kmap_local_folio(struct folio *folio, size_t offset);
145145
* Mappings should always be released by kunmap_atomic().
146146
*
147147
* Do not use in new code. Use kmap_local_page() instead.
148+
*
149+
* It is used in atomic context when code wants to access the contents of a
150+
* page that might be allocated from high memory (see __GFP_HIGHMEM), for
151+
* example a page in the pagecache. The API has two functions, and they
152+
* can be used in a manner similar to the following:
153+
*
154+
* -- Find the page of interest. --
155+
* struct page *page = find_get_page(mapping, offset);
156+
*
157+
* -- Gain access to the contents of that page. --
158+
* void *vaddr = kmap_atomic(page);
159+
*
160+
* -- Do something to the contents of that page. --
161+
* memset(vaddr, 0, PAGE_SIZE);
162+
*
163+
* -- Unmap that page. --
164+
* kunmap_atomic(vaddr);
165+
*
166+
* Note that the kunmap_atomic() call takes the result of the kmap_atomic()
167+
* call, not the argument.
168+
*
169+
* If you need to map two pages because you want to copy from one page to
170+
* another you need to keep the kmap_atomic calls strictly nested, like:
171+
*
172+
* vaddr1 = kmap_atomic(page1);
173+
* vaddr2 = kmap_atomic(page2);
174+
*
175+
* memcpy(vaddr1, vaddr2, PAGE_SIZE);
176+
*
177+
* kunmap_atomic(vaddr2);
178+
* kunmap_atomic(vaddr1);
148179
*/
149180
static inline void *kmap_atomic(struct page *page);
150181

0 commit comments

Comments
 (0)