Lines Matching +full:cache +full:- +full:block
1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2006-2008 Nippon Telegraph and Telephone Corporation.
21 * nilfs_palloc_groups_per_desc_block - get the number of groups that a group
22 * descriptor block can maintain
33 * nilfs_palloc_groups_count - get maximum number of groups
39 return 1UL << (BITS_PER_LONG - (inode->i_blkbits + 3 /* log2(8) */)); in nilfs_palloc_groups_count()
43 * nilfs_palloc_init_blockgroup - initialize private variables for allocator
51 mi->mi_bgl = kmalloc(sizeof(*mi->mi_bgl), GFP_NOFS); in nilfs_palloc_init_blockgroup()
52 if (!mi->mi_bgl) in nilfs_palloc_init_blockgroup()
53 return -ENOMEM; in nilfs_palloc_init_blockgroup()
55 bgl_lock_init(mi->mi_bgl); in nilfs_palloc_init_blockgroup()
59 mi->mi_blocks_per_group = in nilfs_palloc_init_blockgroup()
61 mi->mi_entries_per_block) + 1; in nilfs_palloc_init_blockgroup()
64 * and a bitmap block in nilfs_palloc_init_blockgroup()
66 mi->mi_blocks_per_desc_block = in nilfs_palloc_init_blockgroup()
68 mi->mi_blocks_per_group + 1; in nilfs_palloc_init_blockgroup()
71 * descriptor block in nilfs_palloc_init_blockgroup()
77 * nilfs_palloc_group - get group number and offset from an entry number
92 * nilfs_palloc_desc_blkoff - get block offset of a group descriptor block
96 * nilfs_palloc_desc_blkoff() returns block offset of the descriptor
97 * block which contains a descriptor of the specified group.
104 return desc_block * NILFS_MDT(inode)->mi_blocks_per_desc_block; in nilfs_palloc_desc_blkoff()
108 * nilfs_palloc_bitmap_blkoff - get block offset of a bitmap block
112 * nilfs_palloc_bitmap_blkoff() returns block offset of the bitmap
113 * block used to allocate/deallocate entries in the specified group.
121 desc_offset * NILFS_MDT(inode)->mi_blocks_per_group; in nilfs_palloc_bitmap_blkoff()
125 * nilfs_palloc_group_desc_nfrees - get the number of free entries in a group
136 nfree = le32_to_cpu(desc->pg_nfrees); in nilfs_palloc_group_desc_nfrees()
142 * nilfs_palloc_group_desc_add_entries - adjust count of free entries
154 le32_add_cpu(&desc->pg_nfrees, n); in nilfs_palloc_group_desc_add_entries()
155 nfree = le32_to_cpu(desc->pg_nfrees); in nilfs_palloc_group_desc_add_entries()
161 * nilfs_palloc_entry_blkoff - get block offset of an entry block
173 group_offset / NILFS_MDT(inode)->mi_entries_per_block; in nilfs_palloc_entry_blkoff()
177 * nilfs_palloc_desc_block_init - initialize buffer of a group descriptor block
190 while (n-- > 0) { in nilfs_palloc_desc_block_init()
191 desc->pg_nfrees = nfrees; in nilfs_palloc_desc_block_init()
208 if (prev->bh && blkoff == prev->blkoff && in nilfs_palloc_get_block()
209 likely(buffer_uptodate(prev->bh))) { in nilfs_palloc_get_block()
210 get_bh(prev->bh); in nilfs_palloc_get_block()
211 *bhp = prev->bh; in nilfs_palloc_get_block()
222 * cache contents during the get block call. in nilfs_palloc_get_block()
224 brelse(prev->bh); in nilfs_palloc_get_block()
226 prev->bh = *bhp; in nilfs_palloc_get_block()
227 prev->blkoff = blkoff; in nilfs_palloc_get_block()
234 * nilfs_palloc_delete_block - delete a block on the persistent allocator file
236 * @blkoff: block offset
245 if (prev->bh && blkoff == prev->blkoff) { in nilfs_palloc_delete_block()
246 brelse(prev->bh); in nilfs_palloc_delete_block()
247 prev->bh = NULL; in nilfs_palloc_delete_block()
254 * nilfs_palloc_get_desc_block - get buffer head of a group descriptor block
264 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_get_desc_block() local
269 bhp, &cache->prev_desc, &cache->lock); in nilfs_palloc_get_desc_block()
273 * nilfs_palloc_get_bitmap_block - get buffer head of a bitmap block
283 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_get_bitmap_block() local
288 &cache->prev_bitmap, &cache->lock); in nilfs_palloc_get_bitmap_block()
292 * nilfs_palloc_delete_bitmap_block - delete a bitmap block
299 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_delete_bitmap_block() local
304 &cache->prev_bitmap, &cache->lock); in nilfs_palloc_delete_bitmap_block()
308 * nilfs_palloc_get_entry_block - get buffer head of an entry block
317 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_get_entry_block() local
322 &cache->prev_entry, &cache->lock); in nilfs_palloc_get_entry_block()
326 * nilfs_palloc_delete_entry_block - delete an entry block
332 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_delete_entry_block() local
336 &cache->prev_entry, &cache->lock); in nilfs_palloc_delete_entry_block()
340 * nilfs_palloc_block_get_group_desc - get kernel address of a group descriptor
343 * @bh: buffer head of the buffer storing the group descriptor block
356 * nilfs_palloc_block_get_entry - get kernel address of an entry
359 * @bh: buffer head of the buffer storing the entry block
368 entry_offset = group_offset % NILFS_MDT(inode)->mi_entries_per_block; in nilfs_palloc_block_get_entry()
371 entry_offset * NILFS_MDT(inode)->mi_entry_size; in nilfs_palloc_block_get_entry()
375 * nilfs_palloc_find_available_slot - find available slot in a group
410 return -ENOSPC; in nilfs_palloc_find_available_slot()
414 * nilfs_palloc_rest_groups_in_desc_block - get the remaining number of groups
415 * in a group descriptor block
425 nilfs_palloc_groups_per_desc_block(inode) - in nilfs_palloc_rest_groups_in_desc_block()
427 max - curr + 1); in nilfs_palloc_rest_groups_in_desc_block()
431 * nilfs_palloc_count_desc_blocks - count descriptor blocks number
441 ret = nilfs_bmap_last_key(NILFS_I(inode)->i_bmap, &blknum); in nilfs_palloc_count_desc_blocks()
445 NILFS_MDT(inode)->mi_blocks_per_desc_block); in nilfs_palloc_count_desc_blocks()
450 * nilfs_palloc_mdt_file_can_grow - check potential opportunity for
463 * nilfs_palloc_count_max_entries - count max number of entries that can be
488 return -ERANGE; in nilfs_palloc_count_max_entries()
495 * nilfs_palloc_prepare_alloc_entry - prepare to allocate a persistent object
514 maxgroup = ngroups - 1; in nilfs_palloc_prepare_alloc_entry()
515 group = nilfs_palloc_group(inode, req->pr_entry_nr, &group_offset); in nilfs_palloc_prepare_alloc_entry()
522 maxgroup = nilfs_palloc_group(inode, req->pr_entry_nr, in nilfs_palloc_prepare_alloc_entry()
523 &maxgroup_offset) - 1; in nilfs_palloc_prepare_alloc_entry()
528 desc_kaddr = kmap(desc_bh->b_page); in nilfs_palloc_prepare_alloc_entry()
540 bitmap_kaddr = kmap(bitmap_bh->b_page); in nilfs_palloc_prepare_alloc_entry()
548 desc, lock, -1); in nilfs_palloc_prepare_alloc_entry()
549 req->pr_entry_nr = in nilfs_palloc_prepare_alloc_entry()
551 kunmap(desc_bh->b_page); in nilfs_palloc_prepare_alloc_entry()
552 kunmap(bitmap_bh->b_page); in nilfs_palloc_prepare_alloc_entry()
554 req->pr_desc_bh = desc_bh; in nilfs_palloc_prepare_alloc_entry()
555 req->pr_bitmap_bh = bitmap_bh; in nilfs_palloc_prepare_alloc_entry()
558 kunmap(bitmap_bh->b_page); in nilfs_palloc_prepare_alloc_entry()
565 kunmap(desc_bh->b_page); in nilfs_palloc_prepare_alloc_entry()
570 return -ENOSPC; in nilfs_palloc_prepare_alloc_entry()
573 kunmap(desc_bh->b_page); in nilfs_palloc_prepare_alloc_entry()
579 * nilfs_palloc_commit_alloc_entry - finish allocation of a persistent object
586 mark_buffer_dirty(req->pr_bitmap_bh); in nilfs_palloc_commit_alloc_entry()
587 mark_buffer_dirty(req->pr_desc_bh); in nilfs_palloc_commit_alloc_entry()
590 brelse(req->pr_bitmap_bh); in nilfs_palloc_commit_alloc_entry()
591 brelse(req->pr_desc_bh); in nilfs_palloc_commit_alloc_entry()
595 * nilfs_palloc_commit_free_entry - finish deallocating a persistent object
608 group = nilfs_palloc_group(inode, req->pr_entry_nr, &group_offset); in nilfs_palloc_commit_free_entry()
609 desc_kaddr = kmap(req->pr_desc_bh->b_page); in nilfs_palloc_commit_free_entry()
611 req->pr_desc_bh, desc_kaddr); in nilfs_palloc_commit_free_entry()
612 bitmap_kaddr = kmap(req->pr_bitmap_bh->b_page); in nilfs_palloc_commit_free_entry()
613 bitmap = bitmap_kaddr + bh_offset(req->pr_bitmap_bh); in nilfs_palloc_commit_free_entry()
617 nilfs_warn(inode->i_sb, in nilfs_palloc_commit_free_entry()
619 __func__, inode->i_ino, in nilfs_palloc_commit_free_entry()
620 (unsigned long long)req->pr_entry_nr); in nilfs_palloc_commit_free_entry()
624 kunmap(req->pr_bitmap_bh->b_page); in nilfs_palloc_commit_free_entry()
625 kunmap(req->pr_desc_bh->b_page); in nilfs_palloc_commit_free_entry()
627 mark_buffer_dirty(req->pr_desc_bh); in nilfs_palloc_commit_free_entry()
628 mark_buffer_dirty(req->pr_bitmap_bh); in nilfs_palloc_commit_free_entry()
631 brelse(req->pr_bitmap_bh); in nilfs_palloc_commit_free_entry()
632 brelse(req->pr_desc_bh); in nilfs_palloc_commit_free_entry()
636 * nilfs_palloc_abort_alloc_entry - cancel allocation of a persistent object
649 group = nilfs_palloc_group(inode, req->pr_entry_nr, &group_offset); in nilfs_palloc_abort_alloc_entry()
650 desc_kaddr = kmap(req->pr_desc_bh->b_page); in nilfs_palloc_abort_alloc_entry()
652 req->pr_desc_bh, desc_kaddr); in nilfs_palloc_abort_alloc_entry()
653 bitmap_kaddr = kmap(req->pr_bitmap_bh->b_page); in nilfs_palloc_abort_alloc_entry()
654 bitmap = bitmap_kaddr + bh_offset(req->pr_bitmap_bh); in nilfs_palloc_abort_alloc_entry()
658 nilfs_warn(inode->i_sb, in nilfs_palloc_abort_alloc_entry()
660 __func__, inode->i_ino, in nilfs_palloc_abort_alloc_entry()
661 (unsigned long long)req->pr_entry_nr); in nilfs_palloc_abort_alloc_entry()
665 kunmap(req->pr_bitmap_bh->b_page); in nilfs_palloc_abort_alloc_entry()
666 kunmap(req->pr_desc_bh->b_page); in nilfs_palloc_abort_alloc_entry()
668 brelse(req->pr_bitmap_bh); in nilfs_palloc_abort_alloc_entry()
669 brelse(req->pr_desc_bh); in nilfs_palloc_abort_alloc_entry()
671 req->pr_entry_nr = 0; in nilfs_palloc_abort_alloc_entry()
672 req->pr_bitmap_bh = NULL; in nilfs_palloc_abort_alloc_entry()
673 req->pr_desc_bh = NULL; in nilfs_palloc_abort_alloc_entry()
677 * nilfs_palloc_prepare_free_entry - prepare to deallocate a persistent object
688 group = nilfs_palloc_group(inode, req->pr_entry_nr, &group_offset); in nilfs_palloc_prepare_free_entry()
698 req->pr_desc_bh = desc_bh; in nilfs_palloc_prepare_free_entry()
699 req->pr_bitmap_bh = bitmap_bh; in nilfs_palloc_prepare_free_entry()
704 * nilfs_palloc_abort_free_entry - cancel deallocating a persistent object
711 brelse(req->pr_bitmap_bh); in nilfs_palloc_abort_free_entry()
712 brelse(req->pr_desc_bh); in nilfs_palloc_abort_free_entry()
714 req->pr_entry_nr = 0; in nilfs_palloc_abort_free_entry()
715 req->pr_bitmap_bh = NULL; in nilfs_palloc_abort_free_entry()
716 req->pr_desc_bh = NULL; in nilfs_palloc_abort_free_entry()
720 * nilfs_palloc_freev - deallocate a set of persistent objects
734 const unsigned int epb = NILFS_MDT(inode)->mi_entries_per_block; in nilfs_palloc_freev()
758 bitmap_kaddr = kmap(bitmap_bh->b_page); in nilfs_palloc_freev()
767 nilfs_warn(inode->i_sb, in nilfs_palloc_freev()
769 __func__, inode->i_ino, in nilfs_palloc_freev()
780 group_offset = entry_nrs[j] - group_min_nr; in nilfs_palloc_freev()
783 /* This entry is in the same block */ in nilfs_palloc_freev()
788 /* Test if the entry block is empty or not */ in nilfs_palloc_freev()
792 last_nrs[nempties++] = entry_nrs[j - 1]; in nilfs_palloc_freev()
800 /* Go on to the next entry block */ in nilfs_palloc_freev()
804 kunmap(bitmap_bh->b_page); in nilfs_palloc_freev()
811 if (ret && ret != -ENOENT) in nilfs_palloc_freev()
812 nilfs_warn(inode->i_sb, in nilfs_palloc_freev()
813 "error %d deleting block that object (entry=%llu, ino=%lu) belongs to", in nilfs_palloc_freev()
815 inode->i_ino); in nilfs_palloc_freev()
818 desc_kaddr = kmap_atomic(desc_bh->b_page); in nilfs_palloc_freev()
829 if (ret && ret != -ENOENT) in nilfs_palloc_freev()
830 nilfs_warn(inode->i_sb, in nilfs_palloc_freev()
831 "error %d deleting bitmap block of group=%lu, ino=%lu", in nilfs_palloc_freev()
832 ret, group, inode->i_ino); in nilfs_palloc_freev()
839 struct nilfs_palloc_cache *cache) in nilfs_palloc_setup_cache() argument
841 NILFS_MDT(inode)->mi_palloc_cache = cache; in nilfs_palloc_setup_cache()
842 spin_lock_init(&cache->lock); in nilfs_palloc_setup_cache()
847 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_clear_cache() local
849 spin_lock(&cache->lock); in nilfs_palloc_clear_cache()
850 brelse(cache->prev_desc.bh); in nilfs_palloc_clear_cache()
851 brelse(cache->prev_bitmap.bh); in nilfs_palloc_clear_cache()
852 brelse(cache->prev_entry.bh); in nilfs_palloc_clear_cache()
853 cache->prev_desc.bh = NULL; in nilfs_palloc_clear_cache()
854 cache->prev_bitmap.bh = NULL; in nilfs_palloc_clear_cache()
855 cache->prev_entry.bh = NULL; in nilfs_palloc_clear_cache()
856 spin_unlock(&cache->lock); in nilfs_palloc_clear_cache()
862 NILFS_MDT(inode)->mi_palloc_cache = NULL; in nilfs_palloc_destroy_cache()