@@ -128,23 +128,27 @@ static void part_stat_read_all(struct block_device *part,
128128static void bdev_count_inflight_rw (struct block_device * part ,
129129 unsigned int inflight [2 ], bool mq_driver )
130130{
131+ int write = 0 ;
132+ int read = 0 ;
131133 int cpu ;
132134
133135 if (mq_driver ) {
134136 blk_mq_in_driver_rw (part , inflight );
135- } else {
136- for_each_possible_cpu (cpu ) {
137- inflight [READ ] += part_stat_local_read_cpu (
138- part , in_flight [READ ], cpu );
139- inflight [WRITE ] += part_stat_local_read_cpu (
140- part , in_flight [WRITE ], cpu );
141- }
137+ return ;
138+ }
139+
140+ for_each_possible_cpu (cpu ) {
141+ read += part_stat_local_read_cpu (part , in_flight [READ ], cpu );
142+ write += part_stat_local_read_cpu (part , in_flight [WRITE ], cpu );
142143 }
143144
144- if (WARN_ON_ONCE ((int )inflight [READ ] < 0 ))
145- inflight [READ ] = 0 ;
146- if (WARN_ON_ONCE ((int )inflight [WRITE ] < 0 ))
147- inflight [WRITE ] = 0 ;
145+ /*
146+ * While iterating all CPUs, some IOs may be issued from a CPU already
147+ * traversed and complete on a CPU that has not yet been traversed,
148+ * causing the inflight number to be negative.
149+ */
150+ inflight [READ ] = read > 0 ? read : 0 ;
151+ inflight [WRITE ] = write > 0 ? write : 0 ;
148152}
149153
150154/**
0 commit comments