linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>, linux-raid@vger.kernel.org
Subject: Re: Pointer compare in md driver
Date: Tue, 31 Oct 2017 12:03:56 +1100	[thread overview]
Message-ID: <87efpkw2kj.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <0D106300-EF8D-45D0-9F7B-392FD9D8E824@mails.ucas.ac.cn>

[-- Attachment #1: Type: text/plain, Size: 2358 bytes --]

On Tue, Oct 31 2017, wuzhouhui wrote:

> Hi,
>
> Sorry for disturbing, but I have consider this problem for several days.
> I have a question when reading md driver. Following is the code from
> linux/drivers/md/md.c, function md_do_sync():
>
>>                for_each_mddev(mddev2, tmp) {
>>                        if (mddev2 == mddev)
>>                                continue;
>>                        if (!mddev->parallel_resync
>>                        &&  mddev2->curr_resync
>>                        &&  match_mddev_units(mddev, mddev2)) {
>>                                DEFINE_WAIT(wq);
>>                                if (mddev < mddev2 && mddev->curr_resync == 2) {
>>                                        /* arbitrarily yield */
>>                                        mddev->curr_resync = 1;
>>                                        wake_up(&resync_wait);
>>                                }
>>                                if (mddev > mddev2 && mddev->curr_resync == 1)
>>                                        /* no need to wait here, we can wait the next
>>                                         * time 'round when curr_resync == 2
>>                                         */
>>                                        continue;
>>                                /* We need to wait 'interruptible' so as not to
>
> The type of mddev2 and mddev both are struct mddev *, so what's the
> meaning of comparing these two variables?

The ordering of the pointers provides an arbitrary ordering on different
md arrays.
If two arrays need to resync, and they share some devices (e.g. one uses
sda1, sdb1, sdc, and the other uses sda2, sdb2, sdc2, so both arrays use
the devices sda, sdb, and sdc), then the default policy is that only one
gets to resync at a time, the other one has to wait.
If one tries to start resyncing, and the other isn't resyncing, then it
can just go ahead and resync.  If one tries to start resyncing and the
other is already resyncing, then the new one needs to wait.
But what happens if both try to start at much the same time?
If an array is trying to start resync, and it notices that another array
that it shares devices with is also trying to start resync, then the one
with the larger value of the mddev pointer gets to go first.  The one
with the smaller value waits.

Hope that helps,
NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

      reply	other threads:[~2017-10-31  1:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-30 23:55 Pointer compare in md driver wuzhouhui
2017-10-31  1:03 ` NeilBrown [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=87efpkw2kj.fsf@notabene.neil.brown.name \
    --to=neilb@suse.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=wuzhouhui14@mails.ucas.ac.cn \
    /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).