mm: add pagetrace support [1/2]

PD#SWPL-70022

Problem:
No pagetrace function on 5.15 kernel

Solution:
porting it from 5.4

Verify:
local

Signed-off-by: Tao Zeng <tao.zeng@amlogic.com>
Change-Id: I69cc8b4f4fa4c323204f86e5c76613cd3d6087df
This commit is contained in:
Tao Zeng
2022-01-20 15:09:43 +08:00
committed by Dongjin Kim
parent 99e9f7177e
commit a1db7dca6c
6 changed files with 58 additions and 0 deletions

View File

@@ -1143,7 +1143,23 @@ vm_fault_t finish_mkwrite_fault(struct vm_fault *vmf);
*/
/* Page flags: | [SECTION] | [NODE] | ZONE | [LAST_CPUPID] | ... | FLAGS | */
#ifdef CONFIG_AMLOGIC_PAGE_TRACE_INLINE
/*
* We use high 32bit of page->flags for page trace, Make sure:
* __NR_PAGEFLAGS : about 21 bits
* ZONES_WIDTH : about 2 bits, MAX 4 zone types
* NODES_WIDTH : about 2 bits if open CONFIG_NUMA, else 0 bit
* SECTIONS_WIDTH : 0 bit if defined CONFIG_SPARSEMEM_VMEMMAP otherwise 18
* bits on ARM64
* LAST_CPUPID_SHIFT : 0 bit if not define CONFIG_NUMA_BALANCING, otherwise
* 8 + NR_CPUS_BITS
* All of these macros should be using less than 32bits in total, otherwise
* compile will fail
*/
#define SECTIONS_PGOFF ((sizeof(unsigned int) * 8) - SECTIONS_WIDTH)
#else
#define SECTIONS_PGOFF ((sizeof(unsigned long)*8) - SECTIONS_WIDTH)
#endif /* CONFIG_AMLOGIC_PAGE_TRACE_INLINE */
#define NODES_PGOFF (SECTIONS_PGOFF - NODES_WIDTH)
#define ZONES_PGOFF (NODES_PGOFF - ZONES_WIDTH)
#define LAST_CPUPID_PGOFF (ZONES_PGOFF - LAST_CPUPID_WIDTH)

View File

@@ -70,8 +70,18 @@ struct mem_cgroup;
#endif
struct page {
#ifdef CONFIG_AMLOGIC_PAGE_TRACE_INLINE
union {
unsigned long flags;
struct {
unsigned int s_flags;
unsigned int trace;
};
};
#else
unsigned long flags; /* Atomic flags, some possibly
* updated asynchronously */
#endif /* CONFIG_AMLOGIC_PAGE_TRACE_INLINE */
/*
* Five words (20/40 bytes) are available in this union.
* WARNING: bit 0 of the first word is used for PageTail(). That

View File

@@ -113,6 +113,10 @@
#include <kunit/test.h>
#ifdef CONFIG_AMLOGIC_PAGE_TRACE
#include <linux/amlogic/page_trace.h>
#endif
static int kernel_init(void *);
extern void init_IRQ(void);
@@ -860,6 +864,10 @@ static void __init mm_init(void)
kfence_alloc_pool();
report_meminit();
stack_depot_init();
#ifdef CONFIG_AMLOGIC_PAGE_TRACE
/* allocate memory before first page allocated */
page_trace_mem_init();
#endif
mem_init();
mem_init_print_info();
/* page_owner must be initialized after buddy is ready */

View File

@@ -24,6 +24,9 @@
#include <linux/page_owner.h>
#include <linux/psi.h>
#include "internal.h"
#ifdef CONFIG_AMLOGIC_PAGE_TRACE
#include <linux/amlogic/page_trace.h>
#endif
#ifdef CONFIG_COMPACTION
static inline void count_compact_event(enum vm_event_item item)
@@ -1738,6 +1741,9 @@ static struct page *compaction_alloc(struct page *migratepage,
freepage = list_entry(cc->freepages.next, struct page, lru);
list_del(&freepage->lru);
cc->nr_freepages--;
#ifdef CONFIG_AMLOGIC_PAGE_TRACE
replace_page_trace(freepage, migratepage);
#endif
return freepage;
}

View File

@@ -63,7 +63,12 @@ void __init mminit_verify_pageflags_layout(void)
int shift, width;
unsigned long or_mask, add_mask;
#ifdef CONFIG_AMLOGIC_PAGE_TRACE_INLINE
/* high 32bits have been taken by pagetrace, avoid bug in line 117 */
shift = 8 * sizeof(unsigned int);
#else
shift = 8 * sizeof(unsigned long);
#endif
width = shift - SECTIONS_WIDTH - NODES_WIDTH - ZONES_WIDTH
- LAST_CPUPID_SHIFT - KASAN_TAG_WIDTH - LRU_GEN_WIDTH - LRU_REFS_WIDTH;
mminit_dprintk(MMINIT_TRACE, "pageflags_layout_widths",

View File

@@ -81,6 +81,10 @@
#include "shuffle.h"
#include "page_reporting.h"
#ifdef CONFIG_AMLOGIC_PAGE_TRACE
#include <linux/amlogic/page_trace.h>
#endif
EXPORT_TRACEPOINT_SYMBOL_GPL(mm_page_alloc);
EXPORT_TRACEPOINT_SYMBOL_GPL(mm_page_free);
@@ -1486,6 +1490,9 @@ static __always_inline bool free_pages_prepare(struct page *page,
debug_pagealloc_unmap_pages(page, 1 << order);
#ifdef CONFIG_AMLOGIC_PAGE_TRACE
reset_page_trace(page, order);
#endif /* CONFIG_AMLOGIC_PAGE_TRACE */
return true;
}
@@ -5624,6 +5631,9 @@ unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid,
else
page_array[nr_populated] = page;
nr_populated++;
#ifdef CONFIG_AMLOGIC_PAGE_TRACE
set_page_trace(page, 0, gfp, NULL);
#endif /* CONFIG_AMLOGIC_PAGE_TRACE */
}
pcp_spin_unlock_irqrestore(pcp, flags);
@@ -5717,6 +5727,9 @@ out:
}
trace_mm_page_alloc(page, order, alloc_gfp, ac.migratetype);
#ifdef CONFIG_AMLOGIC_PAGE_TRACE
set_page_trace(page, order, gfp, NULL);
#endif /* CONFIG_AMLOGIC_PAGE_TRACE */
return page;
}