@@ -646,25 +646,30 @@ static void free_tio(struct dm_target_io *tio)
646646 bio_put (& tio -> clone );
647647}
648648
649- int md_in_flight (struct mapped_device * md )
649+ static bool md_in_flight (struct mapped_device * md )
650650{
651- return atomic_read (& md -> pending [READ ]) +
652- atomic_read (& md -> pending [WRITE ]);
651+ int cpu ;
652+ struct hd_struct * part = & dm_disk (md )-> part0 ;
653+
654+ for_each_possible_cpu (cpu ) {
655+ if (part_stat_local_read_cpu (part , in_flight [0 ], cpu ) ||
656+ part_stat_local_read_cpu (part , in_flight [1 ], cpu ))
657+ return true;
658+ }
659+
660+ return false;
653661}
654662
655663static void start_io_acct (struct dm_io * io )
656664{
657665 struct mapped_device * md = io -> md ;
658666 struct bio * bio = io -> orig_bio ;
659- int rw = bio_data_dir (bio );
660667
661668 io -> start_time = jiffies ;
662669
663670 generic_start_io_acct (md -> queue , bio_op (bio ), bio_sectors (bio ),
664671 & dm_disk (md )-> part0 );
665672
666- atomic_inc (& md -> pending [rw ]);
667-
668673 if (unlikely (dm_stats_used (& md -> stats )))
669674 dm_stats_account_io (& md -> stats , bio_data_dir (bio ),
670675 bio -> bi_iter .bi_sector , bio_sectors (bio ),
@@ -676,8 +681,6 @@ static void end_io_acct(struct dm_io *io)
676681 struct mapped_device * md = io -> md ;
677682 struct bio * bio = io -> orig_bio ;
678683 unsigned long duration = jiffies - io -> start_time ;
679- int pending ;
680- int rw = bio_data_dir (bio );
681684
682685 generic_end_io_acct (md -> queue , bio_op (bio ), & dm_disk (md )-> part0 ,
683686 io -> start_time );
@@ -687,16 +690,11 @@ static void end_io_acct(struct dm_io *io)
687690 bio -> bi_iter .bi_sector , bio_sectors (bio ),
688691 true, duration , & io -> stats_aux );
689692
690- /*
691- * After this is decremented the bio must not be touched if it is
692- * a flush.
693- */
694- pending = atomic_dec_return (& md -> pending [rw ]);
695- pending += atomic_read (& md -> pending [rw ^0x1 ]);
696-
697693 /* nudge anyone waiting on suspend queue */
698- if (!pending )
699- wake_up (& md -> wait );
694+ if (unlikely (waitqueue_active (& md -> wait ))) {
695+ if (!md_in_flight (md ))
696+ wake_up (& md -> wait );
697+ }
700698}
701699
702700/*
@@ -1915,8 +1913,6 @@ static struct mapped_device *alloc_dev(int minor)
19151913 if (!md -> disk )
19161914 goto bad ;
19171915
1918- atomic_set (& md -> pending [0 ], 0 );
1919- atomic_set (& md -> pending [1 ], 0 );
19201916 init_waitqueue_head (& md -> wait );
19211917 INIT_WORK (& md -> work , dm_wq_work );
19221918 init_waitqueue_head (& md -> eventq );
0 commit comments