Lines Matching +full:segment +full:-

1 /* SPDX-License-Identifier: GPL-2.0-or-later */
5 #include "segment.h"
38 /* Offset and size definitions for cache segment control */
79 u32 cache_seg_id; /* Index in cache->segments */
80 struct pcache_segment segment; member
225 return FIELD_GET(PCACHE_CACHE_FLAGS_GC_PERCENT_MASK, cache->cache_info.flags); in pcache_cache_get_gc_percent()
268 /* pre-allocated key and backing_dev_req */
276 * |--------| key_tmp
283 * |----------| key_tmp
290 * |----------------| key_tmp
297 * |--------| key_tmp
304 * |----| key_tmp
311 * |-----------| key_tmp
357 if (cache_tree->n_subtrees == 1) in get_subtree()
358 return &cache_tree->subtrees[0]; in get_subtree()
360 return &cache_tree->subtrees[off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT]; in get_subtree()
365 return (pos->cache_seg->segment.data + pos->seg_off); in cache_pos_addr()
370 return cache_pos_addr(&cache->key_head); in get_key_head_addr()
377 div_u64_rem(off >> PCACHE_CACHE_SUBTREE_SIZE_SHIFT, cache->n_ksets, &kset_id); in get_kset_id()
384 return (void *)cache->ksets + PCACHE_KSET_SIZE * kset_id; in get_kset()
389 return this_cpu_ptr(cache->data_heads); in get_data_head()
394 return key->flags & PCACHE_CACHE_KEY_FLAGS_EMPTY; in cache_key_empty()
399 return key->flags & PCACHE_CACHE_KEY_FLAGS_CLEAN; in cache_key_clean()
408 * cache_seg_is_ctrl_seg - Checks if a cache segment is a cache ctrl segment.
409 * @cache_seg_id: ID of the cache segment.
411 * Returns true if the cache segment ID corresponds to a cache ctrl segment.
413 * Note: We extend the segment control of the first cache segment
414 * (cache segment ID 0) to serve as the cache control (pcache_cache_ctrl)
416 * cache segment is the one storing the pcache_cache_ctrl information.
424 * cache_key_cutfront - Cuts a specified length from the front of a cache key.
432 if (key->cache_pos.cache_seg) in cache_key_cutfront()
433 cache_pos_advance(&key->cache_pos, cut_len); in cache_key_cutfront()
435 key->off += cut_len; in cache_key_cutfront()
436 key->len -= cut_len; in cache_key_cutfront()
440 * cache_key_cutback - Cuts a specified length from the back of a cache key.
448 key->len -= cut_len; in cache_key_cutback()
455 cache_subtree = key->cache_subtree; in cache_key_delete()
458 rb_erase(&key->rb_node, &cache_subtree->root); in cache_key_delete()
459 key->flags = 0; in cache_key_delete()
465 return (cache->cache_info.flags & PCACHE_CACHE_FLAGS_DATA_CRC); in cache_data_crc_on()
470 return FIELD_GET(PCACHE_CACHE_FLAGS_CACHE_MODE_MASK, cache->cache_info.flags); in cache_mode_get()
475 cache->cache_info.flags &= ~PCACHE_CACHE_FLAGS_CACHE_MODE_MASK; in cache_mode_set()
476 cache->cache_info.flags |= FIELD_PREP(PCACHE_CACHE_FLAGS_CACHE_MODE_MASK, cache_mode); in cache_mode_set()
480 * cache_key_data_crc - Calculates CRC for data in a cache key.
483 * Returns the CRC-32 checksum of the data within the cache key's position.
489 data = cache_pos_addr(&key->cache_pos); in cache_key_data_crc()
491 return crc32c(PCACHE_CRC_SEED, data, key->len); in cache_key_data_crc()
498 if (kset_onmedia->flags & PCACHE_KSET_FLAGS_LAST) in cache_kset_crc()
499 crc_size = sizeof(struct pcache_cache_kset_onmedia) - 4; in cache_kset_crc()
501 crc_size = struct_size(kset_onmedia, data, kset_onmedia->key_num) - 4; in cache_kset_crc()
508 return struct_size_t(struct pcache_cache_kset_onmedia, data, kset_onmedia->key_num); in get_kset_onmedia_size()
512 * cache_seg_remain - Computes remaining space in a cache segment.
515 * Returns the amount of remaining space in the segment data starting from
521 struct pcache_segment *segment; in cache_seg_remain() local
524 cache_seg = pos->cache_seg; in cache_seg_remain()
525 segment = &cache_seg->segment; in cache_seg_remain()
526 seg_remain = segment->data_size - pos->seg_off; in cache_seg_remain()
532 * cache_key_invalid - Checks if a cache key is invalid.
536 * less than the generation of its segment; otherwise returns false.
538 * When the GC (garbage collection) thread identifies a segment
539 * as reclaimable, it increments the segment's generation (gen). However,
549 return (key->seg_gen < key->cache_pos.cache_seg->gen); in cache_key_invalid()
553 * cache_key_lstart - Retrieves the logical start offset of a cache key.
560 return key->off; in cache_key_lstart()
564 * cache_key_lend - Retrieves the logical end offset of a cache key.
571 return key->off + key->len; in cache_key_lend()
576 key_dst->off = key_src->off; in cache_key_copy()
577 key_dst->len = key_src->len; in cache_key_copy()
578 key_dst->seg_gen = key_src->seg_gen; in cache_key_copy()
579 key_dst->cache_tree = key_src->cache_tree; in cache_key_copy()
580 key_dst->cache_subtree = key_src->cache_subtree; in cache_key_copy()
581 key_dst->flags = key_src->flags; in cache_key_copy()
583 cache_pos_copy(&key_dst->cache_pos, &key_src->cache_pos); in cache_key_copy()
587 * cache_pos_onmedia_crc - Calculates the CRC for an on-media cache position.
590 * Calculates the CRC-32 checksum of the position, excluding the first 4 bytes.
595 return pcache_meta_crc(&pos_om->header, sizeof(struct pcache_cache_pos_onmedia)); in cache_pos_onmedia_crc()
607 cache_pos_encode(cache, cache->cache_ctrl->key_tail_pos, in cache_encode_key_tail()
608 &cache->key_tail, ++cache->key_tail_seq, in cache_encode_key_tail()
609 &cache->key_tail_index); in cache_encode_key_tail()
614 return cache_pos_decode(cache, cache->cache_ctrl->key_tail_pos, in cache_decode_key_tail()
615 &cache->key_tail, &cache->key_tail_seq, in cache_decode_key_tail()
616 &cache->key_tail_index); in cache_decode_key_tail()
621 cache_pos_encode(cache, cache->cache_ctrl->dirty_tail_pos, in cache_encode_dirty_tail()
622 &cache->dirty_tail, ++cache->dirty_tail_seq, in cache_encode_dirty_tail()
623 &cache->dirty_tail_index); in cache_encode_dirty_tail()
628 return cache_pos_decode(cache, cache->cache_ctrl->dirty_tail_pos, in cache_decode_dirty_tail()
629 &cache->dirty_tail, &cache->dirty_tail_seq, in cache_decode_dirty_tail()
630 &cache->dirty_tail_index); in cache_decode_dirty_tail()