All of lore.kernel.org
 help / color / mirror / Atom feed
From: thornber@redhat.com
To: device-mapper development <dm-devel@redhat.com>
Subject: Re: About function bio_detain in file dm-cache-target.c
Date: Tue, 12 Mar 2013 13:23:22 +0000	[thread overview]
Message-ID: <20130312132321.GA6000@raspberrypi> (raw)
In-Reply-To: <513EDD90.6090305@gmail.com>

On Tue, Mar 12, 2013 at 03:47:28PM +0800, majianpeng wrote:
> Hi all,
>     I think bio_detain(in dm-cache-target.c) may cause some bug.

Hi Jianpeng,

I don't really see what you're getting at, but will try and explain
bio_detain a bit.

The bio prison contains a bunch of cells.  When you call bio_detain
the following steps are performed:

    i) look up the cell
    ii) if the cell exists add the bio to that cell
    iii) if there is no cell create it and insert the bio as the holder

It does do more than I'd like a single function to do, but we need
this group of operations to be atomic to avoid race conditions.

Now if you look at cache_map() where bio_detain is used:

        r = bio_detain(cache, block, bio, cell,
                       (cell_free_fn) free_prison_cell,
                       cache, &cell);
        if (r) {
                if (r < 0)
                        defer_bio(cache, bio);

                return DM_MAPIO_SUBMITTED;
        }

We call bio_detain checking the return value, there are 3 cases:

   0 - this bio has been inserted as the holder, we try and process it
       immediately and do not pass it to the worker thread.

   1 - the bio has been inserted into the cell, but it's not the
       holder.  When the holder of that particular cell completes it will
       release all bios in the cell, putting them on the deferred list for
       processing by the worker thread.

   < 0 - we couldn't complete, hand over to the worker thread who has
         a bit more leeway regarding memory allocation etc.

In typical use, a cell is only held while we decide what to do with the
bio (see calls to cell_defer in cache_map).  But sometimes we decide
to move a block from/to the cache, in which case the bio_prison
prevents any io going to that block while the migration is pending.

I hope that helps,

- Joe

      reply	other threads:[~2013-03-12 13:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-12  7:47 About function bio_detain in file dm-cache-target.c majianpeng
2013-03-12 13:23 ` 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=20130312132321.GA6000@raspberrypi \
    --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.