int sectors;
        int best_good_sectors;
        int best_disk, best_dist_disk, best_pending_disk;
-       int has_nonrot_disk;
        int disk;
        sector_t best_dist;
        unsigned int min_pending;
        best_pending_disk = -1;
        min_pending = UINT_MAX;
        best_good_sectors = 0;
-       has_nonrot_disk = 0;
        choose_next_idle = 0;
        clear_bit(R1BIO_FailFast, &r1_bio->state);
 
                sector_t first_bad;
                int bad_sectors;
                unsigned int pending;
-               bool nonrot;
 
                rdev = conf->mirrors[disk].rdev;
                if (r1_bio->bios[disk] == IO_BLOCKED
                        /* At least two disks to choose from so failfast is OK */
                        set_bit(R1BIO_FailFast, &r1_bio->state);
 
-               nonrot = bdev_nonrot(rdev->bdev);
-               has_nonrot_disk |= nonrot;
                pending = atomic_read(&rdev->nr_pending);
                dist = abs(this_sector - conf->mirrors[disk].head_position);
                if (choose_first) {
                         * small, but not a big deal since when the second disk
                         * starts IO, the first disk is likely still busy.
                         */
-                       if (nonrot && opt_iosize > 0 &&
+                       if (test_bit(Nonrot, &rdev->flags) && opt_iosize > 0 &&
                            mirror->seq_start != MaxSector &&
                            mirror->next_seq_sect > opt_iosize &&
                            mirror->next_seq_sect - opt_iosize >=
         * mixed ratation/non-rotational disks depending on workload.
         */
        if (best_disk == -1) {
-               if (has_nonrot_disk || min_pending == 0)
+               if (READ_ONCE(conf->nonrot_disks) || min_pending == 0)
                        best_disk = best_pending_disk;
                else
                        best_disk = best_dist_disk;
        if (info->rdev)
                return false;
 
+       if (bdev_nonrot(rdev->bdev)) {
+               set_bit(Nonrot, &rdev->flags);
+               WRITE_ONCE(conf->nonrot_disks, conf->nonrot_disks + 1);
+       }
+
        rdev->raid_disk = disk;
        info->head_position = 0;
        info->seq_start = MaxSector;
            rdev->mddev->degraded < conf->raid_disks)
                return false;
 
+       if (test_and_clear_bit(Nonrot, &rdev->flags))
+               WRITE_ONCE(conf->nonrot_disks, conf->nonrot_disks - 1);
+
        WRITE_ONCE(info->rdev, NULL);
        return true;
 }