From: David Laight <david.laight.linux@gmail.com>
To: NeilBrown <neilb@ownmail.net>
Cc: NeilBrown <neil@brown.name>, "Chuck Lever" <cel@kernel.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Laight" <David.Laight@ACULAB.COM>,
"Linux NFS Mailing List" <linux-nfs@vger.kernel.org>,
"Linux List Kernel Mailing" <linux-kernel@vger.kernel.org>,
speedcracker@hotmail.com
Subject: Re: Compile Error fs/nfsd/nfs4state.o - clamp() low limit slotsize greater than high limit total_avail/scale_factor
Date: Fri, 7 Nov 2025 11:43:24 +0000 [thread overview]
Message-ID: <20251107114324.33fd69f3@pumpkin> (raw)
In-Reply-To: <176251424056.634289.13464296772500147856@noble.neil.brown.name>
On Fri, 07 Nov 2025 22:17:20 +1100
NeilBrown <neilb@ownmail.net> wrote:
> On Fri, 07 Nov 2025, David Laight wrote:
> > On Thu, 6 Nov 2025 09:33:28 -0500
> > Chuck Lever <cel@kernel.org> wrote:
> >
> > > FYI
> > >
> > > https://bugzilla.kernel.org/show_bug.cgi?id=220745
> >
> > Ugg - that code is horrid.
> > It seems to have got deleted since, but it is:
> >
> > u32 slotsize = slot_bytes(ca);
> > u32 num = ca->maxreqs;
> > unsigned long avail, total_avail;
> > unsigned int scale_factor;
> >
> > spin_lock(&nfsd_drc_lock);
> > if (nfsd_drc_max_mem > nfsd_drc_mem_used)
> > total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used;
> > else
> > /* We have handed out more space than we chose in
> > * set_max_drc() to allow. That isn't really a
> > * problem as long as that doesn't make us think we
> > * have lots more due to integer overflow.
> > */
> > total_avail = 0;
> > avail = min((unsigned long)NFSD_MAX_MEM_PER_SESSION, total_avail);
> > /*
> > * Never use more than a fraction of the remaining memory,
> > * unless it's the only way to give this client a slot.
> > * The chosen fraction is either 1/8 or 1/number of threads,
> > * whichever is smaller. This ensures there are adequate
> > * slots to support multiple clients per thread.
> > * Give the client one slot even if that would require
> > * over-allocation--it is better than failure.
> > */
> > scale_factor = max_t(unsigned int, 8, nn->nfsd_serv->sv_nrthreads);
> >
> > avail = clamp_t(unsigned long, avail, slotsize,
> > total_avail/scale_factor);
> > num = min_t(int, num, avail / slotsize);
> > num = max_t(int, num, 1);
> >
> > Lets rework it a bit...
> > if (nfsd_drc_max_mem > nfsd_drc_mem_used) {
> > total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used;
> > avail = min(NFSD_MAX_MEM_PER_SESSION, total_avail);
> > avail = clamp(avail, n + sizeof(xxx), total_avail/8)
> > } else {
> > total_avail = 0;
> > avail = 0;
> > avail = clamp(0, n + sizeof(xxx), 0);
> > }
> >
> > Neither of those clamp() are sane at all - should be clamp(val, lo, hi)
> > with 'lo <= hi' otherwise the result is dependant on the order of the
> > comparisons.
> > The compiler sees the second one and rightly bleats.
>
> In fact only gcc-9 bleats.
That is probably why it didn't get picked up earlier.
> gcc-7 gcc-10 gcc-13 gcc-15
> all seem to think it is fine.
Which, of course, it isn't...
David
>
> NeilBrown
next prev parent reply other threads:[~2025-11-07 11:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 14:15 Compile Error fs/nfsd/nfs4state.o - clamp() low limit slotsize greater than high limit total_avail/scale_factor Mike-SPC via Bugspray Bot
2025-11-04 14:50 ` Chuck Lever
2025-11-04 22:20 ` NeilBrown
2025-11-05 8:25 ` Mike-SPC via Bugspray Bot
2025-11-05 12:25 ` Mike-SPC via Bugspray Bot
2025-11-05 14:29 ` Chuck Lever
2025-11-06 11:30 ` Mike-SPC via Bugspray Bot
2025-11-06 12:29 ` Jeff Layton
2025-11-06 14:33 ` Fwd: " Chuck Lever
2025-11-06 19:22 ` David Laight
2025-11-06 19:32 ` Chuck Lever
2025-11-06 22:39 ` David Laight
2025-11-07 11:17 ` NeilBrown
2025-11-07 11:43 ` David Laight [this message]
2025-11-07 22:49 ` NeilBrown
2025-11-08 15:49 ` Chuck Lever
2025-11-08 22:40 ` David Laight
2025-11-15 11:00 ` Mike-SPC via Bugspray Bot
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=20251107114324.33fd69f3@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=David.Laight@ACULAB.COM \
--cc=akpm@linux-foundation.org \
--cc=cel@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=neilb@ownmail.net \
--cc=speedcracker@hotmail.com \
--cc=stable@vger.kernel.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.