All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Thornber <thornber@redhat.com>
To: device-mapper development <dm-devel@redhat.com>
Subject: Re: Possible BUG in the entry removal process of dm-btree structure
Date: Mon, 18 May 2015 13:51:53 +0100	[thread overview]
Message-ID: <20150518125152.GA10459@rh-vpn> (raw)
In-Reply-To: <CAKTMprNmf7KKAPMj0CFj32y+0OpYJPiqQTbiQiuUAiteJiQeEg@mail.gmail.com>

On Mon, May 18, 2015 at 03:21:52PM +0800, Dennis Yang wrote:
> Hi,
> 
> Recently, I had run into the same dm-btree-remove bug reported before
> in this mailing list.

Hi Dennis,

You diagnosis looks correct, though I think your patch introduces
entry reordering.

> In dm-btree-remove.c, there is a redistribute3() function which is
> called when we try to rebalance the entry of three nodes with their
> total entry count is higher than a defined threshold. I paste the code
> below for further discussion.
> 
> target = (nr_left + nr_center + nr_right) / 3;
> if (nr_left < nr_right) {
>     s = nr_left - target;
> 
>     if (s < 0 && nr_center < -s) {
>         /* not enough in central node */
>         shift(left, center, nr_center);
>         s = nr_center - target;
>         shift(left, right, s);
>         nr_right += s;
>     } else
>         shift(left, center, s);
> 
>     shift(center, right, target - nr_right);
> } else {
> 
> If the entry count of left node is smaller than target and the entry
> count of center node is not enough to cover this gap, I think what we
> try to do here is to move all the entries in the center node to the
> left node first, then move some entries from the right node to the
> left one to make its entry count equals to target. However, since
> nr_center is always positive, the code above will first move up to
> nr_center entries from the left node to the center node.

Yep, this is a bug, it should be -nr_center.

> To fix this issue, I think we should stick with the plan that move all
> the entries from center node to left/right node first, and then make
> it up to target entries by moving them from right/left node to it. I
> have attached a simple patch to demonstrate the idea here.
> 
> diff --git a/linux-3.12.6/drivers/md/persistent-data/dm-btree-remove.c
> b/linux-3.12.6/drivers/md/persistent-data/dm-btree-remove.c
> index b88757c..9026fb8 100644
> --- a/linux-3.12.6/drivers/md/persistent-data/dm-btree-remove.c
> +++ b/linux-3.12.6/drivers/md/persistent-data/dm-btree-remove.c
> @@ -309,8 +309,9 @@ static void redistribute3(struct dm_btree_info
> *info, struct btree_node *parent,
> 
>           if (s < 0 && nr_center < -s) {
>           /* not enough in central node */
> -             shift(left, center, nr_center);
> -             s = nr_center - target;
> +            shift(center, left, nr_center);

You can't put the nodes out of order, what you actually want to do is:
shift(left, center, -nr_center).  Other than that your patch looks
good.  Updated patch below.

Thanks,

- Joe


diff --git a/drivers/md/persistent-data/dm-btree-remove.c b/drivers/md/persistent-data/dm-btree-remove.c
index e04cfd2..9836c0a 100644
--- a/drivers/md/persistent-data/dm-btree-remove.c
+++ b/drivers/md/persistent-data/dm-btree-remove.c
@@ -309,8 +309,8 @@ static void redistribute3(struct dm_btree_info *info, struct btree_node *parent,
 
                if (s < 0 && nr_center < -s) {
                        /* not enough in central node */
-                       shift(left, center, nr_center);
-                       s = nr_center - target;
+                       shift(left, center, -nr_center);
+                       s += nr_center;
                        shift(left, right, s);
                        nr_right += s;
                } else
@@ -323,7 +323,7 @@ static void redistribute3(struct dm_btree_info *info, struct btree_node *parent,
                if (s > 0 && nr_center < s) {
                        /* not enough in central node */
                        shift(center, right, nr_center);
-                       s = target - nr_center;
+                       s -= nr_center;
                        shift(left, right, s);
                        nr_left -= s;
                } else

      reply	other threads:[~2015-05-18 12:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-18  7:21 Possible BUG in the entry removal process of dm-btree structure Dennis Yang
2015-05-18 12:51 ` Joe Thornber [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=20150518125152.GA10459@rh-vpn \
    --to=thornber@redhat.com \
    --cc=dm-devel@redhat.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.