lkml.org 
[lkml]   [2020]   [Nov]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH V9 1/4] perf/core: Add PERF_SAMPLE_DATA_PAGE_SIZE
On Wed, Nov 11, 2020 at 04:38:48PM +0000, Matthew Wilcox wrote:
> On Wed, Nov 11, 2020 at 04:57:24PM +0100, Peter Zijlstra wrote:
> > On Wed, Nov 11, 2020 at 03:30:22PM +0000, Matthew Wilcox wrote:
> > > This confuses me. Why only special-case hugetlbfs pages here? Should
> > > they really be treated differently from THP? If you want to consider
> > > that we might be mapping a page that's twice as big as a PUD entry and
> > > this is only half of it, then the simple way is:
> > >
> > > if (pud_leaf(pud)) {
> > > #ifdef pud_page
> > > page = compound_head(pud_page(*pud));
> > > return page_size(page);
> >
> > Also; this is 'wrong'. The purpose of this function is to return the
> > hardware TLB size of a given address. The above will return the compound
> > size, for any random compound page, which would be myrads of reasons.
>
> Oh, then the whole thing is overly-complicated. This should just be
>
> if (pud_leaf(pud))
> return PUD_SIZE;

But that doesn't handle non-pagetable aligned hugetlb sizes. Granted,
that's unlikely at the PUD level, but why be inconsistent..

So we really want:

if (p*d_leaf(p*d)) {
if (!'special') {
page = p*d_page(p*d);
if (PageHuge(page))
return page_size(compound_head(page));
}
return P*D_SIZE;
}

That gets us:

- regular page-table aligned large-pages
- 'funny' hugetlb sizes

The only thing it doesn't gets us is kernel usage of 'funny' sizes,
which is why that function is weak (arm64, power32, sparc64 have funny
sizes and at the very least arm64 uses them for kernel mappings too).

Now, when you add !PMD THP sizes (presumably for architectures that have
'funny' sizes, otherwise what's the point), then you get to add '||
PageTransHuge()' to the above PageHuge() (and fix PageTransHuge() to
actually do what it claims it does).

Arguably we could fix arm64 with something like the below, but then, I'd
have to audit powerpc32 and sparc64 again to see if I can make that work
for them too -- not today.

---

--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7003,6 +7003,10 @@ static u64 perf_virt_to_phys(u64 virt)

#ifdef CONFIG_MMU

+#ifndef pte_cont
+#define pte_cont(pte) (false)
+#endif
+
/*
* Return the MMU page size of a given virtual address.
*
@@ -7077,7 +7081,7 @@ __weak u64 arch_perf_get_page_size(struc

if (!pte_devmap(pte) && !pte_special(pte)) {
page = pte_page(pte);
- if (PageHuge(page)) {
+ if (PageHuge(page) || pte_cont(pte)) {
u64 size = page_size(compound_head(page));
pte_unmap(ptep);
return size;
\
 
 \ /
  Last update: 2020-11-11 18:25    [W:0.083 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site