linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: David Sterba <dsterba@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH preview] btrfs: allow to set compression level for zlib
Date: Thu, 27 Jul 2017 15:52:56 +0800	[thread overview]
Message-ID: <e6381f64-0c24-e3ac-ef9a-f9ff761ab74e@oracle.com> (raw)
In-Reply-To: <20170724172939.24527-1-dsterba@suse.com>



On 07/25/2017 01:29 AM, David Sterba wrote:
> Preliminary support for setting compression level for zlib, the
> following works:

  I got too busy with stuff outside of btrfs, though I agreed to work
  on this, sorry that I couldn't prioritize ahead of yours. Now deleted
  this from my list.

> $ mount -o compess=zlib                 # default
> $ mount -o compess=zlib0                # same
> $ mount -o compess=zlib9                # level 9, slower sync, less data
> $ mount -o compess=zlib1                # level 1, faster sync, more data
> $ mount -o remount,compress=zlib3	# level set by remount

  this is much better than what I was initially thinking..

> The level is visible in the same format in /proc/mounts. Level set via
> file property does not work yet.
> 
> Required patch: "btrfs: prepare for extensions in compression options"

  one concern as mentioned in the respective thread.

> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
>   fs/btrfs/compression.c | 20 +++++++++++++++++++-
>   fs/btrfs/compression.h |  6 +++++-
>   fs/btrfs/ctree.h       |  1 +
>   fs/btrfs/inode.c       |  5 ++++-
>   fs/btrfs/lzo.c         |  5 +++++
>   fs/btrfs/super.c       |  7 +++++--
>   fs/btrfs/zlib.c        | 12 +++++++++++-
>   7 files changed, 50 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index 8ba1b86c9b72..142206d68495 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -866,6 +866,11 @@ static void free_workspaces(void)
>    * Given an address space and start and length, compress the bytes into @pages
>    * that are allocated on demand.
>    *
> + * @type_level is encoded algorithm and level, where level 0 means whatever
> + * default the algorithm chooses and is opaque here;
> + * - compression algo are 0-3
> + * - the level are bits 4-7
> + *

  nice ! ..

>    * @out_pages is an in/out parameter, holds maximum number of pages to allocate
>    * and returns number of actually allocated pages
>    *
> @@ -880,7 +885,7 @@ static void free_workspaces(void)
>    * @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,
> +int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping,
>   			 u64 start, struct page **pages,
>   			 unsigned long *out_pages,
>   			 unsigned long *total_in,
> @@ -888,9 +893,11 @@ int btrfs_compress_pages(int type, struct address_space *mapping,
>   {
>   	struct list_head *workspace;
>   	int ret;
> +	int type = type_level & 0xF;
>   
>   	workspace = find_workspace(type);
>   
> +	btrfs_compress_op[type - 1]->set_level(workspace, type_level);
>   	ret = btrfs_compress_op[type-1]->compress_pages(workspace, mapping,
>   						      start, pages,
>   						      out_pages,
> @@ -1047,3 +1054,14 @@ int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start,
>   
>   	return 1;
>   }
> +
> +unsigned int btrfs_compress_str2level(const char *str)
> +{
> +	if (strncmp(str, "zlib", 4) != 0)
> +		return 0;
> +
> +	if ('1' <= str[4] && str[4] <= '9' )
> +		return str[4] - '0';
> +
> +	return 0;
> +}
> diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
> index 89bcf975efb8..8a6db02d8732 100644
> --- a/fs/btrfs/compression.h
> +++ b/fs/btrfs/compression.h
> @@ -76,7 +76,7 @@ struct compressed_bio {
>   void btrfs_init_compress(void);
>   void btrfs_exit_compress(void);
>   
> -int btrfs_compress_pages(int type, struct address_space *mapping,
> +int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping,
>   			 u64 start, struct page **pages,
>   			 unsigned long *out_pages,
>   			 unsigned long *total_in,
> @@ -95,6 +95,8 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start,
>   int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
>   				 int mirror_num, unsigned long bio_flags);
>   
> +unsigned btrfs_compress_str2level(const char *str);
> +
>   enum btrfs_compression_type {
>   	BTRFS_COMPRESS_NONE  = 0,
>   	BTRFS_COMPRESS_ZLIB  = 1,
> @@ -124,6 +126,8 @@ struct btrfs_compress_op {
>   			  struct page *dest_page,
>   			  unsigned long start_byte,
>   			  size_t srclen, size_t destlen);
> +
> +	void (*set_level)(struct list_head *ws, unsigned int type);
>   };
>   
>   extern const struct btrfs_compress_op btrfs_zlib_compress;
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 5bdd36664421..3393aed07132 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -791,6 +791,7 @@ struct btrfs_fs_info {
>   	 */
>   	unsigned long pending_changes;
>   	unsigned long compress_type:4;
> +	unsigned int compress_level;
>   	int commit_interval;
>   	/*
>   	 * It is a suggestive number, the read side is safe even it gets a
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index eb495e956d53..a832bf8cebab 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -525,7 +525,10 @@ static noinline void compress_file_range(struct inode *inode,
>   		 */
>   		extent_range_clear_dirty_for_io(inode, start, end);
>   		redirty = 1;
> -		ret = btrfs_compress_pages(compress_type,
> +
> +		/* Compression level is applied here and only here */
> +		ret = btrfs_compress_pages(
> +			compress_type | (fs_info->compress_level << 4),
>   					   inode->i_mapping, start,
>   					   pages,
>   					   &nr_pages,
> diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
> index d433e75d489a..6c7f18cd3b61 100644
> --- a/fs/btrfs/lzo.c
> +++ b/fs/btrfs/lzo.c
> @@ -430,10 +430,15 @@ static int lzo_decompress(struct list_head *ws, unsigned char *data_in,
>   	return ret;
>   }
>   
> +static void lzo_set_level(struct list_head *ws, unsigned int type)
> +{
> +}
> +
>   const struct btrfs_compress_op btrfs_lzo_compress = {
>   	.alloc_workspace	= lzo_alloc_workspace,
>   	.free_workspace		= lzo_free_workspace,
>   	.compress_pages		= lzo_compress_pages,
>   	.decompress_bio		= lzo_decompress_bio,
>   	.decompress		= lzo_decompress,
> +	.set_level		= lzo_set_level,
>   };
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 147330454c17..25ffebb101c9 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -501,6 +501,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
>   			    strncmp(args[0].from, "zlib", 4) == 0) {
>   				compress_type = "zlib";
>   				info->compress_type = BTRFS_COMPRESS_ZLIB;
> +				info->compress_level = btrfs_compress_str2level(args[0].from);
>   				btrfs_set_opt(info->mount_opt, COMPRESS);
>   				btrfs_clear_opt(info->mount_opt, NODATACOW);
>   				btrfs_clear_opt(info->mount_opt, NODATASUM);
> @@ -540,9 +541,9 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
>   			      compress_force != saved_compress_force)) ||
>   			    (!btrfs_test_opt(info, COMPRESS) &&
>   			     no_compress == 1)) {
> -				btrfs_info(info, "%s %s compression",
> +				btrfs_info(info, "%s %s compression, level %d",
>   					   (compress_force) ? "force" : "use",
> -					   compress_type);
> +					   compress_type, info->compress_level);
>   			}
>   			compress_force = false;
>   			break;
> @@ -1234,6 +1235,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
>   			seq_printf(seq, ",compress-force=%s", compress_type);
>   		else
>   			seq_printf(seq, ",compress=%s", compress_type);
> +		if (info->compress_level)
> +			seq_printf(seq, "%d", info->compress_level);
>   	}
>   	if (btrfs_test_opt(info, NOSSD))
>   		seq_puts(seq, ",nossd");
> diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
> index c248f9286366..c890032e680f 100644
> --- a/fs/btrfs/zlib.c
> +++ b/fs/btrfs/zlib.c
> @@ -37,6 +37,7 @@ struct workspace {
>   	z_stream strm;
>   	char *buf;
>   	struct list_head list;
> +	int level;
>   };

  No need to set it for the workspace. We could just redefine the
  function prototype for btrfs_compress_op->compress_pages()
  and pass as an argument.

Thanks, Anand

>   static void zlib_free_workspace(struct list_head *ws)
> @@ -96,7 +97,7 @@ static int zlib_compress_pages(struct list_head *ws,
>   	*total_out = 0;
>   	*total_in = 0;
>   
> -	if (Z_OK != zlib_deflateInit(&workspace->strm, 3)) {
> +	if (Z_OK != zlib_deflateInit(&workspace->strm, workspace->level)) {
>   		pr_warn("BTRFS: deflateInit failed\n");
>   		ret = -EIO;
>   		goto out;
> @@ -402,10 +403,19 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,
>   	return ret;
>   }
>   
> +static void zlib_set_level(struct list_head *ws, unsigned int type)
> +{
> +	struct workspace *workspace = list_entry(ws, struct workspace, list);
> +	unsigned level = (type & 0xF0) >> 4;
> +
> +	workspace->level = level > 0 ? level : 3;
> +}
> +
>   const struct btrfs_compress_op btrfs_zlib_compress = {
>   	.alloc_workspace	= zlib_alloc_workspace,
>   	.free_workspace		= zlib_free_workspace,
>   	.compress_pages		= zlib_compress_pages,
>   	.decompress_bio		= zlib_decompress_bio,
>   	.decompress		= zlib_decompress,
> +	.set_level              = zlib_set_level,
>   };
> 


How about the compress-force to accept the compression levels ?
or I wonder if your are planning to deprecate it in the long run.

Thanks, Anand

  reply	other threads:[~2017-07-27  7:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-24 17:29 [PATCH preview] btrfs: allow to set compression level for zlib David Sterba
2017-07-27  7:52 ` Anand Jain [this message]
2017-07-27 16:49   ` David Sterba
     [not found] <<20170724172939.24527-1-dsterba@suse.com>
2017-08-04 21:51 ` Nick Terrell
2017-08-05  1:27   ` Adam Borowski
2017-08-05  2:15     ` Nick Terrell
2017-08-18 16:08       ` David Sterba
2017-08-21  0:38         ` Chris Murphy
2017-09-15 14:51           ` David Sterba
2017-09-15 18:13             ` Nick Terrell
2017-08-18 15:55   ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e6381f64-0c24-e3ac-ef9a-f9ff761ab74e@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).