Lines Matching +full:full +full:- +full:bit
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2020-2022 Huawei Technologies Co., Ltd.
23 kvfree(spc->bitmap); in deinit_space()
24 atomic64_sub(BITS_TO_LONGS(spc->nr_ext) * sizeof(long), &spc_mem); in deinit_space()
25 spc->ext_size = 0; in deinit_space()
26 spc->nr_ext = 0; in deinit_space()
27 atomic_set(&spc->last_alloc_bit, 0); in deinit_space()
28 atomic_set(&spc->nr_alloced, 0); in deinit_space()
35 if (ext_size & (PAGE_SIZE - 1)) { in init_space()
39 if (dev_size & (ext_size - 1)) { in init_space()
43 spc->ext_size = ext_size; in init_space()
44 spc->nr_ext = div_u64(dev_size, ext_size); in init_space()
45 atomic_set(&spc->last_alloc_bit, 0); in init_space()
46 atomic_set(&spc->nr_alloced, 0); in init_space()
47 init_waitqueue_head(&spc->empty_wq); in init_space()
48 spc->bitmap = kvzalloc(BITS_TO_LONGS(spc->nr_ext) * sizeof(long), GFP_KERNEL); in init_space()
49 if (!spc->bitmap) { in init_space()
53 atomic64_add(BITS_TO_LONGS(spc->nr_ext) * sizeof(long), &spc_mem); in init_space()
55 pr_info("hyperhold space init succ, capacity = %u x %u.\n", ext_size, spc->nr_ext); in init_space()
62 u32 bit; in alloc_eid() local
66 last_bit = atomic_read(&spc->last_alloc_bit); in alloc_eid()
67 bit = find_next_zero_bit(spc->bitmap, spc->nr_ext, last_bit); in alloc_eid()
68 if (bit == spc->nr_ext) in alloc_eid()
69 bit = find_next_zero_bit(spc->bitmap, spc->nr_ext, 0); in alloc_eid()
70 if (bit == spc->nr_ext) in alloc_eid()
71 goto full; in alloc_eid()
72 if (test_and_set_bit(bit, spc->bitmap)) in alloc_eid()
75 atomic_set(&spc->last_alloc_bit, bit); in alloc_eid()
76 atomic_inc(&spc->nr_alloced); in alloc_eid()
78 pr_info("hyperhold alloc extent %u.\n", bit); in alloc_eid()
80 return bit; in alloc_eid()
81 full: in alloc_eid()
82 pr_err("hyperhold space is full.\n"); in alloc_eid()
84 return -ENOSPC; in alloc_eid()
89 if (!test_and_clear_bit(eid, spc->bitmap)) { in free_eid()
94 if (atomic_dec_and_test(&spc->nr_alloced)) { in free_eid()
96 wake_up(&spc->empty_wq); in free_eid()
106 for (i = 0; i < spc->nr_ext; i++) in dump_space()
107 if (test_bit(i, spc->bitmap)) in dump_space()
113 if (!atomic_read(&spc->nr_alloced)) in wait_for_space_empty()
119 wait_event(spc->empty_wq, !atomic_read(&spc->nr_alloced)); in wait_for_space_empty()