~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/bcachefs/btree_write_buffer.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _BCACHEFS_BTREE_WRITE_BUFFER_H
  3 #define _BCACHEFS_BTREE_WRITE_BUFFER_H
  4 
  5 #include "bkey.h"
  6 #include "disk_accounting.h"
  7 
  8 static inline bool bch2_btree_write_buffer_should_flush(struct bch_fs *c)
  9 {
 10         struct btree_write_buffer *wb = &c->btree_write_buffer;
 11 
 12         return wb->inc.keys.nr + wb->flushing.keys.nr > wb->inc.keys.size / 4;
 13 }
 14 
 15 static inline bool bch2_btree_write_buffer_must_wait(struct bch_fs *c)
 16 {
 17         struct btree_write_buffer *wb = &c->btree_write_buffer;
 18 
 19         return wb->inc.keys.nr > wb->inc.keys.size * 3 / 4;
 20 }
 21 
 22 struct btree_trans;
 23 int bch2_btree_write_buffer_flush_sync(struct btree_trans *);
 24 int bch2_btree_write_buffer_flush_nocheck_rw(struct btree_trans *);
 25 int bch2_btree_write_buffer_tryflush(struct btree_trans *);
 26 
 27 struct bkey_buf;
 28 int bch2_btree_write_buffer_maybe_flush(struct btree_trans *, struct bkey_s_c, struct bkey_buf *);
 29 
 30 struct journal_keys_to_wb {
 31         struct btree_write_buffer_keys  *wb;
 32         size_t                          room;
 33         u64                             seq;
 34 };
 35 
 36 static inline int wb_key_cmp(const void *_l, const void *_r)
 37 {
 38         const struct btree_write_buffered_key *l = _l;
 39         const struct btree_write_buffered_key *r = _r;
 40 
 41         return cmp_int(l->btree, r->btree) ?: bpos_cmp(l->k.k.p, r->k.k.p);
 42 }
 43 
 44 int bch2_accounting_key_to_wb_slowpath(struct bch_fs *,
 45                               enum btree_id, struct bkey_i_accounting *);
 46 
 47 static inline int bch2_accounting_key_to_wb(struct bch_fs *c,
 48                              enum btree_id btree, struct bkey_i_accounting *k)
 49 {
 50         struct btree_write_buffer *wb = &c->btree_write_buffer;
 51         struct btree_write_buffered_key search;
 52         search.btree = btree;
 53         search.k.k.p = k->k.p;
 54 
 55         unsigned idx = eytzinger0_find(wb->accounting.data, wb->accounting.nr,
 56                         sizeof(wb->accounting.data[0]),
 57                         wb_key_cmp, &search);
 58 
 59         if (idx >= wb->accounting.nr)
 60                 return bch2_accounting_key_to_wb_slowpath(c, btree, k);
 61 
 62         struct bkey_i_accounting *dst = bkey_i_to_accounting(&wb->accounting.data[idx].k);
 63         bch2_accounting_accumulate(dst, accounting_i_to_s_c(k));
 64         return 0;
 65 }
 66 
 67 int bch2_journal_key_to_wb_slowpath(struct bch_fs *,
 68                              struct journal_keys_to_wb *,
 69                              enum btree_id, struct bkey_i *);
 70 
 71 static inline int __bch2_journal_key_to_wb(struct bch_fs *c,
 72                              struct journal_keys_to_wb *dst,
 73                              enum btree_id btree, struct bkey_i *k)
 74 {
 75         if (unlikely(!dst->room))
 76                 return bch2_journal_key_to_wb_slowpath(c, dst, btree, k);
 77 
 78         struct btree_write_buffered_key *wb_k = &darray_top(dst->wb->keys);
 79         wb_k->journal_seq       = dst->seq;
 80         wb_k->btree             = btree;
 81         bkey_copy(&wb_k->k, k);
 82         dst->wb->keys.nr++;
 83         dst->room--;
 84         return 0;
 85 }
 86 
 87 static inline int bch2_journal_key_to_wb(struct bch_fs *c,
 88                              struct journal_keys_to_wb *dst,
 89                              enum btree_id btree, struct bkey_i *k)
 90 {
 91         EBUG_ON(!dst->seq);
 92 
 93         return k->k.type == KEY_TYPE_accounting
 94                 ? bch2_accounting_key_to_wb(c, btree, bkey_i_to_accounting(k))
 95                 : __bch2_journal_key_to_wb(c, dst, btree, k);
 96 }
 97 
 98 void bch2_journal_keys_to_write_buffer_start(struct bch_fs *, struct journal_keys_to_wb *, u64);
 99 int bch2_journal_keys_to_write_buffer_end(struct bch_fs *, struct journal_keys_to_wb *);
100 
101 int bch2_btree_write_buffer_resize(struct bch_fs *, size_t);
102 void bch2_fs_btree_write_buffer_exit(struct bch_fs *);
103 int bch2_fs_btree_write_buffer_init(struct bch_fs *);
104 
105 #endif /* _BCACHEFS_BTREE_WRITE_BUFFER_H */
106 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php