All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Bob Liu <lliubbo@gmail.com>
Cc: xen-devel@lists.xenproject.org, keir@xen.org,
	ian.campbell@citrix.com, JBeulich@suse.com
Subject: Re: [PATCH 06/16] tmem: cleanup: reorg do_tmem_put()
Date: Fri, 22 Nov 2013 13:04:41 -0500	[thread overview]
Message-ID: <20131122180441.GD8120@phenom.dumpdata.com> (raw)
In-Reply-To: <1384937185-24749-6-git-send-email-bob.liu@oracle.com>

On Wed, Nov 20, 2013 at 04:46:15PM +0800, Bob Liu wrote:
> Reorg code logic of do_tmem_put() to make it more readable and also drop useless
> local parameters.
> 
> Signed-off-by: Bob Liu <bob.liu@oracle.com>
> ---
>  xen/common/tmem.c |   87 ++++++++++++++++++++++++++++++-----------------------
>  1 file changed, 49 insertions(+), 38 deletions(-)
> 
> diff --git a/xen/common/tmem.c b/xen/common/tmem.c
> index de3559d..1c9dd5a 100644
> --- a/xen/common/tmem.c
> +++ b/xen/common/tmem.c
> @@ -1509,50 +1509,56 @@ static int do_tmem_put(struct tmem_pool *pool,
>                struct oid *oidp, uint32_t index,
>                xen_pfn_t cmfn, tmem_cli_va_param_t clibuf)
>  {
> -    struct tmem_object_root *obj = NULL, *objfound = NULL, *objnew = NULL;
> -    struct tmem_page_descriptor *pgp = NULL, *pgpdel = NULL;
> -    struct client *client = pool->client;
> -    int ret = client->frozen ? -EFROZEN : -ENOMEM;
> +    struct tmem_object_root *obj = NULL;
> +    struct tmem_page_descriptor *pgp = NULL;
> +    struct client *client;
> +    int ret, newobj = 0;
>  
>      ASSERT(pool != NULL);
> +    client = pool->client;
> +    ret = client->frozen ? -EFROZEN : -ENOMEM;
>      pool->puts++;
>      /* does page already exist (dup)?  if so, handle specially */
> -    if ( (obj = objfound = obj_find(pool,oidp)) != NULL )
> +    if ( (obj = obj_find(pool,oidp)) != NULL )
>      {
> -        ASSERT_SPINLOCK(&objfound->obj_spinlock);
> -        if ((pgp = pgp_lookup_in_obj(objfound, index)) != NULL)
> +        if ((pgp = pgp_lookup_in_obj(obj, index)) != NULL)
> +        {
>              return do_tmem_dup_put(pgp, cmfn, clibuf);
> +        }
> +        else
> +        {
> +            /* no puts allowed into a frozen pool (except dup puts) */
> +            if ( client->frozen )
> +	        goto unlock_obj;
> +        }
>      }
> -
> -    /* no puts allowed into a frozen pool (except dup puts) */
> -    if ( client->frozen )
> -        goto free;
> -
> -    if ( (objfound == NULL) )
> +    else
>      {
> +        /* no puts allowed into a frozen pool (except dup puts) */
> +        if ( client->frozen )
> +            return ret;
>          tmem_write_lock(&pool->pool_rwlock);
> -        if ( (obj = objnew = obj_new(pool,oidp)) == NULL )
> +        if ( (obj = obj_new(pool,oidp)) == NULL )
>          {
>              tmem_write_unlock(&pool->pool_rwlock);
>              return -ENOMEM;
>          }
> -        ASSERT_SPINLOCK(&objnew->obj_spinlock);
> +        newobj= 1;

Space before '='

>          tmem_write_unlock(&pool->pool_rwlock);
>      }
>  
> -    ASSERT((obj != NULL)&&((objnew==obj)||(objfound==obj))&&(objnew!=objfound));
> +    /* When arrive here, we have a spinlocked obj for use */
>      ASSERT_SPINLOCK(&obj->obj_spinlock);
>      if ( (pgp = pgp_alloc(obj)) == NULL )
> -        goto free;
> +        goto unlock_obj;
>  
>      ret = pgp_add_to_obj(obj, index, pgp);
>      if ( ret == -ENOMEM  )
>          /* warning, may result in partially built radix tree ("stump") */
> -        goto free;
> -    ASSERT(ret != -EEXIST);
> +        goto free_pgp;
> +
>      pgp->index = index;
>      pgp->size = 0;
> -

Stray. But that might not really matter as this is a cleanup patch after all.

>      if ( client->compress )
>      {
>          ASSERT(pgp->pfp == NULL);
> @@ -1562,7 +1568,7 @@ static int do_tmem_put(struct tmem_pool *pool,
>          if ( ret == -ENOMEM )
>          {
>              client->compress_nomem++;
> -            goto delete_and_free;
> +            goto del_pgp_from_obj;
>          }
>          if ( ret == 0 )
>          {
> @@ -1577,15 +1583,16 @@ copy_uncompressed:
>      if ( ( pgp->pfp = tmem_page_alloc(pool) ) == NULL )
>      {
>          ret = -ENOMEM;
> -        goto delete_and_free;
> +        goto del_pgp_from_obj;
>      }
>      ret = tmem_copy_from_client(pgp->pfp, cmfn, clibuf);
>      if ( ret < 0 )
>          goto bad_copy;
> +
>      if ( tmem_dedup_enabled() && !is_persistent(pool) )
>      {
>          if ( pcd_associate(pgp,NULL,0) == -ENOMEM )
> -            goto delete_and_free;
> +            goto del_pgp_from_obj;
>      }
>  
>  insert_page:
> @@ -1601,18 +1608,23 @@ insert_page:
>          if (++client->eph_count > client->eph_count_max)
>              client->eph_count_max = client->eph_count;
>          tmem_spin_unlock(&eph_lists_spinlock);
> -    } else { /* is_persistent */
> +    }
> +    else
> +    { /* is_persistent */

So StyleGuide fixes too, in which case you might as well:
>          tmem_spin_lock(&pers_lists_spinlock);
>          list_add_tail(&pgp->us.pool_pers_pages,
>              &pool->persistent_page_list);
>          tmem_spin_unlock(&pers_lists_spinlock);
>      }
> -    ASSERT( ((objnew==obj)||(objfound==obj)) && (objnew!=objfound));
> +
>      if ( is_shared(pool) )
>          obj->last_client = client->cli_id;
>      obj->no_evict = 0;
> +
> +    /* free the obj spinlock */
>      tmem_spin_unlock(&obj->obj_spinlock);
>      pool->good_puts++;
> +
>      if ( is_persistent(pool) )
>          client->succ_pers_puts++;
>      else
> @@ -1622,25 +1634,24 @@ insert_page:
>  bad_copy:
>      failed_copies++;
>  
> -delete_and_free:
> +del_pgp_from_obj:
>      ASSERT((obj != NULL) && (pgp != NULL) && (pgp->index != -1));
> -    pgpdel = pgp_delete_from_obj(obj, pgp->index);
> -    ASSERT(pgp == pgpdel);
> +    pgp_delete_from_obj(obj, pgp->index);
>  
> -free:
> -    if ( pgp )
> -        pgp_delete(pgp,0);
> -    if ( objfound )
> -    {
> -        objfound->no_evict = 0;
> -        tmem_spin_unlock(&objfound->obj_spinlock);
> -    }
> -    if ( objnew )
> +free_pgp:
> +    pgp_delete(pgp,0);

.. fix that.
> +unlock_obj:
> +    if ( newobj )
>      {
>          tmem_write_lock(&pool->pool_rwlock);
> -        obj_free(objnew,0);
> +        obj_free(obj,0);

.. and that.

>          tmem_write_unlock(&pool->pool_rwlock);
>      }
> +    else
> +    {
> +        obj->no_evict = 0;
> +        tmem_spin_unlock(&obj->obj_spinlock);
> +    }
>      pool->no_mem_puts++;
>      return ret;
>  }
> -- 
> 1.7.10.4
> 

  reply	other threads:[~2013-11-22 18:04 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-20  8:46 [PATCH 01/16] tmem: cleanup: drop some debug code Bob Liu
2013-11-20  8:46 ` [PATCH 02/16] tmem: cleanup: drop useless function 'tmem_copy_page' Bob Liu
2013-11-20  8:46 ` [PATCH 03/16] tmem: cleanup: rm unused tmem_op Bob Liu
2013-11-22 17:38   ` Konrad Rzeszutek Wilk
2013-11-25  9:43     ` Jan Beulich
2013-11-25  9:52       ` Ian Campbell
2013-11-25  9:58         ` Jan Beulich
2013-11-25 16:37         ` Konrad Rzeszutek Wilk
2013-11-25 16:40           ` Ian Campbell
2013-11-25 17:09             ` Konrad Rzeszutek Wilk
2013-11-25 17:12               ` Ian Campbell
2013-11-25 19:56                 ` Konrad Rzeszutek Wilk
2013-11-26  8:56                   ` Bob Liu
2013-11-20  8:46 ` [PATCH 04/16] tmem: cleanup: rm unneeded parameters from put path Bob Liu
2013-11-22 17:54   ` Konrad Rzeszutek Wilk
2013-11-26  8:22     ` Bob Liu
2013-11-20  8:46 ` [PATCH 05/16] tmem: cleanup: rm unneeded parameters from get path Bob Liu
2013-11-22 17:55   ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 06/16] tmem: cleanup: reorg do_tmem_put() Bob Liu
2013-11-22 18:04   ` Konrad Rzeszutek Wilk [this message]
2013-11-20  8:46 ` [PATCH 07/16] tmem: drop unneeded is_ephemeral() and is_private() Bob Liu
2013-11-20  8:46 ` [PATCH 08/16] tmem: cleanup: rm useless EXPORT/FORWARD define Bob Liu
2013-11-22 18:05   ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 09/16] tmem: cleanup: drop tmemc_list() temporary Bob Liu
2013-11-22 18:07   ` Konrad Rzeszutek Wilk
2013-11-26  8:28     ` Bob Liu
2013-11-22 21:00   ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 10/16] tmem: cleanup: drop runtime statistics Bob Liu
2013-11-22 18:08   ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 11/16] tmem: cleanup: drop tmem_lock_all Bob Liu
2013-11-20  8:46 ` [PATCH 12/16] tmem: cleanup: refactor the alloc/free path Bob Liu
2013-11-20  8:46 ` [PATCH 13/16] tmem: cleanup: __tmem_alloc_page: drop unneed parameters Bob Liu
2013-11-22 18:17   ` Konrad Rzeszutek Wilk
2013-11-26  8:41     ` Bob Liu
2013-11-26 17:38       ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 14/16] tmem: cleanup: drop useless functions from head file Bob Liu
2013-11-27 14:38   ` Andrew Cooper
2013-11-27 14:52     ` Konrad Rzeszutek Wilk
2013-11-27 14:59       ` Andrew Cooper
2013-11-27 15:55         ` Jan Beulich
2013-11-20  8:46 ` [PATCH 15/16] tmem: refator function tmem_ensure_avail_pages() Bob Liu
2013-11-22 18:22   ` Konrad Rzeszutek Wilk
2013-11-20  8:46 ` [PATCH 16/16] tmem: cleanup: rename tmem_relinquish_npages() Bob Liu
2013-11-20  9:08 ` [PATCH 01/16] tmem: cleanup: drop some debug code Jan Beulich
2013-11-20  9:19   ` Bob Liu
2013-11-20  9:25     ` Jan Beulich
2013-11-20 13:51       ` Konrad Rzeszutek Wilk
2013-11-20 14:21         ` Jan Beulich
2013-11-20 18:46           ` Konrad Rzeszutek Wilk

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=20131122180441.GD8120@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=JBeulich@suse.com \
    --cc=ian.campbell@citrix.com \
    --cc=keir@xen.org \
    --cc=lliubbo@gmail.com \
    --cc=xen-devel@lists.xenproject.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 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.