lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YMIaiDaDA/lZ+l2j@cmpxchg.org>
Date:   Thu, 10 Jun 2021 09:58:32 -0400
From:   Johannes Weiner <hannes@...xchg.org>
To:     Suren Baghdasaryan <surenb@...gle.com>
Cc:     Peter Zijlstra <peterz@...radead.org>,
        Jared Pochtar <jpochtar@...com>,
        LKML <linux-kernel@...r.kernel.org>, kernel-team@...com
Subject: Re: [PATCH] psi: fix sampling artifact from pressure file read
 frequency

On Wed, Jun 09, 2021 at 08:32:51PM -0700, Suren Baghdasaryan wrote:
> On Tue, Jun 8, 2021 at 12:03 PM Johannes Weiner <hannes@...xchg.org> wrote:
> >
> > Currently, every time a psi pressure file is read, the per-cpu states
> > are collected and aggregated according to the CPU's non-idle time
> > weight. This dynamically changes the sampling period, which means read
> > frequency can introduce variance into the observed results. This is
> > somewhat unexpected for users and can be confusing, when e.g. two
> > nested cgroups with the same workload report different pressure levels
> > just because they have different consumers reading the pressure files.
> >
> > Consider the following two CPU timelines:
> >
> >         CPU0: [ STALL ] [ SLEEP ]
> >         CPU1: [  RUN  ] [  RUN  ]
> >
> > If we sample and aggregate once for the whole period, we get the
> > following total stall time for CPU0:
> >
> >         CPU0 = stall(1) + nonidle(1) / nonidle_total(3) = 0.3
> >
> > But if we sample twice, the total for the period is higher:
> >
> >         CPU0 = stall(1) + nonidle(1) / nonidle_total(2) = 0.5
> >         CPU0 = stall(0) + nonidle(0) / nonidle_total(1) = 0
> >                                                           ---
> >                                                           0.5
> >
> > Neither answer is inherently wrong: if the user asks for pressure
> > after half the period, we can't know yet that the CPU will go to sleep
> > right after and its weight would be lower over the combined period.
> >
> > We could normalize the weight averaging to a fixed window regardless
> > of how often stall times themselves are sampled. But that would make
> > reporting less adaptive to sudden changes when the user intentionally
> > uses poll() with short intervals in order to get a higher resolution.
> >
> > For now, simply limit sampling of the pressure file contents to the
> > fixed two-second period already used by the aggregation worker.
> 
> Hmm. This is tricky.

Yes ;)

> So, userspace-visible effect of this change is that totals will not
> update when the psi file is read unless the psi_period expires.

That's a visible side effect, but yeah, correct.

> We used to postpone updating only the averages and now the totals
> will follow suit. Not sure if presenting stale data is better than
> having this dependency on timing of the read. As you noted, the
> value we get is not inherently wrong. But one could argue both ways
> I guess... Having this "quantum" effect when the act of observation
> changes the state of the object is indeed weird, to say the least.

Yes. Especially *because* we don't update the averages more than once
per 2s window. It gives the impression they would follow steady
sampling, but they're calculated based on total= which is aggregated
on every read.

Tying the total= updates to the same fixed window presents slightly
less current data, but results in more obvious and intuitive behavior.

For more current data there is always poll() - which is a better idea
than busy-reading the pressure files for a sub-2s resolution...

> In the paragraph above you say "For now". Do you have an idea that
> could solve the issue with totals being stale while removing this
> dependency on the timing of reads?

Yeah, it's hinted at in the paragraph before that.

What we could do is decouple the CPU weight sampling from the stall
time sampling, and use a fixed-window average for the nonidle /
nonidle_total ratio when aggregating. This way, no matter how
frequently you read the stall times, you get the same results.

However, because the update frequency absent any reads is 2s, that
would be the window size we'd have to use. So while we could present
updated total= on every read, they would still be aggregated based on
a relatively stale CPU load distribution.

They wouldn't be as current as they might seem - and as current as the
user would assume them to be if they read the file frequently and got
new totals every time. This is even more subtle than the status quo.

IMO the cleanest interface is simply to be honest and consistent about
the pressure files following a fixed 2s aggregation frequency, and
refer people who need a higher resolution to poll().

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ