btrfs: replace kmap() with kmap_local_page() in lzo.c
The use of kmap() is being deprecated in favor of kmap_local_page() where it is feasible. With kmap_local_page(), the mapping is per thread, CPU local and not globally visible. Therefore, use kmap_local_page() / kunmap_local() in lzo.c wherever the mappings are per thread and not globally visible. Tested on QEMU + KVM 32 bits VM with 4GB of RAM and HIGHMEM64G enabled. Suggested-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
70826b6bd5
commit
51c0674a56
@ -155,7 +155,7 @@ static int copy_compressed_data_to_page(char *compressed_data,
|
|||||||
out_pages[*cur_out / PAGE_SIZE] = cur_page;
|
out_pages[*cur_out / PAGE_SIZE] = cur_page;
|
||||||
}
|
}
|
||||||
|
|
||||||
kaddr = kmap(cur_page);
|
kaddr = kmap_local_page(cur_page);
|
||||||
write_compress_length(kaddr + offset_in_page(*cur_out),
|
write_compress_length(kaddr + offset_in_page(*cur_out),
|
||||||
compressed_size);
|
compressed_size);
|
||||||
*cur_out += LZO_LEN;
|
*cur_out += LZO_LEN;
|
||||||
@ -167,7 +167,7 @@ static int copy_compressed_data_to_page(char *compressed_data,
|
|||||||
u32 copy_len = min_t(u32, sectorsize - *cur_out % sectorsize,
|
u32 copy_len = min_t(u32, sectorsize - *cur_out % sectorsize,
|
||||||
orig_out + compressed_size - *cur_out);
|
orig_out + compressed_size - *cur_out);
|
||||||
|
|
||||||
kunmap(cur_page);
|
kunmap_local(kaddr);
|
||||||
|
|
||||||
if ((*cur_out / PAGE_SIZE) >= max_nr_page)
|
if ((*cur_out / PAGE_SIZE) >= max_nr_page)
|
||||||
return -E2BIG;
|
return -E2BIG;
|
||||||
@ -180,7 +180,7 @@ static int copy_compressed_data_to_page(char *compressed_data,
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
out_pages[*cur_out / PAGE_SIZE] = cur_page;
|
out_pages[*cur_out / PAGE_SIZE] = cur_page;
|
||||||
}
|
}
|
||||||
kaddr = kmap(cur_page);
|
kaddr = kmap_local_page(cur_page);
|
||||||
|
|
||||||
memcpy(kaddr + offset_in_page(*cur_out),
|
memcpy(kaddr + offset_in_page(*cur_out),
|
||||||
compressed_data + *cur_out - orig_out, copy_len);
|
compressed_data + *cur_out - orig_out, copy_len);
|
||||||
@ -202,7 +202,7 @@ static int copy_compressed_data_to_page(char *compressed_data,
|
|||||||
*cur_out += sector_bytes_left;
|
*cur_out += sector_bytes_left;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
kunmap(cur_page);
|
kunmap_local(kaddr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,12 +248,12 @@ int lzo_compress_pages(struct list_head *ws, struct address_space *mapping,
|
|||||||
/* Compress at most one sector of data each time */
|
/* Compress at most one sector of data each time */
|
||||||
in_len = min_t(u32, start + len - cur_in, sectorsize - sector_off);
|
in_len = min_t(u32, start + len - cur_in, sectorsize - sector_off);
|
||||||
ASSERT(in_len);
|
ASSERT(in_len);
|
||||||
data_in = kmap(page_in);
|
data_in = kmap_local_page(page_in);
|
||||||
ret = lzo1x_1_compress(data_in +
|
ret = lzo1x_1_compress(data_in +
|
||||||
offset_in_page(cur_in), in_len,
|
offset_in_page(cur_in), in_len,
|
||||||
workspace->cbuf, &out_len,
|
workspace->cbuf, &out_len,
|
||||||
workspace->mem);
|
workspace->mem);
|
||||||
kunmap(page_in);
|
kunmap_local(data_in);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
pr_debug("BTRFS: lzo in loop returned %d\n", ret);
|
pr_debug("BTRFS: lzo in loop returned %d\n", ret);
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
@ -310,7 +310,6 @@ static void copy_compressed_segment(struct compressed_bio *cb,
|
|||||||
u32 orig_in = *cur_in;
|
u32 orig_in = *cur_in;
|
||||||
|
|
||||||
while (*cur_in < orig_in + len) {
|
while (*cur_in < orig_in + len) {
|
||||||
char *kaddr;
|
|
||||||
struct page *cur_page;
|
struct page *cur_page;
|
||||||
u32 copy_len = min_t(u32, PAGE_SIZE - offset_in_page(*cur_in),
|
u32 copy_len = min_t(u32, PAGE_SIZE - offset_in_page(*cur_in),
|
||||||
orig_in + len - *cur_in);
|
orig_in + len - *cur_in);
|
||||||
@ -318,11 +317,8 @@ static void copy_compressed_segment(struct compressed_bio *cb,
|
|||||||
ASSERT(copy_len);
|
ASSERT(copy_len);
|
||||||
cur_page = cb->compressed_pages[*cur_in / PAGE_SIZE];
|
cur_page = cb->compressed_pages[*cur_in / PAGE_SIZE];
|
||||||
|
|
||||||
kaddr = kmap(cur_page);
|
memcpy_from_page(dest + *cur_in - orig_in, cur_page,
|
||||||
memcpy(dest + *cur_in - orig_in,
|
offset_in_page(*cur_in), copy_len);
|
||||||
kaddr + offset_in_page(*cur_in),
|
|
||||||
copy_len);
|
|
||||||
kunmap(cur_page);
|
|
||||||
|
|
||||||
*cur_in += copy_len;
|
*cur_in += copy_len;
|
||||||
}
|
}
|
||||||
@ -342,9 +338,9 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
|
|||||||
/* Bytes decompressed so far */
|
/* Bytes decompressed so far */
|
||||||
u32 cur_out = 0;
|
u32 cur_out = 0;
|
||||||
|
|
||||||
kaddr = kmap(cb->compressed_pages[0]);
|
kaddr = kmap_local_page(cb->compressed_pages[0]);
|
||||||
len_in = read_compress_length(kaddr);
|
len_in = read_compress_length(kaddr);
|
||||||
kunmap(cb->compressed_pages[0]);
|
kunmap_local(kaddr);
|
||||||
cur_in += LZO_LEN;
|
cur_in += LZO_LEN;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -378,9 +374,9 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
|
|||||||
(cur_in + LZO_LEN - 1) / sectorsize);
|
(cur_in + LZO_LEN - 1) / sectorsize);
|
||||||
cur_page = cb->compressed_pages[cur_in / PAGE_SIZE];
|
cur_page = cb->compressed_pages[cur_in / PAGE_SIZE];
|
||||||
ASSERT(cur_page);
|
ASSERT(cur_page);
|
||||||
kaddr = kmap(cur_page);
|
kaddr = kmap_local_page(cur_page);
|
||||||
seg_len = read_compress_length(kaddr + offset_in_page(cur_in));
|
seg_len = read_compress_length(kaddr + offset_in_page(cur_in));
|
||||||
kunmap(cur_page);
|
kunmap_local(kaddr);
|
||||||
cur_in += LZO_LEN;
|
cur_in += LZO_LEN;
|
||||||
|
|
||||||
if (seg_len > WORKSPACE_CBUF_LENGTH) {
|
if (seg_len > WORKSPACE_CBUF_LENGTH) {
|
||||||
|
Loading…
Reference in New Issue
Block a user