All of lore.kernel.org
 help / color / mirror / Atom feed
From: Minchan Kim <minchan@kernel.org>
To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Jerome Marchand <jmarchan@redhat.com>,
	Nitin Gupta <ngupta@vflare.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCHv6 5/6] zram: enalbe multi stream compression support in zram
Date: Tue, 25 Feb 2014 08:53:15 +0900	[thread overview]
Message-ID: <20140224235315.GE24325@bbox> (raw)
In-Reply-To: <1392983443-9807-6-git-send-email-sergey.senozhatsky@gmail.com>

On Fri, Feb 21, 2014 at 02:50:42PM +0300, Sergey Senozhatsky wrote:
> 1) Add ZRAM_MULTI_STREAM configuration option and make multi stream
> zcomp support available.
> 
> 2) Introduce zram device attribute max_comp_streams to show and store
> current zcomp's max number of zcomp streams (num_strm).
> 
> 3) Extend zcomp zcomp_create() with `num_strm' parameter. `num_strm'
> limits the number of zcomp_strm structs in compression backend's idle
> list (max_comp_streams).
> 
> If ZRAM_MULTI_STREAM option selected:
> -- user can change max number of compression streams (max_comp_streams),
>    otherwise, attempt to change its default value (1) will be ignored.
> -- passing to zcomp_create() num_strm equals to 1 will initialise zcomp
>    using single compression stream zcomp_strm_single (mutex-based locking)
> -- passing to zcomp_create() num_strm greater than 1 will initialise zcomp
>    using multi compression stream zcomp_strm_multi (spinlock-based locking)
> 
> If ZRAM_MULTI_STREAM has not been selected, only single compression stream
> support available.
> 
> iozone -t 3 -R -r 16K -s 60M -I +Z
> 
>        test           base       1 strm (mutex)     3 strm (spinlock)
> -----------------------------------------------------------------------
>  Initial write      589286.78       583518.39          718011.05
>        Rewrite      604837.97       596776.38         1515125.72
>   Random write      584120.11       595714.58         1388850.25
>         Pwrite      535731.17       541117.38          739295.27
>         Fwrite     1418083.88      1478612.72         1484927.06
> 
> Usage example:
> set max_comp_streams to 4
>         echo 4 > /sys/block/zram0/max_comp_streams
> 
> show current max_comp_streams (default value is 1).
>         cat /sys/block/zram0/max_comp_streams
> 
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> ---
>  drivers/block/zram/Kconfig    | 10 ++++++++++
>  drivers/block/zram/zcomp.c    | 13 +++++++++++--
>  drivers/block/zram/zcomp.h    |  2 +-
>  drivers/block/zram/zram_drv.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
>  drivers/block/zram/zram_drv.h |  2 +-
>  5 files changed, 65 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig
> index 3450be8..a2ba9a9 100644
> --- a/drivers/block/zram/Kconfig
> +++ b/drivers/block/zram/Kconfig
> @@ -15,6 +15,16 @@ config ZRAM
>  
>  	  See zram.txt for more information.
>  
> +config ZRAM_MULTI_STREAM
> +	bool "Multi stream compression support"
> +	depends on ZRAM
> +	default n
> +	help
> +	  This option adds additional functionality to ZRAM, that enables
> +	  multi compression stream support and provides ability to control
> +	  maximum number of parallel compressions using max_comp_streams
> +	  device attribute.
> +
>  config ZRAM_DEBUG
>  	bool "Compressed RAM block device debug support"
>  	depends on ZRAM
> diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
> index 41325ed..7faa6bd 100644
> --- a/drivers/block/zram/zcomp.c
> +++ b/drivers/block/zram/zcomp.c
> @@ -240,8 +240,9 @@ void zcomp_destroy(struct zcomp *comp)
>   * if requested algorithm is not supported or in case
>   * of init error
>   */
> -struct zcomp *zcomp_create(const char *compress)
> +struct zcomp *zcomp_create(const char *compress, int num_strm)
>  {
> +	int ret;
>  	struct zcomp *comp;
>  	struct zcomp_backend *backend;
>  
> @@ -254,7 +255,15 @@ struct zcomp *zcomp_create(const char *compress)
>  		return NULL;
>  
>  	comp->backend = backend;
> -	if (zcomp_strm_single_create(comp) != 0) {
> +#ifdef CONFIG_ZRAM_MULTI_STREAM
> +	if (num_strm > 1)
> +		ret = zcomp_strm_multi_create(comp, num_strm);
> +	else
> +		ret = zcomp_strm_single_create(comp);
> +#else
> +	ret = zcomp_strm_single_create(comp);
> +#endif
> +	if (ret != 0) {
>  		zcomp_destroy(comp);
>  		return NULL;
>  	}
> diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
> index 8dc1d7f..d7e1229 100644
> --- a/drivers/block/zram/zcomp.h
> +++ b/drivers/block/zram/zcomp.h
> @@ -42,7 +42,7 @@ struct zcomp {
>  	void (*destroy)(struct zcomp *comp);
>  };
>  
> -struct zcomp *zcomp_create(const char *comp);
> +struct zcomp *zcomp_create(const char *comp, int num_strm);
>  void zcomp_destroy(struct zcomp *comp);
>  
>  struct zcomp_strm *zcomp_strm_get(struct zcomp *comp);
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 200c12a..c147e6f 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -107,6 +107,42 @@ static ssize_t mem_used_total_show(struct device *dev,
>  	return sprintf(buf, "%llu\n", val);
>  }
>  
> +static ssize_t max_comp_streams_show(struct device *dev,
> +		struct device_attribute *attr, char *buf)
> +{
> +	long val;

Why 'long'?

> +	struct zram *zram = dev_to_zram(dev);
> +
> +	down_read(&zram->init_lock);
> +	val = zram->max_comp_streams;
> +	up_read(&zram->init_lock);
> +
> +	return sprintf(buf, "%ld\n", val);
> +}
> +
> +static ssize_t max_comp_streams_store(struct device *dev,
> +		struct device_attribute *attr, const char *buf, size_t len)
> +{
> +#ifdef CONFIG_ZRAM_MULTI_STREAM
> +	long num;
> +	struct zram *zram = dev_to_zram(dev);
> +
> +	if (kstrtol(buf, 0, &num))
> +		return -EINVAL;
> +	if (num < 1)
> +		return -EINVAL;
> +	down_write(&zram->init_lock);
> +	if (init_done(zram)) {
> +		up_write(&zram->init_lock);
> +		pr_info("Can't set max_comp_streams for initialized device\n");
> +		return -EBUSY;
> +	}
> +	zram->max_comp_streams = num;
> +	up_write(&zram->init_lock);

If user decrease max stream in runtime, who care of freeing streams?

> +#endif
> +	return len;
> +}
> +
>  /* flag operations needs meta->tb_lock */
>  static int zram_test_flag(struct zram_meta *meta, u32 index,
>  			enum zram_pageflags flag)
> @@ -503,6 +539,7 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
>  
>  	zcomp_destroy(zram->comp);
>  	zram->comp = NULL;
> +	zram->max_comp_streams = 1;
>  
>  	zram_meta_free(zram->meta);
>  	zram->meta = NULL;
> @@ -532,7 +569,7 @@ static ssize_t disksize_store(struct device *dev,
>  		return -EBUSY;
>  	}
>  
> -	zram->comp = zcomp_create(default_compressor);
> +	zram->comp = zcomp_create(default_compressor, zram->max_comp_streams);
>  	if (!zram->comp) {
>  		up_write(&zram->init_lock);
>  		pr_info("Cannot initialise compressing backend\n");
> @@ -695,6 +732,8 @@ static DEVICE_ATTR(initstate, S_IRUGO, initstate_show, NULL);
>  static DEVICE_ATTR(reset, S_IWUSR, NULL, reset_store);
>  static DEVICE_ATTR(orig_data_size, S_IRUGO, orig_data_size_show, NULL);
>  static DEVICE_ATTR(mem_used_total, S_IRUGO, mem_used_total_show, NULL);
> +static DEVICE_ATTR(max_comp_streams, S_IRUGO | S_IWUSR,
> +		max_comp_streams_show, max_comp_streams_store);
>  
>  ZRAM_ATTR_RO(num_reads);
>  ZRAM_ATTR_RO(num_writes);
> @@ -719,6 +758,7 @@ static struct attribute *zram_disk_attrs[] = {
>  	&dev_attr_orig_data_size.attr,
>  	&dev_attr_compr_data_size.attr,
>  	&dev_attr_mem_used_total.attr,
> +	&dev_attr_max_comp_streams.attr,
>  	NULL,
>  };
>  
> @@ -782,6 +822,7 @@ static int create_device(struct zram *zram, int device_id)
>  
>  	zram->meta = NULL;
>  	zram->comp = NULL;
> +	zram->max_comp_streams = 1;
>  	return 0;
>  
>  out_free_disk:
> diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
> index 45e04f7..8dccb22 100644
> --- a/drivers/block/zram/zram_drv.h
> +++ b/drivers/block/zram/zram_drv.h
> @@ -99,7 +99,7 @@ struct zram {
>  	 * we can store in a disk.
>  	 */
>  	u64 disksize;	/* bytes */
> -
> +	long max_comp_streams;
>  	struct zram_stats stats;
>  };
>  #endif
> -- 
> 1.9.0.291.g027825b
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
Kind regards,
Minchan Kim

  reply	other threads:[~2014-02-24 23:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-21 11:50 [PATCHv6 0/6] add compressing abstraction and multi stream support Sergey Senozhatsky
2014-02-21 11:50 ` [PATCHv6 1/6] zram: introduce compressing backend abstraction Sergey Senozhatsky
2014-02-24  0:37   ` Minchan Kim
2014-02-21 11:50 ` [PATCHv6 2/6] zram: use zcomp compressing backends Sergey Senozhatsky
2014-02-24  1:01   ` Minchan Kim
2014-02-24  8:39     ` Sergey Senozhatsky
2014-02-24 23:14       ` Minchan Kim
2014-02-21 11:50 ` [PATCHv6 3/6] zram: factor out single stream compression Sergey Senozhatsky
2014-02-24  2:31   ` Minchan Kim
2014-02-24  8:31     ` Sergey Senozhatsky
2014-02-24 23:07       ` Minchan Kim
2014-02-24 23:14         ` Sergey Senozhatsky
2014-02-21 11:50 ` [PATCHv6 4/6] zram: add multi stream functionality Sergey Senozhatsky
2014-02-24 23:43   ` Minchan Kim
2014-02-24 23:48     ` Sergey Senozhatsky
2014-02-24 23:51     ` Minchan Kim
2014-02-21 11:50 ` [PATCHv6 5/6] zram: enalbe multi stream compression support in zram Sergey Senozhatsky
2014-02-24 23:53   ` Minchan Kim [this message]
2014-02-24 23:58     ` Sergey Senozhatsky
2014-02-25  0:12       ` Minchan Kim
2014-02-25  0:25         ` Sergey Senozhatsky
2014-02-25  0:40           ` Minchan Kim
2014-02-21 11:50 ` [PATCHv6 6/6] zram: document max_comp_streams Sergey Senozhatsky

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=20140224235315.GE24325@bbox \
    --to=minchan@kernel.org \
    --cc=jmarchan@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ngupta@vflare.org \
    --cc=sergey.senozhatsky@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.