Skip to content

Commit 3c93646

Browse files
davem330David S. Miller
authored andcommitted
[SPARC64]: Kill pgtable quicklists and use SLAB.
Taking a nod from the powerpc port. With the per-cpu caching of both the page allocator and SLAB, the pgtable quicklist scheme becomes relatively silly and primitive. Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 05e28f9 commit 3c93646

5 files changed

Lines changed: 44 additions & 166 deletions

File tree

‎arch/sparc64/kernel/sparc64_ksyms.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,6 @@ EXPORT_SYMBOL(verify_compat_iovec);
241241
#endif
242242

243243
EXPORT_SYMBOL(dump_fpu);
244-
EXPORT_SYMBOL(pte_alloc_one_kernel);
245-
#ifndef CONFIG_SMP
246-
EXPORT_SYMBOL(pgt_quicklists);
247-
#endif
248244
EXPORT_SYMBOL(put_fs_struct);
249245

250246
/* math-emu wants this */

‎arch/sparc64/mm/init.c‎

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,26 +141,25 @@ unsigned long sparc64_kern_sec_context __read_mostly;
141141

142142
int bigkernel = 0;
143143

144-
/* XXX Tune this... */
145-
#define PGT_CACHE_LOW 25
146-
#define PGT_CACHE_HIGH 50
144+
kmem_cache_t *pgtable_cache __read_mostly;
147145

148-
#ifndef CONFIG_SMP
149-
struct pgtable_cache_struct pgt_quicklists;
150-
#endif
146+
static void zero_ctor(void *addr, kmem_cache_t *cache, unsigned long flags)
147+
{
148+
clear_page(addr);
149+
}
151150

152-
void check_pgt_cache(void)
151+
void pgtable_cache_init(void)
153152
{
154-
preempt_disable();
155-
if (pgtable_cache_size > PGT_CACHE_HIGH) {
156-
do {
157-
if (pgd_quicklist)
158-
free_pgd_slow(get_pgd_fast());
159-
if (pte_quicklist)
160-
free_pte_slow(pte_alloc_one_fast());
161-
} while (pgtable_cache_size > PGT_CACHE_LOW);
153+
pgtable_cache = kmem_cache_create("pgtable_cache",
154+
PAGE_SIZE, PAGE_SIZE,
155+
SLAB_HWCACHE_ALIGN |
156+
SLAB_MUST_HWCACHE_ALIGN,
157+
zero_ctor,
158+
NULL);
159+
if (!pgtable_cache) {
160+
prom_printf("pgtable_cache_init(): Could not create!\n");
161+
prom_halt();
162162
}
163-
preempt_enable();
164163
}
165164

166165
#ifdef CONFIG_DEBUG_DCFLUSH
@@ -340,7 +339,6 @@ void show_mem(void)
340339
nr_swap_pages << (PAGE_SHIFT-10));
341340
printk("%ld pages of RAM\n", num_physpages);
342341
printk("%d free pages\n", nr_free_pages());
343-
printk("%d pages in page table cache\n",pgtable_cache_size);
344342
}
345343

346344
void mmu_info(struct seq_file *m)

‎include/asm-sparc64/cpudata.h‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@ typedef struct {
1717
unsigned long clock_tick; /* %tick's per second */
1818
unsigned long udelay_val;
1919

20-
/* Dcache line 2 */
21-
unsigned int pgcache_size;
22-
unsigned int __pad1;
23-
unsigned long *pte_cache;
24-
unsigned long *pgd_cache;
25-
unsigned long __pad2;
26-
27-
/* Dcache line 3, rarely used */
20+
/* Dcache line 2, rarely used */
2821
unsigned int dcache_size;
2922
unsigned int dcache_line_size;
3023
unsigned int icache_size;

‎include/asm-sparc64/pgalloc.h‎

Lines changed: 27 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -6,171 +6,67 @@
66
#include <linux/kernel.h>
77
#include <linux/sched.h>
88
#include <linux/mm.h>
9+
#include <linux/slab.h>
910

1011
#include <asm/spitfire.h>
1112
#include <asm/cpudata.h>
1213
#include <asm/cacheflush.h>
1314
#include <asm/page.h>
1415

1516
/* Page table allocation/freeing. */
16-
#ifdef CONFIG_SMP
17-
/* Sliiiicck */
18-
#define pgt_quicklists local_cpu_data()
19-
#else
20-
extern struct pgtable_cache_struct {
21-
unsigned long *pgd_cache;
22-
unsigned long *pte_cache;
23-
unsigned int pgcache_size;
24-
} pgt_quicklists;
25-
#endif
26-
#define pgd_quicklist (pgt_quicklists.pgd_cache)
27-
#define pte_quicklist (pgt_quicklists.pte_cache)
28-
#define pgtable_cache_size (pgt_quicklists.pgcache_size)
17+
extern kmem_cache_t *pgtable_cache;
2918

30-
static inline void free_pgd_fast(pgd_t *pgd)
19+
static inline pgd_t *pgd_alloc(struct mm_struct *mm)
3120
{
32-
preempt_disable();
33-
*(unsigned long *)pgd = (unsigned long) pgd_quicklist;
34-
pgd_quicklist = (unsigned long *) pgd;
35-
pgtable_cache_size++;
36-
preempt_enable();
21+
return kmem_cache_alloc(pgtable_cache, GFP_KERNEL);
3722
}
3823

39-
static inline pgd_t *get_pgd_fast(void)
24+
static inline void pgd_free(pgd_t *pgd)
4025
{
41-
unsigned long *ret;
42-
43-
preempt_disable();
44-
if((ret = pgd_quicklist) != NULL) {
45-
pgd_quicklist = (unsigned long *)(*ret);
46-
ret[0] = 0;
47-
pgtable_cache_size--;
48-
preempt_enable();
49-
} else {
50-
preempt_enable();
51-
ret = (unsigned long *) __get_free_page(GFP_KERNEL|__GFP_REPEAT);
52-
if(ret)
53-
memset(ret, 0, PAGE_SIZE);
54-
}
55-
return (pgd_t *)ret;
56-
}
57-
58-
static inline void free_pgd_slow(pgd_t *pgd)
59-
{
60-
free_page((unsigned long)pgd);
26+
kmem_cache_free(pgtable_cache, pgd);
6127
}
6228

6329
#define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6430

65-
static inline pmd_t *pmd_alloc_one_fast(void)
66-
{
67-
unsigned long *ret;
68-
69-
preempt_disable();
70-
ret = (unsigned long *) pte_quicklist;
71-
if (likely(ret)) {
72-
pte_quicklist = (unsigned long *)(*ret);
73-
ret[0] = 0;
74-
pgtable_cache_size--;
75-
}
76-
preempt_enable();
77-
78-
return (pmd_t *) ret;
79-
}
80-
81-
static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
82-
{
83-
pmd_t *pmd;
84-
85-
pmd = pmd_alloc_one_fast();
86-
if (unlikely(!pmd)) {
87-
pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
88-
if (pmd)
89-
memset(pmd, 0, PAGE_SIZE);
90-
}
91-
return pmd;
92-
}
93-
94-
static inline void free_pmd_fast(pmd_t *pmd)
95-
{
96-
preempt_disable();
97-
*(unsigned long *)pmd = (unsigned long) pte_quicklist;
98-
pte_quicklist = (unsigned long *) pmd;
99-
pgtable_cache_size++;
100-
preempt_enable();
101-
}
102-
103-
static inline void free_pmd_slow(pmd_t *pmd)
104-
{
105-
free_page((unsigned long)pmd);
106-
}
107-
108-
#define pmd_populate_kernel(MM, PMD, PTE) pmd_set(PMD, PTE)
109-
#define pmd_populate(MM,PMD,PTE_PAGE) \
110-
pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
111-
112-
static inline pte_t *pte_alloc_one_fast(void)
31+
static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
11332
{
114-
unsigned long *ret;
115-
116-
preempt_disable();
117-
ret = (unsigned long *) pte_quicklist;
118-
if (likely(ret)) {
119-
pte_quicklist = (unsigned long *)(*ret);
120-
ret[0] = 0;
121-
pgtable_cache_size--;
122-
}
123-
preempt_enable();
124-
125-
return (pte_t *) ret;
33+
return kmem_cache_alloc(pgtable_cache,
34+
GFP_KERNEL|__GFP_REPEAT);
12635
}
12736

128-
static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
37+
static inline void pmd_free(pmd_t *pmd)
12938
{
130-
pte_t *ptep = pte_alloc_one_fast();
131-
132-
if (likely(ptep))
133-
return ptep;
134-
135-
return (pte_t *) get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
39+
kmem_cache_free(pgtable_cache, pmd);
13640
}
13741

138-
static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long addr)
42+
static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
43+
unsigned long address)
13944
{
140-
pte_t *pte = pte_alloc_one_fast();
141-
142-
if (likely(pte))
143-
return virt_to_page(pte);
144-
145-
return alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
45+
return kmem_cache_alloc(pgtable_cache,
46+
GFP_KERNEL|__GFP_REPEAT);
14647
}
14748

148-
static inline void free_pte_fast(pte_t *pte)
49+
static inline struct page *pte_alloc_one(struct mm_struct *mm,
50+
unsigned long address)
14951
{
150-
preempt_disable();
151-
*(unsigned long *)pte = (unsigned long) pte_quicklist;
152-
pte_quicklist = (unsigned long *) pte;
153-
pgtable_cache_size++;
154-
preempt_enable();
52+
return virt_to_page(pte_alloc_one_kernel(mm, address));
15553
}
156-
157-
static inline void free_pte_slow(pte_t *pte)
158-
{
159-
free_page((unsigned long) pte);
160-
}
161-
54+
16255
static inline void pte_free_kernel(pte_t *pte)
16356
{
164-
free_pte_fast(pte);
57+
kmem_cache_free(pgtable_cache, pte);
16558
}
16659

16760
static inline void pte_free(struct page *ptepage)
16861
{
169-
free_pte_fast(page_address(ptepage));
62+
pte_free_kernel(page_address(ptepage));
17063
}
17164

172-
#define pmd_free(pmd) free_pmd_fast(pmd)
173-
#define pgd_free(pgd) free_pgd_fast(pgd)
174-
#define pgd_alloc(mm) get_pgd_fast()
65+
66+
#define pmd_populate_kernel(MM, PMD, PTE) pmd_set(PMD, PTE)
67+
#define pmd_populate(MM,PMD,PTE_PAGE) \
68+
pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
69+
70+
#define check_pgt_cache() do { } while (0)
17571

17672
#endif /* _SPARC64_PGALLOC_H */

‎include/asm-sparc64/pgtable.h‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,7 @@ extern unsigned long get_fb_unmapped_area(struct file *filp, unsigned long,
432432
unsigned long);
433433
#define HAVE_ARCH_FB_UNMAPPED_AREA
434434

435-
/*
436-
* No page table caches to initialise
437-
*/
438-
#define pgtable_cache_init() do { } while (0)
439-
440-
extern void check_pgt_cache(void);
435+
extern void pgtable_cache_init(void);
441436

442437
#endif /* !(__ASSEMBLY__) */
443438

0 commit comments

Comments
 (0)