@@ -541,11 +541,18 @@ static void dm_start_io_acct(struct dm_io *io, struct bio *clone)
541541 * Expect no possibility for race unless is_duplicate_bio.
542542 */
543543 if (!clone || likely (!clone_to_tio (clone )-> is_duplicate_bio )) {
544- if (WARN_ON_ONCE (io -> was_accounted ))
544+ if (WARN_ON_ONCE (dm_io_flagged ( io , DM_IO_ACCOUNTED ) ))
545545 return ;
546- io -> was_accounted = 1 ;
547- } else if (xchg (& io -> was_accounted , 1 ) == 1 )
548- return ;
546+ dm_io_set_flag (io , DM_IO_ACCOUNTED );
547+ } else {
548+ unsigned long flags ;
549+ if (dm_io_flagged (io , DM_IO_ACCOUNTED ))
550+ return ;
551+ /* Can afford locking given is_duplicate_bio */
552+ spin_lock_irqsave (& io -> startio_lock , flags );
553+ dm_io_set_flag (io , DM_IO_ACCOUNTED );
554+ spin_unlock_irqrestore (& io -> startio_lock , flags );
555+ }
549556
550557 __dm_start_io_acct (io , bio );
551558}
@@ -575,11 +582,10 @@ static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio)
575582 io -> orig_bio = NULL ;
576583 io -> md = md ;
577584 io -> map_task = current ;
585+ spin_lock_init (& io -> startio_lock );
578586 spin_lock_init (& io -> endio_lock );
579-
580587 io -> start_time = jiffies ;
581- io -> start_io_acct = false;
582- io -> was_accounted = 0 ;
588+ io -> flags = 0 ;
583589
584590 dm_stats_record_start (& md -> stats , & io -> stats_aux );
585591
@@ -868,7 +874,7 @@ static void dm_io_complete(struct dm_io *io)
868874 }
869875
870876 io_error = io -> status ;
871- if (io -> was_accounted )
877+ if (dm_io_flagged ( io , DM_IO_ACCOUNTED ) )
872878 dm_end_io_acct (io , bio );
873879 else if (!io_error ) {
874880 /*
@@ -1218,7 +1224,7 @@ void dm_submit_bio_remap(struct bio *clone, struct bio *tgt_clone)
12181224 */
12191225 if (io -> map_task == current ) {
12201226 /* Still in target's map function */
1221- io -> start_io_acct = true ;
1227+ dm_io_set_flag ( io , DM_IO_START_ACCT ) ;
12221228 } else {
12231229 /*
12241230 * Called by another thread, managed by DM target,
@@ -1288,7 +1294,7 @@ static void __map_bio(struct bio *clone)
12881294 case DM_MAPIO_SUBMITTED :
12891295 /* target has assumed ownership of this io */
12901296 if (!ti -> accounts_remapped_io )
1291- io -> start_io_acct = true ;
1297+ dm_io_set_flag ( io , DM_IO_START_ACCT ) ;
12921298 break ;
12931299 case DM_MAPIO_REMAPPED :
12941300 /*
@@ -1297,7 +1303,7 @@ static void __map_bio(struct bio *clone)
12971303 */
12981304 __dm_submit_bio_remap (clone , disk_devt (io -> md -> disk ),
12991305 tio -> old_sector );
1300- io -> start_io_acct = true ;
1306+ dm_io_set_flag ( io , DM_IO_START_ACCT ) ;
13011307 break ;
13021308 case DM_MAPIO_KILL :
13031309 case DM_MAPIO_REQUEUE :
@@ -1591,7 +1597,7 @@ static void dm_split_and_process_bio(struct mapped_device *md,
15911597 if (!orig_bio )
15921598 orig_bio = bio ;
15931599 smp_store_release (& ci .io -> orig_bio , orig_bio );
1594- if (ci .io -> start_io_acct )
1600+ if (dm_io_flagged ( ci .io , DM_IO_START_ACCT ) )
15951601 dm_start_io_acct (ci .io , NULL );
15961602
15971603 /*
0 commit comments