Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fq.h: Port memory limit mechanism from fq_codel

The reusable fairness queueing implementation (fq.h) lacks the memory
usage limit that the fq_codel qdisc has. This means that small
devices (e.g. WiFi routers) can run out of memory when flooded with a
large number of packets. This ports the memory limit feature from
fq_codel to fq.h.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

authored by

Toke Høiland-Jørgensen and committed by
Johannes Berg
097b065b 92bc43bc

+9 -1
+3
include/net/fq.h
··· 72 72 u32 flows_cnt; 73 73 u32 perturbation; 74 74 u32 limit; 75 + u32 memory_limit; 76 + u32 memory_usage; 75 77 u32 quantum; 76 78 u32 backlog; 77 79 u32 overlimit; 80 + u32 overmemory; 78 81 u32 collisions; 79 82 }; 80 83
+6 -1
include/net/fq_impl.h
··· 29 29 tin->backlog_packets--; 30 30 flow->backlog -= skb->len; 31 31 fq->backlog--; 32 + fq->memory_usage -= skb->truesize; 32 33 33 34 if (flow->backlog == 0) { 34 35 list_del_init(&flow->backlogchain); ··· 155 154 flow->backlog += skb->len; 156 155 tin->backlog_bytes += skb->len; 157 156 tin->backlog_packets++; 157 + fq->memory_usage += skb->truesize; 158 158 fq->backlog++; 159 159 160 160 fq_recalc_backlog(fq, tin, flow); ··· 168 166 169 167 __skb_queue_tail(&flow->queue, skb); 170 168 171 - if (fq->backlog > fq->limit) { 169 + if (fq->backlog > fq->limit || fq->memory_usage > fq->memory_limit) { 172 170 flow = list_first_entry_or_null(&fq->backlogs, 173 171 struct fq_flow, 174 172 backlogchain); ··· 183 181 184 182 flow->tin->overlimit++; 185 183 fq->overlimit++; 184 + if (fq->memory_usage > fq->memory_limit) 185 + fq->overmemory++; 186 186 } 187 187 } 188 188 ··· 255 251 fq->perturbation = prandom_u32(); 256 252 fq->quantum = 300; 257 253 fq->limit = 8192; 254 + fq->memory_limit = 16 << 20; /* 16 MBytes */ 258 255 259 256 fq->flows = kcalloc(fq->flows_cnt, sizeof(fq->flows[0]), GFP_KERNEL); 260 257 if (!fq->flows)