From: Stephen Rothwell <sfr@canb.auug.org.au>
To: Chris Down <chris@chrisdown.name>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Nathan Chancellor <natechancellor@gmail.com>,
Randy Dunlap <rdunlap@infradead.org>,
broonie@kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-next@vger.kernel.org, mhocko@suse.cz,
mm-commits@vger.kernel.org
Subject: Re: mmotm 2019-07-24-21-39 uploaded (mm/memcontrol)
Date: Mon, 29 Jul 2019 09:51:21 +1000 [thread overview]
Message-ID: <20190729095121.080c1a93@canb.auug.org.au> (raw)
In-Reply-To: <20190727101608.GA1740@chrisdown.name>
[-- Attachment #1: Type: text/plain, Size: 2171 bytes --]
Hi all,
On Sat, 27 Jul 2019 11:16:08 +0100 Chris Down <chris@chrisdown.name> wrote:
>
> u64 division: truly the gift that keeps on giving. Thanks Andrew for following
> up on these.
>
> Andrew Morton writes:
> >Ah.
> >
> >It's rather unclear why that u64 cast is there anyway. We're dealing
> >with ulongs all over this code. The below will suffice.
>
> This place in particular uses u64 to make sure we don't overflow when left
> shifting, since the numbers can get pretty big (and that's somewhat needed due
> to the need for high precision when calculating the penalty jiffies). It's ok
> if the output after division is an unsigned long, just the intermediate steps
> need to have enough precision.
>
> >Chris, please take a look?
> >
> >--- a/mm/memcontrol.c~mm-throttle-allocators-when-failing-reclaim-over-memoryhigh-fix-fix-fix
> >+++ a/mm/memcontrol.c
> >@@ -2415,7 +2415,7 @@ void mem_cgroup_handle_over_high(void)
> > clamped_high = max(high, 1UL);
> >
> > overage = (u64)(usage - high) << MEMCG_DELAY_PRECISION_SHIFT;
> >- do_div(overage, clamped_high);
> >+ overage /= clamped_high;
>
> I think this isn't going to work because left shifting by
> MEMCG_DELAY_PRECISION_SHIFT can make the number bigger than ULONG_MAX, which
> may cause wraparound -- we need to retain the u64 until we divide.
>
> Maybe div_u64 will satisfy both ARM and i386? ie.
>
> diff --git mm/memcontrol.c mm/memcontrol.c
> index 5c7b9facb0eb..e12a47e96154 100644
> --- mm/memcontrol.c
> +++ mm/memcontrol.c
> @@ -2419,8 +2419,8 @@ void mem_cgroup_handle_over_high(void)
> */
> clamped_high = max(high, 1UL);
>
> - overage = (u64)(usage - high) << MEMCG_DELAY_PRECISION_SHIFT;
> - do_div(overage, clamped_high);
> + overage = div_u64((u64)(usage - high) << MEMCG_DELAY_PRECISION_SHIFT,
> + clamped_high);
>
> penalty_jiffies = ((u64)overage * overage * HZ)
> >> (MEMCG_DELAY_PRECISION_SHIFT + MEMCG_DELAY_SCALING_SHIFT);
I have applied this to the akpm-current tree in linux-next today.
--
Cheers,
Stephen Rothwell
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2019-07-28 23:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-25 4:40 mmotm 2019-07-24-21-39 uploaded akpm
2019-07-25 22:02 ` mmotm 2019-07-24-21-39 uploaded (mm/memcontrol) Randy Dunlap
2019-07-25 23:39 ` Andrew Morton
2019-07-25 23:51 ` Randy Dunlap
2019-07-27 3:42 ` Nathan Chancellor
2019-07-27 4:19 ` Andrew Morton
2019-07-27 4:36 ` Nathan Chancellor
2019-07-27 10:16 ` Chris Down
2019-07-28 23:51 ` Stephen Rothwell [this message]
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=20190729095121.080c1a93@canb.auug.org.au \
--to=sfr@canb.auug.org.au \
--cc=akpm@linux-foundation.org \
--cc=broonie@kernel.org \
--cc=chris@chrisdown.name \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-next@vger.kernel.org \
--cc=mhocko@suse.cz \
--cc=mm-commits@vger.kernel.org \
--cc=natechancellor@gmail.com \
--cc=rdunlap@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