Skip to content

Commit db38d5a

Browse files
committed
nilfs2: add cache framework for persistent object allocator
This adds setup and cleanup routines of the persistent object allocator cache. According to ftrace analyses, accessing buffers of the DAT file suffers indispensable overhead many times. To mitigate the overhead, This introduce cache framework for the persistent object allocator (palloc) which the DAT file and ifile are using. struct nilfs_palloc_cache represents the cache object per metadata file using palloc. The cache is initialized through nilfs_palloc_setup_cache() and destroyed by nilfs_palloc_destroy_cache(); callers of the former function will be added to individual allocators of DAT and ifile on successive patches. nilfs_palloc_destroy_cache() will be called from nilfs_mdt_destroy() if the cache is attached to a metadata file. A companion function nilfs_palloc_clear_cache() is provided to allow releasing buffer head references independently with the cleanup task. This adjunctive function will be used before invalidating pages of metadata file with the cache. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
1 parent 141bbdb commit db38d5a

4 files changed

Lines changed: 52 additions & 0 deletions

File tree

‎fs/nilfs2/alloc.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,30 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems)
491491
}
492492
return 0;
493493
}
494+
495+
void nilfs_palloc_setup_cache(struct inode *inode,
496+
struct nilfs_palloc_cache *cache)
497+
{
498+
NILFS_MDT(inode)->mi_palloc_cache = cache;
499+
spin_lock_init(&cache->lock);
500+
}
501+
502+
void nilfs_palloc_clear_cache(struct inode *inode)
503+
{
504+
struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache;
505+
506+
spin_lock(&cache->lock);
507+
brelse(cache->prev_desc.bh);
508+
brelse(cache->prev_bitmap.bh);
509+
brelse(cache->prev_entry.bh);
510+
cache->prev_desc.bh = NULL;
511+
cache->prev_bitmap.bh = NULL;
512+
cache->prev_entry.bh = NULL;
513+
spin_unlock(&cache->lock);
514+
}
515+
516+
void nilfs_palloc_destroy_cache(struct inode *inode)
517+
{
518+
nilfs_palloc_clear_cache(inode);
519+
NILFS_MDT(inode)->mi_palloc_cache = NULL;
520+
}

‎fs/nilfs2/alloc.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,25 @@ int nilfs_palloc_freev(struct inode *, __u64 *, size_t);
6969
#define nilfs_clear_bit_atomic ext2_clear_bit_atomic
7070
#define nilfs_find_next_zero_bit ext2_find_next_zero_bit
7171

72+
/*
73+
* persistent object allocator cache
74+
*/
75+
76+
struct nilfs_bh_assoc {
77+
unsigned long blkoff;
78+
struct buffer_head *bh;
79+
};
80+
81+
struct nilfs_palloc_cache {
82+
spinlock_t lock;
83+
struct nilfs_bh_assoc prev_desc;
84+
struct nilfs_bh_assoc prev_bitmap;
85+
struct nilfs_bh_assoc prev_entry;
86+
};
87+
88+
void nilfs_palloc_setup_cache(struct inode *inode,
89+
struct nilfs_palloc_cache *cache);
90+
void nilfs_palloc_clear_cache(struct inode *inode);
91+
void nilfs_palloc_destroy_cache(struct inode *inode);
92+
7293
#endif /* _NILFS_ALLOC_H */

‎fs/nilfs2/mdt.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ void nilfs_mdt_destroy(struct inode *inode)
571571
{
572572
struct nilfs_mdt_info *mdi = NILFS_MDT(inode);
573573

574+
if (mdi->mi_palloc_cache)
575+
nilfs_palloc_destroy_cache(inode);
574576
nilfs_mdt_clear(inode);
575577

576578
kfree(mdi->mi_bgl); /* kfree(NULL) is safe */

‎fs/nilfs2/mdt.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* @mi_entry_size: size of an entry
3737
* @mi_first_entry_offset: offset to the first entry
3838
* @mi_entries_per_block: number of entries in a block
39+
* @mi_palloc_cache: persistent object allocator cache
3940
* @mi_blocks_per_group: number of blocks in a group
4041
* @mi_blocks_per_desc_block: number of blocks per descriptor block
4142
*/
@@ -46,6 +47,7 @@ struct nilfs_mdt_info {
4647
unsigned mi_entry_size;
4748
unsigned mi_first_entry_offset;
4849
unsigned long mi_entries_per_block;
50+
struct nilfs_palloc_cache *mi_palloc_cache;
4951
unsigned long mi_blocks_per_group;
5052
unsigned long mi_blocks_per_desc_block;
5153
};

0 commit comments

Comments
 (0)