Skip to content

Commit 097b065

Browse files
tohojojmberg-intel
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent 92bc43b commit 097b065

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

include/net/fq.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ struct fq {
7272
u32 flows_cnt;
7373
u32 perturbation;
7474
u32 limit;
75+
u32 memory_limit;
76+
u32 memory_usage;
7577
u32 quantum;
7678
u32 backlog;
7779
u32 overlimit;
80+
u32 overmemory;
7881
u32 collisions;
7982
};
8083

include/net/fq_impl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static struct sk_buff *fq_flow_dequeue(struct fq *fq,
2929
tin->backlog_packets--;
3030
flow->backlog -= skb->len;
3131
fq->backlog--;
32+
fq->memory_usage -= skb->truesize;
3233

3334
if (flow->backlog == 0) {
3435
list_del_init(&flow->backlogchain);
@@ -154,6 +155,7 @@ static void fq_tin_enqueue(struct fq *fq,
154155
flow->backlog += skb->len;
155156
tin->backlog_bytes += skb->len;
156157
tin->backlog_packets++;
158+
fq->memory_usage += skb->truesize;
157159
fq->backlog++;
158160

159161
fq_recalc_backlog(fq, tin, flow);
@@ -166,7 +168,7 @@ static void fq_tin_enqueue(struct fq *fq,
166168

167169
__skb_queue_tail(&flow->queue, skb);
168170

169-
if (fq->backlog > fq->limit) {
171+
if (fq->backlog > fq->limit || fq->memory_usage > fq->memory_limit) {
170172
flow = list_first_entry_or_null(&fq->backlogs,
171173
struct fq_flow,
172174
backlogchain);
@@ -181,6 +183,8 @@ static void fq_tin_enqueue(struct fq *fq,
181183

182184
flow->tin->overlimit++;
183185
fq->overlimit++;
186+
if (fq->memory_usage > fq->memory_limit)
187+
fq->overmemory++;
184188
}
185189
}
186190

@@ -251,6 +255,7 @@ static int fq_init(struct fq *fq, int flows_cnt)
251255
fq->perturbation = prandom_u32();
252256
fq->quantum = 300;
253257
fq->limit = 8192;
258+
fq->memory_limit = 16 << 20; /* 16 MBytes */
254259

255260
fq->flows = kcalloc(fq->flows_cnt, sizeof(fq->flows[0]), GFP_KERNEL);
256261
if (!fq->flows)

0 commit comments

Comments
 (0)