Skip to content

Commit e664c2c

Browse files
Pintu Kumarakpm00
authored andcommitted
mm/zsmalloc: use memcpy_from/to_page whereever possible
As part of "zsmalloc: replace kmap_atomic with kmap_local_page" [1] we replaced kmap/kunmap_atomic() with kmap_local_page()/kunmap_local(). But later it was found that some of the code could be replaced with already available apis in highmem.h, such as memcpy_from_page()/memcpy_to_page(). Also, update the comments with correct api naming. [1] https://lkml.kernel.org/r/20241001175358.12970-1-quic_pintu@quicinc.com Link: https://lkml.kernel.org/r/20241010175143.27262-1-quic_pintu@quicinc.com Signed-off-by: Pintu Kumar <quic_pintu@quicinc.com> Suggested-by: Matthew Wilcox <willy@infradead.org> Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Joe Perches <joe@perches.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Pintu Agarwal <pintu.ping@gmail.com> Cc: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 91d0ec8 commit e664c2c

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

mm/zsmalloc.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ struct zspage {
263263
struct mapping_area {
264264
local_lock_t lock;
265265
char *vm_buf; /* copy buffer for objects that span pages */
266-
char *vm_addr; /* address of kmap_atomic()'ed pages */
266+
char *vm_addr; /* address of kmap_local_page()'ed pages */
267267
enum zs_mapmode vm_mm; /* mapping mode */
268268
};
269269

@@ -1046,11 +1046,10 @@ static inline void __zs_cpu_down(struct mapping_area *area)
10461046
static void *__zs_map_object(struct mapping_area *area,
10471047
struct page *pages[2], int off, int size)
10481048
{
1049-
int sizes[2];
1050-
void *addr;
1049+
size_t sizes[2];
10511050
char *buf = area->vm_buf;
10521051

1053-
/* disable page faults to match kmap_atomic() return conditions */
1052+
/* disable page faults to match kmap_local_page() return conditions */
10541053
pagefault_disable();
10551054

10561055
/* no read fastpath */
@@ -1061,21 +1060,16 @@ static void *__zs_map_object(struct mapping_area *area,
10611060
sizes[1] = size - sizes[0];
10621061

10631062
/* copy object to per-cpu buffer */
1064-
addr = kmap_local_page(pages[0]);
1065-
memcpy(buf, addr + off, sizes[0]);
1066-
kunmap_local(addr);
1067-
addr = kmap_local_page(pages[1]);
1068-
memcpy(buf + sizes[0], addr, sizes[1]);
1069-
kunmap_local(addr);
1063+
memcpy_from_page(buf, pages[0], off, sizes[0]);
1064+
memcpy_from_page(buf + sizes[0], pages[1], 0, sizes[1]);
10701065
out:
10711066
return area->vm_buf;
10721067
}
10731068

10741069
static void __zs_unmap_object(struct mapping_area *area,
10751070
struct page *pages[2], int off, int size)
10761071
{
1077-
int sizes[2];
1078-
void *addr;
1072+
size_t sizes[2];
10791073
char *buf;
10801074

10811075
/* no write fastpath */
@@ -1091,15 +1085,11 @@ static void __zs_unmap_object(struct mapping_area *area,
10911085
sizes[1] = size - sizes[0];
10921086

10931087
/* copy per-cpu buffer to object */
1094-
addr = kmap_local_page(pages[0]);
1095-
memcpy(addr + off, buf, sizes[0]);
1096-
kunmap_local(addr);
1097-
addr = kmap_local_page(pages[1]);
1098-
memcpy(addr, buf + sizes[0], sizes[1]);
1099-
kunmap_local(addr);
1088+
memcpy_to_page(pages[0], off, buf, sizes[0]);
1089+
memcpy_to_page(pages[1], 0, buf + sizes[0], sizes[1]);
11001090

11011091
out:
1102-
/* enable page faults to match kunmap_atomic() return conditions */
1092+
/* enable page faults to match kunmap_local() return conditions */
11031093
pagefault_enable();
11041094
}
11051095

@@ -1511,10 +1501,10 @@ static void zs_object_copy(struct size_class *class, unsigned long dst,
15111501
d_size -= size;
15121502

15131503
/*
1514-
* Calling kunmap_atomic(d_addr) is necessary. kunmap_atomic()
1515-
* calls must occurs in reverse order of calls to kmap_atomic().
1516-
* So, to call kunmap_atomic(s_addr) we should first call
1517-
* kunmap_atomic(d_addr). For more details see
1504+
* Calling kunmap_local(d_addr) is necessary. kunmap_local()
1505+
* calls must occurs in reverse order of calls to kmap_local_page().
1506+
* So, to call kunmap_local(s_addr) we should first call
1507+
* kunmap_local(d_addr). For more details see
15181508
* Documentation/mm/highmem.rst.
15191509
*/
15201510
if (s_off >= PAGE_SIZE) {

0 commit comments

Comments
 (0)