All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Graf <tgraf@suug.ch>
To: davem@davemloft.net, kaber@trash.net,
	herbert@gondor.apana.org.au, paulmck@linux.vnet.ibm.com,
	ying.xue@windriver.com
Cc: netdev@vger.kernel.org, netfilter-devel@vger.kernel.org
Subject: [PATCH 1/3] rhashtable: Provide notifier for deferred resizes
Date: Tue, 20 Jan 2015 14:20:25 +0100	[thread overview]
Message-ID: <1a7fba3c718fb70f0f5d67c9c49e4c154ebcd915.1421759056.git.tgraf@suug.ch> (raw)
In-Reply-To: <cover.1421759056.git.tgraf@suug.ch>
In-Reply-To: <cover.1421759056.git.tgraf@suug.ch>

Allowing users of rhashtable to bump a sequence counter and invalidate
Netlink dumps which have been interrupted by a deferred resize.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
---
 include/linux/rhashtable.h | 10 +++++++++-
 lib/rhashtable.c           | 13 ++++++++++---
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index a2562ed..b711d16 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -1,7 +1,7 @@
 /*
  * Resizable, Scalable, Concurrent Hash Table
  *
- * Copyright (c) 2014 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2014-2015 Thomas Graf <tgraf@suug.ch>
  * Copyright (c) 2008-2014 Patrick McHardy <kaber@trash.net>
  *
  * Based on the following paper by Josh Triplett, Paul E. McKenney
@@ -64,6 +64,11 @@ typedef u32 (*rht_obj_hashfn_t)(const void *data, u32 seed);
 
 struct rhashtable;
 
+enum rht_resize_op {
+	RHT_GROWING,
+	RHT_SHRINKING,
+};
+
 /**
  * struct rhashtable_params - Hash table construction parameters
  * @nelem_hint: Hint on number of elements, should be 75% of desired size
@@ -79,6 +84,7 @@ struct rhashtable;
  * @obj_hashfn: Function to hash object
  * @grow_decision: If defined, may return true if table should expand
  * @shrink_decision: If defined, may return true if table should shrink
+ * @resize_notify: Called when a table resize is scheduled.
  *
  * Note: when implementing the grow and shrink decision function, min/max
  * shift must be enforced, otherwise, resizing watermarks they set may be
@@ -100,6 +106,8 @@ struct rhashtable_params {
 						 size_t new_size);
 	bool			(*shrink_decision)(const struct rhashtable *ht,
 						   size_t new_size);
+	void			(*resize_notify)(const struct rhashtable *ht,
+						 enum rht_resize_op op);
 };
 
 /**
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 84a78e3..a4449c4 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -1,7 +1,7 @@
 /*
  * Resizable, Scalable, Concurrent Hash Table
  *
- * Copyright (c) 2014 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2014-2015 Thomas Graf <tgraf@suug.ch>
  * Copyright (c) 2008-2014 Patrick McHardy <kaber@trash.net>
  *
  * Based on the following paper:
@@ -489,10 +489,17 @@ static void rht_deferred_worker(struct work_struct *work)
 	mutex_lock(&ht->mutex);
 	tbl = rht_dereference(ht->tbl, ht);
 
-	if (ht->p.grow_decision && ht->p.grow_decision(ht, tbl->size))
+	if (ht->p.grow_decision && ht->p.grow_decision(ht, tbl->size)) {
+		if (ht->p.resize_notify)
+			ht->p.resize_notify(ht, RHT_GROWING);
+
 		rhashtable_expand(ht);
-	else if (ht->p.shrink_decision && ht->p.shrink_decision(ht, tbl->size))
+	} else if (ht->p.shrink_decision && ht->p.shrink_decision(ht, tbl->size)) {
+		if (ht->p.resize_notify)
+			ht->p.resize_notify(ht, RHT_SHRINKING);
+
 		rhashtable_shrink(ht);
+	}
 
 	mutex_unlock(&ht->mutex);
 }
-- 
1.9.3

  reply	other threads:[~2015-01-20 13:20 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-20 13:20 [PATCH 0/3 net-next] rhashtable: Notify on resize to allow signaling interrupted dumps Thomas Graf
2015-01-20 13:20 ` Thomas Graf [this message]
2015-01-20 13:20 ` [PATCH 2/3] netlink: Mark dumps as inconsistent which have been interrupted by a resize Thomas Graf
2015-01-21  8:13   ` Ying Xue
2015-01-21 12:17     ` Thomas Graf
2015-01-22  8:49       ` Herbert Xu
2015-01-22  8:56         ` Patrick McHardy
2015-01-22  9:22           ` Herbert Xu
2015-01-22 10:07             ` Patrick McHardy
2015-01-25 23:20         ` [PATCH 0/2] rhashtable: Add walk iterator primitives and use them in netlink Herbert Xu
2015-01-25 23:21           ` [PATCH 1/2] rhashtable: Introduce rhashtable_walk_* Herbert Xu
2015-01-26  8:20             ` Thomas Graf
2015-01-26 22:21               ` Herbert Xu
2015-01-26 10:09             ` David Laight
2015-01-26 22:23               ` Herbert Xu
2015-01-26 22:36                 ` David Miller
2015-01-26 22:42                   ` Herbert Xu
2015-01-26 23:31                     ` Herbert Xu
2015-01-27  9:45                       ` Thomas Graf
2015-01-27  9:54                         ` Herbert Xu
2015-01-27 10:15                           ` Thomas Graf
2015-01-27 10:24                             ` Herbert Xu
2015-01-27 11:16                               ` Thomas Graf
2015-01-27 11:23                                 ` Herbert Xu
2015-01-27 11:40                                   ` Thomas Graf
2015-01-27 20:39                                     ` Herbert Xu
2015-01-27 22:10                                       ` David Miller
2015-01-27 23:16                                         ` Herbert Xu
2015-01-27 13:09                                   ` Patrick McHardy
2015-01-27 20:36                                     ` Herbert Xu
2015-01-28 19:07                                       ` Patrick McHardy
2015-01-30  5:58                                         ` Herbert Xu
2015-01-30  8:10                                           ` Patrick McHardy
2015-01-27 10:09                 ` David Laight
2015-01-27 10:12                   ` Herbert Xu
2015-01-25 23:21           ` [PATCH 2/2] netlink: Use rhashtable walk iterator Herbert Xu
2015-01-27 23:19           ` [PATCH 0/2] rhashtable: Add walk iterator primitives and use them in netlink Herbert Xu
2015-01-27 23:20             ` [PATCH 1/2] rhashtable: Introduce rhashtable_walk_* Herbert Xu
2015-01-29 22:26               ` Thomas Graf
2015-01-27 23:20             ` [PATCH 2/2] netlink: Use rhashtable walk iterator Herbert Xu
2015-01-29 22:27               ` Thomas Graf
2015-01-29 22:42             ` [PATCH 0/2] rhashtable: Add walk iterator primitives and use them in netlink David Miller
2015-01-31  3:13               ` Herbert Xu
2015-01-31  3:14                 ` [PATCH 1/2] rhashtable: Introduce rhashtable_walk_* Herbert Xu
2015-01-31  3:14                 ` [PATCH 2/2] netlink: Use rhashtable walk iterator Herbert Xu
2015-01-31  4:31                 ` netfilter: " Herbert Xu
2015-02-01  7:45                   ` Patrick McHardy
2015-02-03  3:19                   ` David Miller
2015-02-03  3:19                 ` [PATCH 0/2] rhashtable: Add walk iterator primitives and use them in netlink David Miller
2015-01-20 13:20 ` [PATCH 3/3] netlink: Lock out table resizes while dumping Netlink sockets Thomas Graf
2015-01-20 14:31   ` Patrick McHardy
2015-01-20 14:55     ` Thomas Graf
2015-01-20 15:21       ` Patrick McHardy
2015-01-20 15:35         ` Thomas Graf
2015-01-21  5:08           ` Herbert Xu
2015-01-21  5:15             ` Herbert Xu
2015-01-21  9:14               ` Herbert Xu
2015-01-21  9:56                 ` Thomas Graf
2015-01-21  9:59                   ` Herbert Xu
2015-01-21 10:00                   ` Patrick McHardy
2015-01-21  9:37             ` Thomas Graf
2015-01-21  9:38               ` Herbert Xu
2015-01-21  9:49                 ` Thomas Graf
2015-01-21  9:58                   ` Herbert Xu
2015-01-21 10:23                     ` Thomas Graf
2015-01-22  6:35                       ` Herbert Xu
2015-01-22  7:20                         ` Herbert Xu
2015-01-22  9:05                           ` Thomas Graf
2015-01-22  9:50                             ` Herbert Xu
2015-01-21 10:34                     ` Thomas Graf
2015-01-21 10:40                       ` Patrick McHardy
2015-01-21 11:37                         ` Thomas Graf
2015-01-21 11:59                           ` Patrick McHardy
2015-01-21 12:07                             ` Thomas Graf
2015-01-21 12:09                               ` Patrick McHardy
2015-01-21 10:36               ` David Laight
2015-01-20 15:00     ` David Laight
2015-01-20 15:05       ` Thomas Graf
2015-01-21  5:11     ` Herbert Xu

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=1a7fba3c718fb70f0f5d67c9c49e4c154ebcd915.1421759056.git.tgraf@suug.ch \
    --to=tgraf@suug.ch \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kaber@trash.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=ying.xue@windriver.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.