aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/nilfs2/alloc.c27
-rw-r--r--fs/nilfs2/alloc.h21
-rw-r--r--fs/nilfs2/mdt.c2
-rw-r--r--fs/nilfs2/mdt.h2
4 files changed, 52 insertions, 0 deletions
diff --git a/fs/nilfs2/alloc.c b/fs/nilfs2/alloc.c
index 7e2b3ce57aa9..c56300d8d177 100644
--- a/fs/nilfs2/alloc.c
+++ b/fs/nilfs2/alloc.c
@@ -491,3 +491,30 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems)
491 } 491 }
492 return 0; 492 return 0;
493} 493}
494
495void 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
502void 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
516void nilfs_palloc_destroy_cache(struct inode *inode)
517{
518 nilfs_palloc_clear_cache(inode);
519 NILFS_MDT(inode)->mi_palloc_cache = NULL;
520}
diff --git a/fs/nilfs2/alloc.h b/fs/nilfs2/alloc.h
index 4ace5475c2c7..f4543ac4f560 100644
--- a/fs/nilfs2/alloc.h
+++ b/fs/nilfs2/alloc.h
@@ -69,4 +69,25 @@ int nilfs_palloc_freev(struct inode *, __u64 *, size_t);
69#define nilfs_clear_bit_atomic ext2_clear_bit_atomic 69#define nilfs_clear_bit_atomic ext2_clear_bit_atomic
70#define nilfs_find_next_zero_bit ext2_find_next_zero_bit 70#define nilfs_find_next_zero_bit ext2_find_next_zero_bit
71 71
72/*
73 * persistent object allocator cache
74 */
75
76struct nilfs_bh_assoc {
77 unsigned long blkoff;
78 struct buffer_head *bh;
79};
80
81struct 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
88void nilfs_palloc_setup_cache(struct inode *inode,
89 struct nilfs_palloc_cache *cache);
90void nilfs_palloc_clear_cache(struct inode *inode);
91void nilfs_palloc_destroy_cache(struct inode *inode);
92
72#endif /* _NILFS_ALLOC_H */ 93#endif /* _NILFS_ALLOC_H */
diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c
index 948b1f8bc505..06713ffcc7f2 100644
--- a/fs/nilfs2/mdt.c
+++ b/fs/nilfs2/mdt.c
@@ -571,6 +571,8 @@ void nilfs_mdt_destroy(struct inode *inode)
571{ 571{
572 struct nilfs_mdt_info *mdi = NILFS_MDT(inode); 572 struct nilfs_mdt_info *mdi = NILFS_MDT(inode);
573 573
574 if (mdi->mi_palloc_cache)
575 nilfs_palloc_destroy_cache(inode);
574 nilfs_mdt_clear(inode); 576 nilfs_mdt_clear(inode);
575 577
576 kfree(mdi->mi_bgl); /* kfree(NULL) is safe */ 578 kfree(mdi->mi_bgl); /* kfree(NULL) is safe */
diff --git a/fs/nilfs2/mdt.h b/fs/nilfs2/mdt.h
index c396b6c03931..6c4bbb0470fc 100644
--- a/fs/nilfs2/mdt.h
+++ b/fs/nilfs2/mdt.h
@@ -36,6 +36,7 @@
36 * @mi_entry_size: size of an entry 36 * @mi_entry_size: size of an entry
37 * @mi_first_entry_offset: offset to the first entry 37 * @mi_first_entry_offset: offset to the first entry
38 * @mi_entries_per_block: number of entries in a block 38 * @mi_entries_per_block: number of entries in a block
39 * @mi_palloc_cache: persistent object allocator cache
39 * @mi_blocks_per_group: number of blocks in a group 40 * @mi_blocks_per_group: number of blocks in a group
40 * @mi_blocks_per_desc_block: number of blocks per descriptor block 41 * @mi_blocks_per_desc_block: number of blocks per descriptor block
41 */ 42 */
@@ -46,6 +47,7 @@ struct nilfs_mdt_info {
46 unsigned mi_entry_size; 47 unsigned mi_entry_size;
47 unsigned mi_first_entry_offset; 48 unsigned mi_first_entry_offset;
48 unsigned long mi_entries_per_block; 49 unsigned long mi_entries_per_block;
50 struct nilfs_palloc_cache *mi_palloc_cache;
49 unsigned long mi_blocks_per_group; 51 unsigned long mi_blocks_per_group;
50 unsigned long mi_blocks_per_desc_block; 52 unsigned long mi_blocks_per_desc_block;
51}; 53};