netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ying Xue <ying.xue@windriver.com>
To: <tgraf@suug.ch>
Cc: jon.maloy@ericsson.com, netdev@vger.kernel.org,
	Paul.Gortmaker@windriver.com,
	tipc-discussion@lists.sourceforge.net, davem@davemloft.net
Subject: [PATCH net-next v2 2/7] rhashtable: introduce rhashtable_wakeup_worker helper function
Date: Wed, 7 Jan 2015 13:41:53 +0800	[thread overview]
Message-ID: <1420609318-3261-3-git-send-email-ying.xue@windriver.com> (raw)
In-Reply-To: <1420609318-3261-1-git-send-email-ying.xue@windriver.com>

Introduce rhashtable_wakeup_worker() helper function to reduce
duplicated code where to wake up worker.

By the way, as long as the both "future_tbl" and "tbl" bucket table
pointers point to the same bucket array, we should try to wake up
the resizing worker thread, otherwise, it indicates the work of
resizing hash table is not finished yet. However, currently we will
wake up the worker thread only when the two pointers point to
different bucket array. Obviously this is wrong. So, the issue is
also fixed as well in the patch.

Signed-off-by: Ying Xue <ying.xue@windriver.com>
Cc: Thomas Graf <tgraf@suug.ch>
---
 lib/rhashtable.c |   23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index f2fdd7a..2000685 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -492,6 +492,19 @@ static void rht_deferred_worker(struct work_struct *work)
 	mutex_unlock(&ht->mutex);
 }
 
+static void rhashtable_wakeup_worker(struct rhashtable *ht)
+{
+	struct bucket_table *tbl = rht_dereference_rcu(ht->tbl, ht);
+	struct bucket_table *new_tbl = rht_dereference_rcu(ht->future_tbl, ht);
+	size_t size = tbl->size;
+
+	/* Only adjust the table if no resizing is currently in progress. */
+	if (tbl == new_tbl &&
+	    ((ht->p.grow_decision && ht->p.grow_decision(ht, size)) ||
+	     (ht->p.shrink_decision && ht->p.shrink_decision(ht, size))))
+		schedule_delayed_work(&ht->run_work, 0);
+}
+
 /**
  * rhashtable_insert - insert object into hash hash table
  * @ht:		hash table
@@ -532,10 +545,7 @@ void rhashtable_insert(struct rhashtable *ht, struct rhash_head *obj)
 
 	atomic_inc(&ht->nelems);
 
-	/* Only grow the table if no resizing is currently in progress. */
-	if (ht->tbl != ht->future_tbl &&
-	    ht->p.grow_decision && ht->p.grow_decision(ht, tbl->size))
-		schedule_delayed_work(&ht->run_work, 0);
+	rhashtable_wakeup_worker(ht);
 
 	rcu_read_unlock();
 }
@@ -584,10 +594,7 @@ restart:
 
 		spin_unlock_bh(lock);
 
-		if (ht->tbl != ht->future_tbl &&
-		    ht->p.shrink_decision &&
-		    ht->p.shrink_decision(ht, tbl->size))
-			schedule_delayed_work(&ht->run_work, 0);
+		rhashtable_wakeup_worker(ht);
 
 		rcu_read_unlock();
 
-- 
1.7.9.5


------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net

  parent reply	other threads:[~2015-01-07  5:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-07  5:41 [PATCH net-next v2 0/7] Involve rhashtable_lookup_insert routine Ying Xue
2015-01-07  5:41 ` [PATCH net-next v2 1/7] rhashtable: optimize rhashtable_lookup routine Ying Xue
2015-01-07  5:41 ` Ying Xue [this message]
2015-01-07  9:34   ` [PATCH net-next v2 2/7] rhashtable: introduce rhashtable_wakeup_worker helper function Thomas Graf
2015-01-07  5:41 ` [PATCH net-next v2 3/7] rhashtable: involve rhashtable_lookup_insert routine Ying Xue
2015-01-07  5:41 ` [PATCH net-next v2 4/7] rhashtable: future table needs to be traversed when remove an object Ying Xue
2015-01-07  9:39   ` Thomas Graf
2015-01-07  5:41 ` [PATCH net-next v2 5/7] rhashtable: avoid unnecessary wakeup for worker queue Ying Xue
2015-01-07  9:50   ` Thomas Graf
2015-01-07 10:28     ` Ying Xue
2015-01-07  5:41 ` [PATCH net-next v2 6/7] rhashtable: initialize atomic nelems variable Ying Xue
2015-01-07  9:53   ` Thomas Graf
2015-01-07 10:26     ` Ying Xue
2015-01-07 10:36       ` Thomas Graf
2015-01-07  5:41 ` [PATCH net-next v2 7/7] tipc: convert tipc reference table to use generic rhashtable Ying Xue
2015-01-07  9:54 ` [PATCH net-next v2 0/7] Involve rhashtable_lookup_insert routine Thomas Graf
2015-01-09  3:48 ` David Miller

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=1420609318-3261-3-git-send-email-ying.xue@windriver.com \
    --to=ying.xue@windriver.com \
    --cc=Paul.Gortmaker@windriver.com \
    --cc=davem@davemloft.net \
    --cc=jon.maloy@ericsson.com \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    --cc=tipc-discussion@lists.sourceforge.net \
    /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).