public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Peter Zijlstra" <peterz@infradead.org>,
	"Łukasz Siudut" <lsiudut@fb.com>,
	linux-kernel@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH] psi: avoid divide-by-zero crash inside virtual machines
Date: Thu, 14 Feb 2019 15:53:43 -0500	[thread overview]
Message-ID: <20190214205343.GA17084@cmpxchg.org> (raw)
In-Reply-To: <20190214115855.76869aecd777fbd37d48f45c@linux-foundation.org>

On Thu, Feb 14, 2019 at 11:58:55AM -0800, Andrew Morton wrote:
> On Thu, 14 Feb 2019 14:31:57 -0500 Johannes Weiner <hannes@cmpxchg.org> wrote:
> 
> > --- a/kernel/sched/psi.c
> > +++ b/kernel/sched/psi.c
> > @@ -322,7 +322,7 @@ static bool update_stats(struct psi_group *group)
> >  	expires = group->next_update;
> >  	if (now < expires)
> >  		goto out;
> > -	if (now - expires > psi_period)
> > +	if (now - expires >= psi_period)
> >  		missed_periods = div_u64(now - expires, psi_period);
> >  
> >  	/*
> 
> It seems appropriate to use time_after64() and friends in this code.

These timestamps are all sourced from sched_clock(), which is defined
to be monotonic and never wrap in practice. From the "sched_clock()"
section in Documentation/timers/timekeeping.txt:

	"This function shall return the number of nanoseconds since
	 the system was started."

	"The sched_clock() function may wrap only on unsigned long
	 long boundaries, i.e. after 64 bits. Since this is a
	 nanosecond value this will mean it wraps after circa 585
	 years. (For most practical systems this means "never".)"

As far as readability goes, I have to say I find the naked comparisons
a bit easier to understand (and I'm glad we can use those here since
the code is already complicated):

	if (now < expires)

vs.

	if (time_before64(now, expires))

These macros always have me double check the argument order.

  reply	other threads:[~2019-02-14 20:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-14 19:31 [PATCH] psi: avoid divide-by-zero crash inside virtual machines Johannes Weiner
2019-02-14 19:58 ` Andrew Morton
2019-02-14 20:53   ` Johannes Weiner [this message]
2019-02-14 21:22     ` Andrew Morton

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=20190214205343.GA17084@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lsiudut@fb.com \
    --cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox