Skip to content

Commit cfbc246

Browse files
committed
Btrfs: walk compressed pages based on the nr_pages count instead of bytes
The byte walk counting was awkward and error prone. This uses the number of pages sent the higher layer to build bios. Signed-off-by: Chris Mason <[email protected]>
1 parent 87ef2bb commit cfbc246

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

fs/btrfs/compression.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start,
296296

297297
/* create and submit bios for the compressed pages */
298298
bytes_left = compressed_len;
299-
while(bytes_left > 0) {
299+
for (page_index = 0; page_index < cb->nr_pages; page_index++) {
300300
page = compressed_pages[page_index];
301301
page->mapping = inode->i_mapping;
302302
if (bio->bi_size)
@@ -324,7 +324,10 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start,
324324
bio->bi_end_io = end_compressed_bio_write;
325325
bio_add_page(bio, page, PAGE_CACHE_SIZE, 0);
326326
}
327-
page_index++;
327+
if (bytes_left < PAGE_CACHE_SIZE) {
328+
printk("bytes left %lu compress len %lu nr %lu\n",
329+
bytes_left, cb->compressed_len, cb->nr_pages);
330+
}
328331
bytes_left -= PAGE_CACHE_SIZE;
329332
first_byte += PAGE_CACHE_SIZE;
330333
}

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static int cow_file_range(struct inode *inode, struct page *locked_page,
338338
if (!btrfs_test_flag(inode, NOCOMPRESS) &&
339339
btrfs_test_opt(root, COMPRESS)) {
340340
WARN_ON(pages);
341-
pages = kmalloc(sizeof(struct page *) * nr_pages, GFP_NOFS);
341+
pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS);
342342

343343
/* we want to make sure the amount of IO required to satisfy
344344
* a random read is reasonably small, so we limit the size

0 commit comments

Comments
 (0)