Skip to content

Commit 088bb10

Browse files
hcahcaAlexander Gordeev
authored andcommitted
s390/mm: Add memory allocation profiling hooks
Similar to common code changes [1] add alloc_hook() wrappers to page table allocation functions to allow for memory allocation profiling. If CONFIG_MEM_ALLOC_PROFILING is enabled call sites of page table allocations are accounted, instead of e.g. only crst_table_alloc() and page_table_alloc(). This allows for slightly better profiling data, and the output of /proc/allocinfo is similar to other architectures. Without alloc_hook() wrappers the output of /proc/allocinfo looks like this: 17096704 4174 mm/memory.c:1061 func:folio_prealloc 17809408 4348 mm/memory.c:1063 func:folio_prealloc 0 0 mm/memory.c:4422 func:alloc_swap_folio 0 0 mm/memory.c:4286 func:__alloc_swap_folio 0 0 mm/memory.c:4971 func:alloc_anon_folio ... 1589248 97 arch/s390/mm/pgalloc.c:25 func:crst_table_alloc 0 0 arch/s390/mm/pgalloc.c:124 func:page_table_alloc_pgste 4280320 1045 arch/s390/mm/pgalloc.c:149 func:page_table_alloc With alloc_hook() wrappers: 1097728 268 mm/memory.c:5147 func:__do_fault 20119552 4912 mm/memory.c:1061 func:folio_prealloc 17534976 4281 mm/memory.c:1063 func:folio_prealloc 0 0 mm/memory.c:4422 func:alloc_swap_folio 0 0 mm/memory.c:4286 func:__alloc_swap_folio 786432 192 mm/memory.c:452 func:__pte_alloc 405504 99 mm/memory.c:464 func:__pte_alloc_kernel 1880064 459 mm/memory.c:5525 func:do_fault_around 0 0 mm/memory.c:6403 func:__p4d_alloc 0 0 mm/memory.c:6426 func:__pud_alloc 1064960 65 mm/memory.c:6450 func:__pmd_alloc 0 0 mm/memory.c:4971 func:alloc_anon_folio 0 0 mm/memory.c:5233 func:do_set_pmd [1] commit 2c321f3 ("mm: change inlined allocation helpers to account at the call site") Signed-off-by: Heiko Carstens <[email protected]> Acked-by: Alexander Gordeev <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]>
1 parent 72105fc commit 088bb10

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

arch/s390/include/asm/pgalloc.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919

2020
#define CRST_ALLOC_ORDER 2
2121

22-
unsigned long *crst_table_alloc(struct mm_struct *);
22+
unsigned long *crst_table_alloc_noprof(struct mm_struct *);
23+
#define crst_table_alloc(...) alloc_hooks(crst_table_alloc_noprof(__VA_ARGS__))
2324
void crst_table_free(struct mm_struct *, unsigned long *);
2425

25-
unsigned long *page_table_alloc(struct mm_struct *);
26-
struct ptdesc *page_table_alloc_pgste(struct mm_struct *mm);
26+
unsigned long *page_table_alloc_noprof(struct mm_struct *);
27+
#define page_table_alloc(...) alloc_hooks(page_table_alloc_noprof(__VA_ARGS__))
2728
void page_table_free(struct mm_struct *, unsigned long *);
29+
30+
struct ptdesc *page_table_alloc_pgste_noprof(struct mm_struct *mm);
31+
#define page_table_alloc_pgste(...) alloc_hooks(page_table_alloc_pgste_noprof(__VA_ARGS__))
2832
void page_table_free_pgste(struct ptdesc *ptdesc);
2933

3034
static inline void crst_table_init(unsigned long *crst, unsigned long entry)
@@ -48,9 +52,9 @@ static inline unsigned long check_asce_limit(struct mm_struct *mm, unsigned long
4852
return addr;
4953
}
5054

51-
static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long address)
55+
static inline p4d_t *p4d_alloc_one_noprof(struct mm_struct *mm, unsigned long address)
5256
{
53-
unsigned long *table = crst_table_alloc(mm);
57+
unsigned long *table = crst_table_alloc_noprof(mm);
5458

5559
if (!table)
5660
return NULL;
@@ -59,6 +63,7 @@ static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long address)
5963

6064
return (p4d_t *) table;
6165
}
66+
#define p4d_alloc_one(...) alloc_hooks(p4d_alloc_one_noprof(__VA_ARGS__))
6267

6368
static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
6469
{
@@ -69,9 +74,9 @@ static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d)
6974
crst_table_free(mm, (unsigned long *) p4d);
7075
}
7176

72-
static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
77+
static inline pud_t *pud_alloc_one_noprof(struct mm_struct *mm, unsigned long address)
7378
{
74-
unsigned long *table = crst_table_alloc(mm);
79+
unsigned long *table = crst_table_alloc_noprof(mm);
7580

7681
if (!table)
7782
return NULL;
@@ -80,6 +85,7 @@ static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
8085

8186
return (pud_t *) table;
8287
}
88+
#define pud_alloc_one(...) alloc_hooks(pud_alloc_one_noprof(__VA_ARGS__))
8389

8490
static inline void pud_free(struct mm_struct *mm, pud_t *pud)
8591
{
@@ -90,9 +96,9 @@ static inline void pud_free(struct mm_struct *mm, pud_t *pud)
9096
crst_table_free(mm, (unsigned long *) pud);
9197
}
9298

93-
static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
99+
static inline pmd_t *pmd_alloc_one_noprof(struct mm_struct *mm, unsigned long vmaddr)
94100
{
95-
unsigned long *table = crst_table_alloc(mm);
101+
unsigned long *table = crst_table_alloc_noprof(mm);
96102

97103
if (!table)
98104
return NULL;
@@ -103,6 +109,7 @@ static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
103109
}
104110
return (pmd_t *) table;
105111
}
112+
#define pmd_alloc_one(...) alloc_hooks(pmd_alloc_one_noprof(__VA_ARGS__))
106113

107114
static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
108115
{
@@ -127,16 +134,17 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
127134
set_pud(pud, __pud(_REGION3_ENTRY | __pa(pmd)));
128135
}
129136

130-
static inline pgd_t *pgd_alloc(struct mm_struct *mm)
137+
static inline pgd_t *pgd_alloc_noprof(struct mm_struct *mm)
131138
{
132-
unsigned long *table = crst_table_alloc(mm);
139+
unsigned long *table = crst_table_alloc_noprof(mm);
133140

134141
if (!table)
135142
return NULL;
136143
pagetable_pgd_ctor(virt_to_ptdesc(table));
137144

138145
return (pgd_t *) table;
139146
}
147+
#define pgd_alloc(...) alloc_hooks(pgd_alloc_noprof(__VA_ARGS__))
140148

141149
static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
142150
{

arch/s390/mm/pgalloc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
#include <asm/pgalloc.h>
1515
#include <asm/tlbflush.h>
1616

17-
unsigned long *crst_table_alloc(struct mm_struct *mm)
17+
unsigned long *crst_table_alloc_noprof(struct mm_struct *mm)
1818
{
1919
gfp_t gfp = GFP_KERNEL_ACCOUNT;
2020
struct ptdesc *ptdesc;
2121
unsigned long *table;
2222

2323
if (mm == &init_mm)
2424
gfp &= ~__GFP_ACCOUNT;
25-
ptdesc = pagetable_alloc(gfp, CRST_ALLOC_ORDER);
25+
ptdesc = pagetable_alloc_noprof(gfp, CRST_ALLOC_ORDER);
2626
if (!ptdesc)
2727
return NULL;
2828
table = ptdesc_to_virt(ptdesc);
@@ -116,12 +116,12 @@ int crst_table_upgrade(struct mm_struct *mm, unsigned long end)
116116

117117
#ifdef CONFIG_PGSTE
118118

119-
struct ptdesc *page_table_alloc_pgste(struct mm_struct *mm)
119+
struct ptdesc *page_table_alloc_pgste_noprof(struct mm_struct *mm)
120120
{
121121
struct ptdesc *ptdesc;
122122
u64 *table;
123123

124-
ptdesc = pagetable_alloc(GFP_KERNEL_ACCOUNT, 0);
124+
ptdesc = pagetable_alloc_noprof(GFP_KERNEL_ACCOUNT, 0);
125125
if (ptdesc) {
126126
table = (u64 *)ptdesc_to_virt(ptdesc);
127127
__arch_set_page_dat(table, 1);
@@ -138,15 +138,15 @@ void page_table_free_pgste(struct ptdesc *ptdesc)
138138

139139
#endif /* CONFIG_PGSTE */
140140

141-
unsigned long *page_table_alloc(struct mm_struct *mm)
141+
unsigned long *page_table_alloc_noprof(struct mm_struct *mm)
142142
{
143143
gfp_t gfp = GFP_KERNEL_ACCOUNT;
144144
struct ptdesc *ptdesc;
145145
unsigned long *table;
146146

147147
if (mm == &init_mm)
148148
gfp &= ~__GFP_ACCOUNT;
149-
ptdesc = pagetable_alloc(gfp, 0);
149+
ptdesc = pagetable_alloc_noprof(gfp, 0);
150150
if (!ptdesc)
151151
return NULL;
152152
if (!pagetable_pte_ctor(mm, ptdesc)) {

0 commit comments

Comments
 (0)