On Mon, 03 Jul 2023, Chuck Lever III wrote: > > > On Jul 3, 2023, at 12:48 AM, NeilBrown <neilb@xxxxxxx> wrote: > > > > I guess in practice some of the attributes are "likely" and many are > > "unlikely". > > This is absolutely the case. > > My first attempt at optimizing nfsd4_encode_fattr() was to build > a miniature version that handled just the frequently-requested > combinations of attributes. It made very little difference. My understanding of the effect of these code-movement optimisations is that they affect whole-system performance rather than micro-benchmarks. So they are quite hard to measure. Modern CPUs are quite good at predicting code flow, so the benefit of code movement is not a reduction in pipeline stalls, but a reduction in cache usage. The latter affects the whole system more-or-less equally. > > The conclusions that I drew from that are: > > - The number of conditional branches in here doesn't seem to be > the costly part of encode_fattr(). > > - The frequently-requested attributes are expensive to process > for some reason. Size is easy, but getting the user and > group are not as quick as I would have hoped. > > - It's not the efficiency of encode_fattr() that is the issue, > it's the frequency of its use. That's something the server > can't do much about. There probably needs a protocol revision to improve this. I imagine a GETATTR request including a CTIME value with the implication that if the CTIME hasn't changed, then there is no need to return any attributes. > > > > With the current code we could easily annotate that if we > > wanted to and thought (or measured) there was any value. With the > > looping code we cannot really annotate the likelihood of each. > > Nope, likelihood annotation isn't really possible with a bitmask > loop. But my understanding is that unlikely() means really > really really unlikely, as in "this code is an error case that > is almost never used". And that's not actually the case for most > of these attributes. My understanding of unlikely() (which is largely compatible with yours) is that it tells the compile to pessimise code dependant on the condition being true. Or more accurately: when there is an optimisation trade off between code for the 'true' case and any other code, preference the other code. So it is definitely good to say errors are unlikely, because there is no need to optimise for them. You might also say a fast-path condition is likely() because that path is more worthy of optimisation. > > > > The code-generation idea is intriguing. Even if we didn't reach that > > goal, having the code highly structured as though it were auto-generated > > would be no bad thing. > > Maybe it just calms my yearning for an ordered universe to deal > with these attributes in the same way that we deal with COMPOUND > operations. There are worse reasons for refactoring code:-) Thanks, NeilBrown > > I appreciate the review! > > > -- > Chuck Lever > > >