public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jerome Marchand <jmarchan@redhat.com>
To: Nitin Gupta <ngupta@vflare.org>
Cc: Greg KH <greg@kroah.com>,
	Seth Jennings <sjenning@linux.vnet.ibm.com>,
	Minchan Kim <minchan.kim@gmail.com>,
	Dan Carpenter <dan.carpenter@oracle.com>,
	Sam Hansen <solid.se7en@gmail.com>, Tomas M <tomas@slax.org>,
	Mihail Kasadjikov <hamer.mk@gmail.com>,
	Linux Driver Project <devel@linuxdriverproject.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] zram: reduce metadata overhead
Date: Tue, 27 Nov 2012 17:22:07 +0100	[thread overview]
Message-ID: <50B4E8AF.7050808@redhat.com> (raw)
In-Reply-To: <1354001201-25537-2-git-send-email-ngupta@vflare.org>

On 11/27/2012 08:26 AM, Nitin Gupta wrote:
> For every allocated object, zram maintains the the handle, size,
> flags and count fields. Of these, only the handle is required
> since zsmalloc now provides the object size given the handle.
> The flags field was needed only to mark a given page as zero-filled.
> Instead of this field, we now use an invalid value (-1) to mark such

Since the handle is unsigned, is this really an invalid value?

> pages. Lastly, the count field was unused, so was simply removed.
> 
> Signed-off-by: Nitin Gupta <ngupta@vflare.org>
> ---
>  drivers/staging/zram/zram_drv.c |   80 ++++++++++++++-------------------------
>  drivers/staging/zram/zram_drv.h |   18 +--------
>  2 files changed, 31 insertions(+), 67 deletions(-)
> 

> [...]

> @@ -222,8 +202,8 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
>  
>  	page = bvec->bv_page;
>  
> -	if (unlikely(!zram->table[index].handle) ||
> -			zram_test_flag(zram, index, ZRAM_ZERO)) {
> +	if (unlikely(!zram->handle[index]) ||
> +			(zram->handle[index] == zero_page_handle)) {

This kind of comparison appears often. To my taste, an is_zero_page()
helper would be welcome.

>  		handle_zero_page(bvec);
>  		return 0;
>  	}

> [...]

> @@ -573,8 +551,8 @@ int zram_init_device(struct zram *zram)
>  	}
>  
>  	num_pages = zram->disksize >> PAGE_SHIFT;
> -	zram->table = vzalloc(num_pages * sizeof(*zram->table));
> -	if (!zram->table) {
> +	zram->handle = vzalloc(num_pages * sizeof(*zram->handle));
> +	if (!zram->handle) {
>  		pr_err("Error allocating zram address table\n");
>  		ret = -ENOMEM;
>  		goto fail_no_table;

Since the table goes away, for readability sake, we'd better remove all
reference to it in messages, labels and comment and write "handle"
instead.

Otherwise, the patch looks good to me.

Jerome

> diff --git a/drivers/staging/zram/zram_drv.h b/drivers/staging/zram/zram_drv.h
> index df2eec4..8aa733c 100644
> --- a/drivers/staging/zram/zram_drv.h
> +++ b/drivers/staging/zram/zram_drv.h
> @@ -54,24 +54,10 @@ static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
>  #define ZRAM_SECTOR_PER_LOGICAL_BLOCK	\
>  	(1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT))
>  
> -/* Flags for zram pages (table[page_no].flags) */
> -enum zram_pageflags {
> -	/* Page consists entirely of zeros */
> -	ZRAM_ZERO,
> -
> -	__NR_ZRAM_PAGEFLAGS,
> -};
> +static const unsigned long zero_page_handle = (unsigned long)(-1);
>  
>  /*-- Data structures */
>  
> -/* Allocated for each disk page */
> -struct table {
> -	unsigned long handle;
> -	u16 size;	/* object size (excluding header) */
> -	u8 count;	/* object ref count (not yet used) */
> -	u8 flags;
> -} __aligned(4);
> -
>  struct zram_stats {
>  	u64 compr_size;		/* compressed size of pages stored */
>  	u64 num_reads;		/* failed + successful */
> @@ -90,7 +76,7 @@ struct zram {
>  	struct zs_pool *mem_pool;
>  	void *compress_workmem;
>  	void *compress_buffer;
> -	struct table *table;
> +	unsigned long *handle;	/* memory handle for each disk page */
>  	spinlock_t stat64_lock;	/* protect 64-bit stats */
>  	struct rw_semaphore lock; /* protect compression buffers and table
>  				   * against concurrent read and writes */
> 


  reply	other threads:[~2012-11-27 16:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-27  7:26 [PATCH 1/2] zsmalloc: add function to query object size Nitin Gupta
2012-11-27  7:26 ` [PATCH 2/2] zram: reduce metadata overhead Nitin Gupta
2012-11-27 16:22   ` Jerome Marchand [this message]
2012-11-29  1:40     ` Nitin Gupta
2012-11-29  7:45 ` [PATCH 1/2] zsmalloc: add function to query object size Minchan Kim
2012-11-29  9:09   ` Nitin Gupta
2012-11-30  0:03     ` Minchan Kim
2012-11-30  0:53       ` Nitin Gupta
2012-11-30  1:58         ` Minchan Kim
2012-11-30  2:29           ` Nitin Gupta

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=50B4E8AF.7050808@redhat.com \
    --to=jmarchan@redhat.com \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@linuxdriverproject.org \
    --cc=greg@kroah.com \
    --cc=hamer.mk@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan.kim@gmail.com \
    --cc=ngupta@vflare.org \
    --cc=sjenning@linux.vnet.ibm.com \
    --cc=solid.se7en@gmail.com \
    --cc=tomas@slax.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