29 static int caching_kthread(
void *
data)
65 if (btrfs_fs_closing(fs_info))
68 leaf = path->
nodes[0];
69 slot = path->
slots[0];
70 if (slot >= btrfs_header_nritems(leaf)) {
79 leaf = path->
nodes[0];
81 if (btrfs_header_nritems(leaf) == 0) {
90 btrfs_item_key_to_cpu(leaf, &
key, 0);
100 btrfs_item_key_to_cpu(leaf, &
key, slot);
108 if (last != (
u64)-1 && last + 1 !=
key.objectid) {
110 key.objectid - last - 1);
119 if (last < root->highest_objectid - 1) {
139 static void start_caching(
struct btrfs_root *root)
179 tsk =
kthread_run(caching_kthread, root,
"btrfs-ino-cache-%llu\n",
239 if (objectid <= root->cache_progress ||
290 #define INIT_THRESHOLD (((1024 * 32) / 2) / sizeof(struct btrfs_free_space))
291 #define INODES_PER_BITMAP (PAGE_CACHE_SIZE * 8)
316 max_ino = info->
bytes - 1;
319 if (max_bitmaps <= ctl->total_bitmaps) {
343 .recalc_thresholds = recalculate_thresholds,
365 .recalc_thresholds = pinned_recalc_thresholds,
366 .use_bitmap = pinned_use_bitmap,
378 ctl->
op = &free_ino_op;
392 pinned->
op = &pinned_free_ino_op;
415 if (btrfs_root_refs(&root->
root_item) == 0 &&
416 root != root->
fs_info->tree_root)
441 trace_btrfs_space_reservation(root->
fs_info,
"ino_cache",
445 if (IS_ERR(inode) && (PTR_ERR(inode) != -
ENOENT || retry)) {
446 ret = PTR_ERR(inode);
460 BTRFS_I(inode)->generation = 0;
467 if (i_size_read(inode) > 0) {
497 prealloc, prealloc, &alloc_hint);
508 trace_btrfs_space_reservation(root->
fs_info,
"ino_cache",
519 static int btrfs_find_highest_objectid(
struct btrfs_root *root,
u64 *objectid)
533 search_key.type = -1;
534 search_key.offset = (
u64)-1;
539 if (path->
slots[0] > 0) {
540 slot = path->
slots[0] - 1;
542 btrfs_item_key_to_cpu(l, &found_key, slot);
543 *objectid =
max_t(
u64, found_key.objectid,
560 ret = btrfs_find_highest_objectid(root,