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
25 * Return: Number of groups that a group descriptor block can maintain.
35 * nilfs_palloc_groups_count - get maximum number of groups
43 return 1UL << (BITS_PER_LONG - (inode->i_blkbits + 3 /* log2(8) */)); in nilfs_palloc_groups_count()
47 * nilfs_palloc_init_blockgroup - initialize private variables for allocator
57 mi->mi_bgl = kmalloc(sizeof(*mi->mi_bgl), GFP_NOFS); in nilfs_palloc_init_blockgroup()
58 if (!mi->mi_bgl) in nilfs_palloc_init_blockgroup()
59 return -ENOMEM; in nilfs_palloc_init_blockgroup()
61 bgl_lock_init(mi->mi_bgl); in nilfs_palloc_init_blockgroup()
65 mi->mi_blocks_per_group = in nilfs_palloc_init_blockgroup()
67 mi->mi_entries_per_block) + 1; in nilfs_palloc_init_blockgroup()
70 * and a bitmap block in nilfs_palloc_init_blockgroup()
72 mi->mi_blocks_per_desc_block = in nilfs_palloc_init_blockgroup()
74 mi->mi_blocks_per_group + 1; in nilfs_palloc_init_blockgroup()
77 * descriptor block in nilfs_palloc_init_blockgroup()
83 * nilfs_palloc_group - get group number and offset from an entry number
101 * nilfs_palloc_desc_blkoff - get block offset of a group descriptor block
105 * Return: Index number in the metadata file of the descriptor block of
113 return desc_block * NILFS_MDT(inode)->mi_blocks_per_desc_block; in nilfs_palloc_desc_blkoff()
117 * nilfs_palloc_bitmap_blkoff - get block offset of a bitmap block
121 * nilfs_palloc_bitmap_blkoff() returns block offset of the bitmap
122 * block used to allocate/deallocate entries in the specified group.
124 * Return: Index number in the metadata file of the bitmap block of
133 desc_offset * NILFS_MDT(inode)->mi_blocks_per_group; in nilfs_palloc_bitmap_blkoff()
137 * nilfs_palloc_group_desc_nfrees - get the number of free entries in a group
150 nfree = le32_to_cpu(desc->pg_nfrees); in nilfs_palloc_group_desc_nfrees()
156 * nilfs_palloc_group_desc_add_entries - adjust count of free entries
171 le32_add_cpu(&desc->pg_nfrees, n); in nilfs_palloc_group_desc_add_entries()
172 nfree = le32_to_cpu(desc->pg_nfrees); in nilfs_palloc_group_desc_add_entries()
178 * nilfs_palloc_entry_blkoff - get block offset of an entry block
182 * Return: Index number in the metadata file of the block containing
193 group_offset / NILFS_MDT(inode)->mi_entries_per_block; in nilfs_palloc_entry_blkoff()
197 * nilfs_palloc_desc_block_init - initialize buffer of a group descriptor block
200 * @from: kernel address mapped for a chunk of the block
202 * This function does not yet support the case where block size > PAGE_SIZE.
212 while (n-- > 0) { in nilfs_palloc_desc_block_init()
213 desc->pg_nfrees = nfrees; in nilfs_palloc_desc_block_init()
230 if (prev->bh && blkoff == prev->blkoff && in nilfs_palloc_get_block()
231 likely(buffer_uptodate(prev->bh))) { in nilfs_palloc_get_block()
232 get_bh(prev->bh); in nilfs_palloc_get_block()
233 *bhp = prev->bh; in nilfs_palloc_get_block()
244 * cache contents during the get block call. in nilfs_palloc_get_block()
246 brelse(prev->bh); in nilfs_palloc_get_block()
248 prev->bh = *bhp; in nilfs_palloc_get_block()
249 prev->blkoff = blkoff; in nilfs_palloc_get_block()
256 * nilfs_palloc_delete_block - delete a block on the persistent allocator file
258 * @blkoff: block offset
264 * * %-EIO - I/O error (including metadata corruption).
265 * * %-ENOENT - Non-existent block.
266 * * %-ENOMEM - Insufficient memory available.
273 if (prev->bh && blkoff == prev->blkoff) { in nilfs_palloc_delete_block()
274 brelse(prev->bh); in nilfs_palloc_delete_block()
275 prev->bh = NULL; in nilfs_palloc_delete_block()
282 * nilfs_palloc_get_desc_block - get buffer head of a group descriptor block
294 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_get_desc_block() local
299 bhp, &cache->prev_desc, &cache->lock); in nilfs_palloc_get_desc_block()
303 * nilfs_palloc_get_bitmap_block - get buffer head of a bitmap block
315 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_get_bitmap_block() local
320 &cache->prev_bitmap, &cache->lock); in nilfs_palloc_get_bitmap_block()
324 * nilfs_palloc_delete_bitmap_block - delete a bitmap block
333 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_delete_bitmap_block() local
338 &cache->prev_bitmap, &cache->lock); in nilfs_palloc_delete_bitmap_block()
342 * nilfs_palloc_get_entry_block - get buffer head of an entry block
353 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_get_entry_block() local
358 &cache->prev_entry, &cache->lock); in nilfs_palloc_get_entry_block()
362 * nilfs_palloc_delete_entry_block - delete an entry block
370 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_delete_entry_block() local
374 &cache->prev_entry, &cache->lock); in nilfs_palloc_delete_entry_block()
378 * nilfs_palloc_group_desc_offset - calculate the byte offset of a group
382 * @bh: buffer head of the group descriptor block
390 return offset_in_folio(bh->b_folio, bh->b_data) + in nilfs_palloc_group_desc_offset()
396 * nilfs_palloc_bitmap_offset - calculate the byte offset of a bitmap block
398 * @bh: buffer head of the bitmap block
400 * Return: Byte offset in the folio of the bitmap block for @bh.
404 return offset_in_folio(bh->b_folio, bh->b_data); in nilfs_palloc_bitmap_offset()
408 * nilfs_palloc_entry_offset - calculate the byte offset of an entry in the
412 * @bh: buffer head of the entry block
423 NILFS_MDT(inode)->mi_entries_per_block; in nilfs_palloc_entry_offset()
425 return offset_in_folio(bh->b_folio, bh->b_data) + in nilfs_palloc_entry_offset()
426 entry_index_in_block * NILFS_MDT(inode)->mi_entry_size; in nilfs_palloc_entry_offset()
430 * nilfs_palloc_find_available_slot - find available slot in a group
438 * %-ENOSPC if not found.
460 return -ENOSPC; in nilfs_palloc_find_available_slot()
471 return -ENOSPC; in nilfs_palloc_find_available_slot()
475 * nilfs_palloc_rest_groups_in_desc_block - get the remaining number of groups
476 * in a group descriptor block
482 * block.
489 nilfs_palloc_groups_per_desc_block(inode) - in nilfs_palloc_rest_groups_in_desc_block()
491 max - curr + 1); in nilfs_palloc_rest_groups_in_desc_block()
495 * nilfs_palloc_count_desc_blocks - count descriptor blocks number
507 ret = nilfs_bmap_last_key(NILFS_I(inode)->i_bmap, &blknum); in nilfs_palloc_count_desc_blocks()
511 NILFS_MDT(inode)->mi_blocks_per_desc_block); in nilfs_palloc_count_desc_blocks()
516 * nilfs_palloc_mdt_file_can_grow - check potential opportunity for
531 * nilfs_palloc_count_max_entries - count max number of entries that can be
539 * * %-EIO - I/O error (including metadata corruption).
540 * * %-ENOMEM - Insufficient memory available.
541 * * %-ERANGE - Number of entries in use is out of range.
562 return -ERANGE; in nilfs_palloc_count_max_entries()
569 * nilfs_palloc_prepare_alloc_entry - prepare to allocate a persistent object
576 * * %-EIO - I/O error (including metadata corruption).
577 * * %-ENOMEM - Insufficient memory available.
578 * * %-ENOSPC - Entries exhausted (No entries available for allocation).
579 * * %-EROFS - Read only filesystem
596 maxgroup = ngroups - 1; in nilfs_palloc_prepare_alloc_entry()
597 group = nilfs_palloc_group(inode, req->pr_entry_nr, &group_offset); in nilfs_palloc_prepare_alloc_entry()
604 maxgroup = nilfs_palloc_group(inode, req->pr_entry_nr, in nilfs_palloc_prepare_alloc_entry()
605 &maxgroup_offset) - 1; in nilfs_palloc_prepare_alloc_entry()
612 desc = kmap_local_folio(desc_bh->b_folio, doff); in nilfs_palloc_prepare_alloc_entry()
629 * Re-kmap the folio containing the first (and in nilfs_palloc_prepare_alloc_entry()
632 desc = kmap_local_folio(desc_bh->b_folio, doff); in nilfs_palloc_prepare_alloc_entry()
635 bitmap = kmap_local_folio(bitmap_bh->b_folio, boff); in nilfs_palloc_prepare_alloc_entry()
657 return -ENOSPC; in nilfs_palloc_prepare_alloc_entry()
661 nilfs_palloc_group_desc_add_entries(&desc[j], lock, -1); in nilfs_palloc_prepare_alloc_entry()
662 req->pr_entry_nr = entries_per_group * group + pos; in nilfs_palloc_prepare_alloc_entry()
665 req->pr_desc_bh = desc_bh; in nilfs_palloc_prepare_alloc_entry()
666 req->pr_bitmap_bh = bitmap_bh; in nilfs_palloc_prepare_alloc_entry()
671 * nilfs_palloc_commit_alloc_entry - finish allocation of a persistent object
678 mark_buffer_dirty(req->pr_bitmap_bh); in nilfs_palloc_commit_alloc_entry()
679 mark_buffer_dirty(req->pr_desc_bh); in nilfs_palloc_commit_alloc_entry()
682 brelse(req->pr_bitmap_bh); in nilfs_palloc_commit_alloc_entry()
683 brelse(req->pr_desc_bh); in nilfs_palloc_commit_alloc_entry()
687 * nilfs_palloc_commit_free_entry - finish deallocating a persistent object
700 group = nilfs_palloc_group(inode, req->pr_entry_nr, &group_offset); in nilfs_palloc_commit_free_entry()
701 doff = nilfs_palloc_group_desc_offset(inode, group, req->pr_desc_bh); in nilfs_palloc_commit_free_entry()
702 desc = kmap_local_folio(req->pr_desc_bh->b_folio, doff); in nilfs_palloc_commit_free_entry()
704 boff = nilfs_palloc_bitmap_offset(req->pr_bitmap_bh); in nilfs_palloc_commit_free_entry()
705 bitmap = kmap_local_folio(req->pr_bitmap_bh->b_folio, boff); in nilfs_palloc_commit_free_entry()
709 nilfs_warn(inode->i_sb, in nilfs_palloc_commit_free_entry()
711 __func__, inode->i_ino, in nilfs_palloc_commit_free_entry()
712 (unsigned long long)req->pr_entry_nr); in nilfs_palloc_commit_free_entry()
719 mark_buffer_dirty(req->pr_desc_bh); in nilfs_palloc_commit_free_entry()
720 mark_buffer_dirty(req->pr_bitmap_bh); in nilfs_palloc_commit_free_entry()
723 brelse(req->pr_bitmap_bh); in nilfs_palloc_commit_free_entry()
724 brelse(req->pr_desc_bh); in nilfs_palloc_commit_free_entry()
728 * nilfs_palloc_abort_alloc_entry - cancel allocation of a persistent object
741 group = nilfs_palloc_group(inode, req->pr_entry_nr, &group_offset); in nilfs_palloc_abort_alloc_entry()
742 doff = nilfs_palloc_group_desc_offset(inode, group, req->pr_desc_bh); in nilfs_palloc_abort_alloc_entry()
743 desc = kmap_local_folio(req->pr_desc_bh->b_folio, doff); in nilfs_palloc_abort_alloc_entry()
745 boff = nilfs_palloc_bitmap_offset(req->pr_bitmap_bh); in nilfs_palloc_abort_alloc_entry()
746 bitmap = kmap_local_folio(req->pr_bitmap_bh->b_folio, boff); in nilfs_palloc_abort_alloc_entry()
750 nilfs_warn(inode->i_sb, in nilfs_palloc_abort_alloc_entry()
752 __func__, inode->i_ino, in nilfs_palloc_abort_alloc_entry()
753 (unsigned long long)req->pr_entry_nr); in nilfs_palloc_abort_alloc_entry()
760 brelse(req->pr_bitmap_bh); in nilfs_palloc_abort_alloc_entry()
761 brelse(req->pr_desc_bh); in nilfs_palloc_abort_alloc_entry()
763 req->pr_entry_nr = 0; in nilfs_palloc_abort_alloc_entry()
764 req->pr_bitmap_bh = NULL; in nilfs_palloc_abort_alloc_entry()
765 req->pr_desc_bh = NULL; in nilfs_palloc_abort_alloc_entry()
769 * nilfs_palloc_prepare_free_entry - prepare to deallocate a persistent object
782 group = nilfs_palloc_group(inode, req->pr_entry_nr, &group_offset); in nilfs_palloc_prepare_free_entry()
792 req->pr_desc_bh = desc_bh; in nilfs_palloc_prepare_free_entry()
793 req->pr_bitmap_bh = bitmap_bh; in nilfs_palloc_prepare_free_entry()
798 * nilfs_palloc_abort_free_entry - cancel deallocating a persistent object
805 brelse(req->pr_bitmap_bh); in nilfs_palloc_abort_free_entry()
806 brelse(req->pr_desc_bh); in nilfs_palloc_abort_free_entry()
808 req->pr_entry_nr = 0; in nilfs_palloc_abort_free_entry()
809 req->pr_bitmap_bh = NULL; in nilfs_palloc_abort_free_entry()
810 req->pr_desc_bh = NULL; in nilfs_palloc_abort_free_entry()
814 * nilfs_palloc_freev - deallocate a set of persistent objects
830 const unsigned int epb = NILFS_MDT(inode)->mi_entries_per_block; in nilfs_palloc_freev()
855 bitmap = kmap_local_folio(bitmap_bh->b_folio, boff); in nilfs_palloc_freev()
863 nilfs_warn(inode->i_sb, in nilfs_palloc_freev()
865 __func__, inode->i_ino, in nilfs_palloc_freev()
876 group_offset = entry_nrs[j] - group_min_nr; in nilfs_palloc_freev()
879 /* This entry is in the same block */ in nilfs_palloc_freev()
884 /* Test if the entry block is empty or not */ in nilfs_palloc_freev()
888 last_nrs[nempties++] = entry_nrs[j - 1]; in nilfs_palloc_freev()
896 /* Go on to the next entry block */ in nilfs_palloc_freev()
907 if (ret && ret != -ENOENT) in nilfs_palloc_freev()
908 nilfs_warn(inode->i_sb, in nilfs_palloc_freev()
909 "error %d deleting block that object (entry=%llu, ino=%lu) belongs to", in nilfs_palloc_freev()
911 inode->i_ino); in nilfs_palloc_freev()
915 desc = kmap_local_folio(desc_bh->b_folio, doff); in nilfs_palloc_freev()
924 if (ret && ret != -ENOENT) in nilfs_palloc_freev()
925 nilfs_warn(inode->i_sb, in nilfs_palloc_freev()
926 "error %d deleting bitmap block of group=%lu, ino=%lu", in nilfs_palloc_freev()
927 ret, group, inode->i_ino); in nilfs_palloc_freev()
934 struct nilfs_palloc_cache *cache) in nilfs_palloc_setup_cache() argument
936 NILFS_MDT(inode)->mi_palloc_cache = cache; in nilfs_palloc_setup_cache()
937 spin_lock_init(&cache->lock); in nilfs_palloc_setup_cache()
942 struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache; in nilfs_palloc_clear_cache() local
944 spin_lock(&cache->lock); in nilfs_palloc_clear_cache()
945 brelse(cache->prev_desc.bh); in nilfs_palloc_clear_cache()
946 brelse(cache->prev_bitmap.bh); in nilfs_palloc_clear_cache()
947 brelse(cache->prev_entry.bh); in nilfs_palloc_clear_cache()
948 cache->prev_desc.bh = NULL; in nilfs_palloc_clear_cache()
949 cache->prev_bitmap.bh = NULL; in nilfs_palloc_clear_cache()
950 cache->prev_entry.bh = NULL; in nilfs_palloc_clear_cache()
951 spin_unlock(&cache->lock); in nilfs_palloc_clear_cache()
957 NILFS_MDT(inode)->mi_palloc_cache = NULL; in nilfs_palloc_destroy_cache()