All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Artem Savkov <asavkov@redhat.com>,
	Anna-Maria Behnsen <anna-maria@linutronix.de>
Cc: netdev@vger.kernel.org, Josh Poimboeuf <jpoimboe@redhat.com>,
	davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] timer: add a function to adjust timeouts to be upper bound
Date: Tue, 05 Apr 2022 17:33:23 +0200	[thread overview]
Message-ID: <871qyb35q4.ffs@tglx> (raw)
In-Reply-To: <YkfzZWs+Nj3hCvnE@sparkplug.usersys.redhat.com>

On Sat, Apr 02 2022 at 08:55, Artem Savkov wrote:
> On Wed, Mar 30, 2022 at 03:40:55PM +0200, Anna-Maria Behnsen wrote:
>> When calculating the level/index with a relative timeout, there is no
>> guarantee that the result is the same when actual enqueueing the timer with
>> expiry = jiffies + timeout .
>
> Yes, you are correct. This especially is a problem for timeouts placed
> just before LVL_START(x), which is a good chunk of cases. I don't
> think it is possible to get to timer_base clock without meddling with
> the hot-path.

Especially not when the timer might end up being migrated to a different
base, which would in the worst case require to do the calculation twice
if the base clocks differ.

The problem especially with network timers is that in the traffic case
the timers are often rearmed at high frequency. See the optimizations in
mod_timer() which try to avoid dequeue/enqueue sequences.

One of the main reasons for giving up on accuracy for the timer wheel
back then was to avoid two issues for networking:

    - Full rearming of a timer which ended up in the same expiry bucket
      due to software batching (incomplete, but with the same goal and
      the same 12.5% error margin).

    - Cascading bursts.

      We gathered statistics from various workloads which showed that
      99+% of all timers were canceled or rearmed before expiry, but
      under certain load scenarios a large portion of those timers where
      cascaded into a lower wheel level with smaller granularity before
      cancelation or rearming.

      As the wheel level granularity was strictly exponential the event
      of cascading a large amount (hint: thousands) of timers in one go
      was not uncommon. Cascading happened with interrupts disabled and
      it touched a usualy cold cache line per cascaded timer...

> Is it possible to determine the upper limit of error margin here? My
> assumption is it shouldn't be very big, so maybe it would be enough to
> account for this when adjusting timeout at the edge of a level.
> I know this doesn't sound good but I am running out of ideas here.

Let's just take a step back.

So we know, that the maximal error margin in the wheel is 12.5%, right?
That means, if you take your relative timeout and subtract 12.5% then
you are in the right ballpark and the earliest expiry will not be before
that point obviously, but it's also guaranteed not to expire later than
the original timeout. Obviously this will converge towards the early
expiry the longer the timeouts are, but it's bound.

Also due to the properties of the wheel, the lag of base::clk will
obviously only affect those levels where lag >= LVL_GRAN(level).

That's not perfect, but perfect is the enemy of good.

Thanks,

        tglx

  reply	other threads:[~2022-04-06  1:06 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-23 11:16 [PATCH 0/2] Upper bound mode for kernel timers Artem Savkov
2022-03-23 11:16 ` [PATCH 1/2] timer: introduce upper bound timers Artem Savkov
2022-03-23 18:40   ` Josh Poimboeuf
2022-03-24  9:14     ` [PATCH v2 0/2] Upper bound mode for kernel timers Artem Savkov
2022-03-24  9:14       ` [PATCH v2 1/2] timer: introduce upper bound timers Artem Savkov
2022-03-24  9:15       ` [PATCH v2 2/2] net: make tcp keepalive timer upper bound Artem Savkov
2022-03-24 12:28   ` [PATCH 1/2] timer: introduce upper bound timers Thomas Gleixner
2022-03-24 13:54     ` Thomas Gleixner
2022-03-26 21:13     ` Thomas Gleixner
2022-03-30  8:20       ` [PATCH v3 0/2] Upper bound kernel timers Artem Savkov
2022-03-30  8:20         ` [PATCH v3 1/2] timer: add a function to adjust timeouts to be upper bound Artem Savkov
2022-03-30 13:40           ` Anna-Maria Behnsen
2022-04-02  6:55             ` Artem Savkov
2022-04-05 15:33               ` Thomas Gleixner [this message]
2022-04-07  7:52                 ` [PATCH v4 0/2] Upper bound kernel timers Artem Savkov
2022-04-07  7:52                   ` [PATCH v4 1/2] timer: add a function to adjust timeouts to be upper bound Artem Savkov
2022-04-08  0:37                     ` Thomas Gleixner
2022-04-08  5:39                       ` Josh Poimboeuf
2022-04-12 13:42                       ` Artem Savkov
2022-05-05 13:18                       ` [PATCH v5 0/2] Upper bound kernel timers Artem Savkov
2022-05-05 13:18                         ` [PATCH v5 1/2] timer: add a function to adjust timeouts to be upper bound Artem Savkov
2022-05-05 13:18                         ` [PATCH v5 2/2] net: make tcp keepalive timer " Artem Savkov
2022-05-05 17:56                           ` Josh Poimboeuf
2022-05-06  6:39                             ` Artem Savkov
2022-05-06 16:24                               ` Josh Poimboeuf
2022-07-26 22:42                         ` [PATCH v5 0/2] Upper bound kernel timers Josh Poimboeuf
2022-04-07  7:52                   ` [PATCH v4 2/2] net: make tcp keepalive timer upper bound Artem Savkov
     [not found]                 ` <Yk1i3WrcVIICAiF0@samus.usersys.redhat.com>
2022-04-07 23:26                   ` [PATCH v3 1/2] timer: add a function to adjust timeouts to be " Thomas Gleixner
2022-03-30  8:20         ` [PATCH v3 2/2] net: make tcp keepalive timer " Artem Savkov
2022-04-02  3:09           ` [net] 6ef3f95797: UBSAN:shift-out-of-bounds_in_kernel/time/timer.c kernel test robot
2022-04-02  3:09             ` kernel test robot
2022-04-02  7:11             ` Artem Savkov
2022-04-02  7:11               ` Artem Savkov
2022-03-30 10:28         ` [PATCH v3 0/2] Upper bound kernel timers David Laight
2022-03-25  7:38   ` [timer] d41e0719d5: UBSAN:shift-out-of-bounds_in_lib/flex_proportions.c kernel test robot
2022-03-25  7:38     ` kernel test robot
2022-03-25 19:14     ` Thomas Gleixner
2022-03-25 19:14       ` Thomas Gleixner
2022-03-23 11:16 ` [PATCH 2/2] net: make tcp keepalive timer upper bound Artem Savkov

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=871qyb35q4.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=anna-maria@linutronix.de \
    --cc=asavkov@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=yoshfuji@linux-ipv6.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.