Lines Matching refs:b

34 	struct background_tracker *b = kmalloc(sizeof(*b), GFP_KERNEL);  in btracker_create()  local
36 if (!b) { in btracker_create()
41 b->max_work = max_work; in btracker_create()
42 atomic_set(&b->pending_promotes, 0); in btracker_create()
43 atomic_set(&b->pending_writebacks, 0); in btracker_create()
44 atomic_set(&b->pending_demotes, 0); in btracker_create()
46 INIT_LIST_HEAD(&b->issued); in btracker_create()
47 INIT_LIST_HEAD(&b->queued); in btracker_create()
49 b->pending = RB_ROOT; in btracker_create()
50 b->work_cache = KMEM_CACHE(bt_work, 0); in btracker_create()
51 if (!b->work_cache) { in btracker_create()
53 kfree(b); in btracker_create()
54 b = NULL; in btracker_create()
57 return b; in btracker_create()
61 void btracker_destroy(struct background_tracker *b) in btracker_destroy() argument
63 kmem_cache_destroy(b->work_cache); in btracker_destroy()
64 kfree(b); in btracker_destroy()
79 static bool __insert_pending(struct background_tracker *b, in __insert_pending() argument
84 struct rb_node **new = &b->pending.rb_node, *parent = NULL; in __insert_pending()
103 rb_insert_color(&nw->node, &b->pending); in __insert_pending()
108 static struct bt_work *__find_pending(struct background_tracker *b, in __find_pending() argument
113 struct rb_node **new = &b->pending.rb_node; in __find_pending()
133 static void update_stats(struct background_tracker *b, struct policy_work *w, int delta) in update_stats() argument
137 atomic_add(delta, &b->pending_promotes); in update_stats()
141 atomic_add(delta, &b->pending_demotes); in update_stats()
145 atomic_add(delta, &b->pending_writebacks); in update_stats()
150 unsigned btracker_nr_writebacks_queued(struct background_tracker *b) in btracker_nr_writebacks_queued() argument
152 return atomic_read(&b->pending_writebacks); in btracker_nr_writebacks_queued()
156 unsigned btracker_nr_demotions_queued(struct background_tracker *b) in btracker_nr_demotions_queued() argument
158 return atomic_read(&b->pending_demotes); in btracker_nr_demotions_queued()
162 static bool max_work_reached(struct background_tracker *b) in max_work_reached() argument
164 return atomic_read(&b->pending_promotes) + in max_work_reached()
165 atomic_read(&b->pending_writebacks) + in max_work_reached()
166 atomic_read(&b->pending_demotes) >= b->max_work; in max_work_reached()
169 static struct bt_work *alloc_work(struct background_tracker *b) in alloc_work() argument
171 if (max_work_reached(b)) in alloc_work()
174 return kmem_cache_alloc(b->work_cache, GFP_NOWAIT); in alloc_work()
177 int btracker_queue(struct background_tracker *b, in btracker_queue() argument
186 w = alloc_work(b); in btracker_queue()
192 if (!__insert_pending(b, w)) { in btracker_queue()
197 kmem_cache_free(b->work_cache, w); in btracker_queue()
203 list_add(&w->list, &b->issued); in btracker_queue()
205 list_add(&w->list, &b->queued); in btracker_queue()
206 update_stats(b, &w->work, 1); in btracker_queue()
215 int btracker_issue(struct background_tracker *b, struct policy_work **work) in btracker_issue() argument
219 if (list_empty(&b->queued)) in btracker_issue()
222 w = list_first_entry(&b->queued, struct bt_work, list); in btracker_issue()
223 list_move(&w->list, &b->issued); in btracker_issue()
230 void btracker_complete(struct background_tracker *b, in btracker_complete() argument
235 update_stats(b, &w->work, -1); in btracker_complete()
236 rb_erase(&w->node, &b->pending); in btracker_complete()
238 kmem_cache_free(b->work_cache, w); in btracker_complete()
242 bool btracker_promotion_already_present(struct background_tracker *b, in btracker_promotion_already_present() argument
245 return __find_pending(b, oblock) != NULL; in btracker_promotion_already_present()