Skip to content

Commit 60484cd

Browse files
adam900710kdave
authored andcommitted
btrfs: subpage: make readahead work properly
In readahead infrastructure, we are using a lot of hard coded PAGE_SHIFT while we're not doing anything specific to PAGE_SIZE. One of the most affected part is the radix tree operation of btrfs_fs_info::reada_tree. If using PAGE_SHIFT, subpage metadata readahead is broken and does no help reading metadata ahead. Fix the problem by using btrfs_fs_info::sectorsize_bits so that readahead could work for subpage. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d9bb77d commit 60484cd

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

fs/btrfs/reada.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ int btree_readahead_hook(struct extent_buffer *eb, int err)
209209
/* find extent */
210210
spin_lock(&fs_info->reada_lock);
211211
re = radix_tree_lookup(&fs_info->reada_tree,
212-
eb->start >> PAGE_SHIFT);
212+
eb->start >> fs_info->sectorsize_bits);
213213
if (re)
214214
re->refcnt++;
215215
spin_unlock(&fs_info->reada_lock);
@@ -240,7 +240,7 @@ static struct reada_zone *reada_find_zone(struct btrfs_device *dev, u64 logical,
240240
zone = NULL;
241241
spin_lock(&fs_info->reada_lock);
242242
ret = radix_tree_gang_lookup(&dev->reada_zones, (void **)&zone,
243-
logical >> PAGE_SHIFT, 1);
243+
logical >> fs_info->sectorsize_bits, 1);
244244
if (ret == 1 && logical >= zone->start && logical <= zone->end) {
245245
kref_get(&zone->refcnt);
246246
spin_unlock(&fs_info->reada_lock);
@@ -283,13 +283,13 @@ static struct reada_zone *reada_find_zone(struct btrfs_device *dev, u64 logical,
283283

284284
spin_lock(&fs_info->reada_lock);
285285
ret = radix_tree_insert(&dev->reada_zones,
286-
(unsigned long)(zone->end >> PAGE_SHIFT),
287-
zone);
286+
(unsigned long)(zone->end >> fs_info->sectorsize_bits),
287+
zone);
288288

289289
if (ret == -EEXIST) {
290290
kfree(zone);
291291
ret = radix_tree_gang_lookup(&dev->reada_zones, (void **)&zone,
292-
logical >> PAGE_SHIFT, 1);
292+
logical >> fs_info->sectorsize_bits, 1);
293293
if (ret == 1 && logical >= zone->start && logical <= zone->end)
294294
kref_get(&zone->refcnt);
295295
else
@@ -315,7 +315,7 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info,
315315
u64 length;
316316
int real_stripes;
317317
int nzones = 0;
318-
unsigned long index = logical >> PAGE_SHIFT;
318+
unsigned long index = logical >> fs_info->sectorsize_bits;
319319
int dev_replace_is_ongoing;
320320
int have_zone = 0;
321321

@@ -497,7 +497,7 @@ static void reada_extent_put(struct btrfs_fs_info *fs_info,
497497
struct reada_extent *re)
498498
{
499499
int i;
500-
unsigned long index = re->logical >> PAGE_SHIFT;
500+
unsigned long index = re->logical >> fs_info->sectorsize_bits;
501501

502502
spin_lock(&fs_info->reada_lock);
503503
if (--re->refcnt) {
@@ -538,11 +538,12 @@ static void reada_extent_put(struct btrfs_fs_info *fs_info,
538538
static void reada_zone_release(struct kref *kref)
539539
{
540540
struct reada_zone *zone = container_of(kref, struct reada_zone, refcnt);
541+
struct btrfs_fs_info *fs_info = zone->device->fs_info;
541542

542-
lockdep_assert_held(&zone->device->fs_info->reada_lock);
543+
lockdep_assert_held(&fs_info->reada_lock);
543544

544545
radix_tree_delete(&zone->device->reada_zones,
545-
zone->end >> PAGE_SHIFT);
546+
zone->end >> fs_info->sectorsize_bits);
546547

547548
kfree(zone);
548549
}
@@ -593,7 +594,7 @@ static int reada_add_block(struct reada_control *rc, u64 logical,
593594
static void reada_peer_zones_set_lock(struct reada_zone *zone, int lock)
594595
{
595596
int i;
596-
unsigned long index = zone->end >> PAGE_SHIFT;
597+
unsigned long index = zone->end >> zone->device->fs_info->sectorsize_bits;
597598

598599
for (i = 0; i < zone->ndevs; ++i) {
599600
struct reada_zone *peer;
@@ -628,7 +629,7 @@ static int reada_pick_zone(struct btrfs_device *dev)
628629
(void **)&zone, index, 1);
629630
if (ret == 0)
630631
break;
631-
index = (zone->end >> PAGE_SHIFT) + 1;
632+
index = (zone->end >> dev->fs_info->sectorsize_bits) + 1;
632633
if (zone->locked) {
633634
if (zone->elems > top_locked_elems) {
634635
top_locked_elems = zone->elems;
@@ -709,7 +710,7 @@ static int reada_start_machine_dev(struct btrfs_device *dev)
709710
* plugging to speed things up
710711
*/
711712
ret = radix_tree_gang_lookup(&dev->reada_extents, (void **)&re,
712-
dev->reada_next >> PAGE_SHIFT, 1);
713+
dev->reada_next >> fs_info->sectorsize_bits, 1);
713714
if (ret == 0 || re->logical > dev->reada_curr_zone->end) {
714715
ret = reada_pick_zone(dev);
715716
if (!ret) {
@@ -718,7 +719,7 @@ static int reada_start_machine_dev(struct btrfs_device *dev)
718719
}
719720
re = NULL;
720721
ret = radix_tree_gang_lookup(&dev->reada_extents, (void **)&re,
721-
dev->reada_next >> PAGE_SHIFT, 1);
722+
dev->reada_next >> fs_info->sectorsize_bits, 1);
722723
}
723724
if (ret == 0) {
724725
spin_unlock(&fs_info->reada_lock);
@@ -885,7 +886,7 @@ static void dump_devs(struct btrfs_fs_info *fs_info, int all)
885886
pr_cont(" curr off %llu",
886887
device->reada_next - zone->start);
887888
pr_cont("\n");
888-
index = (zone->end >> PAGE_SHIFT) + 1;
889+
index = (zone->end >> fs_info->sectorsize_bits) + 1;
889890
}
890891
cnt = 0;
891892
index = 0;
@@ -910,7 +911,7 @@ static void dump_devs(struct btrfs_fs_info *fs_info, int all)
910911
}
911912
}
912913
pr_cont("\n");
913-
index = (re->logical >> PAGE_SHIFT) + 1;
914+
index = (re->logical >> fs_info->sectorsize_bits) + 1;
914915
if (++cnt > 15)
915916
break;
916917
}
@@ -926,7 +927,7 @@ static void dump_devs(struct btrfs_fs_info *fs_info, int all)
926927
if (ret == 0)
927928
break;
928929
if (!re->scheduled) {
929-
index = (re->logical >> PAGE_SHIFT) + 1;
930+
index = (re->logical >> fs_info->sectorsize_bits) + 1;
930931
continue;
931932
}
932933
pr_debug("re: logical %llu size %u list empty %d scheduled %d",
@@ -942,7 +943,7 @@ static void dump_devs(struct btrfs_fs_info *fs_info, int all)
942943
}
943944
}
944945
pr_cont("\n");
945-
index = (re->logical >> PAGE_SHIFT) + 1;
946+
index = (re->logical >> fs_info->sectorsize_bits) + 1;
946947
}
947948
spin_unlock(&fs_info->reada_lock);
948949
}

0 commit comments

Comments
 (0)