Re: [PATCH 06/13] mm: pagewalk: Add 'depth' parameter to pte_hole

Steven Price
2019-02-18T15:23:55Z

On 18/02/2019 11:23, Mark Rutland wrote:
> On Fri, Feb 15, 2019 at 05:02:27PM +0000, Steven Price wrote:
>> +/* If the p4ds are actually just pgds then we should report a depth
>> + * of 0 not 1 (as a missing entry is really a missing pgd
>> + */
>
> Nit: comment style violation. This should look like:
> should be:
>
> /*
> * If the p4ds are actually just pgds then we should report a depth
> * of 0 not 1 (as a missing entry is really a missing pgd
> */
>
>> +int depth = (PTRS_PER_P4D == 1)?0:1;
>
> Nit: the ternary should have spacing.
>
> We don't seem to do this at any other level that could be folded, so why
> does p4d need special care?
>
> For example, what happens on arm64 when using 64K pages and 3 level
> paging, where puds are folded into pgds?
>
> Thanks,
> Mark.

Yes, you are entirely correct I've missed the other potential foldings.
I somehow imagined that p4d was special and was folded the opposite
direction (I'm not sure why!).

The best solution I can come up with is a function which will convert
from the level the entry is found at, back to the 'real' level the entry
was missing at. This is needed to produce the correct output in the
debugfs file. Something like:

static int real_depth(int depth)
{
if (depth == 3 && PTRS_PER_PMD == 1)
depth = 2;
if (depth == 2 && PTRS_PER_PUD == 1)
depth = 1;
if (depth == 1 && PTRS_PER_P4D == 1)
depth = 0;
return depth;
}

This should of course get folded by the compiler and not actually
generate any code.

Thanks,

Steve