[PATCH v1] neighbour: Don't let neigh_forced_gc() disable preemption for long

From: Judy Hsiao
Date: Fri Dec 01 2023 - 03:39:47 EST


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 <dianders@xxxxxxxxxxxx>
Signed-off-by: Judy Hsiao <judyhsiao@xxxxxxxxxxxx>

---

net/core/neighbour.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index df81c1f0a570..f7a89c7a7673 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -256,6 +256,8 @@ static int neigh_forced_gc(struct neigh_table *tbl)
unsigned long tref = jiffies - 5 * HZ;
struct neighbour *n, *tmp;
int shrunk = 0;
+ bool finish = true;
+ unsigned long timeout = jiffies + msecs_to_jiffies(1); /* timeout in 1ms */

NEIGH_CACHE_STAT_INC(tbl, forced_gc_runs);

@@ -278,10 +280,14 @@ static int neigh_forced_gc(struct neigh_table *tbl)
shrunk++;
if (shrunk >= max_clean)
break;
+ if (time_after(jiffies, timeout)) {
+ finish = false;
+ break;
+ }
}
}
-
- WRITE_ONCE(tbl->last_flush, jiffies);
+ if (finish)
+ WRITE_ONCE(tbl->last_flush, jiffies);

write_unlock_bh(&tbl->lock);

--
2.43.0.rc2.451.g8631bc7472-goog