Skip to content

Commit 38c3146

Browse files
committed
btrfs: merge length input and output parameter in compress_pages
The length parameter is basically duplicated for input and output in the top level caller of the compress_pages chain. We can simply use one variable for that and reduce stack consumption. The compression implementation will sink the parameter to a local variable so everything works as before. Signed-off-by: David Sterba <[email protected]>
1 parent 52f75f4 commit 38c3146

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

fs/btrfs/compression.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -911,27 +911,25 @@ static void free_workspaces(void)
911911
}
912912

913913
/*
914-
* given an address space and start/len, compress the bytes.
914+
* Given an address space and start and length, compress the bytes into @pages
915+
* that are allocated on demand.
915916
*
916-
* pages are allocated to hold the compressed result and stored
917-
* in 'pages'
917+
* @out_pages is used to return the number of pages allocated. There
918+
* may be pages allocated even if we return an error.
918919
*
919-
* out_pages is used to return the number of pages allocated. There
920-
* may be pages allocated even if we return an error
921-
*
922-
* total_in is used to return the number of bytes actually read. It
923-
* may be smaller then len if we had to exit early because we
920+
* @total_in is used to return the number of bytes actually read. It
921+
* may be smaller than the input length if we had to exit early because we
924922
* ran out of room in the pages array or because we cross the
925923
* max_out threshold.
926924
*
927-
* total_out is used to return the total number of compressed bytes
925+
* @total_out is an in/out parameter, must be set to the input length and will
926+
* be also used to return the total number of compressed bytes
928927
*
929-
* max_out tells us the max number of bytes that we're allowed to
928+
* @max_out tells us the max number of bytes that we're allowed to
930929
* stuff into pages
931930
*/
932931
int btrfs_compress_pages(int type, struct address_space *mapping,
933-
u64 start, unsigned long len,
934-
struct page **pages,
932+
u64 start, struct page **pages,
935933
unsigned long nr_dest_pages,
936934
unsigned long *out_pages,
937935
unsigned long *total_in,
@@ -944,7 +942,7 @@ int btrfs_compress_pages(int type, struct address_space *mapping,
944942
workspace = find_workspace(type);
945943

946944
ret = btrfs_compress_op[type-1]->compress_pages(workspace, mapping,
947-
start, len, pages,
945+
start, pages,
948946
nr_dest_pages, out_pages,
949947
total_in, total_out,
950948
max_out);

fs/btrfs/compression.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ void btrfs_init_compress(void);
2323
void btrfs_exit_compress(void);
2424

2525
int btrfs_compress_pages(int type, struct address_space *mapping,
26-
u64 start, unsigned long len,
27-
struct page **pages,
26+
u64 start, struct page **pages,
2827
unsigned long nr_dest_pages,
2928
unsigned long *out_pages,
3029
unsigned long *total_in,
@@ -59,7 +58,7 @@ struct btrfs_compress_op {
5958

6059
int (*compress_pages)(struct list_head *workspace,
6160
struct address_space *mapping,
62-
u64 start, unsigned long len,
61+
u64 start,
6362
struct page **pages,
6463
unsigned long nr_dest_pages,
6564
unsigned long *out_pages,

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ static noinline void compress_file_range(struct inode *inode,
517517
redirty = 1;
518518
ret = btrfs_compress_pages(compress_type,
519519
inode->i_mapping, start,
520-
total_compressed, pages,
520+
pages,
521521
nr_pages, &nr_pages_ret,
522522
&total_in,
523523
&total_compressed,

fs/btrfs/lzo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static inline size_t read_compress_length(const char *buf)
8686

8787
static int lzo_compress_pages(struct list_head *ws,
8888
struct address_space *mapping,
89-
u64 start, unsigned long len,
89+
u64 start,
9090
struct page **pages,
9191
unsigned long nr_dest_pages,
9292
unsigned long *out_pages,
@@ -102,7 +102,7 @@ static int lzo_compress_pages(struct list_head *ws,
102102
struct page *in_page = NULL;
103103
struct page *out_page = NULL;
104104
unsigned long bytes_left;
105-
105+
unsigned long len = *total_out;
106106
size_t in_len;
107107
size_t out_len;
108108
char *buf;

fs/btrfs/zlib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static struct list_head *zlib_alloc_workspace(void)
7373

7474
static int zlib_compress_pages(struct list_head *ws,
7575
struct address_space *mapping,
76-
u64 start, unsigned long len,
76+
u64 start,
7777
struct page **pages,
7878
unsigned long nr_dest_pages,
7979
unsigned long *out_pages,
@@ -89,6 +89,7 @@ static int zlib_compress_pages(struct list_head *ws,
8989
struct page *in_page = NULL;
9090
struct page *out_page = NULL;
9191
unsigned long bytes_left;
92+
unsigned long len = *total_out;
9293

9394
*out_pages = 0;
9495
*total_out = 0;

0 commit comments

Comments
 (0)