btrfs: merge length input and output parameter in compress_pages
authorDavid Sterba <dsterba@suse.com>
Tue, 14 Feb 2017 18:04:07 +0000 (19:04 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 28 Feb 2017 13:26:35 +0000 (14:26 +0100)
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 <dsterba@suse.com>
fs/btrfs/compression.c
fs/btrfs/compression.h
fs/btrfs/inode.c
fs/btrfs/lzo.c
fs/btrfs/zlib.c

index d426e4a10b2bc8d8e691769d77a9ad48f70bdc63..7e214fd254e4e2f5816cf739a355173e449cc35e 100644 (file)
@@ -911,27 +911,25 @@ static void free_workspaces(void)
 }
 
 /*
- * given an address space and start/len, compress the bytes.
+ * Given an address space and start and length, compress the bytes into @pages
+ * that are allocated on demand.
  *
- * pages are allocated to hold the compressed result and stored
- * in 'pages'
+ * @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 used to return the number of pages allocated.  There
- * may be pages allocated even if we return an error
- *
- * total_in is used to return the number of bytes actually read.  It
- * may be smaller then len if we had to exit early because we
+ * @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
  * ran out of room in the pages array or because we cross the
  * max_out threshold.
  *
- * total_out is used to return the total number of compressed bytes
+ * @total_out is an in/out parameter, must be set to the input length and will
+ * be also used to return the total number of compressed bytes
  *
- * max_out tells us the max number of bytes that we're allowed to
+ * @max_out tells us the max number of bytes that we're allowed to
  * stuff into pages
  */
 int btrfs_compress_pages(int type, struct address_space *mapping,
-                        u64 start, unsigned long len,
-                        struct page **pages,
+                        u64 start, struct page **pages,
                         unsigned long nr_dest_pages,
                         unsigned long *out_pages,
                         unsigned long *total_in,
@@ -944,7 +942,7 @@ int btrfs_compress_pages(int type, struct address_space *mapping,
        workspace = find_workspace(type);
 
        ret = btrfs_compress_op[type-1]->compress_pages(workspace, mapping,
-                                                     start, len, pages,
+                                                     start, pages,
                                                      nr_dest_pages, out_pages,
                                                      total_in, total_out,
                                                      max_out);
index 1c700bb20b52fd91701807a91f4cf9125098ce7d..725d1e0bd25d98af20bef0a675ba02169b24ee8f 100644 (file)
@@ -23,8 +23,7 @@ void btrfs_init_compress(void);
 void btrfs_exit_compress(void);
 
 int btrfs_compress_pages(int type, struct address_space *mapping,
-                        u64 start, unsigned long len,
-                        struct page **pages,
+                        u64 start, struct page **pages,
                         unsigned long nr_dest_pages,
                         unsigned long *out_pages,
                         unsigned long *total_in,
@@ -59,7 +58,7 @@ struct btrfs_compress_op {
 
        int (*compress_pages)(struct list_head *workspace,
                              struct address_space *mapping,
-                             u64 start, unsigned long len,
+                             u64 start,
                              struct page **pages,
                              unsigned long nr_dest_pages,
                              unsigned long *out_pages,
index 596e5cb4bfa29ae43fcf6a743fbcd1fa558d1d9f..8b9eac33d4316cda260b5cdde831502a08135199 100644 (file)
@@ -517,7 +517,7 @@ again:
                redirty = 1;
                ret = btrfs_compress_pages(compress_type,
                                           inode->i_mapping, start,
-                                          total_compressed, pages,
+                                          pages,
                                           nr_pages, &nr_pages_ret,
                                           &total_in,
                                           &total_compressed,
index e074b85aa0542f51e69ca10f6b65247ed3cab756..489f78c4e5eca203a888a8d31bc9383d370dd7a7 100644 (file)
@@ -86,7 +86,7 @@ static inline size_t read_compress_length(const char *buf)
 
 static int lzo_compress_pages(struct list_head *ws,
                              struct address_space *mapping,
-                             u64 start, unsigned long len,
+                             u64 start,
                              struct page **pages,
                              unsigned long nr_dest_pages,
                              unsigned long *out_pages,
@@ -102,7 +102,7 @@ static int lzo_compress_pages(struct list_head *ws,
        struct page *in_page = NULL;
        struct page *out_page = NULL;
        unsigned long bytes_left;
-
+       unsigned long len = *total_out;
        size_t in_len;
        size_t out_len;
        char *buf;
index da497f184ff4d2dad86606ab5776e2c49c211c62..42d76b7824c38422d20db6141f2983d59b31c663 100644 (file)
@@ -73,7 +73,7 @@ fail:
 
 static int zlib_compress_pages(struct list_head *ws,
                               struct address_space *mapping,
-                              u64 start, unsigned long len,
+                              u64 start,
                               struct page **pages,
                               unsigned long nr_dest_pages,
                               unsigned long *out_pages,
@@ -89,6 +89,7 @@ static int zlib_compress_pages(struct list_head *ws,
        struct page *in_page = NULL;
        struct page *out_page = NULL;
        unsigned long bytes_left;
+       unsigned long len = *total_out;
 
        *out_pages = 0;
        *total_out = 0;