mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: Doug Anderson <dianders@chromium.org>,
	Eric Dumazet <edumazet@google.com>
Cc: Judy Hsiao <judyhsiao@chromium.org>,
	Simon Horman <horms@kernel.org>,
	Brian Haley <haleyb.dev@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Joel Granados <joel.granados@gmail.com>,
	Julian Anastasov <ja@ssi.bg>, Leon Romanovsky <leon@kernel.org>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH v1] neighbour: Don't let neigh_forced_gc() disable preemption for long
Date: Mon, 4 Dec 2023 18:08:38 -0700	[thread overview]
Message-ID: <4b095b1c-9fa8-4df9-846b-c33c01e15d97@kernel.org> (raw)
In-Reply-To: <CAD=FV=VqmkydL2XXMWNZ7+89F_6nzGZiGfkknaBgf4Zncng1SQ@mail.gmail.com>

On 12/4/23 4:40 PM, Doug Anderson wrote:
> Hi,
> 
> On Fri, Dec 1, 2023 at 1:10 AM Eric Dumazet <edumazet@google.com> wrote:
>>
>> On Fri, Dec 1, 2023 at 9:39 AM Judy Hsiao <judyhsiao@chromium.org> wrote:
>>>
>>> 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.
>>
>> This will not work in general, because this code runs with BH blocked.
>>
>> jiffies will stay untouched for many more ms on systems with only one CPU.
>>
>> I would rather not rely on jiffies here but ktime_get_ns() [1]
>>
>> Also if we break the loop based on time, we might be unable to purge
>> the last elements in gc_list.
>> We might need to use a second list to make sure to cycle over all
>> elements eventually.
>>
>>
>> [1]
>> diff --git a/net/core/neighbour.c b/net/core/neighbour.c
>> index df81c1f0a57047e176b7c7e4809d2dae59ba6be5..e2340e6b07735db8cf6e75d23ef09bb4b0db53b4
>> 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);
>>
>> @@ -279,10 +281,16 @@ static int neigh_forced_gc(struct neigh_table *tbl)
>>                         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);
> 
> I'm curious what the plan here is. Your patch looks OK to me and I
> could give it a weak Reviewed-by, but I don't know the code well
> enough to know if we also need to address your second comment that we
> need to "use a second list to make sure to cycle over all elements
> eventually". Is that something you'd expect to get resolved before
> landing?
> 
> Thanks! :-)

entries are added to the gc_list at the tail, so it should be ok to take
a break. It will pickup at the head on the next trip through.


  reply	other threads:[~2023-12-05  1:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-01  8:39 Judy Hsiao
2023-12-01  9:10 ` Eric Dumazet
2023-12-01 15:16   ` Doug Anderson
2023-12-01 15:58     ` Eric Dumazet
2023-12-01 17:16       ` Doug Anderson
2023-12-01 17:35         ` Eric Dumazet
2023-12-01 18:40           ` Doug Anderson
2023-12-01 18:21         ` Julian Anastasov
2023-12-04 23:40   ` Doug Anderson
2023-12-05  1:08     ` David Ahern [this message]
2023-12-05  8:00     ` Eric Dumazet
2023-12-05  8:15       ` Eric Dumazet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4b095b1c-9fa8-4df9-846b-c33c01e15d97@kernel.org \
    --to=dsahern@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dianders@chromium.org \
    --cc=edumazet@google.com \
    --cc=haleyb.dev@gmail.com \
    --cc=horms@kernel.org \
    --cc=ja@ssi.bg \
    --cc=joel.granados@gmail.com \
    --cc=judyhsiao@chromium.org \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®