Skip to content

Commit 65e7806

Browse files
jthornbergregkh
authored andcommitted
dm space maps: don't reset space map allocation cursor when committing
[ Upstream commit 5faafc7 ] Current commit code resets the place where the search for free blocks will begin back to the start of the metadata device. There are a couple of repercussions to this: - The first allocation after the commit is likely to take longer than normal as it searches for a free block in an area that is likely to have very few free blocks (if any). - Any free blocks it finds will have been recently freed. Reusing them means we have fewer old copies of the metadata to aid recovery from hardware error. Fix these issues by leaving the cursor alone, only resetting when the search hits the end of the metadata device. Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 313d9f2 commit 65e7806

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎drivers/md/persistent-data/dm-space-map-disk.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ static int sm_disk_new_block(struct dm_space_map *sm, dm_block_t *b)
171171
* Any block we allocate has to be free in both the old and current ll.
172172
*/
173173
r = sm_ll_find_common_free_block(&smd->old_ll, &smd->ll, smd->begin, smd->ll.nr_blocks, b);
174+
if (r == -ENOSPC) {
175+
/*
176+
* There's no free block between smd->begin and the end of the metadata device.
177+
* We search before smd->begin in case something has been freed.
178+
*/
179+
r = sm_ll_find_common_free_block(&smd->old_ll, &smd->ll, 0, smd->begin, b);
180+
}
181+
174182
if (r)
175183
return r;
176184

@@ -199,7 +207,6 @@ static int sm_disk_commit(struct dm_space_map *sm)
199207
return r;
200208

201209
memcpy(&smd->old_ll, &smd->ll, sizeof(smd->old_ll));
202-
smd->begin = 0;
203210
smd->nr_allocated_this_transaction = 0;
204211

205212
r = sm_disk_get_nr_free(sm, &nr_free);

‎drivers/md/persistent-data/dm-space-map-metadata.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@ static int sm_metadata_new_block_(struct dm_space_map *sm, dm_block_t *b)
452452
* Any block we allocate has to be free in both the old and current ll.
453453
*/
454454
r = sm_ll_find_common_free_block(&smm->old_ll, &smm->ll, smm->begin, smm->ll.nr_blocks, b);
455+
if (r == -ENOSPC) {
456+
/*
457+
* There's no free block between smm->begin and the end of the metadata device.
458+
* We search before smm->begin in case something has been freed.
459+
*/
460+
r = sm_ll_find_common_free_block(&smm->old_ll, &smm->ll, 0, smm->begin, b);
461+
}
462+
455463
if (r)
456464
return r;
457465

@@ -503,7 +511,6 @@ static int sm_metadata_commit(struct dm_space_map *sm)
503511
return r;
504512

505513
memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll));
506-
smm->begin = 0;
507514
smm->allocated_this_transaction = 0;
508515

509516
return 0;

0 commit comments

Comments
 (0)