xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Bob Liu <lliubbo@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: james.harper@bendigoit.com.au, ian.campbell@citrix.com,
	andrew.cooper3@citrix.com, JBeulich@suse.com
Subject: [PATCH v3 05/15] tmem: cleanup: reorg function do_tmem_put()
Date: Wed, 11 Dec 2013 16:50:34 +0800	[thread overview]
Message-ID: <1386751844-32387-6-git-send-email-bob.liu@oracle.com> (raw)
In-Reply-To: <1386751844-32387-1-git-send-email-bob.liu@oracle.com>

Reorg code logic of do_tmem_put() to make it more readable and clean.

Signed-off-by: Bob Liu <bob.liu@oracle.com>
---
 xen/common/tmem.c |   86 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 49 insertions(+), 37 deletions(-)

diff --git a/xen/common/tmem.c b/xen/common/tmem.c
index da2326b..bd17893 100644
--- a/xen/common/tmem.c
+++ b/xen/common/tmem.c
@@ -1509,47 +1509,54 @@ 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;
         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;
 
@@ -1562,7 +1569,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 +1584,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 +1609,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 */
         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 +1635,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);
+unlock_obj:
+    if ( newobj )
     {
         tmem_write_lock(&pool->pool_rwlock);
-        obj_free(objnew,0);
+        obj_free(obj, 0);
         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

  parent reply	other threads:[~2013-12-11  8:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-11  8:50 [PATCH v3 00/15] tmem: continue to cleanup tmem Bob Liu
2013-12-11  8:50 ` [PATCH v3 01/15] tmem: cleanup: drop unused sub command Bob Liu
2013-12-11  8:50 ` [PATCH v3 02/15] tmem: cleanup: drop some debug code Bob Liu
2013-12-11  8:50 ` [PATCH v3 03/15] tmem: cleanup: drop useless function 'tmem_copy_page' Bob Liu
2013-12-11  8:50 ` [PATCH v3 04/15] tmem: cleanup: drop useless parameters from put/get page Bob Liu
2013-12-11  8:50 ` Bob Liu [this message]
2013-12-11  8:50 ` [PATCH v3 06/15] tmem: drop unneeded is_ephemeral() and is_private() Bob Liu
2013-12-11  8:50 ` [PATCH v3 07/15] tmem: cleanup: rm useless EXPORT/FORWARD define Bob Liu
2013-12-11  8:50 ` [PATCH v3 08/15] tmem: cleanup: drop runtime statistics Bob Liu
2013-12-11  8:50 ` [PATCH v3 09/15] tmem: cleanup: drop tmem_lock_all Bob Liu
2013-12-11 10:45   ` Andrew Cooper
2013-12-11 13:11     ` Bob Liu
2013-12-11 22:01       ` Konrad Rzeszutek Wilk
2013-12-11  8:50 ` [PATCH v3 10/15] tmem: cleanup: refactor the alloc/free path Bob Liu
2013-12-11  8:50 ` [PATCH v3 11/15] tmem: cleanup: __tmem_alloc_page: drop unneed parameters Bob Liu
2013-12-11  8:50 ` [PATCH v3 12/15] tmem: cleanup: drop useless functions from head file Bob Liu
2013-12-11  8:50 ` [PATCH v3 13/15] tmem: refator function tmem_ensure_avail_pages() Bob Liu
2013-12-11  8:50 ` [PATCH v3 14/15] tmem: cleanup: rename tmem_relinquish_npages() Bob Liu
2013-12-11  8:50 ` [PATCH v3 15/15] tmem: cleanup: rm unused tmem_freeze_all() Bob Liu

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=1386751844-32387-6-git-send-email-bob.liu@oracle.com \
    --to=lliubbo@gmail.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=james.harper@bendigoit.com.au \
    --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 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).