Skip to content

Commit 4d3a800

Browse files
committed
btrfs: merge nr_pages input and output parameter in compress_pages
The parameter saying how many pages can be allocated at maximum can be merged with the output page counter, to save some stack space. The compression implementation will sink the parameter to a local variable so everything works as before. The nr_pages variables can also be simply merged in compress_file_range into one. Signed-off-by: David Sterba <[email protected]>
1 parent 38c3146 commit 4d3a800

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

fs/btrfs/compression.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,8 @@ static void free_workspaces(void)
914914
* Given an address space and start and length, compress the bytes into @pages
915915
* that are allocated on demand.
916916
*
917-
* @out_pages is used to return the number of pages allocated. There
918-
* may be pages allocated even if we return an error.
917+
* @out_pages is an in/out parameter, holds maximum number of pages to allocate
918+
* and returns number of actually allocated pages
919919
*
920920
* @total_in is used to return the number of bytes actually read. It
921921
* may be smaller than the input length if we had to exit early because we
@@ -930,7 +930,6 @@ static void free_workspaces(void)
930930
*/
931931
int btrfs_compress_pages(int type, struct address_space *mapping,
932932
u64 start, struct page **pages,
933-
unsigned long nr_dest_pages,
934933
unsigned long *out_pages,
935934
unsigned long *total_in,
936935
unsigned long *total_out,
@@ -943,7 +942,7 @@ int btrfs_compress_pages(int type, struct address_space *mapping,
943942

944943
ret = btrfs_compress_op[type-1]->compress_pages(workspace, mapping,
945944
start, pages,
946-
nr_dest_pages, out_pages,
945+
out_pages,
947946
total_in, total_out,
948947
max_out);
949948
free_workspace(type, workspace);

fs/btrfs/compression.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ void btrfs_exit_compress(void);
2424

2525
int btrfs_compress_pages(int type, struct address_space *mapping,
2626
u64 start, struct page **pages,
27-
unsigned long nr_dest_pages,
2827
unsigned long *out_pages,
2928
unsigned long *total_in,
3029
unsigned long *total_out,
@@ -60,7 +59,6 @@ struct btrfs_compress_op {
6059
struct address_space *mapping,
6160
u64 start,
6261
struct page **pages,
63-
unsigned long nr_dest_pages,
6462
unsigned long *out_pages,
6563
unsigned long *total_in,
6664
unsigned long *total_out,

fs/btrfs/inode.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ static noinline void compress_file_range(struct inode *inode,
430430
int ret = 0;
431431
struct page **pages = NULL;
432432
unsigned long nr_pages;
433-
unsigned long nr_pages_ret = 0;
434433
unsigned long total_compressed = 0;
435434
unsigned long total_in = 0;
436435
unsigned long max_compressed = SZ_128K;
@@ -518,15 +517,15 @@ static noinline void compress_file_range(struct inode *inode,
518517
ret = btrfs_compress_pages(compress_type,
519518
inode->i_mapping, start,
520519
pages,
521-
nr_pages, &nr_pages_ret,
520+
&nr_pages,
522521
&total_in,
523522
&total_compressed,
524523
max_compressed);
525524

526525
if (!ret) {
527526
unsigned long offset = total_compressed &
528527
(PAGE_SIZE - 1);
529-
struct page *page = pages[nr_pages_ret - 1];
528+
struct page *page = pages[nr_pages - 1];
530529
char *kaddr;
531530

532531
/* zero the tail end of the last page, we might be
@@ -607,7 +606,7 @@ static noinline void compress_file_range(struct inode *inode,
607606
* will submit them to the elevator.
608607
*/
609608
add_async_extent(async_cow, start, num_bytes,
610-
total_compressed, pages, nr_pages_ret,
609+
total_compressed, pages, nr_pages,
611610
compress_type);
612611

613612
if (start + num_bytes < end) {
@@ -624,14 +623,14 @@ static noinline void compress_file_range(struct inode *inode,
624623
* the compression code ran but failed to make things smaller,
625624
* free any pages it allocated and our page pointer array
626625
*/
627-
for (i = 0; i < nr_pages_ret; i++) {
626+
for (i = 0; i < nr_pages; i++) {
628627
WARN_ON(pages[i]->mapping);
629628
put_page(pages[i]);
630629
}
631630
kfree(pages);
632631
pages = NULL;
633632
total_compressed = 0;
634-
nr_pages_ret = 0;
633+
nr_pages = 0;
635634

636635
/* flag the file so we don't compress in the future */
637636
if (!btrfs_test_opt(fs_info, FORCE_COMPRESS) &&
@@ -660,7 +659,7 @@ static noinline void compress_file_range(struct inode *inode,
660659
return;
661660

662661
free_pages_out:
663-
for (i = 0; i < nr_pages_ret; i++) {
662+
for (i = 0; i < nr_pages; i++) {
664663
WARN_ON(pages[i]->mapping);
665664
put_page(pages[i]);
666665
}

fs/btrfs/lzo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ static int lzo_compress_pages(struct list_head *ws,
8888
struct address_space *mapping,
8989
u64 start,
9090
struct page **pages,
91-
unsigned long nr_dest_pages,
9291
unsigned long *out_pages,
9392
unsigned long *total_in,
9493
unsigned long *total_out,
@@ -103,6 +102,7 @@ static int lzo_compress_pages(struct list_head *ws,
103102
struct page *out_page = NULL;
104103
unsigned long bytes_left;
105104
unsigned long len = *total_out;
105+
unsigned long nr_dest_pages = *out_pages;
106106
size_t in_len;
107107
size_t out_len;
108108
char *buf;

fs/btrfs/zlib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ static int zlib_compress_pages(struct list_head *ws,
7575
struct address_space *mapping,
7676
u64 start,
7777
struct page **pages,
78-
unsigned long nr_dest_pages,
7978
unsigned long *out_pages,
8079
unsigned long *total_in,
8180
unsigned long *total_out,
@@ -90,6 +89,7 @@ static int zlib_compress_pages(struct list_head *ws,
9089
struct page *out_page = NULL;
9190
unsigned long bytes_left;
9291
unsigned long len = *total_out;
92+
unsigned long nr_dest_pages = *out_pages;
9393

9494
*out_pages = 0;
9595
*total_out = 0;

0 commit comments

Comments
 (0)