netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] neighbour: Don't let neigh_forced_gc() disable preemption for long
@ 2023-12-06  3:38 Judy Hsiao
  2023-12-06  3:43 ` David Ahern
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Judy Hsiao @ 2023-12-06  3:38 UTC (permalink / raw)
  To: Eric Dumazet, David Ahern, Simon Horman
  Cc: Douglas Anderson, Judy Hsiao, Brian Haley, David S. Miller,
	Jakub Kicinski, Joel Granados, Julian Anastasov, Leon Romanovsky,
	Paolo Abeni, linux-kernel, netdev

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@chromium.org>
Signed-off-by: Judy Hsiao <judyhsiao@chromium.org>

---

Changes in v2:
- Use ktime_get_ns() for timeout calculation instead of jiffies.

 net/core/neighbour.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index df81c1f0a570..552719c3bbc3 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -253,9 +253,11 @@ static int neigh_forced_gc(struct neigh_table *tbl)
 {
 	int max_clean = atomic_read(&tbl->gc_entries) -
 			READ_ONCE(tbl->gc_thresh2);
+	u64 tmax = ktime_get_ns() + NSEC_PER_MSEC;
 	unsigned long tref = jiffies - 5 * HZ;
 	struct neighbour *n, *tmp;
 	int shrunk = 0;
+	int loop = 0;
 
 	NEIGH_CACHE_STAT_INC(tbl, forced_gc_runs);
 
@@ -278,11 +280,16 @@ static int neigh_forced_gc(struct neigh_table *tbl)
 				shrunk++;
 			if (shrunk >= max_clean)
 				break;
+			if (++loop == 16) {
+				if (ktime_get_ns() > tmax)
+					goto unlock;
+				loop = 0;
+			}
 		}
 	}
 
 	WRITE_ONCE(tbl->last_flush, jiffies);
-
+unlock:
 	write_unlock_bh(&tbl->lock);
 
 	return shrunk;
-- 
2.43.0.rc2.451.g8631bc7472-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-12-08 10:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-06  3:38 [PATCH v2] neighbour: Don't let neigh_forced_gc() disable preemption for long Judy Hsiao
2023-12-06  3:43 ` David Ahern
2023-12-06  7:34 ` Eric Dumazet
2023-12-06 17:21 ` Doug Anderson
2023-12-06 17:39 ` Stephen Hemminger
2023-12-06 17:51   ` David Ahern
2023-12-06 18:49     ` Doug Anderson
2023-12-06 19:15       ` David Ahern
2023-12-08 10:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).