Skip to content

Commit 042be37

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: shrink spinlock coverage
In f2fs_try_to_free_nids(), .nid_list_lock spinlock critical region will increase as expected shrink number increase, to avoid spining other CPUs for long time, we change to release nid caches with small batch each time under .nid_list_lock coverage. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 84c9c2d commit 042be37

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

‎fs/f2fs/node.c‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,6 @@ void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid)
24882488
int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink)
24892489
{
24902490
struct f2fs_nm_info *nm_i = NM_I(sbi);
2491-
struct free_nid *i, *next;
24922491
int nr = nr_shrink;
24932492

24942493
if (nm_i->nid_cnt[FREE_NID] <= MAX_FREE_NIDS)
@@ -2497,17 +2496,23 @@ int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink)
24972496
if (!mutex_trylock(&nm_i->build_lock))
24982497
return 0;
24992498

2500-
spin_lock(&nm_i->nid_list_lock);
2501-
list_for_each_entry_safe(i, next, &nm_i->free_nid_list, list) {
2502-
if (nr_shrink <= 0 ||
2503-
nm_i->nid_cnt[FREE_NID] <= MAX_FREE_NIDS)
2504-
break;
2499+
while (nr_shrink && nm_i->nid_cnt[FREE_NID] > MAX_FREE_NIDS) {
2500+
struct free_nid *i, *next;
2501+
unsigned int batch = SHRINK_NID_BATCH_SIZE;
25052502

2506-
__remove_free_nid(sbi, i, FREE_NID);
2507-
kmem_cache_free(free_nid_slab, i);
2508-
nr_shrink--;
2503+
spin_lock(&nm_i->nid_list_lock);
2504+
list_for_each_entry_safe(i, next, &nm_i->free_nid_list, list) {
2505+
if (!nr_shrink || !batch ||
2506+
nm_i->nid_cnt[FREE_NID] <= MAX_FREE_NIDS)
2507+
break;
2508+
__remove_free_nid(sbi, i, FREE_NID);
2509+
kmem_cache_free(free_nid_slab, i);
2510+
nr_shrink--;
2511+
batch--;
2512+
}
2513+
spin_unlock(&nm_i->nid_list_lock);
25092514
}
2510-
spin_unlock(&nm_i->nid_list_lock);
2515+
25112516
mutex_unlock(&nm_i->build_lock);
25122517

25132518
return nr - nr_shrink;

‎fs/f2fs/node.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#define FREE_NID_PAGES 8
1616
#define MAX_FREE_NIDS (NAT_ENTRY_PER_BLOCK * FREE_NID_PAGES)
1717

18+
/* size of free nid batch when shrinking */
19+
#define SHRINK_NID_BATCH_SIZE 8
20+
1821
#define DEF_RA_NID_PAGES 0 /* # of nid pages to be readaheaded */
1922

2023
/* maximum readahead size for node during getting data blocks */

0 commit comments

Comments
 (0)