Lines Matching defs:fq

10 #include <net/fq.h>
16 __fq_adjust_removal(struct fq *fq, struct fq_flow *flow, unsigned int packets,
25 fq->backlog -= packets;
26 fq->memory_usage -= truesize;
36 idx = flow - fq->flows;
37 __clear_bit(idx, fq->flows_bitmap);
40 static void fq_adjust_removal(struct fq *fq,
44 __fq_adjust_removal(fq, flow, 1, skb->len, skb->truesize);
47 static struct sk_buff *fq_flow_dequeue(struct fq *fq,
52 lockdep_assert_held(&fq->lock);
58 fq_adjust_removal(fq, flow, skb);
63 static int fq_flow_drop(struct fq *fq, struct fq_flow *flow,
71 lockdep_assert_held(&fq->lock);
82 free_func(fq, tin, flow, skb);
85 __fq_adjust_removal(fq, flow, packets, bytes, truesize);
90 static struct sk_buff *fq_tin_dequeue(struct fq *fq,
98 lockdep_assert_held(&fq->lock);
111 flow->deficit += fq->quantum;
117 skb = dequeue_func(fq, tin, flow);
137 static u32 fq_flow_idx(struct fq *fq, struct sk_buff *skb)
141 return reciprocal_scale(hash, fq->flows_cnt);
144 static struct fq_flow *fq_flow_classify(struct fq *fq,
150 lockdep_assert_held(&fq->lock);
152 flow = &fq->flows[idx];
156 fq->collisions++;
165 static struct fq_flow *fq_find_fattest_flow(struct fq *fq)
172 for_each_set_bit(i, fq->flows_bitmap, fq->flows_cnt) {
173 struct fq_flow *cur = &fq->flows[i];
184 list_for_each_entry(tin, &fq->tin_backlog, tin_list) {
197 static void fq_tin_enqueue(struct fq *fq,
206 lockdep_assert_held(&fq->lock);
208 flow = fq_flow_classify(fq, tin, idx, skb);
212 __set_bit(idx, fq->flows_bitmap);
214 list_add(&tin->tin_list, &fq->tin_backlog);
223 fq->memory_usage += skb->truesize;
224 fq->backlog++;
229 flow->deficit = fq->quantum;
234 oom = (fq->memory_usage > fq->memory_limit);
235 while (fq->backlog > fq->limit || oom) {
236 flow = fq_find_fattest_flow(fq);
240 if (!fq_flow_drop(fq, flow, free_func))
244 fq->overlimit++;
246 fq->overmemory++;
247 oom = (fq->memory_usage > fq->memory_limit);
252 static void fq_flow_filter(struct fq *fq,
261 lockdep_assert_held(&fq->lock);
264 if (!filter_func(fq, tin, flow, skb, filter_data))
268 fq_adjust_removal(fq, flow, skb);
269 free_func(fq, tin, flow, skb);
273 static void fq_tin_filter(struct fq *fq,
281 lockdep_assert_held(&fq->lock);
284 fq_flow_filter(fq, flow, filter_func, filter_data, free_func);
286 fq_flow_filter(fq, flow, filter_func, filter_data, free_func);
289 static void fq_flow_reset(struct fq *fq,
296 while ((skb = fq_flow_dequeue(fq, flow)))
297 free_func(fq, tin, flow, skb);
311 static void fq_tin_reset(struct fq *fq,
327 fq_flow_reset(fq, flow, free_func);
349 static int fq_init(struct fq *fq, int flows_cnt)
353 memset(fq, 0, sizeof(fq[0]));
354 spin_lock_init(&fq->lock);
355 INIT_LIST_HEAD(&fq->tin_backlog);
356 fq->flows_cnt = max_t(u32, flows_cnt, 1);
357 fq->quantum = 300;
358 fq->limit = 8192;
359 fq->memory_limit = 16 << 20; /* 16 MBytes */
361 fq->flows = kvcalloc(fq->flows_cnt, sizeof(fq->flows[0]), GFP_KERNEL);
362 if (!fq->flows)
365 fq->flows_bitmap = bitmap_zalloc(fq->flows_cnt, GFP_KERNEL);
366 if (!fq->flows_bitmap) {
367 kvfree(fq->flows);
368 fq->flows = NULL;
372 for (i = 0; i < fq->flows_cnt; i++)
373 fq_flow_init(&fq->flows[i]);
378 static void fq_reset(struct fq *fq,
383 for (i = 0; i < fq->flows_cnt; i++)
384 fq_flow_reset(fq, &fq->flows[i], free_func);
386 kvfree(fq->flows);
387 fq->flows = NULL;
389 bitmap_free(fq->flows_bitmap);
390 fq->flows_bitmap = NULL;