Skip to content

Commit e5dc5af

Browse files
Judy Hsiaodavem330
authored andcommitted
neighbour: Don't let neigh_forced_gc() disable preemption for long
We are seeing cases where neigh_cleanup_and_release() is called by neigh_forced_gc() many times in a row with preemption turned off. When running on a low powered CPU at a low CPU frequency, this has been measured to keep preemption off for ~10 ms. That's not great on a system with HZ=1000 which expects tasks to be able to schedule in with ~1ms latency. Suggested-by: Douglas Anderson <[email protected]> Signed-off-by: Judy Hsiao <[email protected]> Reviewed-by: David Ahern <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Reviewed-by: Douglas Anderson <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 179a8b5 commit e5dc5af

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

net/core/neighbour.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,11 @@ static int neigh_forced_gc(struct neigh_table *tbl)
253253
{
254254
int max_clean = atomic_read(&tbl->gc_entries) -
255255
READ_ONCE(tbl->gc_thresh2);
256+
u64 tmax = ktime_get_ns() + NSEC_PER_MSEC;
256257
unsigned long tref = jiffies - 5 * HZ;
257258
struct neighbour *n, *tmp;
258259
int shrunk = 0;
260+
int loop = 0;
259261

260262
NEIGH_CACHE_STAT_INC(tbl, forced_gc_runs);
261263

@@ -278,11 +280,16 @@ static int neigh_forced_gc(struct neigh_table *tbl)
278280
shrunk++;
279281
if (shrunk >= max_clean)
280282
break;
283+
if (++loop == 16) {
284+
if (ktime_get_ns() > tmax)
285+
goto unlock;
286+
loop = 0;
287+
}
281288
}
282289
}
283290

284291
WRITE_ONCE(tbl->last_flush, jiffies);
285-
292+
unlock:
286293
write_unlock_bh(&tbl->lock);
287294

288295
return shrunk;

0 commit comments

Comments
 (0)