Skip to content

Commit

Permalink
btrfs: merge nr_pages input and output parameter in compress_pages
Browse files Browse the repository at this point in the history
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 <dsterba@suse.com>
  • Loading branch information
kdave committed Feb 28, 2017
1 parent 38c3146 commit 4d3a800
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
7 changes: 3 additions & 4 deletions fs/btrfs/compression.c
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,8 @@ static void free_workspaces(void)
* Given an address space and start and length, compress the bytes into @pages
* that are allocated on demand.
*
* @out_pages is used to return the number of pages allocated. There
* may be pages allocated even if we return an error.
* @out_pages is an in/out parameter, holds maximum number of pages to allocate
* and returns number of actually allocated pages
*
* @total_in is used to return the number of bytes actually read. It
* may be smaller than the input length if we had to exit early because we
Expand All @@ -930,7 +930,6 @@ static void free_workspaces(void)
*/
int btrfs_compress_pages(int type, struct address_space *mapping,
u64 start, struct page **pages,
unsigned long nr_dest_pages,
unsigned long *out_pages,
unsigned long *total_in,
unsigned long *total_out,
Expand All @@ -943,7 +942,7 @@ int btrfs_compress_pages(int type, struct address_space *mapping,

ret = btrfs_compress_op[type-1]->compress_pages(workspace, mapping,
start, pages,
nr_dest_pages, out_pages,
out_pages,
total_in, total_out,
max_out);
free_workspace(type, workspace);
Expand Down
2 changes: 0 additions & 2 deletions fs/btrfs/compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ void btrfs_exit_compress(void);

int btrfs_compress_pages(int type, struct address_space *mapping,
u64 start, struct page **pages,
unsigned long nr_dest_pages,
unsigned long *out_pages,
unsigned long *total_in,
unsigned long *total_out,
Expand Down Expand Up @@ -60,7 +59,6 @@ struct btrfs_compress_op {
struct address_space *mapping,
u64 start,
struct page **pages,
unsigned long nr_dest_pages,
unsigned long *out_pages,
unsigned long *total_in,
unsigned long *total_out,
Expand Down
13 changes: 6 additions & 7 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ static noinline void compress_file_range(struct inode *inode,
int ret = 0;
struct page **pages = NULL;
unsigned long nr_pages;
unsigned long nr_pages_ret = 0;
unsigned long total_compressed = 0;
unsigned long total_in = 0;
unsigned long max_compressed = SZ_128K;
Expand Down Expand Up @@ -518,15 +517,15 @@ static noinline void compress_file_range(struct inode *inode,
ret = btrfs_compress_pages(compress_type,
inode->i_mapping, start,
pages,
nr_pages, &nr_pages_ret,
&nr_pages,
&total_in,
&total_compressed,
max_compressed);

if (!ret) {
unsigned long offset = total_compressed &
(PAGE_SIZE - 1);
struct page *page = pages[nr_pages_ret - 1];
struct page *page = pages[nr_pages - 1];
char *kaddr;

/* zero the tail end of the last page, we might be
Expand Down Expand Up @@ -607,7 +606,7 @@ static noinline void compress_file_range(struct inode *inode,
* will submit them to the elevator.
*/
add_async_extent(async_cow, start, num_bytes,
total_compressed, pages, nr_pages_ret,
total_compressed, pages, nr_pages,
compress_type);

if (start + num_bytes < end) {
Expand All @@ -624,14 +623,14 @@ static noinline void compress_file_range(struct inode *inode,
* the compression code ran but failed to make things smaller,
* free any pages it allocated and our page pointer array
*/
for (i = 0; i < nr_pages_ret; i++) {
for (i = 0; i < nr_pages; i++) {
WARN_ON(pages[i]->mapping);
put_page(pages[i]);
}
kfree(pages);
pages = NULL;
total_compressed = 0;
nr_pages_ret = 0;
nr_pages = 0;

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

free_pages_out:
for (i = 0; i < nr_pages_ret; i++) {
for (i = 0; i < nr_pages; i++) {
WARN_ON(pages[i]->mapping);
put_page(pages[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/lzo.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ static int lzo_compress_pages(struct list_head *ws,
struct address_space *mapping,
u64 start,
struct page **pages,
unsigned long nr_dest_pages,
unsigned long *out_pages,
unsigned long *total_in,
unsigned long *total_out,
Expand All @@ -103,6 +102,7 @@ static int lzo_compress_pages(struct list_head *ws,
struct page *out_page = NULL;
unsigned long bytes_left;
unsigned long len = *total_out;
unsigned long nr_dest_pages = *out_pages;
size_t in_len;
size_t out_len;
char *buf;
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ static int zlib_compress_pages(struct list_head *ws,
struct address_space *mapping,
u64 start,
struct page **pages,
unsigned long nr_dest_pages,
unsigned long *out_pages,
unsigned long *total_in,
unsigned long *total_out,
Expand All @@ -90,6 +89,7 @@ static int zlib_compress_pages(struct list_head *ws,
struct page *out_page = NULL;
unsigned long bytes_left;
unsigned long len = *total_out;
unsigned long nr_dest_pages = *out_pages;

*out_pages = 0;
*total_out = 0;
Expand Down

0 comments on commit 4d3a800

Please sign in to comment.