Skip to content

Commit ef629cc

Browse files
kvaneeshmpe
authored andcommitted
powerc/mm/hash: Reduce hash_mm_context size
Allocate subpage protect related variables only if we use the feature. This helps in reducing the hash related mm context struct by around 4K Before the patch sizeof(struct hash_mm_context) = 8288 After the patch sizeof(struct hash_mm_context) = 4160 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 7011018 commit ef629cc

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

arch/powerpc/include/asm/book3s/64/mmu-hash.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,8 @@ struct subpage_prot_table {
687687
#define SBP_L3_SHIFT (SBP_L2_SHIFT + SBP_L2_BITS)
688688

689689
extern void subpage_prot_free(struct mm_struct *mm);
690-
extern void subpage_prot_init_new_context(struct mm_struct *mm);
691690
#else
692691
static inline void subpage_prot_free(struct mm_struct *mm) {}
693-
static inline void subpage_prot_init_new_context(struct mm_struct *mm) { }
694692
#endif /* CONFIG_PPC_SUBPAGE_PROT */
695693

696694
/*
@@ -720,7 +718,7 @@ struct hash_mm_context {
720718
#endif
721719

722720
#ifdef CONFIG_PPC_SUBPAGE_PROT
723-
struct subpage_prot_table spt;
721+
struct subpage_prot_table *spt;
724722
#endif /* CONFIG_PPC_SUBPAGE_PROT */
725723
};
726724

arch/powerpc/include/asm/book3s/64/mmu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static inline struct slice_mask *mm_ctx_slice_mask_16g(mm_context_t *ctx)
206206
#ifdef CONFIG_PPC_SUBPAGE_PROT
207207
static inline struct subpage_prot_table *mm_ctx_subpage_prot(mm_context_t *ctx)
208208
{
209-
return &ctx->hash_context->spt;
209+
return ctx->hash_context->spt;
210210
}
211211
#endif
212212

arch/powerpc/mm/hash_utils_64.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,9 @@ static int subpage_protection(struct mm_struct *mm, unsigned long ea)
11501150
u32 spp = 0;
11511151
u32 **sbpm, *sbpp;
11521152

1153+
if (!spt)
1154+
return 0;
1155+
11531156
if (ea >= spt->maxaddr)
11541157
return 0;
11551158
if (ea < 0x100000000UL) {

arch/powerpc/mm/mmu_context_book3s64.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ static int hash__init_new_context(struct mm_struct *mm)
6363
if (index < 0)
6464
return index;
6565

66-
mm->context.hash_context = kmalloc(sizeof(struct hash_mm_context), GFP_KERNEL);
66+
mm->context.hash_context = kmalloc(sizeof(struct hash_mm_context),
67+
GFP_KERNEL);
6768
if (!mm->context.hash_context) {
6869
ida_free(&mmu_context_ida, index);
6970
return -ENOMEM;
@@ -89,11 +90,21 @@ static int hash__init_new_context(struct mm_struct *mm)
8990
} else {
9091
/* This is fork. Copy hash_context details from current->mm */
9192
memcpy(mm->context.hash_context, current->mm->context.hash_context, sizeof(struct hash_mm_context));
93+
#ifdef CONFIG_PPC_SUBPAGE_PROT
94+
/* inherit subpage prot detalis if we have one. */
95+
if (current->mm->context.hash_context->spt) {
96+
mm->context.hash_context->spt = kmalloc(sizeof(struct subpage_prot_table),
97+
GFP_KERNEL);
98+
if (!mm->context.hash_context->spt) {
99+
ida_free(&mmu_context_ida, index);
100+
kfree(mm->context.hash_context);
101+
return -ENOMEM;
102+
}
103+
}
104+
#endif
92105

93106
}
94107

95-
subpage_prot_init_new_context(mm);
96-
97108
pkey_mm_init(mm);
98109
return index;
99110
}

arch/powerpc/mm/subpage-prot.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ void subpage_prot_free(struct mm_struct *mm)
2929
unsigned long i, j, addr;
3030
u32 **p;
3131

32+
if (!spt)
33+
return;
34+
3235
for (i = 0; i < 4; ++i) {
3336
if (spt->low_prot[i]) {
3437
free_page((unsigned long)spt->low_prot[i]);
@@ -48,13 +51,7 @@ void subpage_prot_free(struct mm_struct *mm)
4851
free_page((unsigned long)p);
4952
}
5053
spt->maxaddr = 0;
51-
}
52-
53-
void subpage_prot_init_new_context(struct mm_struct *mm)
54-
{
55-
struct subpage_prot_table *spt = mm_ctx_subpage_prot(&mm->context);
56-
57-
memset(spt, 0, sizeof(*spt));
54+
kfree(spt);
5855
}
5956

6057
static void hpte_flush_range(struct mm_struct *mm, unsigned long addr,
@@ -99,6 +96,9 @@ static void subpage_prot_clear(unsigned long addr, unsigned long len)
9996
size_t nw;
10097
unsigned long next, limit;
10198

99+
if (!spt)
100+
return ;
101+
102102
down_write(&mm->mmap_sem);
103103
limit = addr + len;
104104
if (limit > spt->maxaddr)
@@ -218,6 +218,20 @@ SYSCALL_DEFINE3(subpage_prot, unsigned long, addr,
218218
return -EFAULT;
219219

220220
down_write(&mm->mmap_sem);
221+
222+
if (!spt) {
223+
/*
224+
* Allocate subpage prot table if not already done.
225+
* Do this with mmap_sem held
226+
*/
227+
spt = kzalloc(sizeof(struct subpage_prot_table), GFP_KERNEL);
228+
if (!spt) {
229+
err = -ENOMEM;
230+
goto out;
231+
}
232+
mm->context.hash_context->spt = spt;
233+
}
234+
221235
subpage_mark_vma_nohuge(mm, addr, len);
222236
for (limit = addr + len; addr < limit; addr = next) {
223237
next = pmd_addr_end(addr, limit);

0 commit comments

Comments
 (0)