Skip to content

Commit 1084e41

Browse files
damien-lemoalaxboe
authored andcommitted
block: rename and simplify disk_get_and_lock_zone_wplug()
disk_get_and_lock_zone_wplug() always returns a zone write plug with the plug lock held. This is unnecessary since this function does not look at the fields of existing plugs, and new plugs need to be locked only after their insertion in the disk hash table, when they are being used. Remove the zone write plug locking from disk_get_and_lock_zone_wplug() and rename this function disk_get_or_alloc_zone_wplug(). blk_zone_wplug_handle_write() is modified to add locking of the zone write plug after calling disk_get_or_alloc_zone_wplug() and before starting to use the plug. This change also simplifies blk_revalidate_seq_zone() as unlocking the plug becomes unnecessary. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 0a8b8af commit 1084e41

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

block/blk-zoned.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -631,23 +631,20 @@ static void disk_mark_zone_wplug_dead(struct blk_zone_wplug *zwplug)
631631
static void blk_zone_wplug_bio_work(struct work_struct *work);
632632

633633
/*
634-
* Get a reference on the write plug for the zone containing @sector.
635-
* If the plug does not exist, it is allocated and hashed.
636-
* Return a pointer to the zone write plug with the plug spinlock held.
634+
* Get a zone write plug for the zone containing @sector.
635+
* If the plug does not exist, it is allocated and inserted in the disk hash
636+
* table.
637637
*/
638-
static struct blk_zone_wplug *disk_get_and_lock_zone_wplug(struct gendisk *disk,
639-
sector_t sector, gfp_t gfp_mask,
640-
unsigned long *flags)
638+
static struct blk_zone_wplug *disk_get_or_alloc_zone_wplug(struct gendisk *disk,
639+
sector_t sector, gfp_t gfp_mask)
641640
{
642641
unsigned int zno = disk_zone_no(disk, sector);
643642
struct blk_zone_wplug *zwplug;
644643

645644
again:
646645
zwplug = disk_get_zone_wplug(disk, sector);
647-
if (zwplug) {
648-
spin_lock_irqsave(&zwplug->lock, *flags);
646+
if (zwplug)
649647
return zwplug;
650-
}
651648

652649
/*
653650
* Allocate and initialize a zone write plug with an extra reference
@@ -668,15 +665,12 @@ static struct blk_zone_wplug *disk_get_and_lock_zone_wplug(struct gendisk *disk,
668665
INIT_WORK(&zwplug->bio_work, blk_zone_wplug_bio_work);
669666
zwplug->disk = disk;
670667

671-
spin_lock_irqsave(&zwplug->lock, *flags);
672-
673668
/*
674669
* Insert the new zone write plug in the hash table. This can fail only
675670
* if another context already inserted a plug. Retry from the beginning
676671
* in such case.
677672
*/
678673
if (!disk_insert_zone_wplug(disk, zwplug)) {
679-
spin_unlock_irqrestore(&zwplug->lock, *flags);
680674
mempool_free(zwplug, disk->zone_wplugs_pool);
681675
goto again;
682676
}
@@ -1398,7 +1392,7 @@ static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs)
13981392
if (bio->bi_opf & REQ_NOWAIT)
13991393
gfp_mask = GFP_NOWAIT;
14001394

1401-
zwplug = disk_get_and_lock_zone_wplug(disk, sector, gfp_mask, &flags);
1395+
zwplug = disk_get_or_alloc_zone_wplug(disk, sector, gfp_mask);
14021396
if (!zwplug) {
14031397
if (bio->bi_opf & REQ_NOWAIT)
14041398
bio_wouldblock_error(bio);
@@ -1407,6 +1401,8 @@ static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs)
14071401
return true;
14081402
}
14091403

1404+
spin_lock_irqsave(&zwplug->lock, flags);
1405+
14101406
/*
14111407
* If we got a zone write plug marked as dead, then the user is issuing
14121408
* writes to a full zone, or without synchronizing with zone reset or
@@ -2045,7 +2041,6 @@ static int blk_revalidate_seq_zone(struct blk_zone *zone, unsigned int idx,
20452041
struct gendisk *disk = args->disk;
20462042
struct blk_zone_wplug *zwplug;
20472043
unsigned int wp_offset;
2048-
unsigned long flags;
20492044

20502045
/*
20512046
* Remember the capacity of the first sequential zone and check
@@ -2075,10 +2070,9 @@ static int blk_revalidate_seq_zone(struct blk_zone *zone, unsigned int idx,
20752070
if (!wp_offset || wp_offset >= zone->capacity)
20762071
return 0;
20772072

2078-
zwplug = disk_get_and_lock_zone_wplug(disk, zone->wp, GFP_NOIO, &flags);
2073+
zwplug = disk_get_or_alloc_zone_wplug(disk, zone->wp, GFP_NOIO);
20792074
if (!zwplug)
20802075
return -ENOMEM;
2081-
spin_unlock_irqrestore(&zwplug->lock, flags);
20822076
disk_put_zone_wplug(zwplug);
20832077

20842078
return 0;

0 commit comments

Comments
 (0)