Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: mathieu.desnoyers@efficios.com (Mathieu Desnoyers)
Subject: [ltt-dev] [PATCH 4/6] rculfhash: Change lazy shrink strategy
Date: Wed, 2 Nov 2011 11:27:33 -0400	[thread overview]
Message-ID: <20111102152733.GD29567@Krystal> (raw)
In-Reply-To: <23191cb487d53146a79f0fae67cfaa6287d5ab1c.1320051657.git.laijs@cn.fujitsu.com>

merged as:

commit 89bb121d8cea974a8b6927499d917620236b7fee
Author: Lai Jiangshan <laijs at cn.fujitsu.com>
Date:   Wed Nov 2 11:31:14 2011 -0400

    rculfhash: Change lazy shrink strategy
    
    We can aggressively grow a ht,
    but we should conservatively shrink a ht.
    
    When we try to shrink the ht after a deletion,
    but if a growing is required after it, we should
    stop this shrink.
    
    But it is more complicated to implement it, so we use more
    conservative strategy to shrink a ht to gain simple code:
    
    We stop to (lazy) shrink when we found growing is
    in progress.
    
    [ Edit by Mathieu Desnoyers: Add documentation, cleanup. ]
    
    Signed-off-by: Lai Jiangshan <laijs at cn.fujitsu.com>
    Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>

diff --git a/rculfhash.c b/rculfhash.c
index ce7197a..600feec 100644
--- a/rculfhash.c
+++ b/rculfhash.c
@@ -1827,13 +1827,36 @@ void cds_lfht_resize_lazy_grow(struct cds_lfht *ht, unsigned long size, int grow
 	__cds_lfht_resize_lazy_launch(ht);
 }
 
+/*
+ * We favor grow operations over shrink. A shrink operation never occurs
+ * if a grow operation is queued for lazy execution. A grow operation
+ * cancels any pending shrink lazy execution.
+ */
 static
 void cds_lfht_resize_lazy_count(struct cds_lfht *ht, unsigned long size,
 				unsigned long count)
 {
 	if (!(ht->flags & CDS_LFHT_AUTO_RESIZE))
 		return;
-
-	resize_target_update_count(ht, count);
+	count = max(count, ht->min_alloc_size);
+	if (count == size)
+		return;		/* Already the right size, no resize needed */
+	if (count > size) {	/* lazy grow */
+		if (resize_target_grow(ht, count) >= count)
+			return;
+	} else {		/* lazy shrink */
+		for (;;) {
+			unsigned long s;
+
+			s = uatomic_cmpxchg(&ht->t.resize_target, size, count);
+			if (s == size)
+				break;	/* no resize needed */
+			if (s > size)
+				return;	/* growing is/(was just) in progress */
+			if (s <= count)
+				return;	/* some other thread do shrink */
+			size = s;
+		}
+	}
 	__cds_lfht_resize_lazy_launch(ht);
 }

-- 
Mathieu Desnoyers
Operating System Efficiency R&D Consultant
EfficiOS Inc.
http://www.efficios.com




      parent reply	other threads:[~2011-11-02 15:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1320051657.git.laijs@cn.fujitsu.com>
     [not found] ` <e790679beb8d966aa5dfc8205aaf844aee1546de.1320051657.git.laijs@cn.fujitsu.com>
2011-11-01 16:49   ` [ltt-dev] [PATCH 1/6] rculfhash: Fix ht allocation bug Mathieu Desnoyers
     [not found] ` <1e66797f29e51b31e9f3b56dad65ac03651df526.1320051657.git.laijs@cn.fujitsu.com>
2011-11-01 17:00   ` [ltt-dev] [PATCH 2/6] rculfhash: Fix ht lazy grow logic Mathieu Desnoyers
2011-11-02  1:42     ` Lai Jiangshan
2011-11-02 15:13       ` Mathieu Desnoyers
2011-11-02 15:15   ` Mathieu Desnoyers
     [not found] ` <a7d9cb37f37875bec47413d43274037be105bcf6.1320051657.git.laijs@cn.fujitsu.com>
2011-11-01 17:04   ` [ltt-dev] [PATCH 6/6] rculfhash: add min_alloc_size test parameter Mathieu Desnoyers
     [not found] ` <bbea95bb9f3203390b69539a5801e1aff0eba3bc.1320051657.git.laijs@cn.fujitsu.com>
2011-11-01 17:06   ` [ltt-dev] [PATCH 3/6] rculfhash: merge duplicated code of cds_lfht_resize_lazy_*() Mathieu Desnoyers
2011-11-02 15:17   ` Mathieu Desnoyers
     [not found] ` <23191cb487d53146a79f0fae67cfaa6287d5ab1c.1320051657.git.laijs@cn.fujitsu.com>
2011-11-01 17:08   ` [ltt-dev] [PATCH 4/6] rculfhash: Change lazy shrink strategy Mathieu Desnoyers
2011-11-02  8:18     ` Lai Jiangshan
2011-11-02 15:27   ` Mathieu Desnoyers [this message]

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=20111102152733.GD29567@Krystal \
    --to=mathieu.desnoyers@efficios.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox