raid5: relieve lock contention in get_active_stripe()
authorShaohua Li <shli@kernel.org>
Thu, 14 Nov 2013 04:16:17 +0000 (15:16 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 19 Nov 2013 04:18:22 +0000 (15:18 +1100)
track empty inactive list count, so md_raid5_congested() can use it to make
decision.

Signed-off-by: Shaohua Li <shli@fusionio.com>
Signed-off-by: NeilBrown <neilb@suse.de>
drivers/md/raid5.c
drivers/md/raid5.h

index 93090b2afab482afcf83b32322188ab8b141c340..1fb28c56457a22a22219a5f13009055453db01ce 100644 (file)
@@ -356,6 +356,9 @@ static void release_inactive_stripe_list(struct r5conf *conf,
                 */
                if (!list_empty_careful(list)) {
                        spin_lock_irqsave(conf->hash_locks + hash, flags);
+                       if (list_empty(conf->inactive_list + hash) &&
+                           !list_empty(list))
+                               atomic_dec(&conf->empty_inactive_list_nr);
                        list_splice_tail_init(list, conf->inactive_list + hash);
                        do_wakeup = true;
                        spin_unlock_irqrestore(conf->hash_locks + hash, flags);
@@ -477,6 +480,8 @@ static struct stripe_head *get_free_stripe(struct r5conf *conf, int hash)
        remove_hash(sh);
        atomic_inc(&conf->active_stripes);
        BUG_ON(hash != sh->hash_lock_index);
+       if (list_empty(conf->inactive_list + hash))
+               atomic_inc(&conf->empty_inactive_list_nr);
 out:
        return sh;
 }
@@ -4059,7 +4064,7 @@ int md_raid5_congested(struct mddev *mddev, int bits)
                return 1;
        if (conf->quiesce)
                return 1;
-       if (atomic_read(&conf->active_stripes) == conf->max_nr_stripes)
+       if (atomic_read(&conf->empty_inactive_list_nr))
                return 1;
 
        return 0;
@@ -5750,6 +5755,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
 
        memory = conf->max_nr_stripes * (sizeof(struct stripe_head) +
                 max_disks * ((sizeof(struct bio) + PAGE_SIZE))) / 1024;
+       atomic_set(&conf->empty_inactive_list_nr, NR_STRIPE_HASH_LOCKS);
        if (grow_stripes(conf, NR_STRIPES)) {
                printk(KERN_ERR
                       "md/raid:%s: couldn't allocate %dkB for buffers\n",
index a9e443a1116f193182c4f7e903f07c7609522fbf..e4407388670a53dc2da94dfdadd3d9cd2188f332 100644 (file)
@@ -475,6 +475,7 @@ struct r5conf {
         */
        atomic_t                active_stripes;
        struct list_head        inactive_list[NR_STRIPE_HASH_LOCKS];
+       atomic_t                empty_inactive_list_nr;
        struct llist_head       released_stripes;
        wait_queue_head_t       wait_for_stripe;
        wait_queue_head_t       wait_for_overlap;