removing mm->rss and mm->anon_rss from kernel?
Subsystems (4)
My page scalability patches need to make rss atomic and now with the addition of anon_rss I would also have to make that atomic.
But when I looked at the code I found that the only significant use of both is in for proc statistics. There are 3 other uses in mm/rmap.c where the use of mm->rss may be replaced by mm->total_vm.
So I removed all uses of mm->rss and anon_rss from the kernel and introduced a bean counter count_vm() that is only run when the corresponding /proc file is used. count_vm then runs throught the vm and counts all the page types. This could also add additional page types to our statistics and solve some of the consistency issues.
The patch is by no means perfect. If you think this is worth pursuing then I will finish the support for other archs and deal with the locking issues etc. This patch may also remove hot spot issues that may arise with the use of these two variables and so is of interest to us.
But a kernel with this patch boots fine and the statistics in /proc look still okay (its late though....)
Index: linux-2.6.9/kernel/fork.c
=================================--- linux-2.6.9.orig/kernel/fork.c 2004-11-03 13:36:35.000000000 -0800
+++ linux-2.6.9/kernel/fork.c 2004-11-05 18:09:53.000000000 -0800
@@ -172,8 +172,6 @@
mm->mmap_cache = NULL;
mm->free_area_cache = oldmm->mmap_base;
mm->map_count = 0;
- mm->rss = 0;
- mm->anon_rss = 0;
cpus_clear(mm->cpu_vm_mask);
mm->mm_rb = RB_ROOT;
rb_link = &mm->mm_rb.rb_node;
Index: linux-2.6.9/include/linux/sched.h
=================================--- linux-2.6.9.orig/include/linux/sched.h 2004-11-03 13:36:35.000000000 -0800
+++ linux-2.6.9/include/linux/sched.h 2004-11-05 18:09:33.000000000 -0800
@@ -216,7 +216,7 @@
atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
int map_count; /* number of VMAs */
struct rw_semaphore mmap_sem;
- spinlock_t page_table_lock; /* Protects page tables, mm->rss, mm->anon_rss */
+ spinlock_t page_table_lock; /* Protects page tables */
struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung
* together off init_mm.mmlist, and are protected
@@ -226,7 +226,7 @@
unsigned long start_code, end_code, start_data, end_data;
unsigned long start_brk, brk, start_stack;
unsigned long arg_start, arg_end, env_start, env_end;
- unsigned long rss, anon_rss, total_vm, locked_vm, shared_vm;
+ unsigned long total_vm, locked_vm, shared_vm;
unsigned long exec_vm, stack_vm, reserved_vm, def_flags, nr_ptes;
unsigned long saved_auxv[42]; /* for /proc/PID/auxv */
Index: linux-2.6.9/fs/proc/task_mmu.c
=================================--- linux-2.6.9.orig/fs/proc/task_mmu.c 2004-11-03 13:36:34.000000000 -0800
+++ linux-2.6.9/fs/proc/task_mmu.c 2004-11-06 00:41:11.000000000 -0800
@@ -7,10 +7,13 @@
char *task_mem(struct mm_struct *mm, char *buffer) {
unsigned long data, text, lib;
+ struct vm_count c;
+
data = mm->total_vm - mm->shared_vm - mm->stack_vm;
text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10; lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text;
+ count_vm(mm, &c);
buffer += sprintf(buffer,
"VmSize:\t%8lu kB\n"
"VmLck:\t%8lu kB\n"
@@ -22,7 +25,7 @@
"VmPTE:\t%8lu kB\n",
(mm->total_vm - mm->reserved_vm) << (PAGE_SHIFT-10), mm->locked_vm << (PAGE_SHIFT-10),
- mm->rss << (PAGE_SHIFT-10),
+ c.resident << (PAGE_SHIFT-10),
data << (PAGE_SHIFT-10),
mm->stack_vm << (PAGE_SHIFT-10), text, lib, (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
@@ -37,11 +40,14 @@
int task_statm(struct mm_struct *mm, int *shared, int *text,
int *data, int *resident)
{
- *shared = mm->rss - mm->anon_rss;
+ struct vm_count c;
+
+ count_vm(mm, &c);
+ *shared = c.shared;
*text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
>> PAGE_SHIFT;
*data = mm->total_vm - mm->shared_vm;
- *resident = mm->rss;
+ *resident = c.resident;
return mm->total_vm;
}
Index: linux-2.6.9/mm/mmap.c
=================================--- linux-2.6.9.orig/mm/mmap.c 2004-11-03 13:36:36.000000000 -0800
+++ linux-2.6.9/mm/mmap.c 2004-11-05 18:12:00.000000000 -0800
@@ -1850,7 +1850,6 @@
vma = mm->mmap;
mm->mmap = mm->mmap_cache = NULL;
mm->mm_rb = RB_ROOT;
- mm->rss = 0;
mm->total_vm = 0;
mm->locked_vm = 0;
Index: linux-2.6.9/include/asm-generic/tlb.h
=================================--- linux-2.6.9.orig/include/asm-generic/tlb.h 2004-10-18 14:53:05.000000000 -0700
+++ linux-2.6.9/include/asm-generic/tlb.h 2004-11-06 01:12:10.000000000 -0800
@@ -86,13 +86,6 @@
static inline void
tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end) {
- int freed = tlb->freed;
- struct mm_struct *mm = tlb->mm;
- int rss = mm->rss;
-
- if (rss < freed)
- freed = rss;
- mm->rss = rss - freed;
tlb_flush_mmu(tlb, start, end);
/* keep the page table cache within bounds */
Index: linux-2.6.9/fs/exec.c
=================================--- linux-2.6.9.orig/fs/exec.c 2004-11-03 13:36:34.000000000 -0800
+++ linux-2.6.9/fs/exec.c 2004-11-05 18:19:42.000000000 -0800
@@ -320,7 +320,6 @@
pte_unmap(pte);
goto out;
}
- mm->rss++;
lru_cache_add_active(page);
set_pte(pte, pte_mkdirty(pte_mkwrite(mk_pte(
page, vma->vm_page_prot))));
Index: linux-2.6.9/fs/binfmt_flat.c
=================================--- linux-2.6.9.orig/fs/binfmt_flat.c 2004-11-03 13:36:29.000000000 -0800
+++ linux-2.6.9/fs/binfmt_flat.c 2004-11-05 18:19:27.000000000 -0800
@@ -650,7 +650,6 @@
current->mm->start_brk = datapos + data_len + bss_len; current->mm->brk = (current->mm->start_brk + 3) & ~3; current->mm->context.end_brk = memp + ksize((void *) memp) - stack_len;
- current->mm->rss = 0;
}
if (flags & FLAT_FLAG_KTRACE)
Index: linux-2.6.9/mm/memory.c
=================================--- linux-2.6.9.orig/mm/memory.c 2004-11-03 13:36:36.000000000 -0800
+++ linux-2.6.9/mm/memory.c 2004-11-06 01:10:19.000000000 -0800
@@ -333,9 +333,6 @@
pte = pte_mkclean(pte);
pte = pte_mkold(pte); get_page(page);
- dst->rss++;
- if (PageAnon(page))
- dst->anon_rss++;
set_pte(dst_pte, pte); page_dup_rmap(page);
cont_copy_pte_range_noset:
@@ -426,8 +423,6 @@
set_pte(ptep, pgoff_to_pte(page->index));
if (pte_dirty(pte))
set_page_dirty(page);
- if (PageAnon(page))
- tlb->mm->anon_rss--;
else if (pte_young(pte))
mark_page_accessed(page);
tlb->freed++;
@@ -1113,11 +1108,7 @@
spin_lock(&mm->page_table_lock);
page_table = pte_offset_map(pmd, address);
if (likely(pte_same(*page_table, pte))) {
- if (PageAnon(old_page))
- mm->anon_rss--;
- if (PageReserved(old_page))
- ++mm->rss;
- else
+ if (!PageReserved(old_page))
page_remove_rmap(old_page);
break_cow(vma, new_page, address, page_table); lru_cache_add_active(new_page);
@@ -1398,7 +1389,6 @@
if (vm_swap_full())
remove_exclusive_swap_page(page);
- mm->rss++;
pte = mk_pte(page, vma->vm_page_prot);
if (write_access && can_share_swap_page(page)) {
pte = maybe_mkwrite(pte_mkdirty(pte), vma);
@@ -1463,7 +1453,6 @@
spin_unlock(&mm->page_table_lock);
goto out;
}
- mm->rss++;
entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
vma->vm_page_prot)),
vma);
@@ -1571,8 +1560,6 @@
*/
/* Only go through if we didn't race with anybody else... */ if (pte_none(*page_table)) {
- if (!PageReserved(new_page))
- ++mm->rss;
flush_icache_page(vma, new_page);
entry = mk_pte(new_page, vma->vm_page_prot);
if (write_access)
@@ -1851,3 +1838,108 @@
}
#endif
+
+static void count_pte_range(pmd_t *pmd,
+ unsigned long address, unsigned long size,
+ struct vm_count *c)
+{
+ unsigned long offset;
+ pte_t *ptep;
+
+ if (pmd_none(*pmd))
+ return;
+ if (unlikely(pmd_bad(*pmd)))
+ return;
+ ptep = pte_offset_map(pmd, address); + offset = address & ~PMD_MASK; + if (offset + size > PMD_SIZE)
+ size = PMD_SIZE - offset;
+ size &= PAGE_MASK;
+ for (offset=0; offset < size; ptep++, offset += PAGE_SIZE) {
+ pte_t pte = *ptep;
+
+ if (pte_none(pte))
+ continue;
+
+ if (pte_present(pte)) {
+ struct page *page = NULL;
+ unsigned long pfn = pte_pfn(pte);
+
+ c->present++;
+ if (pfn_valid(pfn)) {
+ page = pfn_to_page(pfn);
+ if (PageReserved(page))
+ c->reserved++;
+ else
+ if (page_mapped(page) > 1)
+ c->shared++;
+ else
+ if (page_mapped(page) = 1)
+ c->resident++;
+
+ if (PageLocked(page))
+ c->locked++;
+ }
+ if (unlikely(!page))
+ continue;
+ if (pte_dirty(pte))
+ c->dirty++;
+ else if (pte_young(pte))
+ c->young++;
+ } else {
+ if (pte_file(pte))
+ c->file++;
+ else
+ c->swap++;
+ }
+ }
+}
+
+static void count_pmd_range(pgd_t *dir,
+ unsigned long address, unsigned long end, struct vm_count *c)
+{
+ pmd_t * pmd;
+
+ if (pgd_none(*dir))
+ return;
+ if (unlikely(pgd_bad(*dir)))
+ return;
+
+ pmd = pmd_offset(dir, address);
+
+ if (end > ((address + PGDIR_SIZE) & PGDIR_MASK))
+ end = ((address + PGDIR_SIZE) & PGDIR_MASK);
+ do {
+ count_pte_range(pmd, address, end - address, c); + address = (address + PMD_SIZE) & PMD_MASK; + pmd++;
+ } while (address && address < end);
+}
+
+static void count_vma(struct vm_area_struct *vma, struct vm_count *c) +{
+ unsigned long address = vma->vm_start;
+ unsigned long end = vma->vm_end;
+ pgd_t * dir = pgd_offset(vma->vm_mm, address);
+
+ do {
+ count_pmd_range(dir, address, end, c);
+ address = (address + PGDIR_SIZE) & PGDIR_MASK;
+ dir++;
+ } while (address && address < end);
+}
+
+void count_vm(struct mm_struct *mm, struct vm_count *c)
+{
+ struct vm_area_struct *vma;
+
+ memset(c, 0,sizeof(struct vm_count));
+
+ for(vma = mm->mmap; vma; vma = vma->vm_next)
+ if (is_vm_hugetlb_page(vma)) {
+ printk(KERN_WARNING "hugetlb scans not supported.\n");
+ } else
+ count_vma(vma, c);
+}
+
+
Index: linux-2.6.9/fs/binfmt_som.c
=================================--- linux-2.6.9.orig/fs/binfmt_som.c 2004-10-18 14:53:51.000000000 -0700
+++ linux-2.6.9/fs/binfmt_som.c 2004-11-05 18:19:54.000000000 -0800
@@ -259,7 +259,6 @@
create_som_tables(bprm);
current->mm->start_stack = bprm->p;
- current->mm->rss = 0;
#if 0
printk("(start_brk) %08lx\n" , (unsigned long) current->mm->start_brk);
Index: linux-2.6.9/mm/fremap.c
=================================--- linux-2.6.9.orig/mm/fremap.c 2004-11-03 13:36:30.000000000 -0800
+++ linux-2.6.9/mm/fremap.c 2004-11-05 18:11:46.000000000 -0800
@@ -39,7 +39,6 @@
set_page_dirty(page);
page_remove_rmap(page); page_cache_release(page);
- mm->rss--;
}
}
} else {
@@ -87,7 +86,6 @@
zap_pte(mm, vma, addr, pte);
- mm->rss++;
flush_icache_page(vma, page);
set_pte(pte, mk_pte(page, prot)); page_add_file_rmap(page);
Index: linux-2.6.9/mm/swapfile.c
=================================--- linux-2.6.9.orig/mm/swapfile.c 2004-11-03 13:36:36.000000000 -0800
+++ linux-2.6.9/mm/swapfile.c 2004-11-05 18:13:56.000000000 -0800
@@ -431,7 +431,6 @@
unuse_pte(struct vm_area_struct *vma, unsigned long address, pte_t *dir,
swp_entry_t entry, struct page *page)
{
- vma->vm_mm->rss++;
get_page(page);
set_pte(dir, pte_mkold(mk_pte(page, vma->vm_page_prot))); page_add_anon_rmap(page, vma, address);
Index: linux-2.6.9/fs/binfmt_aout.c
=================================--- linux-2.6.9.orig/fs/binfmt_aout.c 2004-11-03 13:36:29.000000000 -0800
+++ linux-2.6.9/fs/binfmt_aout.c 2004-11-05 18:19:16.000000000 -0800
@@ -309,7 +309,6 @@
(current->mm->start_brk = N_BSSADDR(ex));
current->mm->free_area_cache = current->mm->mmap_base;
- current->mm->rss = 0;
current->mm->mmap = NULL;
compute_creds(bprm);
current->flags &= ~PF_FORKNOEXEC;
Index: linux-2.6.9/arch/ia64/mm/hugetlbpage.c
=================================--- linux-2.6.9.orig/arch/ia64/mm/hugetlbpage.c 2004-10-18 14:54:27.000000000 -0700
+++ linux-2.6.9/arch/ia64/mm/hugetlbpage.c 2004-11-05 18:17:34.000000000 -0800
@@ -65,7 +65,6 @@
{
pte_t entry;
- mm->rss += (HPAGE_SIZE / PAGE_SIZE);
if (write_access) {
entry pte_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
@@ -108,7 +107,6 @@
ptepage = pte_page(entry);
get_page(ptepage);
set_pte(dst_pte, entry);
- dst->rss += (HPAGE_SIZE / PAGE_SIZE);
addr += HPAGE_SIZE;
}
return 0;
@@ -249,7 +247,6 @@
put_page(page);
pte_clear(pte);
}
- mm->rss -= (end - start) >> PAGE_SHIFT;
flush_tlb_range(vma, start, end);
}
Index: linux-2.6.9/fs/proc/array.c
=================================--- linux-2.6.9.orig/fs/proc/array.c 2004-11-03 13:36:29.000000000 -0800
+++ linux-2.6.9/fs/proc/array.c 2004-11-06 00:43:28.000000000 -0800
@@ -317,6 +317,7 @@
unsigned long rsslim = 0;
struct task_struct *t;
char tcomm[sizeof(task->comm)];
+ struct vm_count c;
state = *get_task_state(task);
vsize = eip = esp = 0;
@@ -394,6 +395,9 @@
/* convert nsec -> ticks */
start_time = nsec_to_clock_t(start_time);
+ if (mm)
+ count_vm(mm, &c);
+
res = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
%lu %lu %lu %lu %lu %ld %ld %ld %ld %d %ld %llu %lu %ld %lu %lu %lu %lu %lu \
%lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu\n",
@@ -420,7 +424,7 @@
jiffies_to_clock_t(task->it_real_value), start_time,
vsize,
- mm ? mm->rss : 0, /* you might want to shift this left 3 */
+ mm ? c.resident : 0, /* you might want to shift this left 3 */
rsslim,
mm ? mm->start_code : 0,
mm ? mm->end_code : 0,
Index: linux-2.6.9/arch/i386/mm/hugetlbpage.c
=================================--- linux-2.6.9.orig/arch/i386/mm/hugetlbpage.c 2004-11-03 13:36:31.000000000 -0800
+++ linux-2.6.9/arch/i386/mm/hugetlbpage.c 2004-11-05 18:18:05.000000000 -0800
@@ -42,7 +42,6 @@
{
pte_t entry;
- mm->rss += (HPAGE_SIZE / PAGE_SIZE);
if (write_access) {
entry pte_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
@@ -82,7 +81,6 @@
ptepage = pte_page(entry);
get_page(ptepage);
set_pte(dst_pte, entry);
- dst->rss += (HPAGE_SIZE / PAGE_SIZE);
addr += HPAGE_SIZE;
}
return 0;
@@ -218,7 +216,6 @@
page = pte_page(pte);
put_page(page);
}
- mm->rss -= (end - start) >> PAGE_SHIFT;
flush_tlb_range(vma, start, end);
}
Index: linux-2.6.9/fs/binfmt_elf.c
=================================--- linux-2.6.9.orig/fs/binfmt_elf.c 2004-11-03 13:36:29.000000000 -0800
+++ linux-2.6.9/fs/binfmt_elf.c 2004-11-05 18:18:53.000000000 -0800
@@ -716,7 +716,6 @@
/* Do this so that we can load the interpreter, if need be. We will
change some of these later */
- current->mm->rss = 0;
current->mm->free_area_cache = current->mm->mmap_base;
retval = setup_arg_pages(bprm, executable_stack);
if (retval < 0) {
Index: linux-2.6.9/include/asm-ia64/tlb.h
=================================--- linux-2.6.9.orig/include/asm-ia64/tlb.h 2004-10-18 14:53:51.000000000 -0700
+++ linux-2.6.9/include/asm-ia64/tlb.h 2004-11-06 00:33:14.000000000 -0800
@@ -159,13 +159,6 @@
static inline void
tlb_finish_mmu (struct mmu_gather *tlb, unsigned long start, unsigned long end) {
- unsigned long freed = tlb->freed;
- struct mm_struct *mm = tlb->mm;
- unsigned long rss = mm->rss;
-
- if (rss < freed)
- freed = rss;
- mm->rss = rss - freed;
/*
* Note: tlb->nr may be 0 at this point, so we can't rely on tlb->start_addr and
* tlb->end_addr.
Index: linux-2.6.9/include/linux/mm.h
=================================--- linux-2.6.9.orig/include/linux/mm.h 2004-11-03 13:36:35.000000000 -0800
+++ linux-2.6.9/include/linux/mm.h 2004-11-06 00:28:06.000000000 -0800
@@ -792,6 +792,22 @@
-vma_pages(vma));
}
+/* Statistics on pages used in a vm */
+
+struct vm_count {
+ unsigned long shared;
+ unsigned long resident;
+ unsigned long swap;
+ unsigned long file;
+ unsigned long present;
+ unsigned long reserved;
+ unsigned long dirty;
+ unsigned long locked;
+ unsigned long young;
+};
+
+extern void count_vm(struct mm_struct *mm, struct vm_count *c); +
#ifndef CONFIG_DEBUG_PAGEALLOC
static inline void
kernel_map_pages(struct page *page, int numpages, int enable)
Quoted 13 lines · Christoph Lameter
My page scalability patches need to make rss atomic and now with the addition of
anon_rssI would also have to make that atomic.But when I looked at the code I found that the only significant use of both is in for proc statistics. There are 3 other uses in
mm/rmap.cwhere the use ofmm->rssmay be replaced bymm->total_vm.So I removed all uses of
mm->rssandanon_rssfrom the kernel and introduced a bean countercount_vm()that is only run when the corresponding /proc file is used.count_vmthen runs throught the vm and counts all the page types. This could also add additional page types to our statistics and solve some of the consistency issues.
Quoted 8 lines
The patch is by no means perfect. If you think this is worth pursuing then I will finish the support for other archs and deal with the locking issues etc. This patch may also remove hot spot issues that may arise with the use of these two variables and so is of interest to us.
But a kernel with this patch boots fine and the statistics in /proc look still okay (its late though....)
Nice.
Seems like a pretty good idea to me. Optimising the fast path is what we've always done, especially when keeping /proc stats. Maybe this would make the /proc cost prohibitive though? (Hopefully not).
What I was thinking of doing was to keep per-CPU magazines, and use them to amortise operations to a global atomic counter. That would drift, be inaccurate, and possibly go negative (without more logic). Obviously far more unwieldily (and basically crap) compared to your elegant solution. --
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Nick Piggin
Seems like a pretty good idea to me. Optimising the fast path is what we've always done, especially when keeping /proc stats. Maybe this would make the /proc cost prohibitive though? (Hopefully not).
What I was thinking of doing was to keep per-CPU magazines, and use them to amortise operations to a global atomic counter. That would drift, be inaccurate, and possibly go negative (without more logic). Obviously far more unwieldily (and basically crap) compared to your elegant solution.
Doing all the statistics by walking through a process' virtual memory from /proc/ routines was what we started with in 2.4
Reverting it all is a huge step backward. It was done because the /proc/ cost is in fact prohibitive.
And, of course, I fully appreciate being omitted from the thread dedicated to backing out my work.
-- wli
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 3 lines · Christoph Lameter
My page scalability patches need to make rss atomic and now with the addition of
anon_rssI would also have to make that atomic.
Oh, one other thing Christoph - don't forget mm->nr_ptes --
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Christoph Lameter
Quoted 2 lines
My page scalability patches need to make rss atomic and now with the addition of
anon_rssI would also have to make that atomic.
Quoted 1 line · Nick Piggin
Oh, one other thing Christoph - don't forget
mm->nr_ptes
Forget it. Veto.
Normal-sized systems need to monitor their workloads without crippling them. Do the per-cpu splitting of the counters etc. instead, or other proper incremental algorithms. Catastrophic /proc/ overhead won't fly.
-- wli
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · William Lee Irwin III
Quoted 2 lines · Christoph Lameter
Quoted 2 lines
My page scalability patches need to make rss atomic and now with the addition of
anon_rssI would also have to make that atomic.On Sat, Nov 06, 2004 at 09:19:33PM +1100, Nick Piggin wrote:
Quoted 9 lines
Quoted 1 line
Oh, one other thing Christoph - don't forget
mm->nr_ptesForget it. Veto.
Normal-sized systems need to monitor their workloads without crippling them. Do the per-cpu splitting of the counters etc. instead, or other proper incremental algorithms. Catastrophic
/proc/overhead won't fly.
Out of interest, what sort of systems and workloads are we talking about here?
Also, can you suggest how one would do the per-cpu splitting or other proper incremental algorithm? I am not aware of any way except per-cpu magazines which I presume also won't fly due to being inaccurate and hugely bloating the mm_struct on big machines. --
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines
Forget it. Veto.
Normal-sized systems need to monitor their workloads without crippling them. Do the per-cpu splitting of the counters etc. instead, or other proper incremental algorithms. Catastrophic/proc/overhead won't fly.
Quoted 2 lines · Nick Piggin
Out of interest, what sort of systems and workloads are we talking about here?
Normal ones where sysadmins e.g. monitor for students with runaway processes, or DBA's gauge client capacity to estimate redundancy needs, or Joe Blow wants to see what's eating the cpu. <= 4 cpus most likely.
Quoted 4 lines · Nick Piggin
Also, can you suggest how one would do the per-cpu splitting or other proper incremental algorithm? I am not aware of any way except per-cpu magazines which I presume also won't fly due to being inaccurate and hugely bloating the
mm_structon big machines.
Per-cpu magazines look okay to me. Failing that, per groups of cpus. Failing that, hash. And so on. This is all boilerplate material. Split counters are not rocket science. No calc of variations, no time- dependent densities or moments of inertia, etc.
-- wli
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 27 lines · William Lee Irwin III
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines
Forget it. Veto.
Normal-sized systems need to monitor their workloads without crippling them. Do the per-cpu splitting of the counters etc. instead, or other proper incremental algorithms. Catastrophic/proc/overhead won't fly.Quoted 2 lines · Nick Piggin
Out of interest, what sort of systems and workloads are we talking about here?
Normal ones where sysadmins e.g. monitor for students with runaway processes, or DBA's gauge client capacity to estimate redundancy needs, or Joe Blow wants to see what's eating the cpu. <= 4 cpus most likely.
Quoted 4 lines · Nick Piggin
Also, can you suggest how one would do the per-cpu splitting or other proper incremental algorithm? I am not aware of any way except per-cpu magazines which I presume also won't fly due to being inaccurate and hugely bloating the
mm_structon big machines.
Quoted 5 lines
Per-cpu magazines look okay to me. Failing that, per groups of cpus. Failing that, hash. And so on. This is all boilerplate material. Split counters are not rocket science. No calc of variations, no time- dependent densities or moments of inertia, etc.
The problem being that a page can be allocated on one CPU and freed on another.
Well that can actually be workable... but its ugly, and rules out a perfectly scalable, mmap_sem'less page fault (looking far into the future here :P).
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines
Per-cpu magazines look okay to me. Failing that, per groups of cpus. Failing that, hash. And so on. This is all boilerplate material. Split counters are not rocket science. No calc of variations, no time- dependent densities or moments of inertia, etc.
Quoted 5 lines · Nick Piggin
The problem being that a page can be allocated on one CPU and freed on another.
Well that can actually be workable... but its ugly, and rules out a perfectly scalable, mmap_sem'less page fault (looking far into the future here :P).
There is no conflict. The sums are invariant under overflows.
-- wli
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · William Lee Irwin III
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines
Per-cpu magazines look okay to me. Failing that, per groups of cpus. Failing that, hash. And so on. This is all boilerplate material. Split counters are not rocket science. No calc of variations, no time- dependent densities or moments of inertia, etc.
On Sat, Nov 06, 2004 at 10:07:27PM +1100, Nick Piggin wrote:
Quoted 9 lines
Quoted 5 lines
The problem being that a page can be allocated on one CPU and freed on another.
Well that can actually be workable... but its ugly, and rules out a perfectly scalable, mmap_sem'less page fault (looking far into the future here :P).There is no conflict. The sums are invariant under overflows.
If they're not racy.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 1 line · William Lee Irwin III
Quoted 1 line
There is no conflict. The sums are invariant under overflows.
Quoted 1 line · Nick Piggin
If they're not racy.
Only one race matters: contributions to accounting. Reporting is inherently racy without stop-the-world -style locking. But the contributions to accounting are irrelevant: shared counter partitions must be updated atomically, fully-cpu-private partitions can't race with each other. So we are done.
-- wli
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines
The patch is by no means perfect. If you think this is worth pursuing then I will finish the support for other archs and deal with the locking issues etc. This patch may also remove hot spot issues that may arise with the use of these two variables and so is of interest to us.
It's probably better to keep the counters. Otherwise there will be massive slowdown when people run performance monitor applets that read /proc regularly. We went through this several times already, there used to be some other /proc field that also walked everything and there were frequent complaints about it.
-Andi
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines
My page scalability patches need to make rss atomic and now with the addition of
anon_rssI would also have to make that atomic.But when I looked at the code I found that the only significant use of both is in for proc statistics. There are 3 other uses in
mm/rmap.cwhere the use ofmm->rssmay be replaced bymm->total_vm.
Quoted 5 lines
So I removed all uses of
mm->rssandanon_rssfrom the kernel and introduced a bean countercount_vm()that is only run when the corresponding /proc file is used.count_vmthen runs throught the vm and counts all the page types. This could also add additional page types to our statistics and solve some of the consistency issues.
I would've thought SGI would be more worried about this kind of thing than anyone else ... what's going to happen when you type 'ps' on a large box, and it does this for 10,000 processes?
If you want to make it quicker, how about doing per-cpu stats, and totalling them at runtime, which'd be lockless, instead of all the atomic ops?
M.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · Christoph Lameter
My page scalability patches need to make rss atomic and now with the addition of
anon_rssI would also have to make that atomic.
You could remove the additional impact of anon_rss by deleting that and replacing rss by rss[2], adjusting only rss[PageAnon(page)]:
no need to increment or decrement two counters in the one operation.
Introducing anon_rss made for a smaller patch then, but if you're patching all those rss places, might as well separate out to rss[2].
Quoted 3 lines
But when I looked at the code I found that the only significant use of both is in for proc statistics. There are 3 other uses in
mm/rmap.cwhere the use ofmm->rssmay be replaced bymm->total_vm.
The tests on mm->rss in rmap.c were critical at one time (in the anonmm objrmap, to guard against doing the wrong thing in the case of some tiny race with dup_mmap, if I remember correctly). They're stayed on as vague optimizations, but I'd be perfectly happy for you to just remove them - I'd prefer that to putting in total_vm tests.
Quoted 5 lines
So I removed all uses of
mm->rssandanon_rssfrom the kernel and introduced a bean countercount_vm()that is only run when the corresponding /proc file is used.count_vmthen runs throught the vm and counts all the page types. This could also add additional page types to our statistics and solve some of the consistency issues.
You're joking! Certainly not, as others have asserted.
But I don't know what the appropriate solution is. My priorities may be wrong, but I dislike the thought of a struct mm dominated by a huge percpu array of rss longs (or cachelines?), even if the machines on which it would be huge are ones which could well afford the waste of memory. It just offends my sense of proportion, when the exact rss is of no importance. I'm more attracted to just leaving it unatomic, and living with the fact that it's racy and approximate (but /proc report negatives as 0).
It might be interesting to run your anon faulting test on an SGI monster, keeping both atomic and non-atomic counts, to see just how likely, how much they go out of sync.
Hugh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 2 lines · William Lee Irwin III
And, of course, I fully appreciate being omitted from the thread dedicated to backing out my work.
Uhh.. I am very sorry. I just picked up Nick's last thread for the cc list and though you were on it. It was late ...again sorry.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · Martin J. Bligh
Quoted 5 lines
So I removed all uses of
mm->rssandanon_rssfrom the kernel and introduced a bean countercount_vm()that is only run when the corresponding /proc file is used.count_vmthen runs throught the vm and counts all the page types. This could also add additional page types to our statistics and solve some of the consistency issues.I would've thought SGI would be more worried about this kind of thing than anyone else ... what's going to happen when you type 'ps' on a large box, and it does this for 10,000 processes?
Yes but I think this is preferable because of the generally faster operations of the vm without having to continually update statistics. And these statistics seem to be quite difficult to properly generate (why else introduce anon_rss). Without the counters other optimizations are easier to do.
Doing a ps is not a frequent event. Of course this may cause significant load if one does regularly access /proc entities then. Are there any threads from the past with some numbers of what the impact was when we calculated rss via proc?
Quoted 2 lines
If you want to make it quicker, how about doing per-cpu stats, and totalling them at runtime, which'd be lockless, instead of all the atomic ops?
That has its own complications and would require lots of memory with systems that already have up to 10k cpus.
Quoted 7 lines · Hugh Dickins
Quoted 5 lines
So I removed all uses of
mm->rssandanon_rssfrom the kernel and introduced a bean countercount_vm()that is only run when the corresponding /proc file is used.count_vmthen runs throught the vm and counts all the page types. This could also add additional page types to our statistics and solve some of the consistency issues.You're joking! Certainly not, as others have asserted.
Nope. If you lock the vm properly then the bean counter approach will result in an accurate count. Incrementing and decrementing rss in various places may have issues that lead to inaccuracies. The bean counter approach will at least not propagate these any further.
Quoted 8 lines
But I don't know what the appropriate solution is. My priorities may be wrong, but I dislike the thought of a struct mm dominated by a huge percpu array of rss longs (or cachelines?), even if the machines on which it would be huge are ones which could well afford the waste of memory. It just offends my sense of proportion, when the exact rss is of no importance. I'm more attracted to just leaving it unatomic, and living with the fact that it's racy and approximate (but /proc report negatives as 0).
I also thought about the percpu approach but its rather unappealing given also the larger and large cpucounts.
Simply living with the inaccuracies is certainly the easiest solution. Thanks.
Quoted 3 lines
It might be interesting to run your anon faulting test on an SGI monster, keeping both atomic and non-atomic counts, to see just how likely, how much they go out of sync.
Ok. We can try that.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · Christoph Lameter
Yes but I think this is preferable because of the generally faster operations of the vm without having to continually update statistics. And these statistics seem to be quite difficult to properly generate (why else introduce
anon_rss). Without the counters other optimizations are easier to do.
Doing a ps is not a frequent event. Of course this may cause significant load if one does regularly access /proc entities then. Are there any threads from the past with some numbers of what the impact was when we calculated rss via proc?
It was catastrophic. Failure of monitoring tools to make forward progress, long-lived delays of "victim" processes whose locks were held by /proc/ observers, and the like.
Quoted 2 lines · Christoph Lameter
That has its own complications and would require lots of memory with systems that already have up to 10k cpus.
Split counters are a solved problem, even for the 10K cpus case.
-- wli
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Christoph" == Christoph Lameter <[email protected]> writes:
Christoph> So I removed all uses of mm->rss and anon_rss from the Christoph> kernel and introduced a bean counter count_vm() that is Christoph> only run when the corresponding /proc file is Christoph> used. count_vm then runs throught the vm and counts all the Christoph> page types. This could also add additional page types to Christoph> our statistics and solve some of the consistency issues.
Is this going to scale properly to large machines, which usually have large numbers of active processes? top is already
almost unuseably slow on such machines; if all the pagetables have to be scanned to get RSS, it'll probably slow to a halt.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Christoph Lameter
Doing a ps is not a frequent event. Of course this may cause significant load if one does regularly access /proc entities then. Are there any threads from the past with some numbers of what the impact was when we calculated rss via proc?
Running top(1) on stock 2.4 kernels pretty much kills large systems from SGI and IBM. Think about walking the VM for 10,000 processes, with 3GB virtual memory each, every 3 seconds.
Signature · 3 lines
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan
Quoted 4 lines · Peter Chubb
Is this going to scale properly to large machines, which usually have large numbers of active processes? top is already
almost unuseably slow on such machines; if all the pagetables have to be scanned to get RSS, it'll probably slow to a halt.
Not probably. Certainly.
Christopher would do well to actually use his patch, while running eg. an Oracle benchmark and using top to monitor system activity.
Signature · 9 lines
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Peter Chubb
Quoted 4 lines
Is this going to scale properly to large machines, which usually have large numbers of active processes? top is already
almost unuseably slow on such machines; if all the pagetables have to be scanned to get RSS, it'll probably slow to a halt.
Quoted 4 lines · Rik van Riel
Not probably. Certainly.
Christopher would do well to actually use his patch, while running eg. an Oracle benchmark and using top to monitor system activity.
OAST with a few thousand clients should do it. I think it tops out around 5000 or 1000 without benchmark source adjustments. The database itself, of course, has no trouble with many clients, the workload simulator was merely not intended for so many.
-- wli
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · William Lee Irwin III
Quoted 1 line · William Lee Irwin III
Quoted 1 line
There is no conflict. The sums are invariant under overflows.
On Sat, Nov 06, 2004 at 11:08:55PM +1100, Nick Piggin wrote:
Quoted 9 lines
Quoted 1 line
If they're not racy.
Only one race matters: contributions to accounting. Reporting is inherently racy without stop-the-world -style locking. But the contributions to accounting are irrelevant: shared counter partitions must be updated atomically, fully-cpu-private partitions can't race with each other. So we are done.
Hmm, possibly.. if you make the counters signed and have some logic to clamp the total to >= 0. But I expect per CPU counters will be too large for Christoph anyway... and would certainly not be an option for 2.6 (or any mainline kernel) either.
Anyway we'll see how his tests go.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · William Lee Irwin III
Quoted 5 lines
Only one race matters: contributions to accounting. Reporting is inherently racy without stop-the-world -style locking. But the contributions to accounting are irrelevant: shared counter partitions must be updated atomically, fully-cpu-private partitions can't race with each other. So we are done.
Quoted 5 lines · Nick Piggin
Hmm, possibly.. if you make the counters signed and have some logic to clamp the total to >= 0. But I expect per CPU counters will be too large for Christoph anyway... and would certainly not be an option for 2.6 (or any mainline kernel) either. Anyway we'll see how his tests go.
No, they remain an option and a good one. The space requirements are not an issue. If Lameter's customers have 10000 cpus they have the RAM and kernel virtualspace for split counters.
Your purported "tests" have a rather obvious predetermined conclusion. Some minute amount of overhead for normal machines will be exaggerated in a supercomputer environment, and all of the detriments will be carefully hidden by avoiding monitoring processes or monitoring only low numbers of them.
The proposal, on the other hand, has received more objections since my own, and from various sources.
Now to brace myself for another of your petty "last word" shenanigans.
-- wli
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · William Lee Irwin III
No, they remain an option and a good one. The space requirements are not an issue. If Lameter's customers have 10000 cpus they have the RAM and kernel virtualspace for split counters.
I said not an option for 2.6. Which I still believe they are not. Yes they are an option for a private kernel, as may be the address walking method first posted.
Quoted 6 lines
Your purported "tests" have a rather obvious predetermined conclusion. Some minute amount of overhead for normal machines will be exaggerated in a supercomputer environment, and all of the detriments will be carefully hidden by avoiding monitoring processes or monitoring only low numbers of them.
I thought Christoph would be very interested to see the worst cases in semi real world workloads that his systems actually run.
I didn't realise this is part of a conspiracy to covertly back out all your work. Maybe Jeff Merkey is behind it, and you're the last freedom loving kernel hacker who won't sell out? ;)
Quoted 3 lines
The proposal, on the other hand, has received more objections since my own, and from various sources.
Yes, I was CCed on them, even. We're past the fact that it won't get into the kernel - I just meant maybe it's acceptable for Christoph (although it seems unlikely to not have failure cases, even for him).
Quoted 2 lines
Now to brace myself for another of your petty "last word" shenanigans.
I tried to think up some witty remark to go here but couldn't.
OK, sorry. Whatever I've done to offend you I didn't intend it. We don't always seem to be talking on the same level... Can we try to be more light hearted about things? I'm really not interested in shenanigans of any kind with you.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · William Lee Irwin III
Quoted 5 lines
Your purported "tests" have a rather obvious predetermined conclusion. Some minute amount of overhead for normal machines will be exaggerated in a supercomputer environment, and all of the detriments will be carefully hidden by avoiding monitoring processes or monitoring only low numbers of them.
Quoted 5 lines · Nick Piggin
I thought Christoph would be very interested to see the worst cases in semi real world workloads that his systems actually run.
I didn't realise this is part of a conspiracy to covertly back out all your work. Maybe Jeff Merkey is behind it, and you're the last freedom loving kernel hacker who won't sell out? ;)
\begin{vomit}
This attempt at humor, if it was such, inspired very little levity. \end{vomit}
Moving on, I pushed the specific mechanisms for good reasons, and at the very least attempt to maintain the code and watch for problematic issues in the area of basic workload monitoring facilities in the kernel, particularly when they pose catastrophic disruptions to workloads. Basic respect for that effort and those needs would be much appreciated. Though I did realize it was inadvertent, I was still greatly annoyed.
Quoted 1 line · William Lee Irwin III
Quoted 1 line
Now to brace myself for another of your petty "last word" shenanigans.
Quoted 5 lines · Nick Piggin
I tried to think up some witty remark to go here but couldn't. OK, sorry. Whatever I've done to offend you I didn't intend it. We don't always seem to be talking on the same level... Can we try to be more light hearted about things? I'm really not interested in shenanigans of any kind with you.
Yet you've already begun. In general this practice is meant to exhaust the opposition in some debate, and when they fail to respond, claim the silence as assent, to prevent an "unfavorable" conclusion of a debate from being reached by refusing to allow the discussion to conclude so long as its conclusion is unfavorable, and to discourage future "challenges".
Please restrict your methods of patch promotion to technical ones as opposed to rhetorical devices such as that.
-- wli
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines
Quoted 3 lines
I would've thought SGI would be more worried about this kind of thing than anyone else ... what's going to happen when you type 'ps' on a large box, and it does this for 10,000 processes?
Yes but I think this is preferable because of the generally faster operations of the vm without having to continually update statistics. And these statistics seem to be quite difficult to properly generate (why else introduce
anon_rss). Without the counters other optimizations are easier to do.
Quoted 4 lines
Doing a ps is not a frequent event. Of course this may cause significant load if one does regularly access /proc entities then. Are there any threads from the past with some numbers of what the impact was when we calculated rss via proc?
Doing ps or top is not unusual at all, and the sysadmins should be able to monitor their system in a reasonable way without crippling it, or even effecting it significantly.
Quoted 5 lines
Quoted 2 lines
If you want to make it quicker, how about doing per-cpu stats, and totalling them at runtime, which'd be lockless, instead of all the atomic ops?
That has its own complications and would require lots of memory with systems that already have up to 10k cpus.
Ummm 10K cpus? I hope that's a typo for processes, or this discussion is getting rather silly ....
M.
Quoted 2 lines · Martin J. Bligh
Ummm 10K cpus? I hope that's a typo for processes, or this discussion is getting rather silly ....
NASA bought a 10k CPU system, but that's a cluster. I think the largest single system within that cluster is 256 CPUs.
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
Quoted 6 lines · Matthew Wilcox
Quoted 2 lines · Martin J. Bligh
Ummm 10K cpus? I hope that's a typo for processes, or this discussion is getting rather silly ....
NASA bought a 10k CPU system, but that's a cluster. I think the largest single system within that cluster is 256 CPUs.
512 I believe.
Quoted 6 lines · Matthew Wilcox
Quoted 2 lines · Martin J. Bligh
Ummm 10K cpus? I hope that's a typo for processes, or this discussion is getting rather silly ....
NASA bought a 10k CPU system, but that's a cluster. I think the largest single system within that cluster is 256 CPUs.
512 CPUs AFAIK.
-Andi
Quoted 7 lines · Matthew Wilcox
Quoted 2 lines · Martin J. Bligh
Ummm 10K cpus? I hope that's a typo for processes, or this discussion is getting rather silly ....
NASA bought a 10k CPU system, but that's a cluster. I think the largest single system within that cluster is 256 CPUs.
Each "node" is a single linux kernel with 512 processors.. There are 20 nodes in the cluster. 20 x 512p = 10,240 processors.
Signature · 2 lines
Russ Anderson, OS RAS/Partitioning Project Lead SGI - Silicon Graphics Inc [email protected]
Quoted 3 lines · Martin J. Bligh
Doing ps or top is not unusual at all, and the sysadmins should be able to monitor their system in a reasonable way without crippling it, or even effecting it significantly.
Hmm.. What would you think about a pointer to a stats structure in mm, which would only be allocated if stats are requested by /proc actions? The struct would contain a timestamp which would insure that the stats are only generated in certain intervals and not over and over again. This would also make it possible to force a regeneration of the numbers.
Maybe lots of other statistical values in mm_struct could then also be removed?
Quoted 2 lines
Ummm 10K cpus? I hope that's a typo for processes, or this discussion is getting rather silly ....
Nope. The future of computing seems to be very high numbers of cpus. NASAs Columbia has 10k cpus and the new BlueGen solution from IBM is already at 8k.
Quoted 4 lines · Andi Kleen
Quoted 2 lines
NASA bought a 10k CPU system, but that's a cluster. I think the largest single system within that cluster is 256 CPUs.
512 CPUs AFAIK.
We surely would want to go much higher on that....
Quoted 9 lines
Quoted 6 lines · Martin J. Bligh
Quoted 2 lines
Ummm 10K cpus? I hope that's a typo for processes, or this discussion is getting rather silly ....
NASA bought a 10k CPU system, but that's a cluster. I think the largest single system within that cluster is 256 CPUs.
Each "node" is a single linux kernel with 512 processors.. There are 20 nodes in the cluster. 20 x 512p = 10,240 processors.
Fair enough, but for the purposes if this discussion, irrelevant. It's only each node that counts.
M.
Quoted 4 lines
Nope. The future of computing seems to be very high numbers of cpus. NASAs Columbia has 10k cpus and the new BlueGen solution from IBM is already at 8k.
Bluegene isnt a fair comparison, its a cluster (and its much more than 8k cpus).
Anton
--Christoph Lameter <[email protected]> wrote (on Monday, November 08, 2004 08:04:05 -0800):
Quoted 6 lines · Martin J. Bligh
Quoted 4 lines
Doing ps or top is not unusual at all, and the sysadmins should be able to monitor their system in a reasonable way without crippling it, or even effecting it significantly.
Quoted 8 lines
Hmm.. What would you think about a pointer to a stats structure in mm, which would only be allocated if stats are requested by /proc actions? The struct would contain a timestamp which would insure that the stats are only generated in certain intervals and not over and over again. This would also make it possible to force a regeneration of the numbers.
Maybe lots of other statistical values in
mm_structcould then also be removed?
So basically it's the same thing except you're caching it. If you want stale old data, you can cache it in userspace, rather than hack the kernel ... personally, I think it's utterly pointless - if the user didn't want the data, then they wouldn't be requesting it.
Quoted 6 lines
Quoted 2 lines
Ummm 10K cpus? I hope that's a typo for processes, or this discussion is getting rather silly ....
Nope. The future of computing seems to be very high numbers of cpus. NASAs Columbia has 10k cpus and the new BlueGen solution from IBM is already at 8k.
I see where the figure comes from, but each node comes with it's own memory, so it's rather pointless to talk about total over the number of nodes. It'd make as much sense to tot up the total number of processors on all Linux installs in the world, and use that figure ;-)
What exactly was the problem? Far too many atomic ops flying around on a 512 CPU machine? Can't you just say that if the mm count is only 1, then don't bother with atomic? That'd fix all non-multi-threaded workloads, I'd think.
M.
Quoted 6 lines · Martin J. Bligh
Quoted 6 lines
Hmm.. What would you think about a pointer to a stats structure in mm, which would only be allocated if stats are requested by /proc actions? The struct would contain a timestamp which would insure that the stats are only generated in certain intervals and not over and over again. This would also make it possible to force a regeneration of the numbers.
Quoted 7 lines
Quoted 2 lines
Maybe lots of other statistical values in
mm_structcould then also be removed?So basically it's the same thing except you're caching it. If you want stale old data, you can cache it in userspace, rather than hack the kernel ... personally, I think it's utterly pointless - if the user didn't want the data, then they wouldn't be requesting it.
Then we would need userspace caching daemon for /proc?
The caching makes sense since mutiple processes may be interested in the same data and various views of the data exist (statm vs. status vs. cpu node information f.e.)
Removing realtime statistics would remove lots of code from the vm. Maintaining these counters requires locking which interferes with Nick's and my attempts to parallelize the vm.
Also these counters may develop to be hot spots on a NUMA system. If the statistics are updated once in a while by a vm scan running on a single cpu then the issues arising with multiple cpu updating the same memory locations are less severe.
Thus removing the realtime statistics may result in a significant performance increase and may also lead to code that is easier to be maintained since its shorter, simpler and may use less locking.
Quoted 3 lines · Christoph Lameter
Nope. The future of computing seems to be very high numbers of cpus. NASAs Columbia has 10k cpus and the new BlueGen solution from IBM is already at 8k.
You're talking about clusters, i.e. multiple running instances of the operating system. I don't think anybody really wants to go far beyond 512 nowadays. Application-wise 512 cpus/node isn't really needed (but sometimes nice to have, for marketting). Beyond problems with scalability of the interconnect (and very uneven latency distribution) bigger systems would accumulate a too small MTBF. When a broken CPU, DIMM or other chip takes your entire >1k CPU-machine down, you'll hapilly exchage it agains a cluster.
Erich
Quoted 3 lines · Martin J. Bligh
Doing ps or top is not unusual at all, and the sysadmins should be able to monitor their system in a reasonable way without crippling it, or even effecting it significantly.
I don't think there is a single system out there where people throw performance monitoring out the window, in the name of performance.
Signature · 3 lines
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian W. Kernighan
Quoted 2 lines · Christoph Lameter
Removing realtime statistics would remove lots of code from the vm.
Remove lots of code? Adding lots nastier.
Quoted 2 lines
Maintaining these counters requires locking which interferes with Nick's and my attempts to parallelize the vm.
Aren't you rather overestimating the importance of one single, ideally atomic, increment per page fault?
It's great news if this is really the major scalability issue facing Linux.
Hugh
Quoted 3 lines · El Mon, 8 Nov 2004 17:30:37 +0100 Erich Focht <[email protected]> escribió:
You're talking about clusters, i.e. multiple running instances of the operating system. I don't think anybody really wants to go far beyond 512 nowadays. Application-wise 512 cpus/node isn't really needed (but
<the newspaper guy>
SGI is already building one of 1024 CPUs according to some sources:
http://www.computerworld.com/hardwaretopics/hardware/story/0,10801,94564,00.html
but...
"Initially, Pennington said, the system will use two images of Linux -- one per 512 processors -- while it's being tested and configured. Later, all 1,024 processors will address one image of the SGI Advanced Linux operating system being used."
Also here ->
http://www.sgi.com/company_info/newsroom/press_releases/2004/november/jaeri.html
it talks about another supercomputer of 2048 CPUs, but I don't find clear if it's a cluster, or several images.
Quoted 5 lines · Hugh Dickins
Quoted 2 lines
Maintaining these counters requires locking which interferes with Nick's and my attempts to parallelize the vm.
Aren't you rather overestimating the importance of one single, ideally atomic, increment per page fault?
We would need to investigate that in detail. What we know is that if multiple cpus do atomic increments with an additional spinlock/unlock etc as done today then we do have a significant performance impact due to exclusive cache lines oscillating between cpus.
Quoted 1 line
It's great news if this is really the major scalability issue facing Linux.
Not sure. This may just be a part of it.
Quoted 11 lines · Diego Calleja
Quoted 3 lines · El Mon, 8 Nov 2004 17:30:37 +0100 Erich Focht <[email protected]> escribió:
You're talking about clusters, i.e. multiple running instances of the operating system. I don't think anybody really wants to go far beyond 512 nowadays. Application-wise 512 cpus/node isn't really needed (but
<the newspaper guy>
SGI is already building one of 1024 CPUs according to some sources:
http://www.computerworld.com/hardwaretopics/hardware/story/0,10801,94564,00.html
Quoted 6 lines
but...
"Initially, Pennington said, the system will use two images of Linux -- one per 512 processors -- while it's being tested and configured. Later, all 1,024 processors will address one image of the SGI Advanced Linux operating system being used."
1k is not really "far beyond" 512. I'm sure it's doable, but I doubt that this (or bigger machines) will spread too much. The progress in cluster interconnect technology and software is just too fast. Think of price/performance and stability (MTBF accumulation) and judge yourself. Sure, if Linux could survive breaking hardware, the story might change.
Quoted 4 lines
Also here ->
http://www.sgi.com/company_info/newsroom/press_releases/2004/november/jaeri.html
it talks about another supercomputer of 2048 CPUs, but I don't find clear if it's a cluster, or several images.
That was advertised to be a fraction of the Columbia machine, so a cluster of big machines.
Erich
Quoted 16 lines · Christoph Lameter
Quoted 5 lines · Hugh Dickins
Quoted 2 lines
Maintaining these counters requires locking which interferes with Nick's and my attempts to parallelize the vm.
Aren't you rather overestimating the importance of one single, ideally atomic, increment per page fault?
We would need to investigate that in detail. What we know is that if multiple cpus do atomic increments with an additional spinlock/unlock etc as done today then we do have a significant performance impact due to exclusive cache lines oscillating between cpus.
Quoted 5 lines
Quoted 1 line
It's great news if this is really the major scalability issue facing Linux.
Not sure. This may just be a part of it.
I'm sure it would be a part of it. I think we've basically got 3 things that share cachelines now, they are the mmap_sem, page_table_lock, and rss/anon_rss.
After removing the page table lock, it tentatively looks like mmap_sem is the next largest problem. It may be that the mmap_sem cacheline kind of serialises threads coming into handle_mm_fault, so the rss doesn't bounce so much. However I might just try ripping out the rss counters entirely and just see what happens to performance.
I wonder if a per process flag or something could be used to turn off the statistics counters? I guess statistics could still be gathered for that process by using your lazy counting functions, Christoph.
Quoted 3 lines · Nick Piggin
I wonder if a per process flag or something could be used to turn off the statistics counters? I guess statistics could still be gathered for that process by using your lazy counting functions, Christoph.
I don't get it. It seems to me that any process that's going to experience problems with these statistics counters is going to be precisely the one that you want the statistics for! What was the problem with per-cpu counters again?
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
Quoted 7 lines · Matthew Wilcox
Quoted 3 lines · Nick Piggin
I wonder if a per process flag or something could be used to turn off the statistics counters? I guess statistics could still be gathered for that process by using your lazy counting functions, Christoph.
Quoted 5 lines
I don't get it. It seems to me that any process that's going to experience problems with these statistics counters is going to be precisely the one that you want the statistics for! What was the problem with per-cpu counters again?
Not sure if they'd be the ones you want statistics for. If so, then you're stuck between a rock and a hard place really. However if there is room for compromise, then this may be a solution.
I think the problem with per-cpu counters is that it wouldn't be a very good solution for mainline either. It would also penalise all single threaded tasks for zero gain... quite significantly if you did a static cacheline aligned array in the mm_struct even with small CPU counts. Maybe less so resource wise if you used alloc_percpu, but that would increase complexity. I don't know, maybe it is an option.
Quoted 7 lines · Russ Anderson
Quoted 5 lines · Matthew Wilcox
Quoted 2 lines · Martin J. Bligh
Ummm 10K cpus? I hope that's a typo for processes, or this discussion is getting rather silly ....
Quoted 7 lines
Quoted 2 lines
NASA bought a 10k CPU system, but that's a cluster. I think the largest single system within that cluster is 256 CPUs.
Each "node" is a single linux kernel with 512 processors.. There are 20 nodes in the cluster. 20 x 512p = 10,240 processors.
Sorry for wandering off topic here... did I imagine it or did I read that you'd tried to get 2048 CPUs going in a single system at NASA?
I guess the lack of triumphant press release means it didn't go well, or that I was imagining things.
Also, are you using 2.6 kernels on these 512 CPU systems? or are your 2.4 kernels still holding together at that many CPUs?
Quoted 11 lines · Christoph Lameter
Quoted 3 lines · Martin J. Bligh
Doing ps or top is not unusual at all, and the sysadmins should be able to monitor their system in a reasonable way without crippling it, or even effecting it significantly.
Hmm.. What would you think about a pointer to a stats structure in mm, which would only be allocated if stats are requested by /proc actions? The struct would contain a timestamp which would insure that the stats are only generated in certain intervals and not over and over again. This would also make it possible to force a regeneration of the numbers.
I assume you mean that the mm->rss and mm->rss_anon counters have been replaced with stat calculation on demand. Maybe it is possible to keep a needs_update-flag with each vma instead. Then only the vma:s with that flag set needs to be recalculated.
A nice feature would be to be able to assign each process/mm a stat gathering mode - choose between no statistics, statistics updated every N jiffy and real time statistics. Yeah, dream on.
/ magnus
Quoted 2 lines · Nick Piggin
Sorry for wandering off topic here... did I imagine it or did I read that you'd tried to get 2048 CPUs going in a single system at NASA?
We could not try it. The current hardware only supports coherence across 256 nodes with a max of 2 cpus per node.
There is a method to use memory on nodes from the other coherence domains provided there are no cpus at all in that coherence domain. In that case, the hardware uses the coherence domain of the requestor. What that gives us is a theoretical case where we could have 1024 nodes with memory, but only 256 of them with cpus. I forget what the design limit for memory per node is, but I do know DIMMs that large are not currently available.
Quoted 6 lines
I guess the lack of triumphant press release means it didn't go well, or that I was imagining things.
Also, are you using 2.6 kernels on these 512 CPU systems? or are your 2.4 kernels still holding together at that many CPUs?
Our 2.4 kernel is performing better than the 2.6. That is because the 2.4 kernel has a lot more tweaks for our customers than the 2.6. All of our 2.6 work is being pushed towards the community, so we should get parity soon.
Robin
Quoted 8 lines · Nick Piggin
Also, are you using 2.6 kernels on these 512 CPU systems? or are your 2.4 kernels still holding together at that many CPUs?
-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
We aren't supporting customers with 2.6 kernels yet. NASA's systems are all running kernels based on 2.4.x.
Signature · 9 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------Quoted 8 lines · Nick Piggin
Also, are you using 2.6 kernels on these 512 CPU systems? or are your 2.4 kernels still holding together at that many CPUs?
-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
We aren't supporting customers with 2.6 kernels yet. NASA's systems are all running kernels based on 2.4.x.
Signature · 14 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>Quoted 3 lines · Magnus Damm
A nice feature would be to be able to assign each process/mm a stat gathering mode - choose between no statistics, statistics updated every N jiffy and real time statistics. Yeah, dream on.
Hmm... Given the various problems with all these approaches this may be the right way to go. Working on the dream now.
Quoted 8 lines · Christoph Lameter
Quoted 3 lines · Magnus Damm
A nice feature would be to be able to assign each process/mm a stat gathering mode - choose between no statistics, statistics updated every N jiffy and real time statistics. Yeah, dream on.
Hmm... Given the various problems with all these approaches this may be the right way to go. Working on the dream now.
Are you saying that there is no way to solve this in a scalable fashion? Not by seperating the cachelines for the locks and counters? Not by putting in per-cpu counters? Nothing else will work? What is the solution for the customers that do have statistics turned on? What multiplier does the admin give to the job when they need to turn on statistics? How do job-server type sites work with this when one of their reasons to kill jobs is based on RSS? They would need it turned on for nearly every process and we are back in the same boat.
I am embarrased for SGI that this discussion has gone on as long as it has. There are hundreds of counters in the system which have been affected by scaling issues. Why could those be solved and this one not? Can we focus on the correct fix instead of a kludge which will not be acceptable to our customers?
Sorry for the rant. It has been a stressful week.
Robin
Quoted 1 line · Robin Holt
Are you saying that there is no way to solve this in a scalable fashion?
No. I am saying that a variety of approaches may be needed and I actually got a raw draft of a patch here that allows to employ a variety of ways of obtaining vm statistics.
Quoted 3 lines · Nick Piggin
Also, are you using 2.6 kernels on these 512 CPU systems? or are your 2.4 kernels still holding together at that many CPUs?
Nick,
My response to your email was (unfortunately) overly broad. While the NASA 512P systems are running a kernel based on 2.4.x, SLES 9, which is 2.6.5-based, has been certified on a 64p SGI Altix
system (cf. http://developer.novell.com/yes/78980.htm).
So it is possible to buy a supported 2.6 kernel from SuSE that will run your (up to) 64P Altix.
Signature · 9 lines
Best Regards,
Ray
-----------------------------------------------
Ray Bryant
512-453-9679 (work) 512-507-7807 (cell)
[email protected] [email protected]
The box said: "Requires Windows 98 or better",
so I installed Linux.
-----------------------------------------------Quoted 3 lines
... SLES 9, which is
2.6.5-based, has been certified on a 64p SGI Altix system (cf. http://developer.novell.com/yes/78980.htm).
xxxxx
Link correction:
http://developer.novell.com/yes/77348.htm
--steve
another approach to rss : sloppy rss
In reply to Hugh DickinsQuoted 8 lines · Hugh Dickins
But I don't know what the appropriate solution is. My priorities may be wrong, but I dislike the thought of a struct mm dominated by a huge percpu array of rss longs (or cachelines?), even if the machines on which it would be huge are ones which could well afford the waste of memory. It just offends my sense of proportion, when the exact rss is of no importance. I'm more attracted to just leaving it unatomic, and living with the fact that it's racy and approximate (but /proc report negatives as 0).
Here is a patch that enables handling of rss outside of the page table lock by simply ignoring errors introduced by not locking. The loss of rss was always less than 1%.
The patch insures that negative rss values are not displayed and removes 3 checks in mm/rmap.c that utilized rss (unecessarily AFAIK).
Some numbers:
4 Gigabyte concurrent alocation from 4 cpus:
rss protect by page_table_lock:
margin:~/clameter # ./pftn -g4 -r3 -f4
Size&2415 RSS&2233
Size&2479 RSS&2234
Size&2415 RSS&2233
4 3 4 0.180s 16.271s 5.010s 47801.151 154059.862
margin:~/clameter # ./pftn -g4 -r3 -f4
Size&2415 RSS&2233
Size&2415 RSS&2233
Size&2415 RSS&2233
4 3 4 0.155s 14.616s 4.081s 53239.852 163270.962
margin:~/clameter # ./pftn -g4 -r3 -f4
Size&2415 RSS&2233
Size&2479 RSS&2234
Size&2415 RSS&2233
4 3 4 0.172s 16.192s 5.018s 48055.018 151621.738
with sloppy rss:
margin2:~/clameter # ./pftn -g4 -r3 -f4
Size&2415 RSS&1120
Size&2415 RSS&1074
Size&2415 RSS&1215
4 3 4 0.161s 13.058s 4.060s 59489.254 170939.864
margin2:~/clameter # ./pftn -g4 -r3 -f4
Size&2415 RSS&0900
Size&2543 RSS&1001
Size&2415 RSS&1053
4 3 4 0.152s 13.565s 4.031s 57329.397 182103.081
margin2:~/clameter # ./pftn -g4 -r3 -f4
Size&2415 RSS&0988
Size&2479 RSS&1112
Size&2479 RSS&1343
4 3 4 0.143s 12.994s 4.060s 59860.702 170770.399
32 GB allocation with 32 cpus.
with page_table_lock:
Size 99307 RSS 97270
Size 99371 RSS 97271
Size 99307 RSS 97270
Size 99307 RSS 97270
Size 99307 RSS 97270
Size 99307 RSS 97270
Size 99307 RSS 97270
Size 99307 RSS 97270
Size 99307 RSS 97270
Size 99307 RSS 97270
32 10 32 18.105s 5466.913s 202.027s 3823.418 103676.172
sloppy rss:
Size 99307 RSS 94018
Size 99307 RSS 93738
Size 99307 RSS 93907
Size 99307 RSS 93634
Size 99307 RSS 93731
Size 99307 RSS 94343
Size 99307 RSS 94072
Size 99307 RSS 94185
Size 99307 RSS 93845
Size 99307 RSS 93396
32 10 32 14.872s 1036.711s 55.023s 19942.800 379701.332
Index: linux-2.6.9/include/linux/sched.h
=================================--- linux-2.6.9.orig/include/linux/sched.h 2004-11-15 11:13:39.000000000 -0800
+++ linux-2.6.9/include/linux/sched.h 2004-11-17 06:58:51.000000000 -0800
@@ -216,7 +216,7 @@
atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
int map_count; /* number of VMAs */
struct rw_semaphore mmap_sem;
- spinlock_t page_table_lock; /* Protects page tables, mm->rss, mm->anon_rss */
+ spinlock_t page_table_lock; /* Protects page tables */
struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung
* together off init_mm.mmlist, and are protected
@@ -252,6 +252,19 @@
struct kioctx default_kioctx;
};
+/*
+ * rss and anon_rss are incremented and decremented in some locations without
+ * proper locking. This function insures that these values do not become negative
+ * and is called before reporting rss based statistics
+ */
+static void inline rss_fixup(struct mm_struct *mm)
+{
+ if ((long)mm->rss < 0)
+ mm->rss = 0;
+ if ((long)mm->anon_rss < 0)
+ mm->anon_rss = 0;
+}
+
struct sighand_struct {
atomic_t count;
struct k_sigaction action[_NSIG];
Index: linux-2.6.9/fs/proc/task_mmu.c
=================================--- linux-2.6.9.orig/fs/proc/task_mmu.c 2004-11-15 11:13:38.000000000 -0800
+++ linux-2.6.9/fs/proc/task_mmu.c 2004-11-17 06:58:51.000000000 -0800
@@ -11,6 +11,7 @@
data = mm->total_vm - mm->shared_vm - mm->stack_vm;
text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10; lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text;
+ rss_fixup(mm);
buffer += sprintf(buffer,
"VmSize:\t%8lu kB\n"
"VmLck:\t%8lu kB\n"
@@ -37,6 +38,7 @@
int task_statm(struct mm_struct *mm, int *shared, int *text,
int *data, int *resident)
{
+ rss_fixup(mm);
*shared = mm->rss - mm->anon_rss;
*text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
>> PAGE_SHIFT;
Index: linux-2.6.9/fs/proc/array.c
=================================--- linux-2.6.9.orig/fs/proc/array.c 2004-11-15 11:13:38.000000000 -0800
+++ linux-2.6.9/fs/proc/array.c 2004-11-17 06:58:51.000000000 -0800
@@ -325,6 +325,7 @@
vsize = task_vsize(mm);
eip = KSTK_EIP(task);
esp = KSTK_ESP(task);
+ rss_fixup(mm);
}
get_task_comm(tcomm, task);
Index: linux-2.6.9/mm/rmap.c
=================================--- linux-2.6.9.orig/mm/rmap.c 2004-11-15 11:13:40.000000000 -0800
+++ linux-2.6.9/mm/rmap.c 2004-11-17 07:07:00.000000000 -0800
@@ -263,8 +263,6 @@
pte_t *pte;
int referenced = 0;
- if (!mm->rss)
- goto out;
address = vma_address(page, vma);
if (address = -EFAULT)
goto out;
@@ -504,8 +502,6 @@
pte_t pteval;
int ret = SWAP_AGAIN;
- if (!mm->rss)
- goto out;
address = vma_address(page, vma);
if (address = -EFAULT)
goto out;
@@ -788,8 +784,7 @@
if (vma->vm_flags & (VM_LOCKED|VM_RESERVED))
continue;
cursor = (unsigned long) vma->vm_private_data;
- while (vma->vm_mm->rss &&
- cursor < max_nl_cursor &&
+ while (cursor < max_nl_cursor &&
cursor < vma->vm_end - vma->vm_start) { try_to_unmap_cluster(cursor, &mapcount, vma); cursor += CLUSTER_SIZE;
Re: another approach to rss : sloppy rss
Quoted 13 lines · Christoph Lameter
Quoted 8 lines · Hugh Dickins
But I don't know what the appropriate solution is. My priorities may be wrong, but I dislike the thought of a struct mm dominated by a huge percpu array of rss longs (or cachelines?), even if the machines on which it would be huge are ones which could well afford the waste of memory. It just offends my sense of proportion, when the exact rss is of no importance. I'm more attracted to just leaving it unatomic, and living with the fact that it's racy and approximate (but /proc report negatives as 0).
Quoted 7 lines
Here is a patch that enables handling of rss outside of the page table lock by simply ignoring errors introduced by not locking. The loss of rss was always less than 1%.
The patch insures that negative rss values are not displayed and removes 3 checks in
mm/rmap.cthat utilized rss (unecessarily AFAIK).
I wonder if your lazy rss counting still has a place? You still have a shared cacheline with sloppy rss. But is it significantly better for you just by using unlocked instructions...
4 3 4 0.180s 16.271s 5.010s 47801.151 154059.862
... can you tell me what these numbers mean?
And do you have results for tests with no rss counters at all?
Thanks,
Nick
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: another approach to rss : sloppy rss
Quoted 5 lines · Nick Piggin
Quoted 2 lines
The patch insures that negative rss values are not displayed and removes 3 checks in
mm/rmap.cthat utilized rss (unecessarily AFAIK).I wonder if your lazy rss counting still has a place? You still have a shared cacheline with sloppy rss. But is it significantly better for you just by using unlocked instructions...
Right. The fetchadd for atomic increments really bites here.
Got an enhanced lazy rss patch here but it got so much opposition and then I discovered that one of our other projects here at SGI depends on realtime rss.
Quoted 3 lines
4 3 4 0.180s 16.271s 5.010s 47801.151 154059.862... can you tell me what these numbers mean?
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
But that was not relevant to this thread. I should have left that out.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: another approach to rss : sloppy rss
Quoted 11 lines · Christoph Lameter
Quoted 6 lines · Nick Piggin
Quoted 2 lines
The patch insures that negative rss values are not displayed and removes 3 checks in
mm/rmap.cthat utilized rss (unecessarily AFAIK).I wonder if your lazy rss counting still has a place? You still have a shared cacheline with sloppy rss. But is it significantly better for you just by using unlocked instructions...
Quoted 6 lines
Right. The fetchadd for atomic increments really bites here.
Got an enhanced lazy rss patch here but it got so much opposition and then I discovered that one of our other projects here at SGI depends on realtime rss.
What do you think a per-mm flag to switch between realtime and lazy rss?
The only code it would really _add_ would be your mm counting function... I guess another couple of branches in the fault handlers too, but I don't know if they'd be very significant.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
fast path for anonymous memory allocation
In reply to Christoph LameterThis patch conflicts with the page fault scalability patch but I could not leave this stone unturned. No significant performance increases so this is just for the record in case someone else gets the same wild idea.
The patch implements a fastpath where the page_table_lock is not dropped in do_anonymous_page. The fastpath steals a page from the hot or cold lists to get a page quickly.
Results (4 GB and 32 GB allocation on up to 32 processors gradually incrementing the number of processors)
with patch:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
4 10 1 0.524s 24.524s 25.005s104653.150 104642.920 4 10 2 0.456s 29.458s 15.082s 87629.462 165633.410 4 10 4 0.453s 37.064s 11.002s 69872.279 237796.809 4 10 8 0.574s 99.258s 15.003s 26258.236 174308.765 4 10 16 2.171s 279.211s 21.001s 9316.271 124721.683 4 10 32 2.544s 741.273s 27.093s 3524.299 93827.660
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 10 1 4.124s 358.469s 362.061s 57837.481 57834.144 32 10 2 4.217s 440.333s 235.043s 47174.609 89076.709 32 10 4 3.778s 321.754s 100.069s 64422.222 208270.694 32 10 8 3.830s 789.580s 117.067s 26432.116 178211.592 32 10 16 3.921s 2360.026s 170.021s 8871.395 123203.040 32 10 32 9.140s 6213.944s 224.068s 3369.955 93338.297
w/o patch:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
4 10 1 0.449s 24.992s 25.044s103038.282 103022.448 4 10 2 0.448s 30.290s 16.027s 85282.541 161110.770 4 10 4 0.420s 38.700s 11.061s 67008.319 225702.353 4 10 8 0.612s 93.862s 14.059s 27747.547 179564.131 4 10 16 1.554s 265.199s 20.016s 9827.180 129994.843 4 10 32 8.088s 657.280s 25.074s 3939.826 101822.835
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 10 1 3.966s 366.840s 370.082s 56556.456 56553.456 32 10 2 3.604s 319.004s 172.058s 65006.086 121511.453 32 10 4 3.705s 341.550s 106.007s 60741.936 197704.486 32 10 8 3.597s 809.711s 119.021s 25785.427 175917.674 32 10 16 5.886s 2238.122s 163.084s 9345.560 127998.973 32 10 32 21.748s 5458.983s 201.062s 3826.409 104011.521
Only a minimal increase if at all. At the high end the patch leads to even more contention.
Index: linux-2.6.9/mm/memory.c
=================================--- linux-2.6.9.orig/mm/memory.c 2004-11-18 12:25:49.000000000 -0800
+++ linux-2.6.9/mm/memory.c 2004-11-18 16:53:01.000000000 -0800
@@ -1436,28 +1436,56 @@
/* Read-only mapping of ZERO_PAGE. */
entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot));
-
/* ..except if it's a write access */
if (write_access) {
+ struct per_cpu_pageset *pageset;
+ unsigned long flags;
+ int temperature;
+
/* Allocate our own private page. */ pte_unmap(page_table);
- spin_unlock(&mm->page_table_lock);
-
- if (unlikely(anon_vma_prepare(vma)))
- goto no_mem;
- page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
- if (!page)
- goto no_mem;
- clear_user_highpage(page, addr);
-
- spin_lock(&mm->page_table_lock);
- page_table = pte_offset_map(pmd, addr);
- if (!pte_none(*page_table)) {
- pte_unmap(page_table);
- page_cache_release(page);
+ /* This is not numa compatible yet! */
+ pageset = NODE_DATA(numa_node_id())->node_zonelists[GFP_HIGHUSER & GFP_ZONEMASK].zones[0]->pageset+smp_processor_id();
+
+ /* Fastpath for the case that the anonvma is already setup and there are
+ * pages available in the per_cpu_pageset for this node. If so steal
+ * pages from the pageset and avoid dropping the page_table_lock.
+ */
+ local_irq_save(flags);
+ temperature=1;
+ if (vma->anon_vma && (pageset->pcp[temperature].count || pageset->pcp[--temperature].count)) {
+ /* Fastpath for hot/cold pages */
+ page = list_entry(pageset->pcp[temperature].list.next, struct page, lru);
+ list_del(&page->lru);
+ pageset->pcp[temperature].count--;
+ local_irq_restore(flags);
+ page->flags &= ~(1 << PG_uptodate | 1 << PG_error |
+ 1 << PG_referenced | 1 << PG_arch_1 |
+ 1 << PG_checked | 1 << PG_mappedtodisk);
+ page->private = 0;
+ set_page_count(page, 1);
+ /* We skipped updating the zone statistics !*/
+ } else {
+ /* Slow path */
+ local_irq_restore(flags);
spin_unlock(&mm->page_table_lock);
- goto out;
+
+ if (unlikely(anon_vma_prepare(vma)))
+ goto no_mem;
+ page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
+ if (!page)
+ goto no_mem;
+
+ spin_lock(&mm->page_table_lock);
+ page_table = pte_offset_map(pmd, addr);
+
+ if (!pte_none(*page_table)) {
+ pte_unmap(page_table);
+ page_cache_release(page);
+ spin_unlock(&mm->page_table_lock);
+ goto out;
+ }
}
mm->rss++;
entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
@@ -1473,7 +1501,10 @@
/* No need to invalidate - it was non-present before */ update_mmu_cache(vma, addr, entry);
+
spin_unlock(&mm->page_table_lock);
+ if (write_access)
+ clear_user_highpage(page, addr);
out:
return VM_FAULT_MINOR;
no_mem:
Re: fast path for anonymous memory allocation
Quoted 4 lines · Christoph Lameter
This patch conflicts with the page fault scalability patch but I could not leave this stone unturned. No significant performance increases so this is just for the record in case someone else gets the same wild idea.
I had a similar wild idea. Mine was to just make sure we have a spare per-CPU page ready before taking any locks.
Ahh, you're doing clear_user_highpage after the pte is already set up? Won't that be racy? I guess that would be an advantage of my approach, the clear_user_highpage can be done first (although that is more likely to be wasteful of cache).
Re: another approach to rss : sloppy rss
In reply to Nick PigginQuoted 1 line · Nick Piggin
What do you think a per-mm flag to switch between realtime and lazy rss?
Yes thats what the patch has.
Quoted 3 lines
The only code it would really _add_ would be your mm counting function... I guess another couple of branches in the fault handlers too, but I don't know if they'd be very significant.
You would need to add hooks to all uses of rss. That adds additional code to the critical paths.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: fast path for anonymous memory allocation
In reply to Nick PigginQuoted 1 line · Nick Piggin
Ahh, you're doing
clear_user_highpageafter the pte is already set up?
The huge page code also has that optimization. Clearing of pages may take some time which is one reason the kernel drops the page table lock for anonymous page allocation and then reacquires it. The patch does not relinquish the lock on the fast path thus the move outside of the lock.
Quoted 3 lines
Won't that be racy? I guess that would be an advantage of my approach, the
clear_user_highpagecan be done first (although that is more likely to be wasteful of cache).
If you do the clearing with the page table lock held then performance will suffer.
Re: fast path for anonymous memory allocation
Quoted 12 lines · Christoph Lameter
Quoted 1 line · Nick Piggin
Ahh, you're doing
clear_user_highpageafter the pte is already set up?The huge page code also has that optimization. Clearing of pages may take some time which is one reason the kernel drops the page table lock for anonymous page allocation and then reacquires it. The patch does not relinquish the lock on the fast path thus the move outside of the lock.
But you're doing it after you've set up a pte for that page you are clearing... I think? What's to stop another thread trying to read or write to it concurrently?
Quoted 9 lines
Quoted 4 lines
Won't that be racy? I guess that would be an advantage of my approach, the
clear_user_highpagecan be done first (although that is more likely to be wasteful of cache).If you do the clearing with the page table lock held then performance will suffer.
Yeah very much, but if you allocate and clear a "just in case" page _before_ taking any locks for the fault then you'd be able to go straight through do_anonymous_page.
But yeah that has other issues like having a spare page per CPU (maybe not so great a loss), and having anonymous faults much more likely to get pages which are cache cold.
Anyway, glad to see your patches didn't improve things: now we don't have to think about making *more* tradeoffs :)
Re: fast path for anonymous memory allocation
Quoted 3 lines · Nick Piggin
But you're doing it after you've set up a pte for that page you are clearing... I think? What's to stop another thread trying to read or write to it concurrently?
Nothing. If this had led to anything then we would have needed to address this issue. The clearing had to be outside of the lock in order not to impact the performance tests negatively.
Quoted 9 lines
Quoted 2 lines
If you do the clearing with the page table lock held then performance will suffer.
Yeah very much, but if you allocate and clear a "just in case" page _before_ taking any locks for the fault then you'd be able to go straight through
do_anonymous_page.But yeah that has other issues like having a spare page per CPU (maybe not so great a loss), and having anonymous faults much more likely to get pages which are cache cold.
You may be able to implement that using the hot and cold lists. Have something that runs on the lists and prezeros and preformats these pages (idle thread?).
Set some flag to indicate that a page has been prepared and then just zing it in if do_anymous_page finds that flag said.
But I think this may be introduce way too much complexity into the page fault handler.
Re: another approach to rss : sloppy rss
In reply to Christoph LameterQuoted 8 lines · Christoph Lameter
Quoted 1 line · Nick Piggin
What do you think a per-mm flag to switch between realtime and lazy rss?
Yes thats what the patch has.
OK.
Quoted 10 lines
Quoted 4 lines
The only code it would really _add_ would be your mm counting function... I guess another couple of branches in the fault handlers too, but I don't know if they'd be very significant.
You would need to add hooks to all uses of rss. That adds additional code to the critical paths.
It would be an extra branch for each use of rss, yes.
I'm probably going to abstract out direct access to rss anyway (for the abstracted page table locking patch - so eg. the fully locked system needn't use atomics).
So after that, you could do it without much intrusiveness. If it is any consolation, the flag would be read mostly and easily predictable. And you could make the lazy-rss a CONFIG option as well, which would remove the cost in the common case.
Just coming back to your sloppy rss patch - this thing will of course allow unbounded error to build up. Well, it *will* be bounded by the actual RSS if we assume the races can only cause rss to be underestimated. However, such an assumption (I think it is a safe one?) also means that rss won't hover around the correct value, but tend to go increasingly downward.
On your HPC codes that never reclaim memory, and don't do a lot of mapping / unmapping I guess this wouldn't matter... But a long running database or something?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: fast path for anonymous memory allocation
In reply to Nick PigginQuoted 6 lines · Nick Piggin
Quoted 4 lines · Christoph Lameter
This patch conflicts with the page fault scalability patch but I could not leave this stone unturned. No significant performance increases so this is just for the record in case someone else gets the same wild idea.
Quoted 7 lines
I had a similar wild idea. Mine was to just make sure we have a spare per-CPU page ready before taking any locks.
Ahh, you're doing
clear_user_highpageafter the pte is already set up? Won't that be racy? I guess that would be an advantage of my approach, theclear_user_highpagecan be done first (although that is more likely to be wasteful of cache).
Yah, doing clear_user_highpage() after setting the PTE is unfortunately unacceptable. It show interesting bugs... As soon as the PTE is setup, another thread on another CPU can hit the page, you'll then clear what it's writing...
Take for example 2 threads writing to different structures in the same page of anonymous memory. The first one triggers the allocation, the second writes right away, "sees" the new PTE, and writes just before the first one does clear_user_highpage...
Ben.
Re: fast path for anonymous memory allocation
In reply to Christoph LameterQuoted 9 lines · Christoph Lameter
Quoted 3 lines · Nick Piggin
But you're doing it after you've set up a pte for that page you are clearing... I think? What's to stop another thread trying to read or write to it concurrently?
Nothing. If this had led to anything then we would have needed to address this issue. The clearing had to be outside of the lock in order not to impact the performance tests negatively.
No, it's clearly a bug. We even had a very hard to track down bug recently on ppc64 which was caused by the fact that set_pte didn't contain a barrier, thus the stores done by the _previous_ clear_user_high_page() could be re-ordered with the store to the PTE. That could cause another process to "see" the PTE before the writes of 0 to the page, and thus start writing to the page before all zero's went in, thus ending up with corrupted data. We had a real life testcase of this one. This test case would blow up right away with your code I think.
Ben.
Re: another approach to rss : sloppy rss
In reply to Nick PigginQuoted 9 lines · Nick Piggin
Just coming back to your sloppy rss patch - this thing will of course allow unbounded error to build up. Well, it *will* be bounded by the actual RSS if we assume the races can only cause rss to be underestimated. However, such an assumption (I think it is a safe one?) also means that rss won't hover around the correct value, but tend to go increasingly downward.
On your HPC codes that never reclaim memory, and don't do a lot of mapping / unmapping I guess this wouldn't matter... But a long running database or something?
Databases preallocate memory on startup and then manage memory themselves. One reason for this patch is that these applications cause anonymous page fault storms on startup given lots of memory which will make the system seem to freeze for awhile.
It is rare for a program to actually free up memory.
Where this approach could be problematic is when the system is under heavy swap load. Pages of an application will be repeatedly paged in and out and therefore rss will be incremented and decremented. But in those cases these incs and decs are not done in a way that is on purpose parallel like in my test programs. So I would expect rss to be more accurate than in my tests.
I think the sloppy rss approach is the right way to go.
page fault scalability patch V11 [0/7]: overview
In reply to Benjamin HerrenschmidtChanges from V10->V11 of this patch:
- cmpxchg_i386: Optimize code generated after feedback from Linus. Various fixes.
- drop make_rss_atomic in favor of rss_sloppy
- generic: adapt to new changes in Linus tree, some fixes to fallback functions. Add generic ptep_xchg_flush based on xchg.
- S390: remove use of page_table_lock from ptep_xchg_flush (deadlock)
- x86_64: remove ptep_xchg
- i386: integrated Nick Piggin's changes for PAE mode. Create ptep_xchg_flush and various fixes.
- ia64: if necessary flush icache before ptep_cmpxchg. Remove ptep_xchg
This is a series of patches that increases the scalability of the page fault handler for SMP. Here are some performance results on a machine with 32 processors allocating 32 GB with an increasing number of cpus.
Without the patches:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 10 1 3.966s 366.840s 370.082s 56556.456 56553.456 32 10 2 3.604s 319.004s 172.058s 65006.086 121511.453 32 10 4 3.705s 341.550s 106.007s 60741.936 197704.486 32 10 8 3.597s 809.711s 119.021s 25785.427 175917.674 32 10 16 5.886s 2238.122s 163.084s 9345.560 127998.973 32 10 32 21.748s 5458.983s 201.062s 3826.409 104011.521
With the patches:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 10 1 3.772s 330.629s 334.042s 62713.587 62708.706 32 10 2 3.767s 352.252s 185.077s 58905.502 112886.222 32 10 4 3.549s 255.683s 77.000s 80898.177 272326.496 32 10 8 3.522s 263.879s 52.030s 78427.083 400965.857 32 10 16 5.193s 384.813s 42.076s 53772.158 490378.852 32 10 32 15.806s 996.890s 54.077s 20708.587 382879.208
With a high number of CPUs the page fault rate improves more than twofold and may reach 500000 faults/sec betweenr 16-512 cpus. The fault rate drops if a process is running on all processors as also here for the 32 cpu case.
Note that the measurements were done on a NUMA system and this test uses off node memory. Variations may exist due to allocations in memory areas in diverse distances to the local cpu. The slight drop for 2 cpus is probably due to that effect.
The performance increase is accomplished by avoiding the use of the page_table_lock spinlock (but not mm->mmap_sem!) through new atomic operations on pte's (ptep_xchg, ptep_cmpxchg) and on pmd and pgd's (pgd_test_and_populate, pmd_test_and_populate).
The page table lock can be avoided in the following situations:
1. An empty pte or pmd entry is populated
This is safe since the swapper may only depopulate them and the swapper code has been changed to never set a pte to be empty until the page has been evicted. The population of an empty pte is frequent if a process touches newly allocated memory.
2. Modifications of flags in a pte entry (write/accessed).
These modifications are done by the CPU or by low level handlers on various platforms also bypassing the page_table_lock. So this seems to be safe too.
One essential change in the VM is the use of pte_cmpxchg (or its generic emulation) on page table entries before doing an update_mmu_change without holding the page table lock. However, we do similar things now with other atomic pte operations such as ptep_get_and_clear and ptep_test_and_clear_dirty. These operations clear a pte *after* doing an operation on it. The ptep_cmpxchg as used in this patch operates on an *cleared* pte and replaces it with a pte pointing to valid memory. The effect of this change on various architectures has to be thought through. Local definitions of ptep_cmpxchg and ptep_xchg may be necessary.
For IA64 an icache coherency issue may arise that potentially requires the flushing of the icache (as done via update_mmu_cache on IA64) prior to the use of ptep_cmpxchg. Similar issues may arise on other platforms.
The patch uses sloppy rss handling. mm->rss is incremented without
proper locking because locking would introduce too much overhead. Rss
is not essential for vm operations (3 uses of rss in rmap.c were not necessary and were removed). The difference in rss values has been found to be less than 1% in our tests (see also the separate email to linux-mm and linux-ia64 on the subject of "sloppy rss"). The move away from using atomic operations for rss in earlier versions of this patch also increases the performance of the page fault handler in the single thread case over an unpatched kernel.
Note that I have posted two other approaches of dealing with the rss problem:
A. make_rss_atomic. The earlier releases contained that patch but then another
variable (such as anon_rss) was introduced that would have required additional atomic operations. Atomic rss operations are also causing slowdowns on machines with a high number of cpus due to memory contention.
B. remove_rss. Replace rss with a periodic scan over the vm to determine
rss and additional numbers. This was also discussed on linux-mm and linux-ia64. The scans while displaying /proc data were undesirable.
The patchset is composed of 7 patches:
1/7: Sloppy rss
Removes mm->rss usage from mm/rmap.c and insures that negative rss values are not displayed.
2/7: Avoid page_table_lock in handle_mm_fault
This patch defers the acquisition of the page_table_lock as much as possible and uses atomic operations for allocating anonymous memory. These atomic operations are simulated by acquiring the page_table_lock for very small time frames if an architecture does not define __HAVE_ARCH_ATOMIC_TABLE_OPS. It also changes the swapper so that a pte will not be set to empty if a page is in transition to swap.
If only the first two patches are applied then the time that the page_table_lock is held is simply reduced. The lock may then be acquired multiple times during a page fault.
The remaining patches introduce the necessary atomic pte operations to avoid the page_table_lock.
3/7: Atomic pte operations for ia64
4/7: Make cmpxchg generally available on i386
The atomic operations on the page table rely heavily on cmpxchg instructions. This patch adds emulations for cmpxchg and cmpxchg8b for old 80386 and 80486 cpus. The emulations are only included if a kernel is build for these old cpus and are skipped for the real cmpxchg instructions if the kernel that is build for 386 or 486 is then run on a more recent cpu.
This patch may be used independently of the other patches.
5/7: Atomic pte operations for i386
A generally available cmpxchg (last patch) must be available for this patch to preserve the ability to build kernels for 386 and 486.
6/7: Atomic pte operation for x86_64
7/7: Atomic pte operations for s390
page fault scalability patch V11 [1/7]: sloppy rss
Changelog
* Enable the sloppy use of mm->rss and mm->anon_rss atomic without locking
* Insure that negative rss values are not given out by the /proc filesystem
* remove 3 checks of rss in mm/rmap.c
* Prerequisite for page table scalability patch
Index: linux-2.6.9/include/linux/sched.h
=================================--- linux-2.6.9.orig/include/linux/sched.h 2004-11-15 11:13:39.000000000 -0800
+++ linux-2.6.9/include/linux/sched.h 2004-11-18 13:04:30.000000000 -0800
@@ -216,7 +216,7 @@
atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
int map_count; /* number of VMAs */
struct rw_semaphore mmap_sem;
- spinlock_t page_table_lock; /* Protects page tables, mm->rss, mm->anon_rss */
+ spinlock_t page_table_lock; /* Protects page tables */
struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung
* together off init_mm.mmlist, and are protected
@@ -252,6 +252,21 @@
struct kioctx default_kioctx;
};
+/*
+ * rss and anon_rss are incremented and decremented in some locations without
+ * proper locking. This function insures that these values do not become negative.
+ */
+static long inline get_rss(struct mm_struct *mm)
+{
+ long rss = mm->rss;
+
+ if (rss < 0)
+ mm->rss = rss = 0;
+ if ((long)mm->anon_rss < 0)
+ mm->anon_rss = 0;
+ return rss;
+}
+
struct sighand_struct {
atomic_t count;
struct k_sigaction action[_NSIG];
Index: linux-2.6.9/fs/proc/task_mmu.c
=================================--- linux-2.6.9.orig/fs/proc/task_mmu.c 2004-11-15 11:13:38.000000000 -0800
+++ linux-2.6.9/fs/proc/task_mmu.c 2004-11-18 12:56:26.000000000 -0800
@@ -22,7 +22,7 @@
"VmPTE:\t%8lu kB\n",
(mm->total_vm - mm->reserved_vm) << (PAGE_SHIFT-10), mm->locked_vm << (PAGE_SHIFT-10),
- mm->rss << (PAGE_SHIFT-10),
+ get_rss(mm) << (PAGE_SHIFT-10),
data << (PAGE_SHIFT-10),
mm->stack_vm << (PAGE_SHIFT-10), text, lib, (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
@@ -37,7 +37,9 @@
int task_statm(struct mm_struct *mm, int *shared, int *text,
int *data, int *resident)
{
- *shared = mm->rss - mm->anon_rss;
+ *shared = get_rss(mm) - mm->anon_rss;
+ if (*shared <0)
+ *shared = 0;
*text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
>> PAGE_SHIFT;
*data = mm->total_vm - mm->shared_vm;
Index: linux-2.6.9/fs/proc/array.c
=================================--- linux-2.6.9.orig/fs/proc/array.c 2004-11-15 11:13:38.000000000 -0800
+++ linux-2.6.9/fs/proc/array.c 2004-11-18 12:53:16.000000000 -0800
@@ -420,7 +420,7 @@
jiffies_to_clock_t(task->it_real_value),
start_time,
vsize,
- mm ? mm->rss : 0, /* you might want to shift this left 3 */
+ mm ? get_rss(mm) : 0, /* you might want to shift this left 3 */
rsslim,
mm ? mm->start_code : 0,
mm ? mm->end_code : 0,
Index: linux-2.6.9/mm/rmap.c
=================================--- linux-2.6.9.orig/mm/rmap.c 2004-11-15 11:13:40.000000000 -0800
+++ linux-2.6.9/mm/rmap.c 2004-11-18 12:26:45.000000000 -0800
@@ -263,8 +263,6 @@
pte_t *pte;
int referenced = 0;
- if (!mm->rss)
- goto out;
address = vma_address(page, vma);
if (address = -EFAULT)
goto out;
@@ -504,8 +502,6 @@
pte_t pteval;
int ret = SWAP_AGAIN;
- if (!mm->rss)
- goto out;
address = vma_address(page, vma);
if (address = -EFAULT)
goto out;
@@ -788,8 +784,7 @@
if (vma->vm_flags & (VM_LOCKED|VM_RESERVED))
continue;
cursor = (unsigned long) vma->vm_private_data;
- while (vma->vm_mm->rss &&
- cursor < max_nl_cursor &&
+ while (cursor < max_nl_cursor &&
cursor < vma->vm_end - vma->vm_start) { try_to_unmap_cluster(cursor, &mapcount, vma); cursor += CLUSTER_SIZE;
page fault scalability patch V11 [2/7]: page fault handler optimizations
In reply to Christoph LameterChangelog
* Increase parallelism in SMP configurations by deferring the acquisition of page_table_lock in handle_mm_fault
* Anonymous memory page faults bypass the page_table_lock through the use of atomic page table operations
* Swapper does not set pte to empty in transition to swap
* Simulate atomic page table operations using the page_table_lock if an arch does not define __HAVE_ARCH_ATOMIC_TABLE_OPS. This still provides a performance benefit since the page_table_lock is held for shorter periods of time.
Index: linux-2.6.9/mm/memory.c
=================================--- linux-2.6.9.orig/mm/memory.c 2004-11-18 12:25:49.000000000 -0800
+++ linux-2.6.9/mm/memory.c 2004-11-19 06:38:53.000000000 -0800
@@ -1330,8 +1330,7 @@
}
/*
- * We hold the mm semaphore and the page_table_lock on entry and
- * should release the pagetable lock on exit..
+ * We hold the mm semaphore
*/
static int do_swap_page(struct mm_struct * mm,
struct vm_area_struct * vma, unsigned long address,
@@ -1343,15 +1342,13 @@
int ret = VM_FAULT_MINOR;
pte_unmap(page_table);
- spin_unlock(&mm->page_table_lock);
page = lookup_swap_cache(entry);
if (!page) {
swapin_readahead(entry, address, vma); page = read_swap_cache_async(entry, vma, address); if (!page) {
/*
- * Back out if somebody else faulted in this pte while
- * we released the page table lock.
+ * Back out if somebody else faulted in this pte
*/
spin_lock(&mm->page_table_lock); page_table = pte_offset_map(pmd, address);
@@ -1374,8 +1371,7 @@
lock_page(page);
/*
- * Back out if somebody else faulted in this pte while we
- * released the page table lock.
+ * Back out if somebody else faulted in this pte
*/
spin_lock(&mm->page_table_lock); page_table = pte_offset_map(pmd, address);
@@ -1422,14 +1418,12 @@
}
/*
- * We are called with the MM semaphore and page_table_lock
- * spinlock held to protect against concurrent faults in
- * multithreaded programs.
+ * We are called with the MM semaphore held.
*/
static int
do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
pte_t *page_table, pmd_t *pmd, int write_access,
- unsigned long addr)
+ unsigned long addr, pte_t orig_entry)
{
pte_t entry;
struct page * page = ZERO_PAGE(addr);
@@ -1441,7 +1435,6 @@
if (write_access) {
/* Allocate our own private page. */ pte_unmap(page_table);
- spin_unlock(&mm->page_table_lock);
if (unlikely(anon_vma_prepare(vma)))
goto no_mem;
@@ -1450,30 +1443,37 @@
goto no_mem;
clear_user_highpage(page, addr);
- spin_lock(&mm->page_table_lock);
page_table = pte_offset_map(pmd, addr);
- if (!pte_none(*page_table)) {
- pte_unmap(page_table);
- page_cache_release(page);
- spin_unlock(&mm->page_table_lock);
- goto out;
- }
- mm->rss++;
entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
vma->vm_page_prot)),
vma);
- lru_cache_add_active(page);
mark_page_accessed(page);
- page_add_anon_rmap(page, vma, addr);
}
- set_pte(page_table, entry);
+ /* update the entry */
+ if (!ptep_cmpxchg(vma, addr, page_table, orig_entry, entry)) {
+ if (write_access) {
+ pte_unmap(page_table);
+ page_cache_release(page);
+ }
+ goto out;
+ }
+ if (write_access) {
+ /*
+ * These two functions must come after the cmpxchg
+ * because if the page is on the LRU then try_to_unmap may come
+ * in and unmap the pte.
+ */
+ lru_cache_add_active(page);
+ page_add_anon_rmap(page, vma, addr);
+ mm->rss++;
+
+ }
pte_unmap(page_table);
/* No need to invalidate - it was non-present before */ update_mmu_cache(vma, addr, entry);
- spin_unlock(&mm->page_table_lock);
out:
return VM_FAULT_MINOR;
no_mem:
@@ -1489,12 +1489,12 @@
* As this is called only for pages that do not currently exist, we
* do not need to flush old virtual caches or the TLB.
*
- * This is called with the MM semaphore held and the page table
- * spinlock held. Exit with the spinlock released.
+ * This is called with the MM semaphore held.
*/
static int
do_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
- unsigned long address, int write_access, pte_t *page_table, pmd_t *pmd)
+ unsigned long address, int write_access, pte_t *page_table,
+ pmd_t *pmd, pte_t orig_entry)
{
struct page * new_page;
struct address_space *mapping = NULL;
@@ -1505,9 +1505,8 @@
if (!vma->vm_ops || !vma->vm_ops->nopage)
return do_anonymous_page(mm, vma, page_table,
- pmd, write_access, address);
+ pmd, write_access, address, orig_entry);
pte_unmap(page_table);
- spin_unlock(&mm->page_table_lock);
if (vma->vm_file) {
mapping = vma->vm_file->f_mapping;
@@ -1605,7 +1604,7 @@
* nonlinear vmas.
*/
static int do_file_page(struct mm_struct * mm, struct vm_area_struct * vma,
- unsigned long address, int write_access, pte_t *pte, pmd_t *pmd)
+ unsigned long address, int write_access, pte_t *pte, pmd_t *pmd, pte_t entry)
{
unsigned long pgoff;
int err;
@@ -1618,13 +1617,12 @@
if (!vma->vm_ops || !vma->vm_ops->populate ||
(write_access && !(vma->vm_flags & VM_SHARED))) {
pte_clear(pte);
- return do_no_page(mm, vma, address, write_access, pte, pmd);
+ return do_no_page(mm, vma, address, write_access, pte, pmd, entry);
}
pgoff = pte_to_pgoff(*pte);
pte_unmap(pte);
- spin_unlock(&mm->page_table_lock);
err = vma->vm_ops->populate(vma, address & PAGE_MASK, PAGE_SIZE, vma->vm_page_prot, pgoff, 0); if (err = -ENOMEM)
@@ -1643,49 +1641,40 @@
* with external mmu caches can use to update those (ie the Sparc or
* PowerPC hashed page tables that act as extended TLBs).
*
- * Note the "page_table_lock". It is to protect against kswapd removing
- * pages from under us. Note that kswapd only ever _removes_ pages, never
- * adds them. As such, once we have noticed that the page is not present,
- * we can drop the lock early.
- *
- * The adding of pages is protected by the MM semaphore (which we hold),
- * so we don't need to worry about a page being suddenly been added into
- * our VM.
- *
- * We enter with the pagetable spinlock held, we are supposed to
- * release it when done.
+ * Note that kswapd only ever _removes_ pages, never adds them.
+ * We need to insure to handle that case properly.
*/
static inline int handle_pte_fault(struct mm_struct *mm,
struct vm_area_struct * vma, unsigned long address,
int write_access, pte_t *pte, pmd_t *pmd)
{
pte_t entry;
+ pte_t new_entry;
entry = *pte;
if (!pte_present(entry)) {
- /*
- * If it truly wasn't present, we know that kswapd
- * and the PTE updates will not touch it later. So
- * drop the lock.
- */
if (pte_none(entry))
- return do_no_page(mm, vma, address, write_access, pte, pmd);
+ return do_no_page(mm, vma, address, write_access, pte, pmd, entry);
if (pte_file(entry))
- return do_file_page(mm, vma, address, write_access, pte, pmd);
+ return do_file_page(mm, vma, address, write_access, pte, pmd, entry);
return do_swap_page(mm, vma, address, pte, pmd, entry, write_access);
}
+ /*
+ * This is the case in which we only update some bits in the pte.
+ */
+ new_entry = pte_mkyoung(entry);
if (write_access) {
- if (!pte_write(entry))
+ if (!pte_write(entry)) {
+ /* do_wp_page expects us to hold the page_table_lock */
+ spin_lock(&mm->page_table_lock);
return do_wp_page(mm, vma, address, pte, pmd, entry);
-
- entry = pte_mkdirty(entry);
+ }
+ new_entry = pte_mkdirty(new_entry);
}
- entry = pte_mkyoung(entry);
- ptep_set_access_flags(vma, address, pte, entry, write_access);
- update_mmu_cache(vma, address, entry);
+ if (ptep_cmpxchg(vma, address, pte, entry, new_entry))
+ update_mmu_cache(vma, address, new_entry);
pte_unmap(pte);
- spin_unlock(&mm->page_table_lock);
return VM_FAULT_MINOR;
}
@@ -1703,22 +1692,45 @@
inc_page_state(pgfault);
- if (is_vm_hugetlb_page(vma))
+ if (unlikely(is_vm_hugetlb_page(vma)))
return VM_FAULT_SIGBUS; /* mapping truncation does this. */
/*
- * We need the page table lock to synchronize with kswapd
- * and the SMP-safe atomic PTE updates.
+ * We rely on the mmap_sem and the SMP-safe atomic PTE updates.
+ * to synchronize with kswapd
*/
- spin_lock(&mm->page_table_lock);
- pmd = pmd_alloc(mm, pgd, address);
+ if (unlikely(pgd_none(*pgd))) {
+ pmd_t *new = pmd_alloc_one(mm, address);
+ if (!new)
+ return VM_FAULT_OOM;
+
+ /* Insure that the update is done in an atomic way */
+ if (!pgd_test_and_populate(mm, pgd, new))
+ pmd_free(new);
+ }
+
+ pmd = pmd_offset(pgd, address);
+
+ if (likely(pmd)) {
+ pte_t *pte;
+
+ if (!pmd_present(*pmd)) {
+ struct page *new;
- if (pmd) {
- pte_t * pte = pte_alloc_map(mm, pmd, address);
- if (pte)
+ new = pte_alloc_one(mm, address);
+ if (!new)
+ return VM_FAULT_OOM;
+
+ if (!pmd_test_and_populate(mm, pmd, new))
+ pte_free(new);
+ else
+ inc_page_state(nr_page_table_pages);
+ }
+
+ pte = pte_offset_map(pmd, address);
+ if (likely(pte))
return handle_pte_fault(mm, vma, address, write_access, pte, pmd);
}
- spin_unlock(&mm->page_table_lock);
return VM_FAULT_OOM;
}
Index: linux-2.6.9/include/asm-generic/pgtable.h
=================================--- linux-2.6.9.orig/include/asm-generic/pgtable.h 2004-10-18 14:53:46.000000000 -0700
+++ linux-2.6.9/include/asm-generic/pgtable.h 2004-11-19 07:54:05.000000000 -0800
@@ -134,4 +134,60 @@
#define pgd_offset_gate(mm, addr) pgd_offset(mm, addr)
#endif
+#ifndef __HAVE_ARCH_ATOMIC_TABLE_OPS
+/*
+ * If atomic page table operations are not available then use
+ * the page_table_lock to insure some form of locking.
+ * Note thought that low level operations as well as the
+ * page_table_handling of the cpu may bypass all locking.
+ */
+
+#ifndef __HAVE_ARCH_PTEP_CMPXCHG
+#define ptep_cmpxchg(__vma, __addr, __ptep, __oldval, __newval) \
+({ \
+ int __rc; \
+ spin_lock(&__vma->vm_mm->page_table_lock); \
+ __rc = pte_same(*(__ptep), __oldval); \
+ if (__rc) set_pte(__ptep, __newval); \
+ spin_unlock(&__vma->vm_mm->page_table_lock); \
+ __rc; \
+})
+#endif
+
+#ifndef __HAVE_ARCH_PGP_TEST_AND_POPULATE
+#define pgd_test_and_populate(__mm, __pgd, __pmd) \
+({ \
+ int __rc; \
+ spin_lock(&__mm->page_table_lock); \
+ __rc = !pgd_present(*(__pgd)); \
+ if (__rc) pgd_populate(__mm, __pgd, __pmd); \
+ spin_unlock(&__mm->page_table_lock); \
+ __rc; \
+})
+#endif
+
+#ifndef __HAVE_PMD_TEST_AND_POPULATE
+#define pmd_test_and_populate(__mm, __pmd, __page) \
+({ \
+ int __rc; \
+ spin_lock(&__mm->page_table_lock); \
+ __rc = !pmd_present(*(__pmd)); \
+ if (__rc) pmd_populate(__mm, __pmd, __page); \
+ spin_unlock(&__mm->page_table_lock); \
+ __rc; \
+})
+#endif
+
+#endif
+
+#ifndef __HAVE_ARCH_PTEP_XCHG_FLUSH
+#define ptep_xchg_flush(__vma, __address, __ptep, __pteval) \
+({ \
+ pte_t __p = __pte(xchg(&pte_val(*(__ptep)), pte_val(__pteval)));\
+ flush_tlb_page(__vma, __address); \
+ __p; \
+})
+
+#endif
+
#endif /* _ASM_GENERIC_PGTABLE_H */
Index: linux-2.6.9/mm/rmap.c
=================================--- linux-2.6.9.orig/mm/rmap.c 2004-11-19 06:38:51.000000000 -0800
+++ linux-2.6.9/mm/rmap.c 2004-11-19 06:38:53.000000000 -0800
@@ -419,7 +419,10 @@
* @vma: the vm area in which the mapping is added
* @address: the user virtual address mapped
*
- * The caller needs to hold the mm->page_table_lock.
+ * The caller needs to hold the mm->page_table_lock if page
+ * is pointing to something that is known by the vm.
+ * The lock does not need to be held if page is pointing
+ * to a newly allocated page.
*/
void page_add_anon_rmap(struct page *page,
struct vm_area_struct *vma, unsigned long address)
@@ -561,11 +564,6 @@
/* Nuke the page table entry. */
flush_cache_page(vma, address);
- pteval = ptep_clear_flush(vma, address, pte);
-
- /* Move the dirty bit to the physical page now the pte is gone. */
- if (pte_dirty(pteval))
- set_page_dirty(page);
if (PageAnon(page)) {
swp_entry_t entry = { .val = page->private };
@@ -580,11 +578,15 @@
list_add(&mm->mmlist, &init_mm.mmlist); spin_unlock(&mmlist_lock);
}
- set_pte(pte, swp_entry_to_pte(entry));
+ pteval = ptep_xchg_flush(vma, address, pte, swp_entry_to_pte(entry));
BUG_ON(pte_file(*pte)); mm->anon_rss--;
- }
+ } else
+ pteval = ptep_clear_flush(vma, address, pte);
+ /* Move the dirty bit to the physical page now the pte is gone. */
+ if (pte_dirty(pteval))
+ set_page_dirty(page);
mm->rss--;
page_remove_rmap(page); page_cache_release(page);
@@ -671,15 +673,21 @@
if (ptep_clear_flush_young(vma, address, pte))
continue;
- /* Nuke the page table entry. */
flush_cache_page(vma, address);
- pteval = ptep_clear_flush(vma, address, pte);
+ /*
+ * There would be a race here with handle_mm_fault and do_anonymous_page
+ * which bypasses the page_table_lock if we would zap the pte before
+ * putting something into it. On the other hand we need to
+ * have the dirty flag setting at the time we replaced the value.
+ */
/* If nonlinear, store the file page offset in the pte. */ if (page->index != linear_page_index(vma, address))
- set_pte(pte, pgoff_to_pte(page->index));
+ pteval = ptep_xchg_flush(vma, address, pte, pgoff_to_pte(page->index));
+ else
+ pteval = ptep_get_and_clear(pte);
- /* Move the dirty bit to the physical page now the pte is gone. */
+ /* Move the dirty bit to the physical page now that the pte is gone. */
if (pte_dirty(pteval))
set_page_dirty(page);
page fault scalability patch V11 [3/7]: ia64 atomic pte operations
In reply to Christoph LameterChangelog
* Provide atomic pte operations for ia64
* Enhanced parallelism in page fault handler if applied together with the generic patch
Index: linux-2.6.9/include/asm-ia64/pgalloc.h
=================================--- linux-2.6.9.orig/include/asm-ia64/pgalloc.h 2004-10-18 14:53:06.000000000 -0700
+++ linux-2.6.9/include/asm-ia64/pgalloc.h 2004-11-19 07:54:19.000000000 -0800
@@ -34,6 +34,10 @@
#define pmd_quicklist (local_cpu_data->pmd_quick)
#define pgtable_cache_size (local_cpu_data->pgtable_cache_sz)
+/* Empty entries of PMD and PGD */
+#define PMD_NONE 0
+#define PGD_NONE 0
+
static inline pgd_t*
pgd_alloc_one_fast (struct mm_struct *mm)
{
@@ -78,12 +82,19 @@
preempt_enable();
}
+
static inline void
pgd_populate (struct mm_struct *mm, pgd_t *pgd_entry, pmd_t *pmd) {
pgd_val(*pgd_entry) = __pa(pmd);
}
+/* Atomic populate */
+static inline int
+pgd_test_and_populate (struct mm_struct *mm, pgd_t *pgd_entry, pmd_t *pmd) +{
+ return ia64_cmpxchg8_acq(pgd_entry,__pa(pmd), PGD_NONE) = PGD_NONE;
+}
static inline pmd_t*
pmd_alloc_one_fast (struct mm_struct *mm, unsigned long addr)
@@ -132,6 +143,13 @@
pmd_val(*pmd_entry) = page_to_phys(pte);
}
+/* Atomic populate */
+static inline int
+pmd_test_and_populate (struct mm_struct *mm, pmd_t *pmd_entry, struct page *pte) +{
+ return ia64_cmpxchg8_acq(pmd_entry, page_to_phys(pte), PMD_NONE) = PMD_NONE;
+}
+
static inline void
pmd_populate_kernel (struct mm_struct *mm, pmd_t *pmd_entry, pte_t *pte) {
Index: linux-2.6.9/include/asm-ia64/pgtable.h
=================================--- linux-2.6.9.orig/include/asm-ia64/pgtable.h 2004-11-15 11:13:38.000000000 -0800
+++ linux-2.6.9/include/asm-ia64/pgtable.h 2004-11-19 07:55:35.000000000 -0800
@@ -414,6 +425,26 @@
#endif
}
+/*
+ * IA-64 doesn't have any external MMU info: the page tables contain all the necessary
+ * information. However, we use this routine to take care of any (delayed) i-cache
+ * flushing that may be necessary.
+ */
+extern void update_mmu_cache (struct vm_area_struct *vma, unsigned long vaddr, pte_t pte); +
+static inline int
+ptep_cmpxchg (struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t oldval, pte_t newval) +{
+ /*
+ * IA64 defers icache flushes. If the new pte is executable we may
+ * have to flush the icache to insure cache coherency immediately
+ * after the cmpxchg.
+ */
+ if (pte_exec(newval))
+ update_mmu_cache(vma, addr, newval);
+ return ia64_cmpxchg8_acq(&ptep->pte, newval.pte, oldval.pte) = oldval.pte;
+}
+
static inline int
pte_same (pte_t a, pte_t b)
{
@@ -476,13 +507,6 @@
struct vm_area_struct * prev, unsigned long start, unsigned long end);
#endif
-/*
- * IA-64 doesn't have any external MMU info: the page tables contain all the necessary
- * information. However, we use this routine to take care of any (delayed) i-cache
- * flushing that may be necessary.
- */
-extern void update_mmu_cache (struct vm_area_struct *vma, unsigned long vaddr, pte_t pte); -
#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
/*
* Update PTEP with ENTRY, which is guaranteed to be a less
@@ -560,6 +584,8 @@
#define __HAVE_ARCH_PTEP_MKDIRTY
#define __HAVE_ARCH_PTE_SAME
#define __HAVE_ARCH_PGD_OFFSET_GATE
+#define __HAVE_ARCH_ATOMIC_TABLE_OPS
+#define __HAVE_ARCH_LOCK_TABLE_OPS
#include <asm-generic/pgtable.h>
#endif /* _ASM_IA64_PGTABLE_H */
page fault scalability patch V11 [4/7]: universal cmpxchg for i386
In reply to Christoph LameterChangelog
* Make cmpxchg and cmpxchg8b generally available on the i386 platform.
* Provide emulation of cmpxchg suitable for uniprocessor if build and run on 386.
* Provide emulation of cmpxchg8b suitable for uniprocessor systems if build and run on 386 or 486.
* Provide an inline function to atomically get a 64 bit value via cmpxchg8b in an SMP system (courtesy of Nick Piggin) (important for i386 PAE mode and other places where atomic 64 bit operations are useful)
Index: linux-2.6.9/arch/i386/Kconfig
=================================--- linux-2.6.9.orig/arch/i386/Kconfig 2004-11-15 11:13:34.000000000 -0800
+++ linux-2.6.9/arch/i386/Kconfig 2004-11-19 10:02:54.000000000 -0800
@@ -351,6 +351,11 @@
depends on !M386
default y
+config X86_CMPXCHG8B
+ bool
+ depends on !M386 && !M486
+ default y
+
config X86_XADD
bool
depends on !M386
Index: linux-2.6.9/arch/i386/kernel/cpu/intel.c
=================================--- linux-2.6.9.orig/arch/i386/kernel/cpu/intel.c 2004-11-15 11:13:34.000000000 -0800
+++ linux-2.6.9/arch/i386/kernel/cpu/intel.c 2004-11-19 10:38:26.000000000 -0800
@@ -6,6 +6,7 @@
#include <linux/bitops.h>
#include <linux/smp.h>
#include <linux/thread_info.h>
+#include <linux/module.h>
#include <asm/processor.h>
#include <asm/msr.h>
@@ -287,5 +288,103 @@
return 0;
}
+#ifndef CONFIG_X86_CMPXCHG
+unsigned long cmpxchg_386_u8(volatile void *ptr, u8 old, u8 new) +{
+ u8 prev;
+ unsigned long flags;
+ /*
+ * Check if the kernel was compiled for an old cpu but the
+ * currently running cpu can do cmpxchg after all
+ * All CPUs except 386 support CMPXCHG
+ */
+ if (cpu_data->x86 > 3)
+ return __cmpxchg(ptr, old, new, sizeof(u8));
+
+ /* Poor man's cmpxchg for 386. Unsuitable for SMP */
+ local_irq_save(flags);
+ prev = *(u8 *)ptr;
+ if (prev = old)
+ *(u8 *)ptr = new;
+ local_irq_restore(flags);
+ return prev;
+}
+
+EXPORT_SYMBOL(cmpxchg_386_u8);
+
+unsigned long cmpxchg_386_u16(volatile void *ptr, u16 old, u16 new) +{
+ u16 prev;
+ unsigned long flags;
+ /*
+ * Check if the kernel was compiled for an old cpu but the
+ * currently running cpu can do cmpxchg after all
+ * All CPUs except 386 support CMPXCHG
+ */
+ if (cpu_data->x86 > 3)
+ return __cmpxchg(ptr, old, new, sizeof(u16));
+
+ /* Poor man's cmpxchg for 386. Unsuitable for SMP */
+ local_irq_save(flags);
+ prev = *(u16 *)ptr;
+ if (prev = old)
+ *(u16 *)ptr = new;
+ local_irq_restore(flags);
+ return prev;
+}
+
+EXPORT_SYMBOL(cmpxchg_386_u16);
+
+unsigned long cmpxchg_386_u32(volatile void *ptr, u32 old, u32 new) +{
+ u32 prev;
+ unsigned long flags;
+ /*
+ * Check if the kernel was compiled for an old cpu but the
+ * currently running cpu can do cmpxchg after all
+ * All CPUs except 386 support CMPXCHG
+ */
+ if (cpu_data->x86 > 3)
+ return __cmpxchg(ptr, old, new, sizeof(u32));
+
+ /* Poor man's cmpxchg for 386. Unsuitable for SMP */
+ local_irq_save(flags);
+ prev = *(u32 *)ptr;
+ if (prev = old)
+ *(u32 *)ptr = new;
+ local_irq_restore(flags);
+ return prev;
+}
+
+EXPORT_SYMBOL(cmpxchg_386_u32);
+#endif
+
+#ifndef CONFIG_X86_CMPXCHG8B
+unsigned long long cmpxchg8b_486(volatile unsigned long long *ptr,
+ unsigned long long old, unsigned long long newv)
+{
+ unsigned long long prev;
+ unsigned long flags;
+
+ /*
+ * Check if the kernel was compiled for an old cpu but
+ * we are running really on a cpu capable of cmpxchg8b
+ */
+
+ if (cpu_has(cpu_data, X86_FEATURE_CX8))
+ return __cmpxchg8b(ptr, old, newv);
+
+ /* Poor mans cmpxchg8b for 386 and 486. Not suitable for SMP */
+ local_irq_save(flags);
+ prev = *ptr;
+ if (prev = old)
+ *ptr = newv;
+ local_irq_restore(flags);
+ return prev;
+}
+
+EXPORT_SYMBOL(cmpxchg8b_486);
+#endif
+
// arch_initcall(intel_cpu_init);
Index: linux-2.6.9/include/asm-i386/system.h
=================================--- linux-2.6.9.orig/include/asm-i386/system.h 2004-11-15 11:13:38.000000000 -0800
+++ linux-2.6.9/include/asm-i386/system.h 2004-11-19 10:49:46.000000000 -0800
@@ -149,6 +149,9 @@
#define __xg(x) ((struct __xchg_dummy *)(x))
+#define ll_low(x) *(((unsigned int*)&(x))+0)
+#define ll_high(x) *(((unsigned int*)&(x))+1)
+
/*
* The semantics of XCHGCMP8B are a bit strange, this is why
* there is a loop and the loading of %%eax and %%edx has to
@@ -184,8 +187,6 @@
{
__set_64bit(ptr,(unsigned int)(value), (unsigned int)((value)>>32ULL));
}
-#define ll_low(x) *(((unsigned int*)&(x))+0)
-#define ll_high(x) *(((unsigned int*)&(x))+1)
static inline void __set_64bit_var (unsigned long long *ptr,
unsigned long long value)
@@ -203,6 +204,26 @@
__set_64bit(ptr, (unsigned int)(value), (unsigned int)((value)>>32ULL) ) : \
__set_64bit(ptr, ll_low(value), ll_high(value)) )
+static inline unsigned long long __get_64bit(unsigned long long * ptr) +{
+ unsigned long long ret;
+ __asm__ __volatile__ (
+ "\n1:\t"
+ "movl (%1), %%eax\n\t"
+ "movl 4(%1), %%edx\n\t"
+ "movl %%eax, %%ebx\n\t"
+ "movl %%edx, %%ecx\n\t"
+ LOCK_PREFIX "cmpxchg8b (%1)\n\t"
+ "jnz 1b"
+ : "=A"(ret)
+ : "D"(ptr)
+ : "ebx", "ecx", "memory");
+ return ret;
+}
+
+#define get_64bit(ptr) __get_64bit(ptr)
+
+
/*
* Note: no "lock" prefix even on SMP: xchg always implies lock anyway
* Note 2: xchg has side effect, so that attribute volatile is necessary,
@@ -240,7 +261,41 @@
*/
#ifdef CONFIG_X86_CMPXCHG
+
#define __HAVE_ARCH_CMPXCHG 1
+#define cmpxchg(ptr,o,n)\
+ ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
+ (unsigned long)(n), sizeof(*(ptr))))
+
+#else
+
+/*
+ * Building a kernel capable running on 80386. It may be necessary to
+ * simulate the cmpxchg on the 80386 CPU. For that purpose we define
+ * a function for each of the sizes we support.
+ */
+
+extern unsigned long cmpxchg_386_u8(volatile void *, u8, u8); +extern unsigned long cmpxchg_386_u16(volatile void *, u16, u16); +extern unsigned long cmpxchg_386_u32(volatile void *, u32, u32); +
+static inline unsigned long cmpxchg_386(volatile void *ptr, unsigned long old,
+ unsigned long new, int size)
+{
+ switch (size) {
+ case 1:
+ return cmpxchg_386_u8(ptr, old, new);
+ case 2:
+ return cmpxchg_386_u16(ptr, old, new);
+ case 4:
+ return cmpxchg_386_u32(ptr, old, new);
+ }
+ return old;
+}
+
+#define cmpxchg(ptr,o,n)\
+ ((__typeof__(*(ptr)))cmpxchg_386((ptr), (unsigned long)(o), \
+ (unsigned long)(n), sizeof(*(ptr))))
#endif
static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
@@ -270,10 +325,32 @@
return old;
}
-#define cmpxchg(ptr,o,n)\
- ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
- (unsigned long)(n),sizeof(*(ptr))))
-
+static inline unsigned long long __cmpxchg8b(volatile unsigned long long *ptr,
+ unsigned long long old, unsigned long long newv)
+{
+ unsigned long long prev;
+ __asm__ __volatile__(
+ LOCK_PREFIX "cmpxchg8b (%4)"
+ : "=A" (prev)
+ : "0" (old), "c" ((unsigned long)(newv >> 32)),
+ "b" ((unsigned long)(newv & 0xffffffffULL)), "D" (ptr)
+ : "memory");
+ return prev;
+}
+
+#ifdef CONFIG_X86_CMPXCHG8B
+#define cmpxchg8b __cmpxchg8b
+#else
+/*
+ * Building a kernel capable of running on 80486 and 80386. Both
+ * do not support cmpxchg8b. Call a function that emulates the
+ * instruction if necessary.
+ */
+extern unsigned long long cmpxchg8b_486(volatile unsigned long long *,
+ unsigned long long, unsigned long long);
+#define cmpxchg8b cmpxchg8b_486
+#endif
+
#ifdef __KERNEL__
struct alt_instr {
__u8 *instr; /* original instruction */
page fault scalability patch V11 [5/7]: i386 atomic pte operations
In reply to Christoph LameterChangelog
* Atomic pte operations for i386 in regular and PAE modes
Index: linux-2.6.9/include/asm-i386/pgtable.h
=================================--- linux-2.6.9.orig/include/asm-i386/pgtable.h 2004-11-15 11:13:38.000000000 -0800
+++ linux-2.6.9/include/asm-i386/pgtable.h 2004-11-19 10:05:27.000000000 -0800
@@ -413,6 +413,7 @@
#define __HAVE_ARCH_PTEP_SET_WRPROTECT
#define __HAVE_ARCH_PTEP_MKDIRTY
#define __HAVE_ARCH_PTE_SAME
+#define __HAVE_ARCH_ATOMIC_TABLE_OPS
#include <asm-generic/pgtable.h>
#endif /* _I386_PGTABLE_H */
Index: linux-2.6.9/include/asm-i386/pgtable-3level.h
=================================--- linux-2.6.9.orig/include/asm-i386/pgtable-3level.h 2004-10-18 14:54:55.000000000 -0700
+++ linux-2.6.9/include/asm-i386/pgtable-3level.h 2004-11-19 10:10:06.000000000 -0800
@@ -6,7 +6,8 @@
* tables on PPro+ CPUs.
*
* Copyright (C) 1999 Ingo Molnar <[email protected]>
- */
+ * August 26, 2004 added ptep_cmpxchg <[email protected]> +*/
#define pte_ERROR(e) \
printk("%s:%d: bad pte %p(%08lx%08lx).\n", __FILE__, __LINE__, &(e), (e).pte_high, (e).pte_low)
@@ -42,26 +43,15 @@
return pte_x(pte);
}
-/* Rules for using set_pte: the pte being assigned *must* be
- * either not present or in a state where the hardware will
- * not attempt to update the pte. In places where this is
- * not possible, use pte_get_and_clear to obtain the old pte
- * value and then use set_pte to update it. -ben
- */
-static inline void set_pte(pte_t *ptep, pte_t pte)
-{
- ptep->pte_high = pte.pte_high;
- smp_wmb();
- ptep->pte_low = pte.pte_low;
-}
-#define __HAVE_ARCH_SET_PTE_ATOMIC
-#define set_pte_atomic(pteptr,pteval) \
+#define set_pte(pteptr,pteval) \
set_64bit((unsigned long long *)(pteptr),pte_val(pteval))
#define set_pmd(pmdptr,pmdval) \
set_64bit((unsigned long long *)(pmdptr),pmd_val(pmdval))
#define set_pgd(pgdptr,pgdval) \
set_64bit((unsigned long long *)(pgdptr),pgd_val(pgdval))
+#define set_pte_atomic set_pte
+
/*
* Pentium-II erratum A13: in PAE mode we explicitly have to flush
* the TLB via cr3 if the top-level pgd is changed...
@@ -142,4 +132,23 @@
#define __pte_to_swp_entry(pte) ((swp_entry_t){ (pte).pte_high })
#define __swp_entry_to_pte(x) ((pte_t){ 0, (x).val })
+/* Atomic PTE operations */
+#define ptep_xchg_flush(__vma, __addr, __ptep, __newval) \
+({ pte_t __r; \
+ /* xchg acts as a barrier before the setting of the high bits. */\
+ __r.pte_low = xchg(&(__ptep)->pte_low, (__newval).pte_low); \
+ __r.pte_high = (__ptep)->pte_high; \
+ (__ptep)->pte_high = (__newval).pte_high; \
+ flush_tlb_page(__vma, __addr); \
+ (__r); \
+})
+
+#define __HAVE_ARCH_PTEP_XCHG_FLUSH
+
+static inline int ptep_cmpxchg(struct vm_area_struct *vma, unsigned long address, pte_t *ptep, pte_t oldval, pte_t newval) +{
+ return cmpxchg((unsigned int *)ptep, pte_val(oldval), pte_val(newval)) = pte_val(oldval);
+}
+
+
#endif /* _I386_PGTABLE_3LEVEL_H */
Index: linux-2.6.9/include/asm-i386/pgtable-2level.h
=================================--- linux-2.6.9.orig/include/asm-i386/pgtable-2level.h 2004-10-18 14:54:31.000000000 -0700
+++ linux-2.6.9/include/asm-i386/pgtable-2level.h 2004-11-19 10:05:27.000000000 -0800
@@ -82,4 +82,7 @@
#define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_low })
#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
+/* Atomic PTE operations */
+#define ptep_cmpxchg(__vma,__a,__xp,__oldpte,__newpte) (cmpxchg(&(__xp)->pte_low, (__oldpte).pte_low, (__newpte).pte_low)=(__oldpte).pte_low) +
#endif /* _I386_PGTABLE_2LEVEL_H */
Index: linux-2.6.9/include/asm-i386/pgalloc.h
=================================--- linux-2.6.9.orig/include/asm-i386/pgalloc.h 2004-10-18 14:53:10.000000000 -0700
+++ linux-2.6.9/include/asm-i386/pgalloc.h 2004-11-19 10:10:40.000000000 -0800
@@ -4,9 +4,12 @@
#include <linux/config.h>
#include <asm/processor.h>
#include <asm/fixmap.h>
+#include <asm/system.h>
#include <linux/threads.h>
#include <linux/mm.h> /* for struct page */
+#define PMD_NONE 0L
+
#define pmd_populate_kernel(mm, pmd, pte) \
set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(pte)))
@@ -16,6 +19,19 @@
((unsigned long long)page_to_pfn(pte) <<
(unsigned long long) PAGE_SHIFT)));
}
+
+/* Atomic version */
+static inline int pmd_test_and_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte) +{
+#ifdef CONFIG_X86_PAE
+ return cmpxchg8b( ((unsigned long long *)pmd), PMD_NONE, _PAGE_TABLE +
+ ((unsigned long long)page_to_pfn(pte) <<
+ (unsigned long long) PAGE_SHIFT) ) = PMD_NONE;
+#else
+ return cmpxchg( (unsigned long *)pmd, PMD_NONE, _PAGE_TABLE + (page_to_pfn(pte) << PAGE_SHIFT)) = PMD_NONE;
+#endif
+}
+
/*
* Allocate and free page tables.
*/
@@ -49,6 +65,7 @@
#define pmd_free(x) do { } while (0)
#define __pmd_free_tlb(tlb,x) do { } while (0)
#define pgd_populate(mm, pmd, pte) BUG()
+#define pgd_test_and_populate(mm, pmd, pte) ({ BUG(); 1; })
#define check_pgt_cache() do { } while (0)
page fault scalability patch V11 [6/7]: x86_64 atomic pte operations
In reply to Christoph LameterChangelog
* Provide atomic pte operations for x86_64
Index: linux-2.6.9/include/asm-x86_64/pgalloc.h
=================================--- linux-2.6.9.orig/include/asm-x86_64/pgalloc.h 2004-10-18 14:54:30.000000000 -0700
+++ linux-2.6.9/include/asm-x86_64/pgalloc.h 2004-11-19 08:17:55.000000000 -0800
@@ -7,16 +7,26 @@
#include <linux/threads.h>
#include <linux/mm.h>
+#define PMD_NONE 0
+#define PGD_NONE 0
+
#define pmd_populate_kernel(mm, pmd, pte) \
set_pmd(pmd, __pmd(_PAGE_TABLE | __pa(pte)))
#define pgd_populate(mm, pgd, pmd) \
set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pmd)))
+#define pgd_test_and_populate(mm, pgd, pmd) \
+ (cmpxchg((int *)pgd, PGD_NONE, _PAGE_TABLE | __pa(pmd)) = PGD_NONE)
static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte) {
set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)));
}
+static inline int pmd_test_and_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte) +{
+ return cmpxchg((int *)pmd, PMD_NONE, _PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)) = PMD_NONE;
+}
+
extern __inline__ pmd_t *get_pmd(void)
{
return (pmd_t *)get_zeroed_page(GFP_KERNEL);
Index: linux-2.6.9/include/asm-x86_64/pgtable.h
=================================--- linux-2.6.9.orig/include/asm-x86_64/pgtable.h 2004-11-15 11:13:39.000000000 -0800
+++ linux-2.6.9/include/asm-x86_64/pgtable.h 2004-11-19 08:18:52.000000000 -0800
@@ -437,6 +437,10 @@
#define kc_offset_to_vaddr(o) \
(((o) & (1UL << (__VIRTUAL_MASK_SHIFT-1))) ? ((o) | (~__VIRTUAL_MASK)) : (o))+
+#define ptep_cmpxchg(__vma,__addr,__xp,__oldval,__newval) (cmpxchg(&(__xp)->pte, pte_val(__oldval), pte_val(__newval)) = pte_val(__oldval)) +#define __HAVE_ARCH_ATOMIC_TABLE_OPS
+
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
page fault scalability patch V11 [7/7]: s390 atomic pte operations
In reply to Christoph LameterChangelog
* Provide atomic pte operations for s390
Index: linux-2.6.9/include/asm-s390/pgtable.h
=================================--- linux-2.6.9.orig/include/asm-s390/pgtable.h 2004-10-18 14:54:55.000000000 -0700
+++ linux-2.6.9/include/asm-s390/pgtable.h 2004-11-19 11:35:08.000000000 -0800
@@ -567,6 +567,15 @@
return pte;
}
+#define ptep_xchg_flush(__vma, __address, __ptep, __pteval) \
+({ \
+ struct mm_struct *__mm = __vma->vm_mm; \ + pte_t __pte; \ + __pte = ptep_clear_flush(__vma, __address, __ptep); \ + set_pte(__ptep, __pteval); \ + __pte; \
+})
+
static inline void ptep_set_wrprotect(pte_t *ptep) {
pte_t old_pte = *ptep;
@@ -778,6 +787,14 @@
#define kern_addr_valid(addr) (1)
+/* Atomic PTE operations */
+#define __HAVE_ARCH_ATOMIC_TABLE_OPS
+
+static inline int ptep_cmpxchg (struct vm_area_struct *vma, unsigned long address, pte_t *ptep, pte_t oldval, pte_t newval) +{
+ return cmpxchg(ptep, pte_val(oldval), pte_val(newval)) = pte_val(oldval);
+}
+
/*
* No page table caches to initialise
*/
@@ -791,6 +808,7 @@
#define __HAVE_ARCH_PTEP_CLEAR_DIRTY_FLUSH
#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
#define __HAVE_ARCH_PTEP_CLEAR_FLUSH
+#define __HAVE_ARCH_PTEP_XCHG_FLUSH
#define __HAVE_ARCH_PTEP_SET_WRPROTECT
#define __HAVE_ARCH_PTEP_MKDIRTY
#define __HAVE_ARCH_PTE_SAME
Index: linux-2.6.9/include/asm-s390/pgalloc.h
=================================--- linux-2.6.9.orig/include/asm-s390/pgalloc.h 2004-10-18 14:54:37.000000000 -0700
+++ linux-2.6.9/include/asm-s390/pgalloc.h 2004-11-19 11:33:25.000000000 -0800
@@ -97,6 +97,10 @@
pgd_val(*pgd) = _PGD_ENTRY | __pa(pmd);
}
+static inline int pgd_test_and_populate(struct mm_struct *mm, pdg_t *pgd, pmd_t *pmd) +{
+ return cmpxchg(pgd, _PAGE_TABLE_INV, _PGD_ENTRY | __pa(pmd)) = _PAGE_TABLE_INV;
+}
#endif /* __s390x__ */
static inline void
@@ -119,6 +123,18 @@
pmd_populate_kernel(mm, pmd, (pte_t *)((page-mem_map) << PAGE_SHIFT));
}
+static inline int
+pmd_test_and_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page) +{
+ int rc;
+ spin_lock(&mm->page_table_lock);
+
+ rc=pte_same(*pmd, _PAGE_INVALID_EMPTY);
+ if (rc) pmd_populate(mm, pmd, page);
+ spin_unlock(&mm->page_table_lock);
+ return rc;
+}
+
/*
* page table entry allocation/free routines.
*/
Re: another approach to rss : sloppy rss
In reply to Christoph LameterQuoted 19 lines · Christoph Lameter
Quoted 9 lines · Nick Piggin
Just coming back to your sloppy rss patch - this thing will of course allow unbounded error to build up. Well, it *will* be bounded by the actual RSS if we assume the races can only cause rss to be underestimated. However, such an assumption (I think it is a safe one?) also means that rss won't hover around the correct value, but tend to go increasingly downward.
On your HPC codes that never reclaim memory, and don't do a lot of mapping / unmapping I guess this wouldn't matter... But a long running database or something?
Databases preallocate memory on startup and then manage memory themselves. One reason for this patch is that these applications cause anonymous page fault storms on startup given lots of memory which will make the system seem to freeze for awhile.
It is rare for a program to actually free up memory.
Quoted 8 lines
Where this approach could be problematic is when the system is under heavy swap load. Pages of an application will be repeatedly paged in and out and therefore rss will be incremented and decremented. But in those cases these incs and decs are not done in a way that is on purpose parallel like in my test programs. So I would expect rss to be more accurate than in my tests.
I think the sloppy rss approach is the right way to go.
Is this really that much of a problem? Why not leave rss as an _ACCURATE_ count of pages. That way stuff like limits based upon rss and accounting of memory usage are accurate.
Have we tried splitting into seperate cache lines? How about grouped counters for every 16 cpus instead of a per-cpu counter as proposed by someone else earlier.
IMHO, keeping rss as an accurate count is much more important that having a nearly correct value. If this turns into more of a scaling issue later on, your patch will have to be caught by someone accidentally noticing that the rss value is _WAY_ off as opposed to our normal methods for detecting cacheline contention.
Just my opinion,
Robin Holt
Re: page fault scalability patch V11 [0/7]: overview
In reply to Christoph LameterQuoted 2 lines · Christoph Lameter
Note that I have posted two other approaches of dealing with the rss problem:
You could also make "rss" be a _signed_ integer per-thread.
When unmapping a page, you decrement one of the threads that shares the mm (doesn't matter which - which is why the per-thread rss may go negative), and when mapping a page you increment it.
Then, anybody who actually wants a global rss can just iterate over threads and add it all up. If you do it under the mmap_sem, it's stable, and if you do it outside the mmap_sem it's imprecise but stable in the long term (ie errors never _accumulate_, like the non-atomic case will do).
Does anybody care enough? Maybe, maybe not. It certainly sounds a hell of a lot better than the periodic scan.
Linus
Re: page fault scalability patch V11 [1/7]: sloppy rss
In reply to Christoph LameterSorry, against what tree do these patches apply? Apparently not linux-2.6.9, nor latest -bk, nor -mm?
Hugh
Re: page fault scalability patch V11 [0/7]: overview
In reply to Linus TorvaldsQuoted 12 lines · Linus Torvalds
Quoted 1 line · Christoph Lameter
Note that I have posted two other approaches of dealing with the rss problem:
You could also make "rss" be a _signed_ integer per-thread.
When unmapping a page, you decrement one of the threads that shares the mm (doesn't matter which - which is why the per-thread rss may go negative), and when mapping a page you increment it.
Quoted 9 lines
Then, anybody who actually wants a global rss can just iterate over threads and add it all up. If you do it under the
mmap_sem, it's stable, and if you do it outside themmap_semit's imprecise but stable in the long term (ie errors never _accumulate_, like the non-atomic case will do).Does anybody care enough? Maybe, maybe not. It certainly sounds a hell of a lot better than the periodic scan.
I think this sounds like it might be a good idea. I prefer it to having the unbounded error of sloppy rss (as improbable as it may be in practice).
The per thread rss may wrap (maybe not 64-bit counters), but even so, the summation over all threads should still end up being correct I think.
Re: another approach to rss : sloppy rss
In reply to Robin HoltQuoted 9 lines · Robin Holt
Quoted 1 line · Christoph Lameter
I think the sloppy rss approach is the right way to go.
Is this really that much of a problem? Why not leave rss as an _ACCURATE_ count of pages. That way stuff like limits based upon rss and accounting of memory usage are accurate.
I think I agree. (But Christoph is right that in practice probably nobody or very few will ever notice).
Quoted 4 lines
Have we tried splitting into seperate cache lines? How about grouped counters for every 16 cpus instead of a per-cpu counter as proposed by someone else earlier.
Well, you still need to put those counters on seperate cachelines, so you still need to pad them out quite a lot. Then as they are shared, you _still_ need to make them atomic, and they'll still be bouncing around too.
Linus' idea of a per-thread 'pages_in - pages_out' counter may prove to be just the right solution though.
Nick
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 2 lines · Nick Piggin
I think this sounds like it might be a good idea. I prefer it to having the unbounded error of sloppy rss (as improbable as it may be in practice).
It may also be faster since the processors can have exclusive cache lines.
This means we need to move rss into the task struct. But how does one get from mm struct to task struct? current is likely available most of the time. Is that always the case?
Quoted 3 lines
The per thread rss may wrap (maybe not 64-bit counters), but even so, the summation over all threads should still end up being correct I think.
Note though that the mmap_sem is no protection. It is a read lock and may be held by multiple processes while incrementing and decrementing rss. This is likely reducing the number of collisions significantly but it wont be a guarantee like locking or atomic ops.
Re: page fault scalability patch V11 [1/7]: sloppy rss
In reply to Hugh Dickins2.6.10-rc2-bk3
Quoted 2 lines · Hugh Dickins
Sorry, against what tree do these patches apply? Apparently not linux-2.6.9, nor latest -bk, nor -mm?
Re: page fault scalability patch V11 [0/7]: overview
In reply to Christoph LameterQuoted 9 lines · Christoph Lameter
Quoted 2 lines · Nick Piggin
I think this sounds like it might be a good idea. I prefer it to having the unbounded error of sloppy rss (as improbable as it may be in practice).
It may also be faster since the processors can have exclusive cache lines.
Yep.
Quoted 4 lines
This means we need to move rss into the task struct. But how does one get from mm struct to task struct? current is likely available most of the time. Is that always the case?
It is available everywhere that mm_struct is, I guess. So yes, I think current should be OK.
Quoted 11 lines
Quoted 4 lines
The per thread rss may wrap (maybe not 64-bit counters), but even so, the summation over all threads should still end up being correct I think.
Note though that the
mmap_semis no protection. It is a read lock and may be held by multiple processes while incrementing and decrementing rss. This is likely reducing the number of collisions significantly but it wont be a guarantee like locking or atomic ops.
Yeah the read lock won't do anything to serialise it. I think what Linus is saying is that we _don't care_ most of the time (because the error will be bounded). But if it happened that we really do care anywhere, then the write lock should be sufficient.
Re: another approach to rss : sloppy rss
In reply to Nick PigginQuoted 6 lines · Nick Piggin
Well, you still need to put those counters on seperate cachelines, so you still need to pad them out quite a lot. Then as they are shared, you _still_ need to make them atomic, and they'll still be bouncing around too.
Linus' idea of a per-thread '
pages_in-pages_out' counter may prove to be just the right solution though.
I can go with either solution. Not sure how many cpus we can group together before the cacheline becomes so hot that we need to fan them out. I have a gut feeling it is alot.
On the 2.4 kernel which SGI put together, we just changed rss to an atomic and ensured it was in a seperate cacheline from the locks and performance was more than adequate. I realize a lot has changed since 2.4, but the concepts are similar.
Just my 2 cents,
Robin
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 4 lines · Nick Piggin
The per thread rss may wrap (maybe not 64-bit counters), but even so, the summation over all threads should still end up being correct I think.
Yes. As long as the total rss fits in an int, it doesn't matter if any of them wrap. Addition is still associative in twos-complement arithmetic even in the presense of overflows.
If you actually want to make it proper standard C, I guess you'd have to make the thing unsigned, which gives you the mod-2**n guarantees even if somebody were to ever make a non-twos-complement machine.
Linus
Re: page fault scalability patch V11 [0/7]: overview
In reply to Christoph LameterQuoted 5 lines · Christoph Lameter
Note though that the
mmap_semis no protection. It is a read lock and may be held by multiple processes while incrementing and decrementing rss. This is likely reducing the number of collisions significantly but it wont be a guarantee like locking or atomic ops.
It is, though, if you hold it for a write.
The point being that you _can_ get an exact rss value if you want to.
Not that I really see any overwhelming evidence of anybody ever really caring, but it's nice to know that you have the option.
Linus
Re: page fault scalability patch V11 [0/7]: overview
In reply to Linus TorvaldsQuoted 11 lines · Linus Torvalds
You could also make "rss" be a _signed_ integer per-thread. When unmapping a page, you decrement one of the threads that shares the mm (doesn't matter which - which is why the per-thread rss may go negative), and when mapping a page you increment it.
Then, anybody who actually wants a global rss can just iterate over threads and add it all up. If you do it under themmap_sem, it's stable, and if you do it outside themmap_semit's imprecise but stable in the long term (ie errors never _accumulate_, like the non-atomic case will do).
Does anybody care enough? Maybe, maybe not. It certainly sounds a hell of a lot better than the periodic scan.
Unprivileged triggers for full-tasklist scans are NMI oops material.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
In reply to Christoph LameterQuoted 9 lines · Christoph Lameter
A.
make_rss_atomic. The earlier releases contained that patch but then another variable (such asanon_rss) was introduced that would
have required additional atomic operations. Atomic rss operations are also causing slowdowns on machines with a high number of cpus due to memory contention.
B.remove_rss. Replace rss with a periodic scan over the vm to
determine rss and additional numbers. This was also discussed on linux-mm and linux-ia64. The scans while displaying /proc data were undesirable.
Split counters easily resolve the issues with both these approaches (and apparently your co-workers are suggesting it too, and have performance results backing it).
-- wli
Re: page fault scalability patch V11 [0/7]: overview
In reply to Christoph LameterQuoted 10 lines · Christoph Lameter
Note that I have posted two other approaches of dealing with the rss problem:
A.
make_rss_atomic. The earlier releases contained that patch but then another
variable (such asanon_rss) was introduced that would have required additional atomic operations. Atomic rss operations are also causing slowdowns on machines with a high number of cpus due to memory contention.B.
remove_rss. Replace rss with a periodic scan over the vm to determine
rss and additional numbers. This was also discussed on linux-mm and linux-ia64. The scans while displaying /proc data were undesirable.
Can you run a comparison benchmark between atomic rss and anon_rss and the sloppy rss with the rss and anon_rss in seperate cachelines. I am not sure that it is important to seperate the two into seperate lines, just rss and anon_rss from the lock and sema.
If I have the time over the weekend, I might try this myself. If not, can you give it a try.
Thanks,
Robin
Re: page fault scalability patch V11 [0/7]: overview
In reply to Linus TorvaldsQuoted 3 lines · Linus Torvalds
Not that I really see any overwhelming evidence of anybody ever really caring, but it's nice to know that you have the option.
Btw, if you are going to look at doing this rss thing, you need to make sure that thread exit ends up adding its rss to _some_ remaining sibling.
I guess that was obvious, but it's worth pointing out. That may actually be the only case where we do _not_ have a nice SMP-safe access: we do have a stable sibling (tsk->thread_leader), but we don't have any good serialization _except_ for taking mmap_sem for writing. Which we currently don't do: we take it for reading (and then we possibly upgrade it to a write lock if we notice that there is a core-dump starting).
We can avoid this too by having a per-mm atomic rss "spill" counter. So exit_mm() would basically do:
... tsk->mm = NULL; atomic_add(tsk->rss, &mm->rss_spill); ...
and then the algorithm for getting rss would be:
rss = atomic_read(mm->rss_spill); for_each_thread(..) rss += tsk->rss;
Or does anybody see any better approaches?
Linus
Re: page fault scalability patch V11 [0/7]: overview
In reply to William Lee Irwin IIIQuoted 13 lines · William Lee Irwin III
Quoted 9 lines · Christoph Lameter
A.
make_rss_atomic. The earlier releases contained that patch but then another variable (such asanon_rss) was introduced that would
have required additional atomic operations. Atomic rss operations are also causing slowdowns on machines with a high number of cpus due to memory contention.
B.remove_rss. Replace rss with a periodic scan over the vm to
determine rss and additional numbers. This was also discussed on linux-mm and linux-ia64. The scans while displaying /proc data were undesirable.
Quoted 4 lines
Split counters easily resolve the issues with both these approaches (and apparently your co-workers are suggesting it too, and have performance results backing it).
Split counters still require atomic operations though. This is what Christoph's latest effort is directed at removing. And they'll still bounce cachelines around. (I assume we've reached the conclusion that per-cpu split counters per-mm won't fly?).
Re: page fault scalability patch V11 [0/7]: overview
In reply to William Lee Irwin IIIQuoted 15 lines · William Lee Irwin III
Quoted 11 lines · Linus Torvalds
You could also make "rss" be a _signed_ integer per-thread. When unmapping a page, you decrement one of the threads that shares the mm (doesn't matter which - which is why the per-thread rss may go negative), and when mapping a page you increment it.
Then, anybody who actually wants a global rss can just iterate over threads and add it all up. If you do it under themmap_sem, it's stable, and if you do it outside themmap_semit's imprecise but stable in the long term (ie errors never _accumulate_, like the non-atomic case will do).
Does anybody care enough? Maybe, maybe not. It certainly sounds a hell of a lot better than the periodic scan.
Quoted 2 lines
Unprivileged triggers for full-tasklist scans are NMI oops material.
What about pushing the per-thread rss delta back into the global atomic rss counter in each schedule()?
Pros:
This would take the task exiting problem into its stride as a matter of course.
Single atomic read to get rss.
Cons:
would just be moving the atomic op somewhere else if we don't get many page faults per schedule.
Not really nice dependancies.
Assumes schedule (not context switch) must occur somewhat regularly. At present this is not true for SCHED_FIFO tasks.
Too nasty?
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 3 lines · William Lee Irwin III
Quoted 3 lines
Split counters easily resolve the issues with both these approaches (and apparently your co-workers are suggesting it too, and have performance results backing it).
Quoted 4 lines · Nick Piggin
Split counters still require atomic operations though. This is what Christoph's latest effort is directed at removing. And they'll still bounce cachelines around. (I assume we've reached the conclusion that per-cpu split counters per-mm won't fly?).
Split != per-cpu, though it may be. Counterexamples are
as simple as atomic_inc(&mm->rss[smp_processor_id()>>RSS_IDX_SHIFT]); Furthermore, see Robin Holt's results regarding the performance of the atomic operations and their relation to cacheline sharing.
And frankly, the argument that the space overhead of per-cpu counters is problematic is not compelling. Even at 1024 cpus it's smaller than an ia64 pagetable page, of which there are numerous instances attached to each mm.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
Quoted 9 lines · William Lee Irwin III
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines
Split counters easily resolve the issues with both these approaches (and apparently your co-workers are suggesting it too, and have performance results backing it).
On Sat, Nov 20, 2004 at 01:18:22PM +1100, Nick Piggin wrote:
Quoted 8 lines
Quoted 4 lines
Split counters still require atomic operations though. This is what Christoph's latest effort is directed at removing. And they'll still bounce cachelines around. (I assume we've reached the conclusion that per-cpu split counters per-mm won't fly?).
Split != per-cpu, though it may be. Counterexamples are
as simple as atomic_inc(&mm->rss[smp_processor_id()>>RSS_IDX_SHIFT]);
Oh yes, I just meant that the only way split counters will relieve the atomic ops and bouncing is by having them per-cpu. But you knew that :)
Quoted 3 lines
Furthermore, see Robin Holt's results regarding the performance of the atomic operations and their relation to cacheline sharing.
Well yeah, but a. their patch isn't in 2.6 (or 2.4), and b. anon_rss means another atomic op. While this doesn't immediately make it a showstopper, it is gradually slowing down the single threaded page fault path too, which is bad.
Quoted 5 lines
And frankly, the argument that the space overhead of per-cpu counters is problematic is not compelling. Even at 1024 cpus it's smaller than an ia64 pagetable page, of which there are numerous instances attached to each mm.
1024 CPUs * 64 byte cachelines = 64K, no? Well I'm sure they probably don't even care about 64K on their large machines, but...
On i386 this would be maybe 32 * 128 byte = 4K per task for distro kernels. Not so good.
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 1 line · William Lee Irwin III
Quoted 1 line
Unprivileged triggers for full-tasklist scans are NMI oops material.
Quoted 5 lines · Nick Piggin
What about pushing the per-thread rss delta back into the global atomic rss counter in each
schedule()?
Pros:
This would take the task exiting problem into its stride as a matter of course.
Quoted 8 lines
Single atomic read to get rss.
Cons:
would just be moving the atomic op somewhere else if we don't get many page faults per schedule.
Not really nice dependancies.
Assumes schedule (not context switch) must occur somewhat regularly. At present this is not true forSCHED_FIFOtasks.
Too nasty?
This doesn't sound too hot. There's enough accounting that can't be done anywhere but schedule(), and this can be done elsewhere. Plus, you're moving an already too-frequent operation to a more frequent callsite.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
Quoted 22 lines · William Lee Irwin III
Quoted 1 line · William Lee Irwin III
Quoted 1 line
Unprivileged triggers for full-tasklist scans are NMI oops material.
Quoted 5 lines · Nick Piggin
What about pushing the per-thread rss delta back into the global atomic rss counter in each
schedule()?
Pros:
This would take the task exiting problem into its stride as a matter of course.Quoted 8 lines
Single atomic read to get rss.
Cons:
would just be moving the atomic op somewhere else if we don't get many page faults per schedule.
Not really nice dependancies.
Assumes schedule (not context switch) must occur somewhat regularly. At present this is not true forSCHED_FIFOtasks.
Too nasty?
Quoted 5 lines
This doesn't sound too hot. There's enough accounting that can't be done anywhere but
schedule(), and this can be done elsewhere. Plus, you're moving an already too-frequent operation to a more frequent callsite.
No, it won't somehow increase the number of atomic rss operations just because schedule is called more often. The number of ops will be at _most_ the number of page faults.
But I agree with your overall evaluation of its 'hotness'. Just another idea. Give this monkey another thousand years at the keys and he'll come up with the perfect solution :P
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 2 lines · William Lee Irwin III
Quoted 2 lines
Furthermore, see Robin Holt's results regarding the performance of the atomic operations and their relation to cacheline sharing.
Quoted 1 line · Nick Piggin
Well yeah, but a. their patch isn't in 2.6 (or 2.4), and b.
anon_rss
Irrelevant. Unshare cachelines with hot mm-global ones, and the "problem" goes away.
This stuff is going on and on about some purist "no atomic operations anywhere" weirdness even though killing the last atomic operation creates problems and doesn't improve performance.
Quoted 3 lines · Nick Piggin
means another atomic op. While this doesn't immediately make it a showstopper, it is gradually slowing down the single threaded page fault path too, which is bad.
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines
And frankly, the argument that the space overhead of per-cpu counters is problematic is not compelling. Even at 1024 cpus it's smaller than an ia64 pagetable page, of which there are numerous instances attached to each mm.
Quoted 4 lines · Nick Piggin
1024 CPUs * 64 byte cachelines = 64K, no? Well I'm sure they probably don't even care about 64K on their large machines, but... On i386 this would be maybe 32 * 128 byte = 4K per task for distro kernels. Not so good.
Why the Hell would you bother giving each cpu a separate cacheline? The odds of bouncing significantly merely amongst the counters are not particularly high.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
Quoted 6 lines · William Lee Irwin III
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines
Furthermore, see Robin Holt's results regarding the performance of the atomic operations and their relation to cacheline sharing.
Quoted 8 lines
Quoted 1 line · Nick Piggin
Well yeah, but a. their patch isn't in 2.6 (or 2.4), and b.
anon_rssIrrelevant. Unshare cachelines with hot mm-global ones, and the "problem" goes away.
That's the idea.
Quoted 4 lines
This stuff is going on and on about some purist "no atomic operations anywhere" weirdness even though killing the last atomic operation creates problems and doesn't improve performance.
Huh? How is not wanting to impact single threaded performance being "purist weirdness"? Practical, I'd call it.
Quoted 24 lines · Nick Piggin
Quoted 4 lines
means another atomic op. While this doesn't immediately make it a showstopper, it is gradually slowing down the single threaded page fault path too, which is bad.
Quoted 4 lines · William Lee Irwin III
Quoted 4 lines
And frankly, the argument that the space overhead of per-cpu counters is problematic is not compelling. Even at 1024 cpus it's smaller than an ia64 pagetable page, of which there are numerous instances attached to each mm.
Quoted 4 lines · Nick Piggin
1024 CPUs * 64 byte cachelines = 64K, no? Well I'm sure they probably don't even care about 64K on their large machines, but... On i386 this would be maybe 32 * 128 byte = 4K per task for distro kernels. Not so good.
Quoted 4 lines
Why the Hell would you bother giving each cpu a separate cacheline? The odds of bouncing significantly merely amongst the counters are not particularly high.
Hmm yeah I guess wouldn't put them all on different cachelines. As you can see though, Christoph ran into a wall at 8 CPUs, so having them densly packed still might not be enough.
Re: page fault scalability patch V11 [0/7]: overview
In reply to William Lee Irwin IIIQuoted 3 lines · William Lee Irwin III
Why the Hell would you bother giving each cpu a separate cacheline? The odds of bouncing significantly merely amongst the counters are not particularly high.
Agree, we are currently using atomic ops on a global rss on our 2.4 kernel with 512cpu systems and not seeing much cacheline contention. I don't remember how little it ended up being, but it was very little. We had gone to dropping the page_table_lock and only reaquiring it if the pte was non-null when we went to insert our new one. I think that was how we had it working. I would have to wake up and actually look at that code as it was many months ago that Ray Bryant did that work. We did make rss atomic. Most of the contention is sorted out by the mmap_sem. Processes acquiring themselves off of mmap_sem were found to have spaced themselves out enough that they were all approximately equal time from doing their atomic_add and therefore had very little contention for the cacheline. At least it was not enough that we could measure it as significant.
Re: page fault scalability patch V11 [0/7]: overview
In reply to William Lee Irwin IIIQuoted 15 lines · William Lee Irwin III
Quoted 11 lines · Linus Torvalds
You could also make "rss" be a _signed_ integer per-thread. When unmapping a page, you decrement one of the threads that shares the mm (doesn't matter which - which is why the per-thread rss may go negative), and when mapping a page you increment it.
Then, anybody who actually wants a global rss can just iterate over threads and add it all up. If you do it under themmap_sem, it's stable, and if you do it outside themmap_semit's imprecise but stable in the long term (ie errors never _accumulate_, like the non-atomic case will do).
Does anybody care enough? Maybe, maybe not. It certainly sounds a hell of a lot better than the periodic scan.
Quoted 2 lines
Unprivileged triggers for full-tasklist scans are NMI oops material.
Hang on, let's come back to this...
We already have unprivileged do-for-each-thread triggers in the proc code. It's in do_task_stat, even. Rss reporting would basically just involve one extra addition within that loop.
So... hmm, I can't see a problem with it.
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 2 lines · William Lee Irwin III
Quoted 2 lines
Irrelevant. Unshare cachelines with hot mm-global ones, and the "problem" goes away.
Quoted 1 line · Nick Piggin
That's the idea.
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines
This stuff is going on and on about some purist "no atomic operations anywhere" weirdness even though killing the last atomic operation creates problems and doesn't improve performance.
Quoted 2 lines · Nick Piggin
Huh? How is not wanting to impact single threaded performance being "purist weirdness"? Practical, I'd call it.
Empirically demonstrate the impact on single-threaded performance.
Quoted 3 lines · Nick Piggin
Quoted 3 lines
Why the Hell would you bother giving each cpu a separate cacheline? The odds of bouncing significantly merely amongst the counters are not particularly high.
Quoted 3 lines · Nick Piggin
Hmm yeah I guess wouldn't put them all on different cachelines. As you can see though, Christoph ran into a wall at 8 CPUs, so having them densly packed still might not be enough.
Please be more specific about the result, and cite the Message-Id.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 1 line · William Lee Irwin III
Quoted 1 line
Unprivileged triggers for full-tasklist scans are NMI oops material.
Quoted 5 lines · Nick Piggin
Hang on, let's come back to this...
We already have unprivileged do-for-each-thread triggers in the proc code. It's indo_task_stat, even. Rss reporting would basically just involve one extra addition within that loop.
So... hmm, I can't see a problem with it.
/proc/ triggering NMI oopses was a persistent problem even before that code was merged. I've not bothered testing it as it at best aggravates it.
And thread groups can share mm's. do_for_each_thread() won't suffice.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
In reply to William Lee Irwin IIIQuoted 19 lines · William Lee Irwin III
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines
Irrelevant. Unshare cachelines with hot mm-global ones, and the "problem" goes away.
Quoted 1 line · Nick Piggin
That's the idea.
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines
This stuff is going on and on about some purist "no atomic operations anywhere" weirdness even though killing the last atomic operation creates problems and doesn't improve performance.
Quoted 8 lines
Quoted 2 lines · Nick Piggin
Huh? How is not wanting to impact single threaded performance being "purist weirdness"? Practical, I'd call it.
Empirically demonstrate the impact on single-threaded performance.
I can tell you its worse. I don't have to demonstrate anything, more atomic RMW ops in the page fault path is going to have an impact.
I'm not saying we must not compromise *anywhere*, but it would just be nice to try to avoid making the path heavier, that's all. I'm not being purist when I say I'd first rather explore all other options before adding atomics.
But nevermind arguing, it appears Linus' suggested method will be fine and *does* mean we don't have to compromise.
Quoted 8 lines · Nick Piggin
Quoted 4 lines
Quoted 4 lines
Why the Hell would you bother giving each cpu a separate cacheline? The odds of bouncing significantly merely amongst the counters are not particularly high.
Quoted 9 lines
Quoted 3 lines · Nick Piggin
Hmm yeah I guess wouldn't put them all on different cachelines. As you can see though, Christoph ran into a wall at 8 CPUs, so having them densly packed still might not be enough.
Please be more specific about the result, and cite the Message-Id.
Start of this thread.
Re: page fault scalability patch V11 [0/7]: overview
Quoted 1 line · William Lee Irwin III
Quoted 1 line
Please be more specific about the result, and cite the Message-Id.
Quoted 1 line · Nick Piggin
Start of this thread.
Those do not have testing results of different RSS counter implementations in isolation.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
In reply to William Lee Irwin IIIQuoted 14 lines · William Lee Irwin III
Quoted 1 line · William Lee Irwin III
Quoted 1 line
Unprivileged triggers for full-tasklist scans are NMI oops material.
Quoted 5 lines · Nick Piggin
Hang on, let's come back to this...
We already have unprivileged do-for-each-thread triggers in the proc code. It's indo_task_stat, even. Rss reporting would basically just involve one extra addition within that loop.
So... hmm, I can't see a problem with it.
Quoted 3 lines
/proc/triggering NMI oopses was a persistent problem even before that code was merged. I've not bothered testing it as it at best aggravates it.
It isn't a problem. If it ever became a problem then we can just touch the nmi oopser in the loop.
Quoted 2 lines
And thread groups can share mm's.
do_for_each_thread()won't suffice.
I think it will be just fine.
Re: page fault scalability patch V11 [0/7]: overview
Quoted 7 lines · Nick Piggin
Quoted 2 lines · William Lee Irwin III
And thread groups can share mm's.
do_for_each_thread()won't suffice.I think it will be just fine.
Sorry, I misread. I think having per-thread rss counters will be fine (regardless of whether or not do_for_each_thread itself will suffice).
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 2 lines · William Lee Irwin III
Quoted 2 lines
/proc/triggering NMI oopses was a persistent problem even before that code was merged. I've not bothered testing it as it at best aggravates it.
Quoted 2 lines · Nick Piggin
It isn't a problem. If it ever became a problem then we can just touch the nmi oopser in the loop.
Very, very wrong. The tasklist scans hold the read side of the lock and aren't even what's running with interrupts off. The contenders on the write side are what the NMI oopser oopses.
And supposing the arch reenables interrupts in the write side's spinloop, you just get a box that silently goes out of service for extended periods of time, breaking cluster membership and more. The NMI oopser is just the report of the problem, not the problem itself. It's not a false report. The box is dead for > 5s at a time.
Quoted 1 line · William Lee Irwin III
Quoted 1 line
And thread groups can share mm's.
do_for_each_thread()won't suffice.
Quoted 1 line · Nick Piggin
I think it will be just fine.
And that makes it wrong on both counts. The above fails any time LD_ASSUME_KERNEL=2.4 is used, we well as when actual Linux features are used directly.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
In reply to Robin HoltQuoted 5 lines · Robin Holt
Agree, we are currently using atomic ops on a global rss on our 2.4 kernel with 512cpu systems and not seeing much cacheline contention. I don't remember how little it ended up being, but it was very little. We had gone to dropping the
page_table_lockand only reaquiring it if the pte was non-null when we went to insert our new one. I think that
Quoted 8 lines
was how we had it working. I would have to wake up and actually look at that code as it was many months ago that Ray Bryant did that work. We did make rss atomic. Most of the contention is sorted out by the
mmap_sem. Processes acquiring themselves off ofmmap_semwere found to have spaced themselves out enough that they were all approximately equal time from doing theiratomic_addand therefore had very little contention for the cacheline. At least it was not enough that we could measure it as significant.
Also, the densely-packed split counter can only get 4-16 cpus to a cacheline with cachelines <= 128B, so there are definite limitations to the amount of cacheline contention in such schemes.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
In reply to William Lee Irwin IIIQuoted 8 lines · William Lee Irwin III
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines
/proc/triggering NMI oopses was a persistent problem even before that code was merged. I've not bothered testing it as it at best aggravates it.On Sat, Nov 20, 2004 at 03:03:17PM +1100, Nick Piggin wrote:
Quoted 8 lines
Quoted 2 lines
It isn't a problem. If it ever became a problem then we can just touch the nmi oopser in the loop.
Very, very wrong. The tasklist scans hold the read side of the lock and aren't even what's running with interrupts off. The contenders on the write side are what the NMI oopser oopses.
*blinks*
So explain how this is "very very wrong", then?
Quoted 6 lines
And supposing the arch reenables interrupts in the write side's spinloop, you just get a box that silently goes out of service for extended periods of time, breaking cluster membership and more. The NMI oopser is just the report of the problem, not the problem itself. It's not a false report. The box is dead for > 5s at a time.
The point is, adding a for-each-thread loop or two in /proc isn't going to cause a problem that isn't already there.
If you had zero for-each-thread loops then you might have a valid complaint. Seeing as you have more than zero, with slim chances of reducing that number, then there is no valid complaint.
Quoted 6 lines
Quoted 1 line · William Lee Irwin III
Quoted 1 line
And thread groups can share mm's.
do_for_each_thread()won't suffice.
Quoted 9 lines
Quoted 1 line · Nick Piggin
I think it will be just fine.
And that makes it wrong on both counts. The above fails any time LD_ASSUME_KERNEL=2.4 is used, we well as when actual Linux features are used directly.
See my followup.
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 4 lines · Nick Piggin
Quoted 2 lines
Please be more specific about the result, and cite the Message-Id.
Start of this thread.
Part of the impact was having the page table lock, the mmap_sem, and these two atomic counters in the same cacheline. What about seperating the counters from the locks?
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 3 lines · William Lee Irwin III
Quoted 3 lines
Very, very wrong. The tasklist scans hold the read side of the lock and aren't even what's running with interrupts off. The contenders on the write side are what the NMI oopser oopses.
Quoted 2 lines · Nick Piggin
*blinks*
So explain how this is "very very wrong", then?
There isn't anything left to explain. So if there's a question, be specific about it.
Quoted 5 lines · William Lee Irwin III
Quoted 5 lines
And supposing the arch reenables interrupts in the write side's spinloop, you just get a box that silently goes out of service for extended periods of time, breaking cluster membership and more. The NMI oopser is just the report of the problem, not the problem itself. It's not a false report. The box is dead for > 5s at a time.
Quoted 5 lines · Nick Piggin
The point is, adding a for-each-thread loop or two in /proc isn't going to cause a problem that isn't already there.
If you had zero for-each-thread loops then you might have a valid complaint. Seeing as you have more than zero, with slim chances of reducing that number, then there is no valid complaint.
This entire line of argument is bogus. A preexisting bug of a similar nature is not grounds for deliberately introducing any bug.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
Quoted 7 lines · William Lee Irwin III
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines
Very, very wrong. The tasklist scans hold the read side of the lock and aren't even what's running with interrupts off. The contenders on the write side are what the NMI oopser oopses.
Quoted 9 lines
Quoted 2 lines · Nick Piggin
*blinks*
So explain how this is "very very wrong", then?There isn't anything left to explain. So if there's a question, be specific about it.
Why am I very very wrong? Why won't touch_nmi_watchdog work from the read loop?
And let's just be nice and try not to jump at the chance to point out when people are very very wrong, and keep count of the times they have been very very wrong. I'm trying to be constructive.
Quoted 19 lines
Quoted 5 lines · William Lee Irwin III
Quoted 5 lines
And supposing the arch reenables interrupts in the write side's spinloop, you just get a box that silently goes out of service for extended periods of time, breaking cluster membership and more. The NMI oopser is just the report of the problem, not the problem itself. It's not a false report. The box is dead for > 5s at a time.
Quoted 5 lines · Nick Piggin
The point is, adding a for-each-thread loop or two in /proc isn't going to cause a problem that isn't already there.
If you had zero for-each-thread loops then you might have a valid complaint. Seeing as you have more than zero, with slim chances of reducing that number, then there is no valid complaint.
Quoted 3 lines
This entire line of argument is bogus. A preexisting bug of a similar nature is not grounds for deliberately introducing any bug.
Sure, if that is a bug and someone is just about to fix it then yes you're right, we shouldn't introduce this. I didn't realise it was a bug. Sounds like it would be causing you lots of problems though - have you looked at how to fix it?
Re: page fault scalability patch V11 [0/7]: overview
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines
There isn't anything left to explain. So if there's a question, be specific about it.
Quoted 5 lines · Nick Piggin
Why am I very very wrong? Why won't
touch_nmi_watchdogwork from the read loop?
And let's just be nice and try not to jump at the chance to point out when people are very very wrong, and keep count of the times they have been very very wrong. I'm trying to be constructive.
touch_nmi_watchdog() is only "protection" against local interrupt disablement triggering the NMI oopser because alert_counter[] increments are not atomic. Yet even supposing they were made so, the net effect of "covering up" this gross deficiency is making the user-observable problems it causes undiagnosable, as noted before.
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines
This entire line of argument is bogus. A preexisting bug of a similar nature is not grounds for deliberately introducing any bug.
Quoted 4 lines · Nick Piggin
Sure, if that is a bug and someone is just about to fix it then yes you're right, we shouldn't introduce this. I didn't realise it was a bug. Sounds like it would be causing you lots of problems though - have you looked at how to fix it?
Kevin Marin was the first to report this issue to lkml. I had seen instances of it in internal corporate bugreports and it was one of the motivators for the work I did on pidhashing (one of the causes of the timeouts was worst cases in pid allocation). Manfred Spraul and myself wrote patches attempting to reduce read-side hold time in /proc/ algorithms, Ingo Molnar wrote patches to hierarchically subdivide the /proc/ iterations, and Dipankar Sarma and Maneesh Soni wrote patches to carry out the long iterations in /proc/ locklessly.
The last several of these affecting /proc/ have not gained acceptance, though the work has not been halted in any sense, as this problem recurs quite regularly. A considerable amount of sustained effort has gone toward mitigating and resolving rwlock starvation.
Aggravating the rwlock starvation destabilizes, not pessimizes, and performance is secondary to stability.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
Quoted 15 lines · William Lee Irwin III
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines
There isn't anything left to explain. So if there's a question, be specific about it.
Quoted 5 lines · Nick Piggin
Why am I very very wrong? Why won't
touch_nmi_watchdogwork from the read loop?
And let's just be nice and try not to jump at the chance to point out when people are very very wrong, and keep count of the times they have been very very wrong. I'm trying to be constructive.
Quoted 3 lines
touch_nmi_watchdog()is only "protection" against local interrupt disablement triggering the NMI oopser because alert_counter[] increments are not atomic. Yet even supposing they were made so, the
That would be a bug in touch_nmi_watchdog then, because you're racy against your own NMI too.
So I'm actually not very very wrong at all. I'm technically wrong because touch_nmi_watchdog has a theoretical 'bug'. In practice, multiple races with the non atomic increments to the same counter, and in an unbroken sequence would be about as likely as hardware failure.
Anyway, this touch nmi thing is going off topic, sorry list.
Quoted 3 lines
net effect of "covering up" this gross deficiency is making the user-observable problems it causes undiagnosable, as noted before.
Well the loops that are in there now aren't covered up, and they don't seem to be causing problems. Ergo there is no problem (we're being _practical_ here, right?)
Quoted 24 lines
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines
This entire line of argument is bogus. A preexisting bug of a similar nature is not grounds for deliberately introducing any bug.
Quoted 4 lines · Nick Piggin
Sure, if that is a bug and someone is just about to fix it then yes you're right, we shouldn't introduce this. I didn't realise it was a bug. Sounds like it would be causing you lots of problems though - have you looked at how to fix it?
Kevin Marin was the first to report this issue to lkml. I had seen instances of it in internal corporate bugreports and it was one of the motivators for the work I did on pidhashing (one of the causes of the timeouts was worst cases in pid allocation). Manfred Spraul and myself wrote patches attempting to reduce read-side hold time in
/proc/algorithms, Ingo Molnar wrote patches to hierarchically subdivide the/proc/iterations, and Dipankar Sarma and Maneesh Soni wrote patches to carry out the long iterations in/proc/locklessly.
Quoted 5 lines
The last several of these affecting
/proc/have not gained acceptance, though the work has not been halted in any sense, as this problem recurs quite regularly. A considerable amount of sustained effort has gone toward mitigating and resolving rwlock starvation.
That's very nice. But there is no problem _now_, is there?
Quoted 3 lines
Aggravating the rwlock starvation destabilizes, not pessimizes, and performance is secondary to stability.
Well luckily we're not going to be aggravating the rwlock stavation.
If you found a problem with, and fixed do_task_stat: ?time, ???_flt, et al, then you would apply the same solution to per thread rss to fix it in the same way.
Re: page fault scalability patch V11 [0/7]: overview
Quoted 2 lines · Nick Piggin
per thread rss
Given that we have contention problems updating a single mm-wide rss and given that the way to fix that up is to spread things out a bit, it seems wildly arbitrary to me that the way in which we choose to spread the counter out is to stick a bit of it into each task_struct.
I'd expect that just shoving a pointer into mm_struct which points at a dynamically allocated array[NR_CPUS] of longs would suffice. We probably don't even need to spread them out on cachelines - having four or eight cpus sharing the same cacheline probably isn't going to hurt much.
At least, that'd be my first attempt. If it's still not good enough, try something else.
Re: page fault scalability patch V11 [0/7]: overview
Quoted 3 lines · Andrew Morton
I'd expect that just shoving a pointer into
mm_structwhich points at a
dynamically allocated array[NR_CPUS] of longs would suffice.
One might even be able to use percpu_counter.h, although that might end up hurting many-cpu fork times, due to all that work in __alloc_percpu().
Re: page fault scalability patch V11 [0/7]: overview
In reply to Andrew MortonQuoted 10 lines · Andrew Morton
Quoted 1 line · Nick Piggin
per thread rss
Given that we have contention problems updating a single mm-wide rss and given that the way to fix that up is to spread things out a bit, it seems wildly arbitrary to me that the way in which we choose to spread the counter out is to stick a bit of it into each
task_struct.
Quoted 9 lines
I'd expect that just shoving a pointer into
mm_structwhich points at a dynamically allocated array[NR_CPUS] of longs would suffice. We probably don't even need to spread them out on cachelines - having four or eight cpus sharing the same cacheline probably isn't going to hurt much.At least, that'd be my first attempt. If it's still not good enough, try something else.
That is what Bill thought too. I guess per-cpu and per-thread rss are the leading candidates.
Per thread rss has the benefits of cacheline exclusivity, and not causing task bloat in the common case.
Per CPU array has better worst case /proc properties, but shares cachelines (or not, if using percpu_counter as you suggested).
I think I'd better leave it to others to finish off the arguments ;)
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 3 lines · William Lee Irwin III
Quoted 3 lines
touch_nmi_watchdog()is only "protection" against local interrupt disablement triggering the NMI oopser because alert_counter[] increments are not atomic. Yet even supposing they were made so, the
Quoted 8 lines · Nick Piggin
That would be a bug in
touch_nmi_watchdogthen, because you're racy against your own NMI too.
So I'm actually not very very wrong at all. I'm technically wrong becausetouch_nmi_watchdoghas a theoretical 'bug'. In practice, multiple races with the non atomic increments to the same counter, and in an unbroken sequence would be about as likely as hardware failure.
Anyway, this touch nmi thing is going off topic, sorry list.
No, it's on-topic.
(1) The issue is not theoretical. e.g. sysrq t does trigger NMI oopses, merely not every time, and not on every system. It is not associated with hardware failure. It is, however, tolerable because sysrq's require privilege to trigger and are primarly used when the box is dying anyway.
(2) NMI's don't nest. There is no possibility of NMI's racing against themselves while the data is per-cpu.
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines
net effect of "covering up" this gross deficiency is making the user-observable problems it causes undiagnosable, as noted before.
Quoted 3 lines · Nick Piggin
Well the loops that are in there now aren't covered up, and they don't seem to be causing problems. Ergo there is no problem (we're being _practical_ here, right?)
They are causing problems. They never stopped causing problems. None of the above attempts to reduce rwlock starvation has been successful in reducing it to untriggerable-in-the-field levels, and empirical demonstrations of starvation recurring after those available at the time of testing were put into place did in fact happen. Reduction of frequency and making starvation more difficult to trigger are all that they've achieved thus far.
Quoted 12 lines · William Lee Irwin III
Quoted 12 lines
Kevin Marin was the first to report this issue to lkml. I had seen instances of it in internal corporate bugreports and it was one of the motivators for the work I did on pidhashing (one of the causes of the timeouts was worst cases in pid allocation). Manfred Spraul and myself wrote patches attempting to reduce read-side hold time in
/proc/algorithms, Ingo Molnar wrote patches to hierarchically subdivide the/proc/iterations, and Dipankar Sarma and Maneesh Soni wrote patches to carry out the long iterations in/proc/locklessly. The last several of these affecting/proc/have not gained acceptance, though the work has not been halted in any sense, as this problem recurs quite regularly. A considerable amount of sustained effort has gone toward mitigating and resolving rwlock starvation.
Quoted 1 line · Nick Piggin
That's very nice. But there is no problem _now_, is there?
There is and has always been. All of the above merely mitigate the issue, with the possible exception of the tasklist RCU patch, for which I know of no testing results. Also note that almost none of the work on /proc/ has been merged.
Quoted 2 lines · William Lee Irwin III
Quoted 2 lines
Aggravating the rwlock starvation destabilizes, not pessimizes, and performance is secondary to stability.
Quoted 4 lines · Nick Piggin
Well luckily we're not going to be aggravating the rwlock stavation. If you found a problem with, and fixed
do_task_stat: ?time, ???_flt, et al, then you would apply the same solution to per thread rss to fix it in the same way.
You are aggravating the rwlock starvation by introducing gratuitous full tasklist iterations. There is no solution to do_task_stat() because it was recently introduced. There will be one as part of a port of the usual mitigation patches when the perennial problem is reported against a sufficiently recent kernel version, as usual. The already- demonstrated problematic iterations have not been removed.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
Quoted 19 lines · William Lee Irwin III
Quoted 3 lines · William Lee Irwin III
Quoted 3 lines
touch_nmi_watchdog()is only "protection" against local interrupt disablement triggering the NMI oopser because alert_counter[] increments are not atomic. Yet even supposing they were made so, theQuoted 8 lines · Nick Piggin
That would be a bug in
touch_nmi_watchdogthen, because you're racy against your own NMI too.
So I'm actually not very very wrong at all. I'm technically wrong becausetouch_nmi_watchdoghas a theoretical 'bug'. In practice, multiple races with the non atomic increments to the same counter, and in an unbroken sequence would be about as likely as hardware failure.
Anyway, this touch nmi thing is going off topic, sorry list.
Quoted 6 lines
No, it's on-topic.
(1) The issue is not theoretical. e.g. sysrq t does trigger NMI oopses, merely not every time, and not on every system. It is not associated with hardware failure. It is, however, tolerable because sysrq's require privilege to trigger and are primarly used when the box is dying anyway.
OK then put a touch_nmi_watchdog in there if you must.
Quoted 3 lines
(2) NMI's don't nest. There is no possibility of NMI's racing against themselves while the data is per-cpu.
Your point was that touch_nmi_watchdog() which resets alert_counter, is racy when resetting the counter of other CPUs. Yes it is racy. It is also racy against the NMI on the _current_ CPU.
This has nothing whatsoever to do with NMIs racing against themselves, I don't know how you got that idea when you were the one to bring up this race anyway.
[ snip back-and-forth that is going nowhere ]
I'll bow out of the argument here. I grant you raise valid concens WRT the /proc issues, of course.
touch_nmi_watchdog (was: page fault scalability patch V11 [0/7]: overview)
Quoted 7 lines · Nick Piggin
Quoted 3 lines
(2) NMI's don't nest. There is no possibility of NMI's racing against themselves while the data is per-cpu.
Your point was that
touch_nmi_watchdog()which resetsalert_counter, is racy when resetting the counter of other CPUs. Yes it is racy. It is also racy against the NMI on the _current_ CPU.
Hmm no I think you're right in that it is only a problem WRT the remote CPUs. However that would still be a problem, as the comment in i386 touch_nmi_watchdog attests.
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 10 lines · Nick Piggin
Quoted 6 lines · William Lee Irwin III
No, it's on-topic.
(1) The issue is not theoretical. e.g. sysrq t does trigger NMI oopses, merely not every time, and not on every system. It is not associated with hardware failure. It is, however, tolerable because sysrq's require privilege to trigger and are primarly used when the box is dying anyway.
Quoted 2 lines
OK then put a
touch_nmi_watchdogin there if you must.
Duh, there is one in there :\
Still, that doesn't really say much about a normal tasklist traversal because this thing will spend ages writing stuff to serial console.
Now I know going over the whole tasklist is crap. Anything O(n) for things like this is crap. I happen to just get frustrated to see concessions being made to support more efficient /proc access. I know you are one of the ones who has to deal with the practical realities of that though. Sigh. Well try to bear with me... :|
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 10 lines · Andrew Morton
Quoted 10 lines
Given that we have contention problems updating a single mm-wide rss and given that the way to fix that up is to spread things out a bit, it seems wildly arbitrary to me that the way in which we choose to spread the counter out is to stick a bit of it into each
task_struct. I'd expect that just shoving a pointer intomm_structwhich points at a dynamically allocated array[NR_CPUS] of longs would suffice. We probably don't even need to spread them out on cachelines - having four or eight cpus sharing the same cacheline probably isn't going to hurt much. At least, that'd be my first attempt. If it's still not good enough, try something else.
Quoted 7 lines · Nick Piggin
That is what Bill thought too. I guess per-cpu and per-thread rss are the leading candidates.
Per thread rss has the benefits of cacheline exclusivity, and not causing task bloat in the common case.
Per CPU array has better worst case /proc properties, but shares cachelines (or not, if usingpercpu_counteras you suggested). I think I'd better leave it to others to finish off the arguments ;)
(1) The "task bloat" is more than tolerable on the systems capable of having enough cpus to see significant per-process memory footprint, where "significant" is smaller than a pagetable page even for systems twice as large as now shipped.
(2) The cacheline exclusivity is not entirely gone in dense per-cpu arrays, it's merely "approximated" by sharing amongst small groups of adjacent cpus. This is fine for e.g. NUMA because those small groups of adjacent cpus will typically be on nearby nodes.
(3) The price paid to get "perfect exclusivity" instead of "approximate exclusivity" is unbounded tasklist_lock hold time, which takes boxen down outright in every known instance.
The properties are not for /proc/, they are for tasklist_lock. Every read stops all other writes. When you hold tasklist_lock for an extended period of time for read or write, (e.g. exhaustive tasklist search) you stop all fork()'s and exit()'s and execve()'s on a running system. The "worst case" analysis has nothing to do with speed. It has everything to do with taking a box down outright, much like unplugging power cables or dereferencing NULL. Unbounded tasklist_lock hold time kills running boxen dead.
Read sides of rwlocks are not licenses to spin for aeons with locks held.
And the "question" of sufficiency has in fact already been answered. SGI's own testing during the 2.4 out-of-tree patching cycle determined that an mm-global atomic counter was already sufficient so long as the cacheline was not shared with ->mmap_sem and the like. The "simplest" optimization of moving the field out of the way of ->mmap_sem already worked. The grander ones, if and *ONLY* if they don't have showstoppers like unbounded tasklist_lock hold time or castrating workload monitoring to unusability, will merely be more robust for future systems. Reiterating, this is all just fine so long as they don't cause any showstopping problems, like castrating the ability to monitor processes, or introducing more tasklist_lock starvation.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 1 line · Nick Piggin
Quoted 1 line
OK then put a
touch_nmi_watchdogin there if you must.
Quoted 8 lines · Nick Piggin
Duh, there is one in there :\
Still, that doesn't really say much about a normal tasklist traversal because this thing will spend ages writing stuff to serial console. Now I know going over the whole tasklist is crap. Anything O(n) for things like this is crap. I happen to just get frustrated to see concessions being made to support more efficient /proc access. I know you are one of the ones who has to deal with the practical realities of that though. Sigh. Well try to bear with me... :|
I sure as Hell don't have any interest in /proc/ in and of itself, but this stuff does really bite people, and hard, too.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
In reply to Nick PigginQuoted 15 lines
Quoted 5 lines
Given that we have contention problems updating a single mm-wide rss and given that the way to fix that up is to spread things out a bit, it seems wildly arbitrary to me that the way in which we choose to spread the counter out is to stick a bit of it into each
task_struct.Quoted 9 lines
I'd expect that just shoving a pointer into
mm_structwhich points at a dynamically allocated array[NR_CPUS] of longs would suffice. We probably don't even need to spread them out on cachelines - having four or eight cpus sharing the same cacheline probably isn't going to hurt much.At least, that'd be my first attempt. If it's still not good enough, try something else.
Quoted 8 lines
That is what Bill thought too. I guess per-cpu and per-thread rss are the leading candidates.
Per thread rss has the benefits of cacheline exclusivity, and not causing task bloat in the common case.
Per CPU array has better worst case /proc properties, but shares cachelines (or not, if using
percpu_counteras you suggested).
Per thread seems much nicer to me - mainly because it degrades cleanly to a single counter for 99% of processes, which are single threaded.
M.
Re: page fault scalability patch V11 [0/7]: overview
Quoted 3 lines · Martin J. Bligh
Per thread seems much nicer to me - mainly because it degrades cleanly to a single counter for 99% of processes, which are single threaded.
I will pretty much guarantee that if you put the per-thread patches next to some abomination with per-cpu allocation for each mm, the choice will be clear. Especially if the per-cpu/per-mm thing tries to avoid false cacheline sharing, which sounds really "interesting" in itself.
And without the cacheline sharing avoidance, what's the point of this again? It sure wasn't to make the code simpler. It was about performance and scalability.
Linus
Re: page fault scalability patch V11 [0/7]: overview
Quoted 7 lines · Linus Torvalds
I will pretty much guarantee that if you put the per-thread patches next to some abomination with per-cpu allocation for each mm, the choice will be clear. Especially if the per-cpu/per-mm thing tries to avoid false cacheline sharing, which sounds really "interesting" in itself. And without the cacheline sharing avoidance, what's the point of this again? It sure wasn't to make the code simpler. It was about performance and scalability.
"The perfect is the enemy of the good."
The "perfect" cacheline separation achieved that way is at the cost of destabilizing the kernel. The dense per-cpu business is only really a concession to the notion that the counter needs to be split up at all, which has never been demonstrated with performance measurements. In fact, Robin Holt has performance measurements demonstrating the opposite.
The "good" alternatives are negligibly different wrt. performance, and don't carry the high cost of rwlock starvation that breaks boxen.
-- wli
Re: page fault scalability patch V11 [0/7]: overview
Quoted 2 lines · William Lee Irwin III
"The perfect is the enemy of the good."
Yes. But in this case, my suggestion _is_ the good. You seem to be pushing for a really horrid thing which allocates a per-cpu array for each mm_struct.
What is it that you have against the per-thread rss? We already have several places that do the thread-looping, so it's not like "you can't do that" is a valid argument.
Linus
Re: page fault scalability patch V11 [0/7]: overview
Quoted 1 line · William Lee Irwin III
Quoted 1 line
"The perfect is the enemy of the good."
Quoted 6 lines · Linus Torvalds
Yes. But in this case, my suggestion _is_ the good. You seem to be pushing for a really horrid thing which allocates a per-cpu array for each
mm_struct.
What is it that you have against the per-thread rss? We already have several places that do the thread-looping, so it's not like "you can't do that" is a valid argument.
Okay, first thread groups can share mm's, so it's worse than iterating over a thread group. Second, the long loops under tasklist_lock didn't stop causing rwlock starvation because what patches there were to do something about them didn't get merged.
I'm not particularly "stuck on" the per-cpu business, it was merely the most obvious method of splitting the RSS counter without catastrophes elsewhere. Robin Holt's 2.4 performance studies actually show that splitting the counter is not even essential.
-- wli
[OT] Re: page fault scalability patch V11 [0/7]: overview
In reply to William Lee Irwin IIIQuoted 1 line · William Lee Irwin III
"The perfect is the enemy of the good."
"With the proper course of action made so explicit, we had merely to choose between wisdom and folly. Precisely how we chose folly in this instance is not entirely clear."
Quote taken from Andrew Suffield on irc, who said he got it from Penny Arcade.
Re: page fault scalability patch V11 [1/7]: sloppy rss
In reply to Christoph LameterQuoted 6 lines · Christoph Lameter
Quoted 2 lines · Hugh Dickins
Sorry, against what tree do these patches apply? Apparently not linux-2.6.9, nor latest -bk, nor -mm?
2.6.10-rc2-bk3
Ah, thanks - got it patched now, but your mailer (or something else) is eating trailing spaces. Better than adding them, but we have to apply this patch before your set:
include/asm-i386/system.h +2 -2
@@ -273,9 +273,9 @@ static inline unsigned long __cmpxchg(vo#define cmpxchg (ptr,o,n)\ ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\ (unsigned long)(n),sizeof(*(ptr)))) - + #ifdef __KERNEL__ -struct alt_instr { +struct alt_instr { __u8 *instr; /* original instruction */ __u8 *replacement; __u8 cpuid; /* cpuid bit set for replacement */
include/asm-s390/pgalloc.h +1 -1
@@ -99,7 +99,7 @@ static inline void pgd_populate(struct m#endif /* __s390x__ */ -static inline void +static inline void pmd_populate_kernel (struct mm_struct *mm,pmd_t *pmd,pte_t *pte) {#ifndef __s390x__
mm/memory.c +2 -2
@@ -1424,7 +1424,7 @@ out:/* * We are called with the MM semaphore and page_table_lock * spinlock held to protect against concurrent faults in -* multithreaded programs. +* multithreaded programs. */ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
@@ -1615,7 +1615,7 @@ static int do_file_page(struct mm_struct* Fall back to the linear mapping if the fs does not support * ->populate: */ -if (!vma->vm_ops || !vma->vm_ops->populate || +if (!vma->vm_ops || !vma->vm_ops->populate || (write_access && !(vma->vm_flags &VM_SHARED ))) {pte_clear (pte);return do_no_page (mm, vma, address, write_access, pte, pmd);
Re: page fault scalability patch V11 [0/7]: overview
In reply to William Lee Irwin IIIQuoted 4 lines · William Lee Irwin III
I'm not particularly "stuck on" the per-cpu business, it was merely the most obvious method of splitting the RSS counter without catastrophes elsewhere. Robin Holt's 2.4 performance studies actually show that splitting the counter is not even essential.
There is no problem moving back to the atomic approach that is if it is okay to also make anon_rss atomic. But its a pretty significant performance hit (comparison with some old data from V4 of patch which makes this data a bit suspect since the test environment is likely slightly different. I should really test this again. Note that the old performance test was only run 3 times instead of 10):
atomic vs. sloppy rss performance 64G allocation:
sloppy rss:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
16 10 1 1.818s 131.556s 133.038s 78618.592 78615.672 16 10 2 1.736s 121.167s 65.026s 85317.098 160656.362 16 10 4 1.835s 120.444s 36.002s 85751.810 291074.998 16 10 8 1.820s 131.068s 25.049s 78906.310 411304.895 16 10 16 3.275s 194.971s 22.019s 52892.356 472497.962 16 10 32 13.006s 496.628s 27.044s 20575.038 381999.865
atomic:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
16 3 1 0.610s 61.557s 62.016s 50600.438 50599.822 16 3 2 0.640s 83.116s 43.016s 37557.847 72869.978 16 3 4 0.621s 73.897s 26.023s 42214.002 119908.246 16 3 8 0.596s 86.587s 14.098s 36081.229 209962.059 16 3 16 0.646s 69.601s 7.000s 44780.269 448823.690 16 3 32 0.903s 185.609s 8.085s 16866.018 355301.694
Lets go for the approach to move rss into the thread structure but keep the rss in the mm structure as is (need to take page_table_lock for update) to consolidate the values. This allows to keep most of the code as is and the rss in the task struct is only used if we are not holding page_table_lock.
Maybe we can then find some way to regularly update the rss in the mm structure to avoid the loop over the tasklist in proc.
Re: page fault scalability patch V11 [0/7]: overview
In reply to Linus TorvaldsQuoted 8 lines · Linus Torvalds
Quoted 3 lines · Nick Piggin
The per thread rss may wrap (maybe not 64-bit counters), but even so, the summation over all threads should still end up being correct I think.
Quoted 7 lines
Yes. As long as the total rss fits in an int, it doesn't matter if any of them wrap. Addition is still associative in twos-complement arithmetic even in the presense of overflows.
If you actually want to make it proper standard C, I guess you'd have to make the thing unsigned, which gives you the mod-2**n guarantees even if somebody were to ever make a non-twos-complement machine.
I think other stuff breaks as well, I think I saw you post some example code using something like (a & -a) or similar within the last few months. Fortunately neither 1's comp or BCD are likeliy to return in hardware. Big-end vs. little-end is still an issue, though.
Signature · 3 lines
-bill davidsen ([email protected]) "The secret to procrastination is to put things off until the last possible moment - but no longer" -me
deferred rss update instead of sloppy rss
In reply to Hugh DickinsOne way to solve the rss issues is--as discussed--to put rss into the task structure and then have the page fault increment that rss.
The problem is then that the proc filesystem must do an extensive scan over all threads to find users of a certain mm_struct.
The following patch does put the rss into task_struct. The page fault handler is then incrementing current->rss if the page_table_lock is not held.
The timer interrupt checks if task->rss is non zero (when doing stime/utime updates. rss is defined near those so its hopefully on the same cacheline and has a minimal impact).
If rss is non zero and the page_table_lock and the mmap_sem can be taken then the mm->rss will be updated by the value of the task->rss and task->rss will be zeroed. This avoids all proc issues. The only disadvantage is that rss may be inaccurate for a couple of clock ticks.
This also adds some performance (sorry only a 4p system):
sloppy rss:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec 4 10 1 0.593s 29.897s 30.050s 85973.585 85948.565 4 10 2 0.616s 42.184s 22.045s 61247.450 116719.558 4 10 4 0.559s 44.918s 14.076s 57641.255 177553.945
deferred rss:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
4 10 1 0.565s 29.429s 30.000s 87395.518 87366.580 4 10 2 0.500s 33.514s 18.002s 77067.935 145426.659 4 10 4 0.533s 44.455s 14.085s 58269.368 176413.196
Index: linux-2.6.9/include/linux/sched.h
=================================--- linux-2.6.9.orig/include/linux/sched.h 2004-11-15 11:13:39.000000000 -0800
+++ linux-2.6.9/include/linux/sched.h 2004-11-22 13:18:58.000000000 -0800
@@ -584,6 +584,10 @@
unsigned long it_real_incr, it_prof_incr, it_virt_incr;
struct timer_list real_timer;
unsigned long utime, stime;
+ long rss; /* rss counter when mm->rss is not usable. mm->page_table_lock
+ * not held but mm->mmap_sem must be held for sync with
+ * the timer interrupt which clears rss and updates mm->rss.
+ */
unsigned long nvcsw, nivcsw; /* context switch counts */
struct timespec start_time;
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
Index: linux-2.6.9/mm/rmap.c
=================================--- linux-2.6.9.orig/mm/rmap.c 2004-11-22 09:51:58.000000000 -0800
+++ linux-2.6.9/mm/rmap.c 2004-11-22 11:16:02.000000000 -0800
@@ -263,8 +263,6 @@
pte_t *pte;
int referenced = 0;
- if (!mm->rss)
- goto out;
address = vma_address(page, vma);
if (address = -EFAULT)
goto out;
@@ -507,8 +505,6 @@
pte_t pteval;
int ret = SWAP_AGAIN;
- if (!mm->rss)
- goto out;
address = vma_address(page, vma);
if (address = -EFAULT)
goto out;
@@ -791,8 +787,7 @@
if (vma->vm_flags & (VM_LOCKED|VM_RESERVED))
continue;
cursor = (unsigned long) vma->vm_private_data;
- while (vma->vm_mm->rss &&
- cursor < max_nl_cursor &&
+ while (cursor < max_nl_cursor &&
cursor < vma->vm_end - vma->vm_start) { try_to_unmap_cluster(cursor, &mapcount, vma); cursor += CLUSTER_SIZE;
Index: linux-2.6.9/kernel/fork.c
=================================--- linux-2.6.9.orig/kernel/fork.c 2004-11-22 09:51:58.000000000 -0800
+++ linux-2.6.9/kernel/fork.c 2004-11-22 11:16:02.000000000 -0800
@@ -876,6 +876,7 @@
p->io_context = NULL;
p->io_wait = NULL;
p->audit_context = NULL;
+ p->rss = 0;
#ifdef CONFIG_NUMA
p->mempolicy = mpol_copy(p->mempolicy);
if (IS_ERR(p->mempolicy)) {
Index: linux-2.6.9/kernel/exit.c
=================================--- linux-2.6.9.orig/kernel/exit.c 2004-11-22 09:51:58.000000000 -0800
+++ linux-2.6.9/kernel/exit.c 2004-11-22 11:16:02.000000000 -0800
@@ -501,6 +501,9 @@
/* more a memory barrier than a real lock */ task_lock(tsk);
tsk->mm = NULL;
+ /* only holding mmap_sem here maybe get page_table_lock too? */
+ mm->rss += tsk->rss;
+ tsk->rss = 0;
up_read(&mm->mmap_sem);
enter_lazy_tlb(mm, current);
task_unlock(tsk);
Index: linux-2.6.9/kernel/timer.c
=================================--- linux-2.6.9.orig/kernel/timer.c 2004-11-22 09:51:58.000000000 -0800
+++ linux-2.6.9/kernel/timer.c 2004-11-22 11:42:12.000000000 -0800
@@ -815,6 +815,15 @@
if (psecs / HZ >= p->signal->rlim[RLIMIT_CPU].rlim_max)
send_sig(SIGKILL, p, 1);
}
+ /* Update mm->rss if necessary */
+ if (p->rss && p->mm && down_write_trylock(&p->mm->mmap_sem)) {
+ if (spin_trylock(&p->mm->page_table_lock)) {
+ p->mm->rss += p->rss;
+ p->rss = 0;
+ spin_unlock(&p->mm->page_table_lock);
+ }
+ up_write(&p->mm->mmap_sem);
+ }
}
static inline void do_it_virt(struct task_struct * p, unsigned long ticks)
Re: deferred rss update instead of sloppy rss
Quoted 29 lines · Christoph Lameter
One way to solve the rss issues is--as discussed--to put rss into the task structure and then have the page fault increment that rss.
The problem is then that the proc filesystem must do an extensive scan over all threads to find users of a certain
mm_struct.The following patch does put the rss into
task_struct. The page fault handler is then incrementingcurrent->rssif thepage_table_lockis not held.The timer interrupt checks if
task->rssis non zero (when doing stime/utime updates. rss is defined near those so its hopefully on the same cacheline and has a minimal impact).If rss is non zero and the
page_table_lockand themmap_semcan be taken then themm->rsswill be updated by the value of thetask->rssandtask->rsswill be zeroed. This avoids all proc issues. The only disadvantage is that rss may be inaccurate for a couple of clock ticks.This also adds some performance (sorry only a 4p system):
sloppy rss:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec 4 10 1 0.593s 29.897s 30.050s 85973.585 85948.565 4 10 2 0.616s 42.184s 22.045s 61247.450 116719.558 4 10 4 0.559s 44.918s 14.076s 57641.255 177553.945
Quoted 5 lines
deferred rss:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec4 10 1 0.565s 29.429s 30.000s 87395.518 87366.580 4 10 2 0.500s 33.514s 18.002s 77067.935 145426.659 4 10 4 0.533s 44.455s 14.085s 58269.368 176413.196
hrm. I cannot see anywhere in this patch where you update task_struct.rss.
Review line 507
Quoted 11 lines
Index:
linux-2.6.9/kernel/exit.c
=================================> ---linux-2.6.9.orig/kernel/exit.c2004-11-22 09:51:58.000000000 -0800
+++linux-2.6.9/kernel/exit.c2004-11-22 11:16:02.000000000 -0800(quoted diff) +3
-0@@ -501,6 +501,9 @@ /* more a memory barrier than a real lock */ task_lock(tsk); tsk->mm = NULL; + /* only holding mmap_sem here maybe get page_table_lock too? */ + mm->rss += tsk->rss; + tsk->rss = 0; up_read(&mm->mmap_sem);
mmap_sem needs to be held for writing, surely?
Review
Quoted 10 lines
(quoted diff) +9
-0+ /* Update mm->rss if necessary */ + if (p->rss && p->mm && down_write_trylock(&p->mm->mmap_sem)) { + if (spin_trylock(&p->mm->page_table_lock)) { + p->mm->rss += p->rss; + p->rss = 0; + spin_unlock(&p->mm->page_table_lock); + } + up_write(&p->mm->mmap_sem); + } }
I'd also suggest that you do:
tsk->rss++;
if (tsk->rss > 16) {
spin_lock(&mm->page_table_lock);
mm->rss += tsk->rss;
spin_unlock(&mm->page_table_lock);
tsk->rss = 0;
}just to prevent transient gross inaccuracies. For some value of "16".
Re: deferred rss update instead of sloppy rss
Quoted 1 line · Andrew Morton
hrm. I cannot see anywhere in this patch where you update task_struct.rss.
This is just the piece around it dealing with rss. The updating of rss happens in the generic code. The change to that is trivial. I can repost the whole shebang if you want.
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ /* only holding mmap_sem here maybe get page_table_lock too? */ + mm->rss += tsk->rss; + tsk->rss = 0; up_read(&mm->mmap_sem);
mmap_semneeds to be held for writing, surely?
If there are no page faults occurring anymore then we would not need to get the lock. Q: Is it safe to assume that no faults occur anymore at this point?
Quoted 1 line
just to prevent transient gross inaccuracies. For some value of "16".
The page fault code only increments rss. For larger transactions that increase / decrease rss significantly the page_table_lock is taken and mm->rss is updated directly. So no
gross inaccuracies can result.
Re: deferred rss update instead of sloppy rss
Quoted 15 lines · Christoph Lameter
Quoted 1 line · Andrew Morton
hrm. I cannot see anywhere in this patch where you update task_struct.rss.
This is just the piece around it dealing with rss. The updating of rss happens in the generic code. The change to that is trivial. I can repost the whole shebang if you want.
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ /* only holding mmap_sem here maybe get page_table_lock too? */ + mm->rss += tsk->rss; + tsk->rss = 0; up_read(&mm->mmap_sem);
mmap_semneeds to be held for writing, surely?
Quoted 3 lines
If there are no page faults occurring anymore then we would not need to get the lock. Q: Is it safe to assume that no faults occur anymore at this point?
Why wouldn't the mm take faults on other CPUs ? (other threads)
Quoted 11 lines
Quoted 1 line
just to prevent transient gross inaccuracies. For some value of "16".
The page fault code only increments rss. For larger transactions that increase / decrease rss significantly the
page_table_lockis taken andmm->rssis updated directly. So no
gross inaccuracies can result.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 1 line
Benjamin Herrenschmidt <[email protected]>
Re: deferred rss update instead of sloppy rss
In reply to Christoph LameterQuoted 3 lines · Christoph Lameter
The problem is then that the proc filesystem must do an extensive scan over all threads to find users of a certain
mm_struct.
The alternative is to just add a simple list into the task_struct and the head of it into mm_struct. Then, at fork, you just finish the fork() with
list_add(p->mm_list, p->mm->thread_list);
and do the proper list_del() in exit_mm() or wherever.
You'll still loop in /proc, but you'll do the minimal loop necessary.
Linus
Re: deferred rss update instead of sloppy rss
Quoted 8 lines · Linus Torvalds
The alternative is to just add a simple list into the
task_structand the head of it intomm_struct. Then, at fork, you just finish thefork()withlist_add(p->mm_list, p->mm->thread_list);and do the proper
list_del()inexit_mm()or wherever.You'll still loop in /proc, but you'll do the minimal loop necessary.
I think the approach that I posted is simpler unless there are other benefits to be gained if it would be easy to figure out which tasks use an mm.
Re: deferred rss update instead of sloppy rss
In reply to Linus TorvaldsQuoted 7 lines · Linus Torvalds
Quoted 2 lines · Christoph Lameter
The problem is then that the proc filesystem must do an extensive scan over all threads to find users of a certain
mm_struct.
Quoted 9 lines
The alternative is to just add a simple list into the
task_structand the head of it intomm_struct. Then, at fork, you just finish thefork()withlist_add(p->mm_list, p->mm->thread_list);and do the proper
list_del()inexit_mm()or wherever.You'll still loop in /proc, but you'll do the minimal loop necessary.
Yes, that was what I was thinking we'd have to resort to. Not a bad idea.
It would be nice if you could have it integrated with the locking that is already there - for example mmap_sem, although that might mean you'd have to take mmap_sem for writing which may limit scalability of thread creation / destruction... maybe a seperate lock / semaphore for that list itself would be OK.
Deferred rss might be a practical solution, but I'd prefer this if it can be made workable.
Re: deferred rss update instead of sloppy rss
Quoted 2 lines · Nick Piggin
Deferred rss might be a practical solution, but I'd prefer this if it can be made workable.
Both results in an additional field in task_struct that is going to be incremented when the page_table_lock is not held. It would be possible to switch to looping in procfs later. The main question with this patchset is:
How and when can we get this get into the kernel?
Re: deferred rss update instead of sloppy rss
In reply to Christoph LameterQuoted 4 lines · Christoph Lameter
I think the approach that I posted is simpler unless there are other benefits to be gained if it would be easy to figure out which tasks use an mm.
I'm just worried that your timer tick thing won't catch things in a timely manner. That said, if that isn't an issue, and people don't have problems with it. On the other hand, if /proc literally is the only real user, then I guess it really can't matter.
Linus
Re: page fault scalability patch V11 [0/7]: overview
In reply to Christoph LameterQuoted 4 lines · William Lee Irwin III
Quoted 4 lines
I'm not particularly "stuck on" the per-cpu business, it was merely the most obvious method of splitting the RSS counter without catastrophes elsewhere. Robin Holt's 2.4 performance studies actually show that splitting the counter is not even essential.
Quoted 7 lines · Christoph Lameter
There is no problem moving back to the atomic approach that is if it is okay to also make
anon_rssatomic. But its a pretty significant performance hit (comparison with some old data from V4 of patch which makes this data a bit suspect since the test environment is likely slightly different. I should really test this again. Note that the old performance test was only run 3 times instead of 10):
atomic vs. sloppy rss performance 64G allocation:
The specific patches you compared matter a great deal as there are implementation blunders (e.g. poor placement of counters relative to ->mmap_sem) that can ruin the results. URL's to the specific patches would rule out that source of error.
-- wli
Re: deferred rss update instead of sloppy rss
In reply to Christoph LameterQuoted 7 lines · Christoph Lameter
Quoted 2 lines
just to prevent transient gross inaccuracies. For some value of "16".
The page fault code only increments rss. For larger transactions that increase / decrease rss significantly the
page_table_lockis taken andmm->rssis updated directly. So no
gross inaccuracies can result.
Sure. Take a million successive pagefaults and mm->rss is grossly inaccurate. Hence my suggestion that it be spilled into mm->rss periodically.
Re: deferred rss update instead of sloppy rss
Quoted 8 lines · Andrew Morton
Quoted 4 lines
The page fault code only increments rss. For larger transactions that increase / decrease rss significantly the
page_table_lockis taken andmm->rssis updated directly. So no
gross inaccuracies can result.Sure. Take a million successive pagefaults and
mm->rssis grossly inaccurate. Hence my suggestion that it be spilled intomm->rssperiodically.
It is spilled into mm->rss periodically. That is the whole point of the patch.
The timer tick occurs every 1 ms. The maximum pagefault frequency that I have seen is 500000 faults /second. The max deviation is therefore less than 500 (could be greater if page table lock / mmap_sem always held when the tick occurs).
Re: page fault scalability patch V11 [0/7]: overview
In reply to William Lee Irwin IIIQuoted 4 lines · William Lee Irwin III
The specific patches you compared matter a great deal as there are implementation blunders (e.g. poor placement of counters relative to ->mmap_sem) that can ruin the results. URL's to the specific patches would rule out that source of error.
I mentioned V4 of this patch which was posted to lkml. A simple search should get you there.
Re: deferred rss update instead of sloppy rss
In reply to Christoph LameterQuoted 13 lines · Christoph Lameter
Quoted 8 lines · Andrew Morton
Quoted 4 lines
The page fault code only increments rss. For larger transactions that increase / decrease rss significantly the
page_table_lockis taken andmm->rssis updated directly. So no
gross inaccuracies can result.Sure. Take a million successive pagefaults and
mm->rssis grossly inaccurate. Hence my suggestion that it be spilled intomm->rssperiodically.
Quoted 7 lines
It is spilled into
mm->rssperiodically. That is the whole point of the patch.The timer tick occurs every 1 ms. The maximum pagefault frequency that I have seen is 500000 faults /second. The max deviation is therefore less than 500 (could be greater if page table lock /
mmap_semalways held when the tick occurs).
You could imagine a situation where something pagefaults and sleeps in lock-step with the timer though. Theoretical problem only?
I think that by the time you get the spilling code in, the mm-list method will be looking positively elegant!
Re: deferred rss update instead of sloppy rss
Quoted 6 lines · Nick Piggin
Quoted 4 lines
The timer tick occurs every 1 ms. The maximum pagefault frequency that I have seen is 500000 faults /second. The max deviation is therefore less than 500 (could be greater if page table lock /
mmap_semalways held when the tick occurs).I think that by the time you get the spilling code in, the mm-list method will be looking positively elegant!
I do not care what gets in as long as something goes in to address the performance issues. So far everyone seems to have their pet ideas. By all means do the mm-list method and post it. But we have already seen objections by other against loops in proc. So that will also cause additional controversy.
Re: deferred rss update instead of sloppy rss
In reply to Christoph LameterQuoted 12 lines · Christoph Lameter
Quoted 2 lines · Nick Piggin
Deferred rss might be a practical solution, but I'd prefer this if it can be made workable.
Both results in an additional field in
task_structthat is going to be incremented when thepage_table_lockis not held. It would be possible to switch to looping in procfs later. The main question with this patchset is:
Sure.
Quoted 2 lines
How and when can we get this get into the kernel?
Well it is a good starting platform for the various PTL reduction patches floating around.
I'd say Andrew could be convinced to stick it in -mm after 2.6.10, but we'd probably need a clear path to one of the PTL patches before anything would move into 2.6.
Re: deferred rss update instead of sloppy rss
In reply to Christoph LameterQuoted 8 lines · Christoph Lameter
Quoted 5 lines · Andrew Morton
Quoted 4 lines
The page fault code only increments rss. For larger transactions that increase / decrease rss significantly the
page_table_lockis taken andmm->rssis updated directly. So no
gross inaccuracies can result.
Quoted 8 lines
Quoted 3 lines
Sure. Take a million successive pagefaults and
mm->rssis grossly inaccurate. Hence my suggestion that it be spilled intomm->rssperiodically.It is spilled into
mm->rssperiodically. That is the whole point of the patch.The timer tick occurs every 1 ms.
That only works if the task happens to have the CPU when the timer tick occurs. There remains no theoretical upper bound to the error in mm->rss, and that's very easy to fix.
Re: deferred rss update instead of sloppy rss
Quoted 5 lines · Andrew Morton
Quoted 1 line
The timer tick occurs every 1 ms.
That only works if the task happens to have the CPU when the timer tick occurs. There remains no theoretical upper bound to the error in
mm->rss, and that's very easy to fix.
Page fault intensive programs typically hog the cpu. But you are in principle right.
The "easy fix" that you propose is to add additional logic to some very hot code paths. Then we are probably better off with another approach.
Re: page fault scalability patch V11 [0/7]: overview
In reply to Christoph LameterQuoted 4 lines · William Lee Irwin III
Quoted 4 lines
The specific patches you compared matter a great deal as there are implementation blunders (e.g. poor placement of counters relative to ->mmap_sem) that can ruin the results. URL's to the specific patches would rule out that source of error.
Quoted 2 lines · Christoph Lameter
I mentioned V4 of this patch which was posted to lkml. A simple search should get you there.
The counter's placement was poor in that version of the patch. The results are very suspect and likely invalid. It would have been more helpful if you provided some kind of unique identifier when requests for complete disambiguation are made. For instance, the version tags of your patches are not visible in Subject: lines.
There are, of course, other issues, e.g. where the arch sweeps went. This discussion has degenerated into non-cooperation making it beyond my power to help, and I'm in the midst of several rather urgent bughunts, of which there are apparently more to come.
-- wli
page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Linus TorvaldsChanges from V11->V12 of this patch:
- dump sloppy_rss in favor of list_rss (Linus' proposal)
- keep up against current Linus tree (patch is based on 2.6.10-rc2-bk14)
This is a series of patches that increases the scalability of the page fault handler for SMP. Here are some performance results on a machine with 512 processors allocating 32 GB with an increasing number of threads (that are assigned a processor each).
Without the patches:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.416s 138.165s 139.050s 45073.831 45097.498 32 3 2 1.397s 148.523s 78.044s 41965.149 80201.646 32 3 4 1.390s 152.618s 44.044s 40851.258 141545.239 32 3 8 1.500s 374.008s 53.001s 16754.519 118671.950 32 3 16 1.415s 1051.759s 73.094s 5973.803 85087.358 32 3 32 1.867s 3400.417s 117.003s 1849.186 53754.928 32 3 64 5.361s 11633.040s 197.034s 540.577 31881.112 32 3 128 23.387s 39386.390s 332.055s 159.642 18918.599 32 3 256 15.409s 20031.450s 168.095s 313.837 37237.918 32 3 512 18.720s 10338.511s 86.047s 607.446 72752.686
With the patches:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.451s 140.151s 141.060s 44430.367 44428.115 32 3 2 1.399s 136.349s 73.041s 45673.303 85699.793 32 3 4 1.321s 129.760s 39.027s 47996.303 160197.217 32 3 8 1.279s 100.648s 20.039s 61724.641 308454.557 32 3 16 1.414s 153.975s 15.090s 40488.236 395681.716 32 3 32 2.534s 337.021s 17.016s 18528.487 366445.400 32 3 64 4.271s 709.872s 18.057s 8809.787 338656.440 32 3 128 18.734s 1805.094s 21.084s 3449.586 288005.644 32 3 256 14.698s 963.787s 11.078s 6429.787 534077.540 32 3 512 15.299s 453.990s 5.098s 13406.321 1050416.414
For more than 8 cpus the page fault rate increases by orders of magnitude. For more than 64 cpus the improvement in performace is 10 times better.
The performance increase is accomplished by avoiding the use of the page_table_lock spinlock (but not mm->mmap_sem!) through new atomic operations on pte's (ptep_xchg, ptep_cmpxchg) and on pmd and pgd's (pgd_test_and_populate, pmd_test_and_populate).
The page table lock can be avoided in the following situations:
1. An empty pte or pmd entry is populated
This is safe since the swapper may only depopulate them and the swapper code has been changed to never set a pte to be empty until the page has been evicted. The population of an empty pte is frequent if a process touches newly allocated memory.
2. Modifications of flags in a pte entry (write/accessed).
These modifications are done by the CPU or by low level handlers on various platforms also bypassing the page_table_lock. So this seems to be safe too.
One essential change in the VM is the use of pte_cmpxchg (or its generic emulation) on page table entries before doing an update_mmu_change without holding the page table lock. However, we do similar things now with other atomic pte operations such as ptep_get_and_clear and ptep_test_and_clear_dirty. These operations clear a pte *after* doing an operation on it. The ptep_cmpxchg as used in this patch operates on an *cleared* pte and replaces it with a pte pointing to valid memory. The effect of this change on various architectures has to be thought through. Local definitions of ptep_cmpxchg and ptep_xchg may be necessary.
For IA64 an icache coherency issue may arise that potentially requires the flushing of the icache (as done via update_mmu_cache on IA64) prior to the use of ptep_cmpxchg. Similar issues may arise on other platforms.
The patch introduces a split counter for rss handling to avoid atomic operations and locks currently necessary for rss modifications. In addition to mm->rss, tsk->rss is introduced. tsk->rss is defined to be in the same cache line as tsk->mm (which is already used by the fault handler) and thus tsk->rss can be incremented without locks in a fast way. The cache line does not need to be shared between processors in the page table handler.
A tasklist is generated for each mm (rcu based). Values in that list are added up to calculate rss or anon_rss values.
The patchset is composed of 7 patches:
1/7: Avoid page_table_lock in handle_mm_fault
This patch defers the acquisition of the page_table_lock as much as possible and uses atomic operations for allocating anonymous memory. These atomic operations are simulated by acquiring the page_table_lock for very small time frames if an architecture does not define __HAVE_ARCH_ATOMIC_TABLE_OPS. It also changes the swapper so that a pte will not be set to empty if a page is in transition to swap.
If only the first two patches are applied then the time that the page_table_lock is held is simply reduced. The lock may then be acquired multiple times during a page fault.
2/7: Atomic pte operations for ia64
3/7: Make cmpxchg generally available on i386
The atomic operations on the page table rely heavily on cmpxchg instructions. This patch adds emulations for cmpxchg and cmpxchg8b for old 80386 and 80486 cpus. The emulations are only included if a kernel is build for these old cpus and are skipped for the real cmpxchg instructions if the kernel that is build for 386 or 486 is then run on a more recent cpu.
This patch may be used independently of the other patches.
4/7: Atomic pte operations for i386
A generally available cmpxchg (last patch) must be available for this patch to preserve the ability to build kernels for 386 and 486.
5/7: Atomic pte operation for x86_64
6/7: Atomic pte operations for s390
7/7: Split counter implementation for rss
Add tsk->rss and tsk->anon_rss. Add tasklist. Add logic to calculate rss from tasklist.
There are some additional outstanding performance enhancements that are not available yet but which require this patch. Those modifications push the maximum page fault rate from ~ 1 mio faults per second as shown above to above 3 mio faults per second.
The last editions of the sloppy rss, atomic rss and deferred rss patch will be posted to linux-ia64 for archival purpose.
page fault scalability patch V12 [1/7]: Reduce use of thepage_table_lock
Changelog
* Increase parallelism in SMP configurations by deferring the acquisition of page_table_lock in handle_mm_fault
* Anonymous memory page faults bypass the page_table_lock through the use of atomic page table operations
* Swapper does not set pte to empty in transition to swap
* Simulate atomic page table operations using the page_table_lock if an arch does not define __HAVE_ARCH_ATOMIC_TABLE_OPS. This still provides a performance benefit since the page_table_lock is held for shorter periods of time.
Index: linux-2.6.9/mm/memory.c
=================================--- linux-2.6.9.orig/mm/memory.c 2004-11-23 10:06:03.000000000 -0800
+++ linux-2.6.9/mm/memory.c 2004-11-23 10:07:55.000000000 -0800
@@ -1330,8 +1330,7 @@
}
/*
- * We hold the mm semaphore and the page_table_lock on entry and
- * should release the pagetable lock on exit..
+ * We hold the mm semaphore
*/
static int do_swap_page(struct mm_struct * mm,
struct vm_area_struct * vma, unsigned long address,
@@ -1343,15 +1342,13 @@
int ret = VM_FAULT_MINOR;
pte_unmap(page_table);
- spin_unlock(&mm->page_table_lock);
page = lookup_swap_cache(entry);
if (!page) {
swapin_readahead(entry, address, vma); page = read_swap_cache_async(entry, vma, address); if (!page) {
/*
- * Back out if somebody else faulted in this pte while
- * we released the page table lock.
+ * Back out if somebody else faulted in this pte
*/
spin_lock(&mm->page_table_lock); page_table = pte_offset_map(pmd, address);
@@ -1374,8 +1371,7 @@
lock_page(page);
/*
- * Back out if somebody else faulted in this pte while we
- * released the page table lock.
+ * Back out if somebody else faulted in this pte
*/
spin_lock(&mm->page_table_lock); page_table = pte_offset_map(pmd, address);
@@ -1422,14 +1418,12 @@
}
/*
- * We are called with the MM semaphore and page_table_lock
- * spinlock held to protect against concurrent faults in
- * multithreaded programs.
+ * We are called with the MM semaphore held.
*/
static int
do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
pte_t *page_table, pmd_t *pmd, int write_access,
- unsigned long addr)
+ unsigned long addr, pte_t orig_entry)
{
pte_t entry;
struct page * page = ZERO_PAGE(addr);
@@ -1441,7 +1435,6 @@
if (write_access) {
/* Allocate our own private page. */ pte_unmap(page_table);
- spin_unlock(&mm->page_table_lock);
if (unlikely(anon_vma_prepare(vma)))
goto no_mem;
@@ -1450,30 +1443,37 @@
goto no_mem;
clear_user_highpage(page, addr);
- spin_lock(&mm->page_table_lock);
page_table = pte_offset_map(pmd, addr);
- if (!pte_none(*page_table)) {
- pte_unmap(page_table);
- page_cache_release(page);
- spin_unlock(&mm->page_table_lock);
- goto out;
- }
- mm->rss++;
entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
vma->vm_page_prot)),
vma);
- lru_cache_add_active(page);
mark_page_accessed(page);
- page_add_anon_rmap(page, vma, addr);
}
- set_pte(page_table, entry);
+ /* update the entry */
+ if (!ptep_cmpxchg(vma, addr, page_table, orig_entry, entry)) {
+ if (write_access) {
+ pte_unmap(page_table);
+ page_cache_release(page);
+ }
+ goto out;
+ }
+ if (write_access) {
+ /*
+ * These two functions must come after the cmpxchg
+ * because if the page is on the LRU then try_to_unmap may come
+ * in and unmap the pte.
+ */
+ lru_cache_add_active(page);
+ page_add_anon_rmap(page, vma, addr);
+ mm->rss++;
+
+ }
pte_unmap(page_table);
/* No need to invalidate - it was non-present before */ update_mmu_cache(vma, addr, entry);
- spin_unlock(&mm->page_table_lock);
out:
return VM_FAULT_MINOR;
no_mem:
@@ -1489,12 +1489,12 @@
* As this is called only for pages that do not currently exist, we
* do not need to flush old virtual caches or the TLB.
*
- * This is called with the MM semaphore held and the page table
- * spinlock held. Exit with the spinlock released.
+ * This is called with the MM semaphore held.
*/
static int
do_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
- unsigned long address, int write_access, pte_t *page_table, pmd_t *pmd)
+ unsigned long address, int write_access, pte_t *page_table,
+ pmd_t *pmd, pte_t orig_entry)
{
struct page * new_page;
struct address_space *mapping = NULL;
@@ -1505,9 +1505,8 @@
if (!vma->vm_ops || !vma->vm_ops->nopage)
return do_anonymous_page(mm, vma, page_table,
- pmd, write_access, address);
+ pmd, write_access, address, orig_entry);
pte_unmap(page_table);
- spin_unlock(&mm->page_table_lock);
if (vma->vm_file) {
mapping = vma->vm_file->f_mapping;
@@ -1605,7 +1604,7 @@
* nonlinear vmas.
*/
static int do_file_page(struct mm_struct * mm, struct vm_area_struct * vma,
- unsigned long address, int write_access, pte_t *pte, pmd_t *pmd)
+ unsigned long address, int write_access, pte_t *pte, pmd_t *pmd, pte_t entry)
{
unsigned long pgoff;
int err;
@@ -1618,13 +1617,12 @@
if (!vma->vm_ops || !vma->vm_ops->populate ||
(write_access && !(vma->vm_flags & VM_SHARED))) {
pte_clear(pte);
- return do_no_page(mm, vma, address, write_access, pte, pmd);
+ return do_no_page(mm, vma, address, write_access, pte, pmd, entry);
}
pgoff = pte_to_pgoff(*pte);
pte_unmap(pte);
- spin_unlock(&mm->page_table_lock);
err = vma->vm_ops->populate(vma, address & PAGE_MASK, PAGE_SIZE, vma->vm_page_prot, pgoff, 0); if (err = -ENOMEM)
@@ -1643,49 +1641,40 @@
* with external mmu caches can use to update those (ie the Sparc or
* PowerPC hashed page tables that act as extended TLBs).
*
- * Note the "page_table_lock". It is to protect against kswapd removing
- * pages from under us. Note that kswapd only ever _removes_ pages, never
- * adds them. As such, once we have noticed that the page is not present,
- * we can drop the lock early.
- *
- * The adding of pages is protected by the MM semaphore (which we hold),
- * so we don't need to worry about a page being suddenly been added into
- * our VM.
- *
- * We enter with the pagetable spinlock held, we are supposed to
- * release it when done.
+ * Note that kswapd only ever _removes_ pages, never adds them.
+ * We need to insure to handle that case properly.
*/
static inline int handle_pte_fault(struct mm_struct *mm,
struct vm_area_struct * vma, unsigned long address,
int write_access, pte_t *pte, pmd_t *pmd)
{
pte_t entry;
+ pte_t new_entry;
entry = *pte;
if (!pte_present(entry)) {
- /*
- * If it truly wasn't present, we know that kswapd
- * and the PTE updates will not touch it later. So
- * drop the lock.
- */
if (pte_none(entry))
- return do_no_page(mm, vma, address, write_access, pte, pmd);
+ return do_no_page(mm, vma, address, write_access, pte, pmd, entry);
if (pte_file(entry))
- return do_file_page(mm, vma, address, write_access, pte, pmd);
+ return do_file_page(mm, vma, address, write_access, pte, pmd, entry);
return do_swap_page(mm, vma, address, pte, pmd, entry, write_access);
}
+ /*
+ * This is the case in which we only update some bits in the pte.
+ */
+ new_entry = pte_mkyoung(entry);
if (write_access) {
- if (!pte_write(entry))
+ if (!pte_write(entry)) {
+ /* do_wp_page expects us to hold the page_table_lock */
+ spin_lock(&mm->page_table_lock);
return do_wp_page(mm, vma, address, pte, pmd, entry);
-
- entry = pte_mkdirty(entry);
+ }
+ new_entry = pte_mkdirty(new_entry);
}
- entry = pte_mkyoung(entry);
- ptep_set_access_flags(vma, address, pte, entry, write_access);
- update_mmu_cache(vma, address, entry);
+ if (ptep_cmpxchg(vma, address, pte, entry, new_entry))
+ update_mmu_cache(vma, address, new_entry);
pte_unmap(pte);
- spin_unlock(&mm->page_table_lock);
return VM_FAULT_MINOR;
}
@@ -1703,22 +1692,45 @@
inc_page_state(pgfault);
- if (is_vm_hugetlb_page(vma))
+ if (unlikely(is_vm_hugetlb_page(vma)))
return VM_FAULT_SIGBUS; /* mapping truncation does this. */
/*
- * We need the page table lock to synchronize with kswapd
- * and the SMP-safe atomic PTE updates.
+ * We rely on the mmap_sem and the SMP-safe atomic PTE updates.
+ * to synchronize with kswapd
*/
- spin_lock(&mm->page_table_lock);
- pmd = pmd_alloc(mm, pgd, address);
+ if (unlikely(pgd_none(*pgd))) {
+ pmd_t *new = pmd_alloc_one(mm, address);
+ if (!new)
+ return VM_FAULT_OOM;
+
+ /* Insure that the update is done in an atomic way */
+ if (!pgd_test_and_populate(mm, pgd, new))
+ pmd_free(new);
+ }
+
+ pmd = pmd_offset(pgd, address);
+
+ if (likely(pmd)) {
+ pte_t *pte;
+
+ if (!pmd_present(*pmd)) {
+ struct page *new;
- if (pmd) {
- pte_t * pte = pte_alloc_map(mm, pmd, address);
- if (pte)
+ new = pte_alloc_one(mm, address);
+ if (!new)
+ return VM_FAULT_OOM;
+
+ if (!pmd_test_and_populate(mm, pmd, new))
+ pte_free(new);
+ else
+ inc_page_state(nr_page_table_pages);
+ }
+
+ pte = pte_offset_map(pmd, address);
+ if (likely(pte))
return handle_pte_fault(mm, vma, address, write_access, pte, pmd);
}
- spin_unlock(&mm->page_table_lock);
return VM_FAULT_OOM;
}
Index: linux-2.6.9/include/asm-generic/pgtable.h
=================================--- linux-2.6.9.orig/include/asm-generic/pgtable.h 2004-10-18 14:53:46.000000000 -0700
+++ linux-2.6.9/include/asm-generic/pgtable.h 2004-11-23 10:06:12.000000000 -0800
@@ -134,4 +134,60 @@
#define pgd_offset_gate(mm, addr) pgd_offset(mm, addr)
#endif
+#ifndef __HAVE_ARCH_ATOMIC_TABLE_OPS
+/*
+ * If atomic page table operations are not available then use
+ * the page_table_lock to insure some form of locking.
+ * Note thought that low level operations as well as the
+ * page_table_handling of the cpu may bypass all locking.
+ */
+
+#ifndef __HAVE_ARCH_PTEP_CMPXCHG
+#define ptep_cmpxchg(__vma, __addr, __ptep, __oldval, __newval) \
+({ \
+ int __rc; \
+ spin_lock(&__vma->vm_mm->page_table_lock); \
+ __rc = pte_same(*(__ptep), __oldval); \
+ if (__rc) set_pte(__ptep, __newval); \
+ spin_unlock(&__vma->vm_mm->page_table_lock); \
+ __rc; \
+})
+#endif
+
+#ifndef __HAVE_ARCH_PGP_TEST_AND_POPULATE
+#define pgd_test_and_populate(__mm, __pgd, __pmd) \
+({ \
+ int __rc; \
+ spin_lock(&__mm->page_table_lock); \
+ __rc = !pgd_present(*(__pgd)); \
+ if (__rc) pgd_populate(__mm, __pgd, __pmd); \
+ spin_unlock(&__mm->page_table_lock); \
+ __rc; \
+})
+#endif
+
+#ifndef __HAVE_PMD_TEST_AND_POPULATE
+#define pmd_test_and_populate(__mm, __pmd, __page) \
+({ \
+ int __rc; \
+ spin_lock(&__mm->page_table_lock); \
+ __rc = !pmd_present(*(__pmd)); \
+ if (__rc) pmd_populate(__mm, __pmd, __page); \
+ spin_unlock(&__mm->page_table_lock); \
+ __rc; \
+})
+#endif
+
+#endif
+
+#ifndef __HAVE_ARCH_PTEP_XCHG_FLUSH
+#define ptep_xchg_flush(__vma, __address, __ptep, __pteval) \
+({ \
+ pte_t __p = __pte(xchg(&pte_val(*(__ptep)), pte_val(__pteval)));\
+ flush_tlb_page(__vma, __address); \
+ __p; \
+})
+
+#endif
+
#endif /* _ASM_GENERIC_PGTABLE_H */
Index: linux-2.6.9/mm/rmap.c
=================================--- linux-2.6.9.orig/mm/rmap.c 2004-11-23 10:06:03.000000000 -0800
+++ linux-2.6.9/mm/rmap.c 2004-11-23 10:06:12.000000000 -0800
@@ -424,7 +424,10 @@
* @vma: the vm area in which the mapping is added
* @address: the user virtual address mapped
*
- * The caller needs to hold the mm->page_table_lock.
+ * The caller needs to hold the mm->page_table_lock if page
+ * is pointing to something that is known by the vm.
+ * The lock does not need to be held if page is pointing
+ * to a newly allocated page.
*/
void page_add_anon_rmap(struct page *page,
struct vm_area_struct *vma, unsigned long address)
@@ -568,11 +571,6 @@
/* Nuke the page table entry. */
flush_cache_page(vma, address);
- pteval = ptep_clear_flush(vma, address, pte);
-
- /* Move the dirty bit to the physical page now the pte is gone. */
- if (pte_dirty(pteval))
- set_page_dirty(page);
if (PageAnon(page)) {
swp_entry_t entry = { .val = page->private };
@@ -587,11 +585,15 @@
list_add(&mm->mmlist, &init_mm.mmlist); spin_unlock(&mmlist_lock);
}
- set_pte(pte, swp_entry_to_pte(entry));
+ pteval = ptep_xchg_flush(vma, address, pte, swp_entry_to_pte(entry));
BUG_ON(pte_file(*pte)); mm->anon_rss--;
- }
+ } else
+ pteval = ptep_clear_flush(vma, address, pte);
+ /* Move the dirty bit to the physical page now the pte is gone. */
+ if (pte_dirty(pteval))
+ set_page_dirty(page);
mm->rss--;
page_remove_rmap(page); page_cache_release(page);
@@ -678,15 +680,21 @@
if (ptep_clear_flush_young(vma, address, pte))
continue;
- /* Nuke the page table entry. */
flush_cache_page(vma, address);
- pteval = ptep_clear_flush(vma, address, pte);
+ /*
+ * There would be a race here with handle_mm_fault and do_anonymous_page
+ * which bypasses the page_table_lock if we would zap the pte before
+ * putting something into it. On the other hand we need to
+ * have the dirty flag setting at the time we replaced the value.
+ */
/* If nonlinear, store the file page offset in the pte. */ if (page->index != linear_page_index(vma, address))
- set_pte(pte, pgoff_to_pte(page->index));
+ pteval = ptep_xchg_flush(vma, address, pte, pgoff_to_pte(page->index));
+ else
+ pteval = ptep_get_and_clear(pte);
- /* Move the dirty bit to the physical page now the pte is gone. */
+ /* Move the dirty bit to the physical page now that the pte is gone. */
if (pte_dirty(pteval))
set_page_dirty(page);
page fault scalability patch V12 [2/7]: atomic pte operations for ia64
In reply to Christoph LameterChangelog
* Provide atomic pte operations for ia64
* Enhanced parallelism in page fault handler if applied together with the generic patch
Index: linux-2.6.9/include/asm-ia64/pgalloc.h
=================================--- linux-2.6.9.orig/include/asm-ia64/pgalloc.h 2004-10-18 14:53:06.000000000 -0700
+++ linux-2.6.9/include/asm-ia64/pgalloc.h 2004-11-19 07:54:19.000000000 -0800
@@ -34,6 +34,10 @@
#define pmd_quicklist (local_cpu_data->pmd_quick)
#define pgtable_cache_size (local_cpu_data->pgtable_cache_sz)
+/* Empty entries of PMD and PGD */
+#define PMD_NONE 0
+#define PGD_NONE 0
+
static inline pgd_t*
pgd_alloc_one_fast (struct mm_struct *mm)
{
@@ -78,12 +82,19 @@
preempt_enable();
}
+
static inline void
pgd_populate (struct mm_struct *mm, pgd_t *pgd_entry, pmd_t *pmd) {
pgd_val(*pgd_entry) = __pa(pmd);
}
+/* Atomic populate */
+static inline int
+pgd_test_and_populate (struct mm_struct *mm, pgd_t *pgd_entry, pmd_t *pmd) +{
+ return ia64_cmpxchg8_acq(pgd_entry,__pa(pmd), PGD_NONE) = PGD_NONE;
+}
static inline pmd_t*
pmd_alloc_one_fast (struct mm_struct *mm, unsigned long addr)
@@ -132,6 +143,13 @@
pmd_val(*pmd_entry) = page_to_phys(pte);
}
+/* Atomic populate */
+static inline int
+pmd_test_and_populate (struct mm_struct *mm, pmd_t *pmd_entry, struct page *pte) +{
+ return ia64_cmpxchg8_acq(pmd_entry, page_to_phys(pte), PMD_NONE) = PMD_NONE;
+}
+
static inline void
pmd_populate_kernel (struct mm_struct *mm, pmd_t *pmd_entry, pte_t *pte) {
Index: linux-2.6.9/include/asm-ia64/pgtable.h
=================================--- linux-2.6.9.orig/include/asm-ia64/pgtable.h 2004-11-15 11:13:38.000000000 -0800
+++ linux-2.6.9/include/asm-ia64/pgtable.h 2004-11-19 07:55:35.000000000 -0800
@@ -30,6 +30,8 @@
#define _PAGE_P_BIT 0
#define _PAGE_A_BIT 5
#define _PAGE_D_BIT 6
+#define _PAGE_IG_BITS 53
+#define _PAGE_LOCK_BIT (_PAGE_IG_BITS+3) /* bit 56. Aligned to 8 bits */
#define _PAGE_P (1 << _PAGE_P_BIT) /* page present bit */
#define _PAGE_MA_WB (0x0 << 2) /* write back memory attribute */
@@ -58,6 +60,7 @@
#define _PAGE_PPN_MASK (((__IA64_UL(1) << IA64_MAX_PHYS_BITS) - 1) & ~0xfffUL)
#define _PAGE_ED (__IA64_UL(1) << 52) /* exception deferral */
#define _PAGE_PROTNONE (__IA64_UL(1) << 63)
+#define _PAGE_LOCK (__IA64_UL(1) << _PAGE_LOCK_BIT)
/* Valid only for a PTE with the present bit cleared: */
#define _PAGE_FILE (1 << 1) /* see swap & file pte remarks below */
@@ -270,6 +273,8 @@
#define pte_dirty(pte) ((pte_val(pte) & _PAGE_D) != 0)
#define pte_young(pte) ((pte_val(pte) & _PAGE_A) != 0)
#define pte_file(pte) ((pte_val(pte) & _PAGE_FILE) != 0)
+#define pte_locked(pte) ((pte_val(pte) & _PAGE_LOCK)!=0)
+
/*
* Note: we convert AR_RWX to AR_RX and AR_RW to AR_R by clearing the 2nd bit in the
* access rights:
@@ -281,8 +286,15 @@
#define pte_mkyoung(pte) (__pte(pte_val(pte) | _PAGE_A))
#define pte_mkclean(pte) (__pte(pte_val(pte) & ~_PAGE_D))
#define pte_mkdirty(pte) (__pte(pte_val(pte) | _PAGE_D))
+#define pte_mkunlocked(pte) (__pte(pte_val(pte) & ~_PAGE_LOCK))
/*
+ * Lock functions for pte's
+ */
+#define ptep_lock(ptep) test_and_set_bit(_PAGE_LOCK_BIT, ptep)
+#define ptep_unlock(ptep) { clear_bit(_PAGE_LOCK_BIT,ptep); smp_mb__after_clear_bit(); }
+#define ptep_unlock_set(ptep, val) set_pte(ptep, pte_mkunlocked(val))
+/*
* Macro to a page protection value as "uncacheable". Note that "protection" is really a
* misnomer here as the protection value contains the memory attribute bits, dirty bits,
* and various other bits as well.
@@ -342,7 +354,6 @@
#define pte_unmap_nested(pte) do { } while (0)
/* atomic versions of the some PTE manipulations: */
-
static inline int
ptep_test_and_clear_young (pte_t *ptep)
{
@@ -414,6 +425,26 @@
#endif
}
+/*
+ * IA-64 doesn't have any external MMU info: the page tables contain all the necessary
+ * information. However, we use this routine to take care of any (delayed) i-cache
+ * flushing that may be necessary.
+ */
+extern void update_mmu_cache (struct vm_area_struct *vma, unsigned long vaddr, pte_t pte); +
+static inline int
+ptep_cmpxchg (struct vm_area_struct *vma, unsigned long addr, pte_t *ptep, pte_t oldval, pte_t newval) +{
+ /*
+ * IA64 defers icache flushes. If the new pte is executable we may
+ * have to flush the icache to insure cache coherency immediately
+ * after the cmpxchg.
+ */
+ if (pte_exec(newval))
+ update_mmu_cache(vma, addr, newval);
+ return ia64_cmpxchg8_acq(&ptep->pte, newval.pte, oldval.pte) = oldval.pte;
+}
+
static inline int
pte_same (pte_t a, pte_t b)
{
@@ -476,13 +507,6 @@
struct vm_area_struct * prev, unsigned long start, unsigned long end);
#endif
-/*
- * IA-64 doesn't have any external MMU info: the page tables contain all the necessary
- * information. However, we use this routine to take care of any (delayed) i-cache
- * flushing that may be necessary.
- */
-extern void update_mmu_cache (struct vm_area_struct *vma, unsigned long vaddr, pte_t pte); -
#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
/*
* Update PTEP with ENTRY, which is guaranteed to be a less
@@ -560,6 +584,8 @@
#define __HAVE_ARCH_PTEP_MKDIRTY
#define __HAVE_ARCH_PTE_SAME
#define __HAVE_ARCH_PGD_OFFSET_GATE
+#define __HAVE_ARCH_ATOMIC_TABLE_OPS
+#define __HAVE_ARCH_LOCK_TABLE_OPS
#include <asm-generic/pgtable.h>
#endif /* _ASM_IA64_PGTABLE_H */
page fault scalability patch V12 [3/7]: universal cmpxchg for i386
In reply to Christoph LameterChangelog
* Make cmpxchg and cmpxchg8b generally available on the i386 platform.
* Provide emulation of cmpxchg suitable for uniprocessor if build and run on 386.
* Provide emulation of cmpxchg8b suitable for uniprocessor systems if build and run on 386 or 486.
* Provide an inline function to atomically get a 64 bit value via cmpxchg8b in an SMP system (courtesy of Nick Piggin) (important for i386 PAE mode and other places where atomic 64 bit operations are useful)
Index: linux-2.6.9/arch/i386/Kconfig
=================================--- linux-2.6.9.orig/arch/i386/Kconfig 2004-11-15 11:13:34.000000000 -0800
+++ linux-2.6.9/arch/i386/Kconfig 2004-11-19 10:02:54.000000000 -0800
@@ -351,6 +351,11 @@
depends on !M386
default y
+config X86_CMPXCHG8B
+ bool
+ depends on !M386 && !M486
+ default y
+
config X86_XADD
bool
depends on !M386
Index: linux-2.6.9/arch/i386/kernel/cpu/intel.c
=================================--- linux-2.6.9.orig/arch/i386/kernel/cpu/intel.c 2004-11-15 11:13:34.000000000 -0800
+++ linux-2.6.9/arch/i386/kernel/cpu/intel.c 2004-11-19 10:38:26.000000000 -0800
@@ -6,6 +6,7 @@
#include <linux/bitops.h>
#include <linux/smp.h>
#include <linux/thread_info.h>
+#include <linux/module.h>
#include <asm/processor.h>
#include <asm/msr.h>
@@ -287,5 +288,103 @@
return 0;
}
+#ifndef CONFIG_X86_CMPXCHG
+unsigned long cmpxchg_386_u8(volatile void *ptr, u8 old, u8 new) +{
+ u8 prev;
+ unsigned long flags;
+ /*
+ * Check if the kernel was compiled for an old cpu but the
+ * currently running cpu can do cmpxchg after all
+ * All CPUs except 386 support CMPXCHG
+ */
+ if (cpu_data->x86 > 3)
+ return __cmpxchg(ptr, old, new, sizeof(u8));
+
+ /* Poor man's cmpxchg for 386. Unsuitable for SMP */
+ local_irq_save(flags);
+ prev = *(u8 *)ptr;
+ if (prev = old)
+ *(u8 *)ptr = new;
+ local_irq_restore(flags);
+ return prev;
+}
+
+EXPORT_SYMBOL(cmpxchg_386_u8);
+
+unsigned long cmpxchg_386_u16(volatile void *ptr, u16 old, u16 new) +{
+ u16 prev;
+ unsigned long flags;
+ /*
+ * Check if the kernel was compiled for an old cpu but the
+ * currently running cpu can do cmpxchg after all
+ * All CPUs except 386 support CMPXCHG
+ */
+ if (cpu_data->x86 > 3)
+ return __cmpxchg(ptr, old, new, sizeof(u16));
+
+ /* Poor man's cmpxchg for 386. Unsuitable for SMP */
+ local_irq_save(flags);
+ prev = *(u16 *)ptr;
+ if (prev = old)
+ *(u16 *)ptr = new;
+ local_irq_restore(flags);
+ return prev;
+}
+
+EXPORT_SYMBOL(cmpxchg_386_u16);
+
+unsigned long cmpxchg_386_u32(volatile void *ptr, u32 old, u32 new) +{
+ u32 prev;
+ unsigned long flags;
+ /*
+ * Check if the kernel was compiled for an old cpu but the
+ * currently running cpu can do cmpxchg after all
+ * All CPUs except 386 support CMPXCHG
+ */
+ if (cpu_data->x86 > 3)
+ return __cmpxchg(ptr, old, new, sizeof(u32));
+
+ /* Poor man's cmpxchg for 386. Unsuitable for SMP */
+ local_irq_save(flags);
+ prev = *(u32 *)ptr;
+ if (prev = old)
+ *(u32 *)ptr = new;
+ local_irq_restore(flags);
+ return prev;
+}
+
+EXPORT_SYMBOL(cmpxchg_386_u32);
+#endif
+
+#ifndef CONFIG_X86_CMPXCHG8B
+unsigned long long cmpxchg8b_486(volatile unsigned long long *ptr,
+ unsigned long long old, unsigned long long newv)
+{
+ unsigned long long prev;
+ unsigned long flags;
+
+ /*
+ * Check if the kernel was compiled for an old cpu but
+ * we are running really on a cpu capable of cmpxchg8b
+ */
+
+ if (cpu_has(cpu_data, X86_FEATURE_CX8))
+ return __cmpxchg8b(ptr, old, newv);
+
+ /* Poor mans cmpxchg8b for 386 and 486. Not suitable for SMP */
+ local_irq_save(flags);
+ prev = *ptr;
+ if (prev = old)
+ *ptr = newv;
+ local_irq_restore(flags);
+ return prev;
+}
+
+EXPORT_SYMBOL(cmpxchg8b_486);
+#endif
+
// arch_initcall(intel_cpu_init);
Index: linux-2.6.9/include/asm-i386/system.h
=================================--- linux-2.6.9.orig/include/asm-i386/system.h 2004-11-15 11:13:38.000000000 -0800
+++ linux-2.6.9/include/asm-i386/system.h 2004-11-19 10:49:46.000000000 -0800
@@ -149,6 +149,9 @@
#define __xg(x) ((struct __xchg_dummy *)(x))
+#define ll_low(x) *(((unsigned int*)&(x))+0)
+#define ll_high(x) *(((unsigned int*)&(x))+1)
+
/*
* The semantics of XCHGCMP8B are a bit strange, this is why
* there is a loop and the loading of %%eax and %%edx has to
@@ -184,8 +187,6 @@
{
__set_64bit(ptr,(unsigned int)(value), (unsigned int)((value)>>32ULL));
}
-#define ll_low(x) *(((unsigned int*)&(x))+0)
-#define ll_high(x) *(((unsigned int*)&(x))+1)
static inline void __set_64bit_var (unsigned long long *ptr,
unsigned long long value)
@@ -203,6 +204,26 @@
__set_64bit(ptr, (unsigned int)(value), (unsigned int)((value)>>32ULL) ) : \
__set_64bit(ptr, ll_low(value), ll_high(value)) )
+static inline unsigned long long __get_64bit(unsigned long long * ptr) +{
+ unsigned long long ret;
+ __asm__ __volatile__ (
+ "\n1:\t"
+ "movl (%1), %%eax\n\t"
+ "movl 4(%1), %%edx\n\t"
+ "movl %%eax, %%ebx\n\t"
+ "movl %%edx, %%ecx\n\t"
+ LOCK_PREFIX "cmpxchg8b (%1)\n\t"
+ "jnz 1b"
+ : "=A"(ret)
+ : "D"(ptr)
+ : "ebx", "ecx", "memory");
+ return ret;
+}
+
+#define get_64bit(ptr) __get_64bit(ptr)
+
+
/*
* Note: no "lock" prefix even on SMP: xchg always implies lock anyway
* Note 2: xchg has side effect, so that attribute volatile is necessary,
@@ -240,7 +261,41 @@
*/
#ifdef CONFIG_X86_CMPXCHG
+
#define __HAVE_ARCH_CMPXCHG 1
+#define cmpxchg(ptr,o,n)\
+ ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
+ (unsigned long)(n), sizeof(*(ptr))))
+
+#else
+
+/*
+ * Building a kernel capable running on 80386. It may be necessary to
+ * simulate the cmpxchg on the 80386 CPU. For that purpose we define
+ * a function for each of the sizes we support.
+ */
+
+extern unsigned long cmpxchg_386_u8(volatile void *, u8, u8); +extern unsigned long cmpxchg_386_u16(volatile void *, u16, u16); +extern unsigned long cmpxchg_386_u32(volatile void *, u32, u32); +
+static inline unsigned long cmpxchg_386(volatile void *ptr, unsigned long old,
+ unsigned long new, int size)
+{
+ switch (size) {
+ case 1:
+ return cmpxchg_386_u8(ptr, old, new);
+ case 2:
+ return cmpxchg_386_u16(ptr, old, new);
+ case 4:
+ return cmpxchg_386_u32(ptr, old, new);
+ }
+ return old;
+}
+
+#define cmpxchg(ptr,o,n)\
+ ((__typeof__(*(ptr)))cmpxchg_386((ptr), (unsigned long)(o), \
+ (unsigned long)(n), sizeof(*(ptr))))
#endif
static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
@@ -270,10 +325,32 @@
return old;
}
-#define cmpxchg(ptr,o,n)\
- ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
- (unsigned long)(n),sizeof(*(ptr))))
-
+static inline unsigned long long __cmpxchg8b(volatile unsigned long long *ptr,
+ unsigned long long old, unsigned long long newv)
+{
+ unsigned long long prev;
+ __asm__ __volatile__(
+ LOCK_PREFIX "cmpxchg8b (%4)"
+ : "=A" (prev)
+ : "0" (old), "c" ((unsigned long)(newv >> 32)),
+ "b" ((unsigned long)(newv & 0xffffffffULL)), "D" (ptr)
+ : "memory");
+ return prev;
+}
+
+#ifdef CONFIG_X86_CMPXCHG8B
+#define cmpxchg8b __cmpxchg8b
+#else
+/*
+ * Building a kernel capable of running on 80486 and 80386. Both
+ * do not support cmpxchg8b. Call a function that emulates the
+ * instruction if necessary.
+ */
+extern unsigned long long cmpxchg8b_486(volatile unsigned long long *,
+ unsigned long long, unsigned long long);
+#define cmpxchg8b cmpxchg8b_486
+#endif
+
#ifdef __KERNEL__
struct alt_instr {
__u8 *instr; /* original instruction */
page fault scalability patch V12 [4/7]: atomic pte operations for i386
In reply to Christoph LameterChangelog
* Atomic pte operations for i386 in regular and PAE modes
Index: linux-2.6.9/include/asm-i386/pgtable.h
=================================--- linux-2.6.9.orig/include/asm-i386/pgtable.h 2004-11-15 11:13:38.000000000 -0800
+++ linux-2.6.9/include/asm-i386/pgtable.h 2004-11-19 10:05:27.000000000 -0800
@@ -413,6 +413,7 @@
#define __HAVE_ARCH_PTEP_SET_WRPROTECT
#define __HAVE_ARCH_PTEP_MKDIRTY
#define __HAVE_ARCH_PTE_SAME
+#define __HAVE_ARCH_ATOMIC_TABLE_OPS
#include <asm-generic/pgtable.h>
#endif /* _I386_PGTABLE_H */
Index: linux-2.6.9/include/asm-i386/pgtable-3level.h
=================================--- linux-2.6.9.orig/include/asm-i386/pgtable-3level.h 2004-10-18 14:54:55.000000000 -0700
+++ linux-2.6.9/include/asm-i386/pgtable-3level.h 2004-11-19 10:10:06.000000000 -0800
@@ -6,7 +6,8 @@
* tables on PPro+ CPUs.
*
* Copyright (C) 1999 Ingo Molnar <[email protected]>
- */
+ * August 26, 2004 added ptep_cmpxchg <[email protected]> +*/
#define pte_ERROR(e) \
printk("%s:%d: bad pte %p(%08lx%08lx).\n", __FILE__, __LINE__, &(e), (e).pte_high, (e).pte_low)
@@ -42,26 +43,15 @@
return pte_x(pte);
}
-/* Rules for using set_pte: the pte being assigned *must* be
- * either not present or in a state where the hardware will
- * not attempt to update the pte. In places where this is
- * not possible, use pte_get_and_clear to obtain the old pte
- * value and then use set_pte to update it. -ben
- */
-static inline void set_pte(pte_t *ptep, pte_t pte)
-{
- ptep->pte_high = pte.pte_high;
- smp_wmb();
- ptep->pte_low = pte.pte_low;
-}
-#define __HAVE_ARCH_SET_PTE_ATOMIC
-#define set_pte_atomic(pteptr,pteval) \
+#define set_pte(pteptr,pteval) \
set_64bit((unsigned long long *)(pteptr),pte_val(pteval))
#define set_pmd(pmdptr,pmdval) \
set_64bit((unsigned long long *)(pmdptr),pmd_val(pmdval))
#define set_pgd(pgdptr,pgdval) \
set_64bit((unsigned long long *)(pgdptr),pgd_val(pgdval))
+#define set_pte_atomic set_pte
+
/*
* Pentium-II erratum A13: in PAE mode we explicitly have to flush
* the TLB via cr3 if the top-level pgd is changed...
@@ -142,4 +132,23 @@
#define __pte_to_swp_entry(pte) ((swp_entry_t){ (pte).pte_high })
#define __swp_entry_to_pte(x) ((pte_t){ 0, (x).val })
+/* Atomic PTE operations */
+#define ptep_xchg_flush(__vma, __addr, __ptep, __newval) \
+({ pte_t __r; \
+ /* xchg acts as a barrier before the setting of the high bits. */\
+ __r.pte_low = xchg(&(__ptep)->pte_low, (__newval).pte_low); \
+ __r.pte_high = (__ptep)->pte_high; \
+ (__ptep)->pte_high = (__newval).pte_high; \
+ flush_tlb_page(__vma, __addr); \
+ (__r); \
+})
+
+#define __HAVE_ARCH_PTEP_XCHG_FLUSH
+
+static inline int ptep_cmpxchg(struct vm_area_struct *vma, unsigned long address, pte_t *ptep, pte_t oldval, pte_t newval) +{
+ return cmpxchg((unsigned int *)ptep, pte_val(oldval), pte_val(newval)) = pte_val(oldval);
+}
+
+
#endif /* _I386_PGTABLE_3LEVEL_H */
Index: linux-2.6.9/include/asm-i386/pgtable-2level.h
=================================--- linux-2.6.9.orig/include/asm-i386/pgtable-2level.h 2004-10-18 14:54:31.000000000 -0700
+++ linux-2.6.9/include/asm-i386/pgtable-2level.h 2004-11-19 10:05:27.000000000 -0800
@@ -82,4 +82,7 @@
#define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_low })
#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
+/* Atomic PTE operations */
+#define ptep_cmpxchg(__vma,__a,__xp,__oldpte,__newpte) (cmpxchg(&(__xp)->pte_low, (__oldpte).pte_low, (__newpte).pte_low)=(__oldpte).pte_low) +
#endif /* _I386_PGTABLE_2LEVEL_H */
Index: linux-2.6.9/include/asm-i386/pgalloc.h
=================================--- linux-2.6.9.orig/include/asm-i386/pgalloc.h 2004-10-18 14:53:10.000000000 -0700
+++ linux-2.6.9/include/asm-i386/pgalloc.h 2004-11-19 10:10:40.000000000 -0800
@@ -4,9 +4,12 @@
#include <linux/config.h>
#include <asm/processor.h>
#include <asm/fixmap.h>
+#include <asm/system.h>
#include <linux/threads.h>
#include <linux/mm.h> /* for struct page */
+#define PMD_NONE 0L
+
#define pmd_populate_kernel(mm, pmd, pte) \
set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(pte)))
@@ -16,6 +19,19 @@
((unsigned long long)page_to_pfn(pte) <<
(unsigned long long) PAGE_SHIFT)));
}
+
+/* Atomic version */
+static inline int pmd_test_and_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte) +{
+#ifdef CONFIG_X86_PAE
+ return cmpxchg8b( ((unsigned long long *)pmd), PMD_NONE, _PAGE_TABLE +
+ ((unsigned long long)page_to_pfn(pte) <<
+ (unsigned long long) PAGE_SHIFT) ) = PMD_NONE;
+#else
+ return cmpxchg( (unsigned long *)pmd, PMD_NONE, _PAGE_TABLE + (page_to_pfn(pte) << PAGE_SHIFT)) = PMD_NONE;
+#endif
+}
+
/*
* Allocate and free page tables.
*/
@@ -49,6 +65,7 @@
#define pmd_free(x) do { } while (0)
#define __pmd_free_tlb(tlb,x) do { } while (0)
#define pgd_populate(mm, pmd, pte) BUG()
+#define pgd_test_and_populate(mm, pmd, pte) ({ BUG(); 1; })
#define check_pgt_cache() do { } while (0)
page fault scalability patch V12 [5/7]: atomic pte operations for x86_64
In reply to Christoph LameterChangelog
* Provide atomic pte operations for x86_64
Index: linux-2.6.9/include/asm-x86_64/pgalloc.h
=================================--- linux-2.6.9.orig/include/asm-x86_64/pgalloc.h 2004-10-18 14:54:30.000000000 -0700
+++ linux-2.6.9/include/asm-x86_64/pgalloc.h 2004-11-23 10:59:01.000000000 -0800
@@ -7,16 +7,26 @@
#include <linux/threads.h>
#include <linux/mm.h>
+#define PMD_NONE 0
+#define PGD_NONE 0
+
#define pmd_populate_kernel(mm, pmd, pte) \
set_pmd(pmd, __pmd(_PAGE_TABLE | __pa(pte)))
#define pgd_populate(mm, pgd, pmd) \
set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pmd)))
+#define pgd_test_and_populate(mm, pgd, pmd) \
+ (cmpxchg((int *)pgd, PGD_NONE, _PAGE_TABLE | __pa(pmd)) = PGD_NONE)
static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte) {
set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)));
}
+static inline int pmd_test_and_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte) +{
+ return cmpxchg((int *)pmd, PMD_NONE, _PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)) = PMD_NONE;
+}
+
extern __inline__ pmd_t *get_pmd(void)
{
return (pmd_t *)get_zeroed_page(GFP_KERNEL);
Index: linux-2.6.9/include/asm-x86_64/pgtable.h
=================================--- linux-2.6.9.orig/include/asm-x86_64/pgtable.h 2004-11-22 15:08:43.000000000 -0800
+++ linux-2.6.9/include/asm-x86_64/pgtable.h 2004-11-23 10:59:01.000000000 -0800
@@ -437,6 +437,10 @@
#define kc_offset_to_vaddr(o) \
(((o) & (1UL << (__VIRTUAL_MASK_SHIFT-1))) ? ((o) | (~__VIRTUAL_MASK)) : (o))+
+#define ptep_cmpxchg(__vma,__addr,__xp,__oldval,__newval) (cmpxchg(&(__xp)->pte, pte_val(__oldval), pte_val(__newval)) = pte_val(__oldval)) +#define __HAVE_ARCH_ATOMIC_TABLE_OPS
+
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
page fault scalability patch V12 [6/7]: atomic pte operations for s390
In reply to Christoph LameterChangelog
* Provide atomic pte operations for s390
Index: linux-2.6.9/include/asm-s390/pgtable.h
=================================--- linux-2.6.9.orig/include/asm-s390/pgtable.h 2004-10-18 14:54:55.000000000 -0700
+++ linux-2.6.9/include/asm-s390/pgtable.h 2004-11-19 11:35:08.000000000 -0800
@@ -567,6 +567,15 @@
return pte;
}
+#define ptep_xchg_flush(__vma, __address, __ptep, __pteval) \
+({ \
+ struct mm_struct *__mm = __vma->vm_mm; \ + pte_t __pte; \ + __pte = ptep_clear_flush(__vma, __address, __ptep); \ + set_pte(__ptep, __pteval); \ + __pte; \
+})
+
static inline void ptep_set_wrprotect(pte_t *ptep) {
pte_t old_pte = *ptep;
@@ -778,6 +787,14 @@
#define kern_addr_valid(addr) (1)
+/* Atomic PTE operations */
+#define __HAVE_ARCH_ATOMIC_TABLE_OPS
+
+static inline int ptep_cmpxchg (struct vm_area_struct *vma, unsigned long address, pte_t *ptep, pte_t oldval, pte_t newval) +{
+ return cmpxchg(ptep, pte_val(oldval), pte_val(newval)) = pte_val(oldval);
+}
+
/*
* No page table caches to initialise
*/
@@ -791,6 +808,7 @@
#define __HAVE_ARCH_PTEP_CLEAR_DIRTY_FLUSH
#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
#define __HAVE_ARCH_PTEP_CLEAR_FLUSH
+#define __HAVE_ARCH_PTEP_XCHG_FLUSH
#define __HAVE_ARCH_PTEP_SET_WRPROTECT
#define __HAVE_ARCH_PTEP_MKDIRTY
#define __HAVE_ARCH_PTE_SAME
Index: linux-2.6.9/include/asm-s390/pgalloc.h
=================================--- linux-2.6.9.orig/include/asm-s390/pgalloc.h 2004-10-18 14:54:37.000000000 -0700
+++ linux-2.6.9/include/asm-s390/pgalloc.h 2004-11-19 11:33:25.000000000 -0800
@@ -97,6 +97,10 @@
pgd_val(*pgd) = _PGD_ENTRY | __pa(pmd);
}
+static inline int pgd_test_and_populate(struct mm_struct *mm, pdg_t *pgd, pmd_t *pmd) +{
+ return cmpxchg(pgd, _PAGE_TABLE_INV, _PGD_ENTRY | __pa(pmd)) = _PAGE_TABLE_INV;
+}
#endif /* __s390x__ */
static inline void
@@ -119,6 +123,18 @@
pmd_populate_kernel(mm, pmd, (pte_t *)((page-mem_map) << PAGE_SHIFT));
}
+static inline int
+pmd_test_and_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page) +{
+ int rc;
+ spin_lock(&mm->page_table_lock);
+
+ rc=pte_same(*pmd, _PAGE_INVALID_EMPTY);
+ if (rc) pmd_populate(mm, pmd, page);
+ spin_unlock(&mm->page_table_lock);
+ return rc;
+}
+
/*
* page table entry allocation/free routines.
*/
page fault scalability patch V12 [7/7]: Split counter for rss
In reply to Christoph LameterChangelog
* Split rss counter into the task structure
* remove 3 checks of rss in mm/rmap.c
* Prerequisite for page table scalability patch
Index: linux-2.6.9/include/linux/sched.h
=================================--- linux-2.6.9.orig/include/linux/sched.h 2004-11-30 20:33:31.000000000 -0800
+++ linux-2.6.9/include/linux/sched.h 2004-11-30 20:33:50.000000000 -0800
@@ -30,6 +30,7 @@
#include <linux/pid.h>
#include <linux/percpu.h>
#include <linux/topology.h>
+#include <linux/rcupdate.h>
struct exec_domain;
@@ -217,6 +218,7 @@
int map_count; /* number of VMAs */
struct rw_semaphore mmap_sem;
spinlock_t page_table_lock; /* Protects page tables, mm->rss, mm->anon_rss */
+ long rss, anon_rss;
struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung
* together off init_mm.mmlist, and are protected
@@ -226,7 +228,7 @@
unsigned long start_code, end_code, start_data, end_data;
unsigned long start_brk, brk, start_stack;
unsigned long arg_start, arg_end, env_start, env_end;
- unsigned long rss, anon_rss, total_vm, locked_vm, shared_vm;
+ unsigned long total_vm, locked_vm, shared_vm;
unsigned long exec_vm, stack_vm, reserved_vm, def_flags, nr_ptes;
unsigned long saved_auxv[42]; /* for /proc/PID/auxv */
@@ -236,6 +238,8 @@
/* Architecture-specific MM context */
mm_context_t context;
+ struct list_head task_list; /* Tasks using this mm */
+ struct rcu_head rcu_head; /* For freeing mm via rcu */
/* Token based thrashing protection. */
unsigned long swap_token_time;
@@ -545,6 +549,9 @@
struct list_head ptrace_list;
struct mm_struct *mm, *active_mm;
+ /* Split counters from mm */
+ long rss;
+ long anon_rss;
/* task state */
struct linux_binfmt *binfmt;
@@ -578,6 +585,9 @@
struct completion *vfork_done; /* for vfork() */
int __user *set_child_tid; /* CLONE_CHILD_SETTID */
int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
+
+ /* List of other tasks using the same mm */
+ struct list_head mm_tasks;
unsigned long rt_priority;
unsigned long it_real_value, it_prof_value, it_virt_value;
@@ -1111,6 +1121,14 @@
#endif
+unsigned long get_rss(struct mm_struct *mm);
+unsigned long get_anon_rss(struct mm_struct *mm); +unsigned long get_shared(struct mm_struct *mm);
+
+void mm_remove_thread(struct mm_struct *mm, struct task_struct *tsk); +void mm_add_thread(struct mm_struct *mm, struct task_struct *tsk); +
#endif /* __KERNEL__ */
#endif
+
Index: linux-2.6.9/fs/proc/task_mmu.c
=================================--- linux-2.6.9.orig/fs/proc/task_mmu.c 2004-11-30 20:33:26.000000000 -0800
+++ linux-2.6.9/fs/proc/task_mmu.c 2004-11-30 20:33:50.000000000 -0800
@@ -22,7 +22,7 @@
"VmPTE:\t%8lu kB\n",
(mm->total_vm - mm->reserved_vm) << (PAGE_SHIFT-10), mm->locked_vm << (PAGE_SHIFT-10),
- mm->rss << (PAGE_SHIFT-10),
+ get_rss(mm) << (PAGE_SHIFT-10),
data << (PAGE_SHIFT-10),
mm->stack_vm << (PAGE_SHIFT-10), text, lib, (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
@@ -37,7 +37,7 @@
int task_statm(struct mm_struct *mm, int *shared, int *text,
int *data, int *resident)
{
- *shared = mm->rss - mm->anon_rss;
+ *shared = get_shared(mm);
*text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
>> PAGE_SHIFT;
*data = mm->total_vm - mm->shared_vm;
Index: linux-2.6.9/fs/proc/array.c
=================================--- linux-2.6.9.orig/fs/proc/array.c 2004-11-30 20:33:26.000000000 -0800
+++ linux-2.6.9/fs/proc/array.c 2004-11-30 20:33:50.000000000 -0800
@@ -420,7 +420,7 @@
jiffies_to_clock_t(task->it_real_value), start_time,
vsize,
- mm ? mm->rss : 0, /* you might want to shift this left 3 */
+ mm ? get_rss(mm) : 0, /* you might want to shift this left 3 */
rsslim,
mm ? mm->start_code : 0,
mm ? mm->end_code : 0,
Index: linux-2.6.9/mm/rmap.c
=================================--- linux-2.6.9.orig/mm/rmap.c 2004-11-30 20:33:46.000000000 -0800
+++ linux-2.6.9/mm/rmap.c 2004-11-30 20:33:50.000000000 -0800
@@ -263,8 +263,6 @@
pte_t *pte;
int referenced = 0;
- if (!mm->rss)
- goto out;
address = vma_address(page, vma);
if (address = -EFAULT)
goto out;
@@ -438,7 +436,7 @@
BUG_ON(PageReserved(page));
BUG_ON(!anon_vma);
- vma->vm_mm->anon_rss++;
+ current->anon_rss++;
anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON; index = (address - vma->vm_start) >> PAGE_SHIFT;
@@ -510,8 +508,6 @@
pte_t pteval;
int ret = SWAP_AGAIN;
- if (!mm->rss)
- goto out;
address = vma_address(page, vma);
if (address = -EFAULT)
goto out;
@@ -799,8 +795,7 @@
if (vma->vm_flags & (VM_LOCKED|VM_RESERVED))
continue;
cursor = (unsigned long) vma->vm_private_data;
- while (vma->vm_mm->rss &&
- cursor < max_nl_cursor &&
+ while (cursor < max_nl_cursor &&
cursor < vma->vm_end - vma->vm_start) { try_to_unmap_cluster(cursor, &mapcount, vma); cursor += CLUSTER_SIZE;
Index: linux-2.6.9/kernel/fork.c
=================================--- linux-2.6.9.orig/kernel/fork.c 2004-11-30 20:33:42.000000000 -0800
+++ linux-2.6.9/kernel/fork.c 2004-11-30 20:33:50.000000000 -0800
@@ -151,6 +151,7 @@
*tsk = *orig;
tsk->thread_info = ti;
ti->task = tsk;
+ tsk->rss = 0;
/* One for us, one for whoever does the "release_task()" (usually parent) */ atomic_set(&tsk->usage,2);
@@ -292,6 +293,7 @@
atomic_set(&mm->mm_count, 1);
init_rwsem(&mm->mmap_sem);
INIT_LIST_HEAD(&mm->mmlist);
+ INIT_LIST_HEAD(&mm->task_list);
mm->core_waiters = 0;
mm->nr_ptes = 0;
spin_lock_init(&mm->page_table_lock);
@@ -323,6 +325,13 @@
return mm;
}
+static void rcu_free_mm(struct rcu_head *head)
+{
+ struct mm_struct *mm = container_of(head ,struct mm_struct, rcu_head);
+
+ free_mm(mm);
+}
+
/*
* Called when the last reference to the mm
* is dropped: either by a lazy thread or by
@@ -333,7 +342,7 @@
BUG_ON(mm = &init_mm);
mm_free_pgd(mm);
destroy_context(mm);
- free_mm(mm);
+ call_rcu(&mm->rcu_head, rcu_free_mm);
}
/*
@@ -400,6 +409,8 @@
/* Get rid of any cached register state */ deactivate_mm(tsk, mm);
+ if (mm)
+ mm_remove_thread(mm, tsk);
/* notify parent sleeping on vfork() */
if (vfork_done) {
@@ -447,8 +458,8 @@
* new threads start up in user mode using an mm, which
* allows optimizing out ipis; the tlb_gather_mmu code
* is an example.
+ * (mm_add_thread does use the ptl .... )
*/
- spin_unlock_wait(&oldmm->page_table_lock);
goto good_mm;
}
@@ -470,6 +481,7 @@
goto free_pt;
good_mm:
+ mm_add_thread(mm, tsk);
tsk->mm = mm;
tsk->active_mm = mm;
return 0;
Index: linux-2.6.9/mm/memory.c
=================================--- linux-2.6.9.orig/mm/memory.c 2004-11-30 20:33:46.000000000 -0800
+++ linux-2.6.9/mm/memory.c 2004-11-30 20:33:50.000000000 -0800
@@ -1467,7 +1467,7 @@
*/
lru_cache_add_active(page); page_add_anon_rmap(page, vma, addr);
- mm->rss++;
+ current->rss++;
}
pte_unmap(page_table);
@@ -1859,3 +1859,87 @@
}
#endif
+
+unsigned long get_rss(struct mm_struct *mm)
+{
+ struct list_head *y;
+ struct task_struct *t;
+ long rss;
+
+ if (!mm)
+ return 0;
+
+ rcu_read_lock();
+ rss = mm->rss;
+ list_for_each_rcu(y, &mm->task_list) {
+ t = list_entry(y, struct task_struct, mm_tasks);
+ rss += t->rss;
+ }
+ if (rss < 0)
+ rss = 0;
+ rcu_read_unlock();
+ return rss;
+}
+
+unsigned long get_anon_rss(struct mm_struct *mm)
+{
+ struct list_head *y;
+ struct task_struct *t;
+ long rss;
+
+ if (!mm)
+ return 0;
+
+ rcu_read_lock();
+ rss = mm->anon_rss;
+ list_for_each_rcu(y, &mm->task_list) {
+ t = list_entry(y, struct task_struct, mm_tasks);
+ rss += t->anon_rss;
+ }
+ if (rss < 0)
+ rss = 0;
+ rcu_read_unlock();
+ return rss;
+}
+
+unsigned long get_shared(struct mm_struct *mm)
+{
+ struct list_head *y;
+ struct task_struct *t;
+ long rss;
+
+ if (!mm)
+ return 0;
+
+ rcu_read_lock();
+ rss = mm->rss - mm->anon_rss;
+ list_for_each_rcu(y, &mm->task_list) {
+ t = list_entry(y, struct task_struct, mm_tasks);
+ rss += t->rss - t->anon_rss;
+ }
+ if (rss < 0)
+ rss = 0;
+ rcu_read_unlock();
+ return rss;
+}
+
+void mm_remove_thread(struct mm_struct *mm, struct task_struct *tsk) +{
+ if (!mm)
+ return;
+
+ spin_lock(&mm->page_table_lock);
+ mm->rss += tsk->rss;
+ mm->anon_rss += tsk->anon_rss;
+ list_del_rcu(&tsk->mm_tasks);
+ spin_unlock(&mm->page_table_lock);
+}
+
+void mm_add_thread(struct mm_struct *mm, struct task_struct *tsk) +{
+ spin_lock(&mm->page_table_lock);
+ list_add_rcu(&tsk->mm_tasks, &mm->task_list);
+ spin_unlock(&mm->page_table_lock);
+}
+
+
Index: linux-2.6.9/include/linux/init_task.h
=================================--- linux-2.6.9.orig/include/linux/init_task.h 2004-11-30 20:33:30.000000000 -0800
+++ linux-2.6.9/include/linux/init_task.h 2004-11-30 20:33:50.000000000 -0800
@@ -42,6 +42,7 @@
.mmlist = LIST_HEAD_INIT(name.mmlist), \
.cpu_vm_mask = CPU_MASK_ALL, \
.default_kioctx = INIT_KIOCTX(name.default_kioctx, name), \
+ .task_list = LIST_HEAD_INIT(name.task_list), \
}
#define INIT_SIGNALS(sig) { \
@@ -112,6 +113,7 @@
.proc_lock = SPIN_LOCK_UNLOCKED, \
.switch_lock = SPIN_LOCK_UNLOCKED, \
.journal_info = NULL, \
+ .mm_tasks = LIST_HEAD_INIT(tsk.mm_tasks), \
}
Index: linux-2.6.9/fs/exec.c
=================================--- linux-2.6.9.orig/fs/exec.c 2004-11-30 20:33:41.000000000 -0800
+++ linux-2.6.9/fs/exec.c 2004-11-30 20:33:50.000000000 -0800
@@ -543,6 +543,7 @@
active_mm = tsk->active_mm;
tsk->mm = mm;
tsk->active_mm = mm;
+ mm_add_thread(mm, current);
activate_mm(active_mm, mm);
task_unlock(tsk);
arch_pick_mmap_layout(mm);
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Christoph LameterQuoted 9 lines · Christoph Lameter
Changes from
V11->V12of this patch:
- dumpsloppy_rssin favor oflist_rss(Linus' proposal)
- keep up against current Linus tree (patch is based on 2.6.10-rc2-bk14)This is a series of patches that increases the scalability of the page fault handler for SMP. Here are some performance results on a machine with 512 processors allocating 32 GB with an increasing number of threads (that are assigned a processor each).
Ok, consider me convinced. I don't want to apply this before I get 2.6.10 out the door, but I'm happy with it. I assume Andrew has already picked up the previous version.
Linus
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 9 lines · Linus Torvalds
Quoted 5 lines · Christoph Lameter
Changes from
V11->V12of this patch:
- dumpsloppy_rssin favor oflist_rss(Linus' proposal)
- keep up against current Linus tree (patch is based on 2.6.10-rc2-bk14)
Quoted 7 lines
Quoted 4 lines
This is a series of patches that increases the scalability of the page fault handler for SMP. Here are some performance results on a machine with 512 processors allocating 32 GB with an increasing number of threads (that are assigned a processor each).
Ok, consider me convinced. I don't want to apply this before I get 2.6.10 out the door, but I'm happy with it.
There were concerns about some architectures relying upon page_table_lock for exclusivity within their own pte handling functions. Have they all been resolved?
Quoted 1 line
I assume Andrew has already picked up the previous version.
Nope. It has major clashes with the 4-level-pagetable work.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 6 lines · Andrew Morton
Quoted 2 lines
Ok, consider me convinced. I don't want to apply this before I get 2.6.10 out the door, but I'm happy with it.
There were concerns about some architectures relying upon
page_table_lockfor exclusivity within their own pte handling functions. Have they all been resolved?
The patch will fall back on the page_table_lock if an architecture cannot provide atomic pte operations.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Linus TorvaldsQuoted 3 lines · Linus Torvalds
Ok, consider me convinced. I don't want to apply this before I get 2.6.10 out the door, but I'm happy with it. I assume Andrew has already picked up the previous version.
Does that mean that 2.6.10 is actually close to the door?
/me runs...
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 9 lines · Jeff Garzik
Quoted 3 lines · Linus Torvalds
Ok, consider me convinced. I don't want to apply this before I get 2.6.10 out the door, but I'm happy with it. I assume Andrew has already picked up the previous version.
Does that mean that 2.6.10 is actually close to the door?
We need an -rc3 yet. And I need to do another pass through the regressions-since-2.6.9 list. We've made pretty good progress there recently. Mid to late December is looking like the 2.6.10 date.
We need to be be achieving higher-quality major releases than we did in 2.6.8 and 2.6.9. Really the only tool we have to ensure this is longer stabilisation periods.
Of course, nobody will test -rc3 and a zillion people will test final 2.6.10, which is when we get lots of useful bug reports. If this keeps on happening then we'll need to get more serious about the 2.6.10.n process.
Or start alternating between stable and flakey releases, so 2.6.11 will be a feature release with a 2-month development period and 2.6.12 will be a bugfix-only release, with perhaps a 2-week development period, so people know that the even-numbered releases are better stabilised.
We'll see. It all depends on how many bugs you can fix in the next two weeks ;)
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 3 lines · Andrew Morton
We need to be be achieving higher-quality major releases than we did in 2.6.8 and 2.6.9. Really the only tool we have to ensure this is longer stabilisation periods.
I'm still hoping that distros (like my employer) and orgs like OSDL will step up, and hook 2.6.x BK snapshots into daily test harnesses.
Something like John Cherry's reports to lkml on warnings and errors would be darned useful. His reports are IMO an ideal model: show day-to-day _changes_ in test results. Don't just dump a huge list of testsuite results, results which are often clogged with expected failures and testsuite bug noise.
Jeff
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Andrew MortonQuoted 3 lines · Andrew Morton
We need an -rc3 yet. And I need to do another pass through the regressions-since-2.6.9 list. We've made pretty good progress there recently. Mid to late December is looking like the 2.6.10 date.
another for that list, BTW:
I am currently chasing a 2.6.8->2.6.9 SATA regression, which causes ata_piix (Intel ICH5/6/7) to not-find some SATA devices on x86-64 SMP, but works on UP. Potentially related to >=4GB of RAM.
Details, in case anyone is interested:
Unless my code is screwed up (certainly possible), PIO data-in [using the insw() call] seems to return all zeroes on a true-blue SMP machine, for the identify-device command. When this happens, libata (correctly) detects a bad id page and bails. (problem doesn't show up on single CPU w/ HT)
What changed from 2.6.8 to 2.6.9 is
2.6.8:
bitbang ATA taskfile registers (loads command) bitbang ATA data register (read id page)
2.6.9:
bitbang ATA taskfile registers
queue_work()
workqueue thread bitbangs ATA data register (read id page)
So I wonder if <something> doesn't like CPU 0 sending I/O traffic to the on-board SATA PCI device, then immediately after that, CPU 1 sending I/O traffic.
Anyway, back to debugging... :)
Jeff
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Jeff GarzikQuoted 9 lines · Jeff Garzik
Quoted 3 lines · Andrew Morton
We need to be be achieving higher-quality major releases than we did in 2.6.8 and 2.6.9. Really the only tool we have to ensure this is longer stabilisation periods.
I'm still hoping that distros (like my employer) and orgs like OSDL will step up, and hook 2.6.x BK snapshots into daily test harnesses.
I believe that both IBM and OSDL are doing this, or are getting geared up to do this. With both Linus bk and -mm.
However I have my doubts about how useful it will end up being. These test suites don't seem to pick up many regressions. I've challenged Gerrit to go back through a release cycle's bugfixes and work out how many of those bugs would have been detected by the test suite.
My suspicion is that the answer will be "a very small proportion", and that really is the bottom line.
We simply get far better coverage testing by releasing code, because of all the wild, whacky and weird things which people do with their computers. Bless them.
Quoted 6 lines
Something like John Cherry's reports to lkml on warnings and errors would be darned useful. His reports are IMO an ideal model: show day-to-day _changes_ in test results. Don't just dump a huge list of testsuite results, results which are often clogged with expected failures and testsuite bug noise.
Yes, we need humans between the tests and the developers. Someone who has good experience with the tests and who can say "hey, something changed when I do X". If nothing changed, we don't hear anything.
It's a developer role, not a testing role. All testing is, really.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Jeff GarzikQuoted 11 lines · Jeff Garzik
2.6.9:
bitbang ATA taskfile registers
queue_work()
workqueue thread bitbangs ATA data register (read id page)So I wonder if <something> doesn't like CPU 0 sending I/O traffic to the on-board SATA PCI device, then immediately after that, CPU 1 sending I/O traffic.
Anyway, back to debugging... :)
They may not end up in order if they are stores (the stores to the taskfile may be out of order vs; the loads/stores to/from the data register) unless you have a spinlock protecting both or a full sync (on ppc), but then, I don't know the ordering things on x86_64. This could certainly be a problem on ppc & ppc64 too.
Ben.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 5 lines · Benjamin Herrenschmidt
They may not end up in order if they are stores (the stores to the taskfile may be out of order vs; the loads/stores to/from the data register) unless you have a spinlock protecting both or a full sync (on ppc), but then, I don't know the ordering things on
x86_64. This could certainly be a problem on ppc & ppc64 too.
Is synchronization beyond in[bwl] needed, do you think?
This specific problem is only on Intel ICHx AFAICS, which is PIO not MMIO and x86-only. I presumed insw() by its very nature already has synchronization, but perhaps not...
Jeff
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Andrew Morton--Andrew Morton <[email protected]> wrote (on Wednesday, December 01, 2004 23:02:17 -0800):
Quoted 8 lines
Quoted 7 lines · Jeff Garzik
Quoted 3 lines · Andrew Morton
We need to be be achieving higher-quality major releases than we did in 2.6.8 and 2.6.9. Really the only tool we have to ensure this is longer stabilisation periods.
Quoted 5 lines
Quoted 2 lines
I'm still hoping that distros (like my employer) and orgs like OSDL will step up, and hook 2.6.x BK snapshots into daily test harnesses.
I believe that both IBM and OSDL are doing this, or are getting geared up to do this. With both Linus bk and -mm.
I already run a bunch of tests on a variety of machines for every new kernel ... but don't have an automated way to compare the results as yet, so don't actually look at them much ;-(. Sometime soon (quite possibly over Christmas) things will calm down enough I'll get a couple of days to write the appropriate perl script, and start publishing stuff.
Quoted 7 lines
However I have my doubts about how useful it will end up being. These test suites don't seem to pick up many regressions. I've challenged Gerrit to go back through a release cycle's bugfixes and work out how many of those bugs would have been detected by the test suite.
My suspicion is that the answer will be "a very small proportion", and that really is the bottom line.
Yeah, probably. Though the stress tests catch a lot more than the functionality ones. The big pain in the ass is drivers, because I don't have a hope in hell of testing more than 1% of them.
M.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 3 lines · Martin J. Bligh
Yeah, probably. Though the stress tests catch a lot more than the functionality ones. The big pain in the ass is drivers, because I don't have a hope in hell of testing more than 1% of them.
My dream is that hardware vendors rotate their current machines through a test shop :) It would be nice to make sure that the popular drivers get daily test coverage.
Jeff, dreaming on
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Jeff GarzikQuoted 9 lines · Jeff Garzik
Quoted 5 lines · Benjamin Herrenschmidt
They may not end up in order if they are stores (the stores to the taskfile may be out of order vs; the loads/stores to/from the data register) unless you have a spinlock protecting both or a full sync (on ppc), but then, I don't know the ordering things on
x86_64. This could certainly be a problem on ppc & ppc64 too.Is synchronization beyond in[bwl] needed, do you think?
Yes, when potentially hop'ing between CPUs, definitely.
Quoted 3 lines
This specific problem is only on Intel ICHx AFAICS, which is PIO not MMIO and x86-only. I presumed
insw()by its very nature already has synchronization, but perhaps not...
Hrm... on "pure" x86, I would expect so at the HW level, not sure about x86_64... but there would be definitely an issue on ppc with your scheme. You need at least a full barrier before you trigger the workqueue. That may not be the problem you are facing now, but it would become one.
Ben.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Jeff GarzikQuoted 7 lines · Jeff Garzik
[...]
I am currently chasing a 2.6.8->2.6.9 SATA regression, which causesata_piix(Intel ICH5/6/7) to not-find some SATA devices on x86-64 SMP, but works on UP. Potentially related to >=4GB of RAM.
Quoted 6 lines
Details, in case anyone is interested:
Unless my code is screwed up (certainly possible), PIO data-in [using theinsw()call] seems to return all zeroes on a true-blue SMP machine, for the identify-device command. When this happens, libata (correctly) detects a bad id page and bails. (problem doesn't show up on single CPU w/ HT)
Ah, I might have been here recently, with the pass-thru stuff.
What I saw was that in an SMP machine:
1. queue_work() can result in the work running (on another CPU) instantly.
2. Having one CPU beat on PIO registers reading data from one port would significantly alter the timing of the CMD->BSY->DRQ sequence used in PIO. This behaviour was far worse for competing ports within one chip, which I put down to arbitration problems.
3. CPU utilisation would go through the roof. Effectively the entire pio_task state machine reduced to a busy spin loop.
4. The state machine needed some tweaks, especially in error handling cases.
I made some changes, which effectively solved the problem for promise TX4-150 cards, and was going to test the results on other chipsets next week before speaking up. Specifically, I have seen some issues with SiI 3114 cards.
I was trying to explore using interrupts instead of polling state but for some reason, I was not getting them for PIO data operations, or I misunderstand the spec, after removing ata_qc_set_polling() - again I saw a difference in behaviour between the Promise & SiI cards here.
I'm about to go offline for 3 days, and hadn't prepared for this yet. The best I can do is provide a patch (attached) that applies against 2.6.9. It also seems to apply against libata-2.6, but barfs a bit against libata-dev-2.6.
The changes boil down to these:
1. Minor changes in how status/error regs are read. Including attempts to use altstatus, while I was exploring interrupts.
2. State machine logic changes.
3. Replace calls to queue_work() with queue_delayed_work() to stop SMP machines going crazy.
With these changes, on a platform consisting of 2.6.9 and Promise TX4-150 cards, I can move terabytes of parallel PIO data, without error.
My gut says that the PIO mechanism should be overhauled, I composed a "how much should we pay for this muffler" email to linux-ide at least twice while working on this, but never sent it - wanting to send a solution in rather than just making more comments from the peanut gallery.
I'll pick up the thread on this next week, when I'm back online. I hope this helps.
Signature · 3 lines
[email protected] Andy Warner Voice: (612) 801-8549 Fax: (208) 575-5634
drivers/scsi/libata-core.c +9 -17
@@ -2099,7 +2099,7 @@ } drv_stat =ata_wait_idle (ap); -if (!ata_ok (drv_stat)) { +if (drv_stat & (ATA_ERR |ATA_DF )) { ap->pio_task_state =PIO_ST_ERR ;return ; }
@@ -2254,23 +2254,17 @@* chk-status again. If still busy, fall back to * PIO_ST_POLL state. */ - status =ata_busy_wait (ap,ATA_BUSY ,5 ); -if (status &ATA_BUSY ) { + status =ata_altstatus (ap) ; +if (!(status &ATA_DRQ )) {msleep (2 ); - status =ata_busy_wait (ap,ATA_BUSY ,10 ); -if (status &ATA_BUSY ) { + status =ata_altstatus (ap) ; +if (!(status &ATA_DRQ )) { ap->pio_task_state =PIO_ST_POLL ; ap->pio_task_timeout = jiffies +ATA_TMOUT_PIO ;return ; } } -/* handle BSY=0, DRQ=0 as error */ -if ((status &ATA_DRQ ) ==0 ) { - ap->pio_task_state =PIO_ST_ERR ; -return ; - } - qc =ata_qc_from_tag (ap, ap->active_tag);assert (qc !=NULL );
@@ -2321,17 +2315,15 @@case PIO_ST_TMOUT :case PIO_ST_ERR :ata_pio_error (ap); -break ; +return ; } -if ((ap->pio_task_state !=PIO_ST_IDLE ) && - (ap->pio_task_state !=PIO_ST_TMOUT ) && - (ap->pio_task_state !=PIO_ST_ERR )) { +if (ap->pio_task_state !=PIO_ST_IDLE ) {if (timeout)queue_delayed_work (ata_wq, &ap->pio_task, timeout);else -queue_work (ata_wq, &ap->pio_task); +queue_delayed_work (ata_wq, &ap->pio_task,2 ); } }
@@ -2624,7 +2616,7 @@ata_qc_set_polling (qc);ata_tf_to_host_nolock (ap, &qc->tf); ap->pio_task_state =PIO_ST ; -queue_work (ata_wq, &ap->pio_task); +queue_delayed_work (ata_wq, &ap->pio_task,2 );break ;case ATA_PROT_ATAPI :
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Andrew MortonQuoted 14 lines · Andrew Morton
Quoted 9 lines · Jeff Garzik
Quoted 3 lines · Andrew Morton
We need to be be achieving higher-quality major releases than we did in 2.6.8 and 2.6.9. Really the only tool we have to ensure this is longer stabilisation periods.
I'm still hoping that distros (like my employer) and orgs like OSDL will step up, and hook 2.6.x BK snapshots into daily test harnesses.
I believe that both IBM and OSDL are doing this, or are getting geared up to do this. With both Linus bk and -mm.
Quoted 7 lines
However I have my doubts about how useful it will end up being. These test suites don't seem to pick up many regressions. I've challenged Gerrit to go back through a release cycle's bugfixes and work out how many of those bugs would have been detected by the test suite.
My suspicion is that the answer will be "a very small proportion", and that really is the bottom line.
Yeah, sort of what Martin said. LTP, for instance, doesn't find a lot of what is in our internal bugzilla or the bugme database. Automated testing tends not to cover all the range of desktop peripherals and drivers that make up a large quantity of the code but gets very little coverage. Our stress testing is extensive and was finding 3 year old problems when we first ran it but it is pretty expensive to run those types of tests (machines, people, data analysis) so we typically run those tests on distros rather than mainline to help validate distro quality.
However, that said, the LTP stuff is still *necessary* - it would catch quite a number of regressions if we were to regress. The good thing is that most changes today haven't been leading to regressions. That could change at any time, and one of the keys is to make sure that when we do find regressions we get a test into LTP to make sure that that particular regression never happens again.
I haven't looked at the code coverage for LTP in a while but it is actually a high line count coverage test for core kernel. I don't remember if it was over 80% or not, but usually 85-88% is the point of diminishing returns for a regression suite. I think a more important proactive step here is to understand what regressions we *do* have an whether or not we can construct a test that in the future will catch that regression (or better, a class of regressions).
And, maybe we need some kind of filter person or group for lkml that can see what the key regressions are (e.g. akpm, if you know of a set of regressions that you are working, maybe periodically sending those to the ltp mailing list) we could focus on creating tests for those regressions.
We are also working to set up large ISV applications in a couple of spots - both inside IBM and there is a similar effort underway at OSDL. Those ISV applications will catch a class of real world usage models and also check for regressions. I don't know if it is possible to set up a better testing environment for the wild, whacky and weird things that people do but, yes, Bless them. ;-)
Quoted 10 lines
We simply get far better coverage testing by releasing code, because of all the wild, whacky and weird things which people do with their computers. Bless them.
Quoted 5 lines
Something like John Cherry's reports to lkml on warnings and errors would be darned useful. His reports are IMO an ideal model: show day-to-day _changes_ in test results. Don't just dump a huge list of testsuite results, results which are often clogged with expected failures and testsuite bug noise.
Quoted 5 lines
Yes, we need humans between the tests and the developers. Someone who has good experience with the tests and who can say "hey, something changed when I do X". If nothing changed, we don't hear anything.
It's a developer role, not a testing role. All testing is, really.
Yep. However, smart developers continue to write scripts to automate the rote and mundane tasks that they hate doing. Towards that end, there was a recent effort at Bull on the NPTL work which serves as a very interesting model:
http://nptl.bullopensource.org/Tests/results/run-browse.php
Basically, you can compare results from any test run with any other and get a summary of differences. That helps give a quick status check and helps you focus on the correct issues when tracking down defects.
gerrit
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Andrew MortonQuoted 8 lines · On Wed, 1 Dec 2004 23:02:17 -0800 Andrew Morton <[email protected]> wrote:
Quoted 7 lines · Jeff Garzik
Quoted 3 lines · Andrew Morton
We need to be be achieving higher-quality major releases than we did in 2.6.8 and 2.6.9. Really the only tool we have to ensure this is longer stabilisation periods.
Quoted 5 lines
Quoted 2 lines
I'm still hoping that distros (like my employer) and orgs like OSDL will step up, and hook 2.6.x BK snapshots into daily test harnesses.
I believe that both IBM and OSDL are doing this, or are getting geared up to do this. With both Linus bk and -mm.
Gee, OSDL has been doing this sort of testing for > 1 years now. Getting bandwidth to look at the results has been a problem. We need more eyeballs and community support badly, i'm very glad Marcelo has shown recent interest.
Quoted 21 lines
However I have my doubts about how useful it will end up being. These test suites don't seem to pick up many regressions. I've challenged Gerrit to go back through a release cycle's bugfixes and work out how many of those bugs would have been detected by the test suite.
My suspicion is that the answer will be "a very small proportion", and that really is the bottom line.
We simply get far better coverage testing by releasing code, because of all the wild, whacky and weird things which people do with their computers. Bless them.
Quoted 6 lines
Something like John Cherry's reports to lkml on warnings and errors would be darned useful. His reports are IMO an ideal model: show day-to-day _changes_ in test results. Don't just dump a huge list of testsuite results, results which are often clogged with expected failures and testsuite bug noise.
Quoted 3 lines
Yes, we need humans between the tests and the developers. Someone who has good experience with the tests and who can say "hey, something changed when I do X". If nothing changed, we don't hear anything.
I would agree, and would do almost anything to help/assist/enable any humans interested. We need some expertise on when to run certain tests, to avoid data overload.
I've noticed that when developer's submit test results with a patch, it sometimes helps in the decision on patch acceptance. Is there a way to promote this sort of behaviour?
cliffw
OSDL
Quoted 8 lines
It's a developer role, not a testing role. All testing is, really.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 2 lines
The church is near, but the road is icy. The bar is far, but i will walk carefully. - Russian proverb
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Jeff GarzikQuoted 10 lines · On Thu, 02 Dec 2004 02:31:35 -0500 Jeff Garzik <[email protected]> wrote:
Quoted 3 lines · Martin J. Bligh
Yeah, probably. Though the stress tests catch a lot more than the functionality ones. The big pain in the ass is drivers, because I don't have a hope in hell of testing more than 1% of them.
My dream is that hardware vendors rotate their current machines through a test shop :) It would be nice to make sure that the popular drivers get daily test coverage.
Jeff, dreaming on
OSDL has recently re-done the donation policy, and we're much better positioned to support that sort of thing now - Contact Tom Hanrahan at OSDL if you are a vendor, or know a vendor. ( Or you can become a vendor )
cliffw
Quoted 8 lines
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 2 lines
The church is near, but the road is icy. The bar is far, but i will walk carefully. - Russian proverb
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 12 lines · cliff white
Quoted 9 lines · On Thu, 02 Dec 2004 02:31:35 -0500 Jeff Garzik <[email protected]> wrote:
Quoted 3 lines · Martin J. Bligh
Yeah, probably. Though the stress tests catch a lot more than the functionality ones. The big pain in the ass is drivers, because I don't have a hope in hell of testing more than 1% of them.
My dream is that hardware vendors rotate their current machines through a test shop :) It would be nice to make sure that the popular drivers get daily test coverage.
Quoted 5 lines
Quoted 1 line
Jeff, dreaming on
OSDL has recently re-done the donation policy, and we're much better positioned to support that sort of thing now - Contact Tom Hanrahan at OSDL if you are a vendor, or know a vendor. ( Or you can become a vendor )
Specifically Tom Hanrahan = [email protected]
gerrit
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Andrew MortonQuoted 8 lines · Andrew Morton
Of course, nobody will test -rc3 and a zillion people will test final 2.6.10, which is when we get lots of useful bug reports. If this keeps on happening then we'll need to get more serious about the 2.6.10.n process.
Or start alternating between stable and flakey releases, so 2.6.11 will be a feature release with a 2-month development period and 2.6.12 will be a bugfix-only release, with perhaps a 2-week development period, so people know that the even-numbered releases are better stabilised.
No matter what scheme you adopt, I (and others) will adapt as well. When working on a new feature or bug fix, I don't chase -bk releases since I don't want to find new, unrelated issues that interfere with the issue I was originally chasing. I roll to a new release when the issue I care about is "cooked". Anything that takes longer than a month or so is just hopeless since I fall too far behind.
(e.g. IRQ handling in parisc-linux needs to be completely rewritten to pickup irq_affinity support - I just don't have enough time to get it done in < 2 monthes. We started on this last year and gave up.)
I see "2.6.10.n process" as the right way to handle bug fix only releases. I'm happy to work on 2.6.10.0 and understand the initial release was a "best effort".
2.6.odd/.even release described above is a variant of 2.6.10.n releases where n = {0, 1}. The question is how many parallel releases do people (you and linus) want us keep "alive" at the same time? odd/even implies only one vs several if 2.6.X.n scheme is continued beyond 2.6.8.1.
Also need to think about how well any scheme align's with what distro's need to support releases. Like the "Adopt-a-Highway" program in California to pickup trash along highways, I'm wondering if distros would be willing/interested in adopting a particular release and maintain it in bk. e.g. SuSE clearly has interest in some sort of 2.6.5.n series for SLES9. ditto for RHEL4 (but for 2.6.9.n). The question of *who* (at respective distro) would be the release maintainer is a titanic sized rathole. But there is a release manager today at each distro and perhaps it's easier if s/he remains invisible to us.
hth,
grant
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 4 lines · Grant Grundler
2.6.odd/.even release described above is a variant of 2.6.10.n releases
where n = {0, 1}. The question is how many parallel releases do people (you and linus) want us keep "alive" at the same time?
2.6.odd/.even is actually a significantly different process. a) because there's only one tree, linearly growing. That's considerably simpler than maintaining a branch. And b) because everyone knows that there won't be a new development tree opened until we've all knuckled down and fixed the bugs which we put into the previous one, dammit.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Grant GrundlerQuoted 6 lines · Grant Grundler
Also need to think about how well any scheme align's with what distro's need to support releases. Like the "Adopt-a-Highway" program in California to pickup trash along highways, I'm wondering if distros would be willing/interested in adopting a particular release and maintain it in bk. e.g. SuSE clearly has interest in some sort of 2.6.5.n series for SLES9. ditto for RHEL4 (but for 2.6.9.n).
Unfortunately the SLES9 kernels don't really look anything like 2.6.5 except from the version number. There's far too much trash from Business Partners in there.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Martin J. BlighQuoted 13 lines · On Wed, 01 Dec 2004 23:26:59 -0800 "Martin J. Bligh" <[email protected]> wrote:
--Andrew Morton <[email protected]> wrote (on Wednesday, December 01, 2004 23:02:17 -0800):
Quoted 11 lines
Quoted 9 lines · Jeff Garzik
Quoted 3 lines · Andrew Morton
We need to be be achieving higher-quality major releases than we did in 2.6.8 and 2.6.9. Really the only tool we have to ensure this is longer stabilisation periods.
I'm still hoping that distros (like my employer) and orgs like OSDL will step up, and hook 2.6.x BK snapshots into daily test harnesses.
Quoted 8 lines
Quoted 2 lines
I believe that both IBM and OSDL are doing this, or are getting geared up to do this. With both Linus bk and -mm.
I already run a bunch of tests on a variety of machines for every new kernel ... but don't have an automated way to compare the results as yet, so don't actually look at them much ;-(. Sometime soon (quite possibly over Christmas) things will calm down enough I'll get a couple of days to write the appropriate perl script, and start publishing stuff.
We've had the most success when one person has an itch to scratch, and works with us to scratch it. We (OSDL) worked with Sebastien at Bull, and we're very glad he had the time to do such excellent work. We worked with Con Kolivas, likewise.
We've done tools to automate LTP comparisons ( [email protected] has posted results ) and reaim, we've been able to post some regression to lkml, and tied in with developers to get bugs fixed. But OSDL has been limited by manpower.
One of the issues with the performance tests is the amount of data produced -
for example, the deep IO tests produce ton's o' numbers, but the developer community wants
a single "+/- 5%" type response- we need some opinions and help on how to do the data reduction necessary.
What would be really kewl is some test/analysis code that could be re-used, so the Martin's of the future have a good starting place.
cliffw
OSDL
Quoted 20 lines
Quoted 8 lines
However I have my doubts about how useful it will end up being. These test suites don't seem to pick up many regressions. I've challenged Gerrit to go back through a release cycle's bugfixes and work out how many of those bugs would have been detected by the test suite.
My suspicion is that the answer will be "a very small proportion", and that really is the bottom line.
Yeah, probably. Though the stress tests catch a lot more than the functionality ones. The big pain in the ass is drivers, because I don't have a hope in hell of testing more than 1% of them.
M.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 2 lines
The church is near, but the road is icy. The bar is far, but i will walk carefully. - Russian proverb
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Jeff GarzikQuoted 2 lines · El Thu, 02 Dec 2004 01:48:25 -0500 Jeff Garzik <[email protected]> escribió:
I'm still hoping that distros (like my employer) and orgs like OSDL will step up, and hook 2.6.x BK snapshots into daily test harnesses.
Automated .deb's and .rpm's for the -bk snapshots (and yum/apt repositories) would be nice for all those people who run unsupported distros.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 10 lines · Diego Calleja
Quoted 1 line · El Thu, 02 Dec 2004 01:48:25 -0500 Jeff Garzik <[email protected]> escribió:
I'm still hoping that distros (like my employer) and orgs like OSDL will step up, and hook 2.6.x BK snapshots into daily test harnesses.
Automated .deb's and .rpm's for the -bk snapshots (and yum/apt repositories) would be nice for all those people who run unsupported distros.
Now, that's a darned good idea...
Should be simple for rpm at least, given the "make rpm" target. I wonder if we have, or could add, a 'make deb' target.
Jeff
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to cliff whiteQuoted 8 lines · cliff white
Quoted 5 lines · On Thu, 02 Dec 2004 02:31:35 -0500 Jeff Garzik <[email protected]> wrote:
Quoted 3 lines · Martin J. Bligh
Yeah, probably. Though the stress tests catch a lot more than the functionality ones. The big pain in the ass is drivers, because I don't have a hope in hell of testing more than 1% of them.
Quoted 6 lines
Quoted 5 lines
My dream is that hardware vendors rotate their current machines through a test shop :) It would be nice to make sure that the popular drivers get daily test coverage.
Jeff, dreaming on
It isn't going to happen until the time when the vendors call somebody a liar, try to get them fired, and then that somebody takes them to court and they lose 100 million dollars or so.
Until that happens, vendors will continue to make junk and they will continue to lie about the performance of that junk. It doesn't help that Software Engineering has become a "hardware junk fixing" job.
Basically many vendors in the PC and PC peripheral business are, for lack of a better word, liars who are in the business of perpetrating fraud upon the unsuspecting PC user.
We have vendors who convincingly change mega-bits to mega-bytes, improving performance 8-fold without any expense at all. We have vendors reducing the size of a kilobyte and a megabyte, then getting the new lies entered into dictionaries, etc. The scheme goes on.
In the meantime, if you try to perform DMA across a PCI/Bus at or near the specified rates, you will learn that the specifications are for "this chip" or "that chip", and have nothing to do with the performance when these chips get connected together. You will find that real performance is about 20 percent of the specification.
Occasionally you find a vendor that doesn't lie and the same chip-set magically performs close to the published specifications. This is becoming rare because it costs money to build motherboards that work. This might require two or more prototypes to get the timing just right so the artificial delays and re-clocking, used to make junk work, isn't required.
Once the PC (and not just the desk-top PC) became a commodity, everything points to the bottom-line. You get into the business by making something that looks and smells new. Then you sell it by writing specifications that are better than the most expensive on the market. Your sales-price is set below average market so you can unload this junk as rapidly as possible.
Then, you do this over again, claiming that your equipment is "state-of-the-art"! And if anybody ever tests the junk and claims that it doesn't work as specified, you contact the president of his company and try to kill the messenger.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by John Ashcroft.
98.36% of all statistics are fiction.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Jeff GarzikQuoted 8 lines · El Thu, 02 Dec 2004 15:12:22 -0500 Jeff Garzik <[email protected]> escribió:
Quoted 3 lines
Automated .deb's and .rpm's for the -bk snapshots (and yum/apt repositories) would be nice for all those people who run unsupported distros.
Now, that's a darned good idea...
Should be simple for rpm at least, given the "make rpm" target. I wonder if we have, or could add, a 'make deb' target.
There was a patch for that long time ago before 2.6 was out IIRC? I don't know where it went (CC'ing Sam who should know ;)
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Jeff GarzikQuoted 2 lines · Previously Jeff Garzik
Should be simple for rpm at least, given the "make rpm" target. I wonder if we have, or could add, a 'make deb' target.
make deb-pkg has been there for a while.
Wichert.
Signature · 2 lines
Wichert Akkerman <[email protected]> It is simple to make things. http://www.wiggy.net/ It is hard to make things simple.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Jeff GarzikJeff Garzik <[email protected]> :
[...]
Quoted 2 lines
Should be simple for rpm at least, given the "make rpm" target. I wonder if we have, or could add, a 'make deb' target.
http://www.wiggy.net/files/kerneldeb-1.2.ptc ?
--
Ueimor
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to cliff whiteQuoted 29 lines · cliff white
Quoted 13 lines · On Wed, 01 Dec 2004 23:26:59 -0800 "Martin J. Bligh" <[email protected]> wrote:
--Andrew Morton <[email protected]> wrote (on Wednesday, December 01, 2004 23:02:17 -0800):
Quoted 11 lines
Quoted 9 lines · Jeff Garzik
Quoted 3 lines · Andrew Morton
We need to be be achieving higher-quality major releases than we did in 2.6.8 and 2.6.9. Really the only tool we have to ensure this is longer stabilisation periods.
I'm still hoping that distros (like my employer) and orgs like OSDL will step up, and hook 2.6.x BK snapshots into daily test harnesses.
Quoted 8 lines
Quoted 2 lines
I believe that both IBM and OSDL are doing this, or are getting geared up to do this. With both Linus bk and -mm.
I already run a bunch of tests on a variety of machines for every new kernel ... but don't have an automated way to compare the results as yet, so don't actually look at them much ;-(. Sometime soon (quite possibly over Christmas) things will calm down enough I'll get a couple of days to write the appropriate perl script, and start publishing stuff.
We've had the most success when one person has an itch to scratch, and works with us to scratch it. We (OSDL) worked with Sebastien at Bull, and we're very glad he had the time to do such excellent work. We worked with Con Kolivas, likewise.
Quoted 8 lines
We've done tools to automate LTP comparisons ( [email protected] has posted results ) and reaim, we've been able to post some regression to lkml, and tied in with developers to get bugs fixed. But OSDL has been limited by manpower.
One of the issues with the performance tests is the amount of data produced -
for example, the deep IO tests produce ton's o' numbers, but the developer community wants
a single "+/- 5%" type response- we need some opinions and help on how to do the data reduction necessary.
Yep, reaim produces a single "global throughput" result in MB/s, which is wonderful for readability.
Now iozone on the other extreme produces output for each kind of operation (read, write, rw, sync version of those) for each client IIRC. tiobench also has detailed output for each operation.
We ought to reduce all benchmark results to "read", "write" and "global" (read+write/2) numbers.
I'm willing to work on the data reduction and graphic generation scripts for STP results. I think I can do that.
Quoted 3 lines
What would be really kewl is some test/analysis code that could be re-used, so the Martin's of the future have a good starting place.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Andrew MortonHi!
Quoted 4 lines
Or start alternating between stable and flakey releases, so 2.6.11 will be a feature release with a 2-month development period and 2.6.12 will be a bugfix-only release, with perhaps a 2-week development period, so people know that the even-numbered releases are better stabilised.
If you expect "feature 2.6.11", you might as well call it 2.7.0, followed by 2.8.0.
Pavel
Signature · 2 lines
People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Anticipatory prefaulting in the page fault handler V1
In reply to cliff whiteThe page fault handler for anonymous pages can generate significant overhead apart from its essential function which is to clear and setup a new page table entry for a never accessed memory location. This overhead increases significantly in an SMP environment.
In the page table scalability patches, we addressed the issue by changing the locking scheme so that multiple fault handlers are able to be processed concurrently on multiple cpus. This patch attempts to aggregate multiple page faults into a single one. It does that by noting
anonymous page faults generated in sequence by an application.
If a fault occurred for page x and is then followed by page x+1 then it may be reasonable to expect another page fault at x+2 in the future. If page table entries for x+1 and x+2 would be prepared in the fault handling for page x+1 then the overhead of taking a fault for x+2 is avoided. However page x+2 may never be used and thus we may have increased the rss of an application unnecessarily. The swapper will take care of removing that page if memory should get tight.
The following patch makes the anonymous fault handler anticipate future faults. For each fault a prediction is made where the fault would occur (assuming linear acccess by the application). If the prediction turns out to be right (next fault is where expected) then a number of pages is preallocated in order to avoid a series of future faults. The order of the preallocation increases by the power of two for each success in sequence.
The first successful prediction leads to an additional page being allocated. Second successful prediction leads to 2 additional pages being allocated. Third to 4 pages and so on. The max order is 3 by default. In a large continous allocation the number of faults is reduced by a factor of 8.
The patch may be combined with the page fault scalability patch (another edition of the patch is needed which will be forthcoming after the page fault scalability patch has been included). The combined patches will triple the possible page fault rate from ~1 mio faults sec to 3 mio faults sec.
Standard Kernel on a 512 Cpu machine allocating 32GB with an increasing number of threads (and thus increasing parallellism of page faults):
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.416s 138.165s 139.050s 45073.831 45097.498 32 3 2 1.397s 148.523s 78.044s 41965.149 80201.646 32 3 4 1.390s 152.618s 44.044s 40851.258 141545.239 32 3 8 1.500s 374.008s 53.001s 16754.519 118671.950 32 3 16 1.415s 1051.759s 73.094s 5973.803 85087.358 32 3 32 1.867s 3400.417s 117.003s 1849.186 53754.928 32 3 64 5.361s 11633.040s 197.034s 540.577 31881.112 32 3 128 23.387s 39386.390s 332.055s 159.642 18918.599 32 3 256 15.409s 20031.450s 168.095s 313.837 37237.918 32 3 512 18.720s 10338.511s 86.047s 607.446 72752.686
Patched kernel:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.098s 138.544s 139.063s 45053.657 45057.920 32 3 2 1.022s 127.770s 67.086s 48849.350 92707.085 32 3 4 0.995s 119.666s 37.045s 52141.503 167955.292 32 3 8 0.928s 87.400s 18.034s 71227.407 342934.242 32 3 16 1.067s 72.943s 11.035s 85007.293 553989.377 32 3 32 1.248s 133.753s 10.038s 46602.680 606062.151 32 3 64 5.557s 438.634s 13.093s 14163.802 451418.617 32 3 128 17.860s 1496.797s 19.048s 4153.714 322808.509 32 3 256 13.382s 766.063s 10.016s 8071.695 618816.838 32 3 512 17.067s 369.106s 5.041s 16291.764 1161285.521
These number are roughly equal to what can be accomplished with the page fault scalability patches.
Kernel patches with both the page fault scalability patches and prefaulting:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 10 1 4.103s 456.384s 460.046s 45541.992 45544.369 32 10 2 4.005s 415.119s 221.095s 50036.407 94484.174 32 10 4 3.855s 371.317s 111.076s 55898.259 187635.724 32 10 8 3.902s 308.673s 67.094s 67092.476 308634.397 32 10 16 4.011s 224.213s 37.016s 91889.781 564241.062 32 10 32 5.483s 209.391s 27.046s 97598.647 763495.417 32 10 64 19.166s 219.925s 26.030s 87713.212 797286.395 32 10 128 53.482s 342.342s 27.024s 52981.744 769687.791 32 10 256 67.334s 180.321s 15.036s 84679.911 1364614.334 32 10 512 66.516s 93.098s 9.015s131387.893 2291548.865
The fault rate doubles when both patches are applied.
And on the high end (512 processors allocating 256G) (No numbers for regular kernels because they are extremely slow, also no number for a low number of threads. Also very slow)
With prefaulting:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
256 3 4 8.241s 1414.348s 449.016s 35380.301 112056.239 256 3 8 8.306s 1300.982s 247.025s 38441.977 203559.271 256 3 16 8.368s 1223.853s 154.089s 40846.272 324940.924 256 3 32 8.536s 1284.041s 110.097s 38938.970 453556.624 256 3 64 13.025s 3587.203s 110.010s 13980.123 457131.492 256 3 128 25.025s 11460.700s 145.071s 4382.104 345404.909 256 3 256 26.150s 6061.649s 75.086s 8267.625 663414.482 256 3 512 20.637s 3037.097s 38.062s 16460.435 1302993.019
Page fault scalability patch and prefaulting. Max prefault order increased to 5 (max preallocation of 32 pages):
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
256 10 8 33.571s 4516.293s 863.021s 36874.099 194356.930 256 10 16 33.103s 3737.688s 461.028s 44492.553 363704.484 256 10 32 35.094s 3436.561s 321.080s 48326.262 521352.840 256 10 64 46.675s 2899.997s 245.020s 56936.124 684214.256 256 10 128 85.493s 2890.198s 203.008s 56380.890 826122.524 256 10 256 74.299s 1374.973s 99.088s115762.963 1679630.272 256 10 512 62.760s 706.559s 53.027s218078.311 3149273.714
We are getting into an almost linear scalability in the high end with both patches and end up with a fault rate > 3 mio faults per second.
The one thing that takes up a lot of time is still be the zeroing of pages in the page fault handler. There is a another set of patches that I am working on which will prezero pages and led to another an increase in performance by a factor of 2-4 (if prezeroed pages are available which may not always be the case). Maybe we can reach 10 mio fault /sec that way.
Patch against 2.6.10-rc3-bk3:
Index: linux-2.6.9/include/linux/sched.h
=================================--- linux-2.6.9.orig/include/linux/sched.h 2004-12-01 10:37:31.000000000 -0800
+++ linux-2.6.9/include/linux/sched.h 2004-12-01 10:38:15.000000000 -0800
@@ -537,6 +537,8 @@
#endif
struct list_head tasks;
+ unsigned long anon_fault_next_addr; /* Predicted sequential fault address */
+ int anon_fault_order; /* Last order of allocation on fault */
/*
* ptrace_list/ptrace_children forms the list of my children
* that were stolen by a ptracer.
Index: linux-2.6.9/mm/memory.c
=================================--- linux-2.6.9.orig/mm/memory.c 2004-12-01 10:38:11.000000000 -0800
+++ linux-2.6.9/mm/memory.c 2004-12-01 10:45:01.000000000 -0800
@@ -55,6 +55,7 @@
#include <linux/swapops.h>
#include <linux/elf.h>
+#include <linux/pagevec.h>
#ifndef CONFIG_DISCONTIGMEM
/* use the per-pgdat data instead for discontigmem - mbligh */
@@ -1432,8 +1433,106 @@
unsigned long addr)
{
pte_t entry;
- struct page * page = ZERO_PAGE(addr);
+ struct page * page;
+
+ addr &= PAGE_MASK;
+
+ if (current->anon_fault_next_addr = addr) {
+ unsigned long end_addr;
+ int order = current->anon_fault_order;
+
+ /* Sequence of page faults detected. Perform preallocation of pages */
+ /* The order of preallocations increases with each successful prediction */
+ order++;
+
+ if ((1 << order) < PAGEVEC_SIZE)
+ end_addr = addr + (1 << (order + PAGE_SHIFT));
+ else
+ end_addr = addr + PAGEVEC_SIZE * PAGE_SIZE;
+
+ if (end_addr > vma->vm_end)
+ end_addr = vma->vm_end;
+ if ((addr & PMD_MASK) != (end_addr & PMD_MASK))
+ end_addr &= PMD_MASK;
+
+ current->anon_fault_next_addr = end_addr;
+ current->anon_fault_order = order;
+
+ if (write_access) {
+
+ struct pagevec pv;
+ unsigned long a;
+ struct page **p;
+
+ pte_unmap(page_table);
+ spin_unlock(&mm->page_table_lock);
+
+ pagevec_init(&pv, 0);
+
+ if (unlikely(anon_vma_prepare(vma)))
+ return VM_FAULT_OOM;
+
+ /* Allocate the necessary pages */
+ for(a = addr;a < end_addr ; a += PAGE_SIZE) {
+ struct page *p = alloc_page_vma(GFP_HIGHUSER, vma, a);
+
+ if (p) {
+ clear_user_highpage(p, a);
+ pagevec_add(&pv,p);
+ } else
+ break;
+ }
+ end_addr = a;
+
+ spin_lock(&mm->page_table_lock);
+
+ for(p = pv.pages; addr < end_addr; addr += PAGE_SIZE, p++) {
+
+ page_table = pte_offset_map(pmd, addr);
+ if (!pte_none(*page_table)) {
+ /* Someone else got there first */
+ page_cache_release(*p);
+ pte_unmap(page_table);
+ continue;
+ }
+
+ entry = maybe_mkwrite(pte_mkdirty(mk_pte(*p,
+ vma->vm_page_prot)),
+ vma);
+
+ mm->rss++;
+ lru_cache_add_active(*p);
+ mark_page_accessed(*p);
+ page_add_anon_rmap(*p, vma, addr);
+
+ set_pte(page_table, entry);
+ pte_unmap(page_table);
+
+ /* No need to invalidate - it was non-present before */
+ update_mmu_cache(vma, addr, entry);
+ }
+ } else {
+ /* Read */
+ for(;addr < end_addr; addr += PAGE_SIZE) {
+ page_table = pte_offset_map(pmd, addr);
+ entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot));
+ set_pte(page_table, entry);
+ pte_unmap(page_table);
+
+ /* No need to invalidate - it was non-present before */
+ update_mmu_cache(vma, addr, entry);
+
+ };
+ }
+ spin_unlock(&mm->page_table_lock);
+ return VM_FAULT_MINOR;
+ }
+
+ current->anon_fault_next_addr = addr + PAGE_SIZE;
+ current->anon_fault_order = 0;
+
+ page = ZERO_PAGE(addr);
/* Read-only mapping of ZERO_PAGE. */
entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot));
Re: Anticipatory prefaulting in the page fault handler V1
Quoted 12 lines · Christoph Lameter
Page fault scalability patch and prefaulting. Max prefault order increased to 5 (max preallocation of 32 pages):
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
256 10 8 33.571s 4516.293s 863.021s 36874.099 194356.930 256 10 16 33.103s 3737.688s 461.028s 44492.553 363704.484 256 10 32 35.094s 3436.561s 321.080s 48326.262 521352.840 256 10 64 46.675s 2899.997s 245.020s 56936.124 684214.256 256 10 128 85.493s 2890.198s 203.008s 56380.890 826122.524 256 10 256 74.299s 1374.973s 99.088s115762.963 1679630.272 256 10 512 62.760s 706.559s 53.027s218078.311 3149273.714
Quoted 2 lines
We are getting into an almost linear scalability in the high end with both patches and end up with a fault rate > 3 mio faults per second.
Nice results! Any idea how many applications benefit from this sort of anticipatory faulting? It has implications for NUMA allocation. Imagine an app that allocates a large virtual address space and then tries to fault in pages near each CPU in turn. With this patch applied, CPU 2 would be referencing pages near CPU 1, and CPU 3 would then fault in 4 pages, which would then be used by CPUs 4-6. Unless I'm missing something...
And again, I'm not sure how important that is, maybe this approach will work well in the majority of cases (obviously it's a big win in faults/sec for your benchmark, but I wonder about subsequent references from other CPUs to those pages). You can look at /sys/devices/platform/nodeN/meminfo to see where the pages are coming from.
Jesse
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Christoph LameterQuoted 4 lines · Christoph Lameter
The page fault handler for anonymous pages can generate significant overhead apart from its essential function which is to clear and setup a new page table entry for a never accessed memory location. This overhead increases significantly in an SMP environment.
do_anonymous_page() is a relatively compact function at this point. This would probably be a lot more readable if it was broken out into at least another function or two that do_anonymous_page() calls into. That way, you also get a much cleaner separation if anyone needs to turn it off in the future.
Speaking of that, have you seen this impair performance on any other workloads?
-- Dave
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Jesse BarnesQuoted 6 lines · Jesse Barnes
Nice results! Any idea how many applications benefit from this sort of anticipatory faulting? It has implications for NUMA allocation. Imagine an app that allocates a large virtual address space and then tries to fault in pages near each CPU in turn. With this patch applied, CPU 2 would be referencing pages near CPU 1, and CPU 3 would then fault in 4 pages, which would then be used by CPUs 4-6. Unless I'm missing something...
Faults are predicted for each thread executing on a different processor. So each processor does its own predictions which will not generate preallocations on a different processor (unless the thread is moved to another processor but that is a very special situation).
Quoted 5 lines
And again, I'm not sure how important that is, maybe this approach will work well in the majority of cases (obviously it's a big win in faults/sec for your benchmark, but I wonder about subsequent references from other CPUs to those pages). You can look at
/sys/devices/platform/nodeN/meminfoto see where the pages are coming from.
The origin of the pages has not changed and the existing locality constraints are observed.
A patch like this is important for applications that allocate and preset large amounts of memory on startup. It will drastically reduce the startup times.
Re: Anticipatory prefaulting in the page fault handler V1
Quoted 7 lines · Christoph Lameter
Quoted 6 lines
And again, I'm not sure how important that is, maybe this approach will work well in the majority of cases (obviously it's a big win in faults/sec for your benchmark, but I wonder about subsequent references from other CPUs to those pages). You can look at
/sys/devices/platform/nodeN/meminfoto see where the pages are coming from.
Quoted 6 lines
The origin of the pages has not changed and the existing locality constraints are observed.
A patch like this is important for applications that allocate and preset large amounts of memory on startup. It will drastically reduce the startup times.
Ok, that sounds good. My case was probably a bit contrived, but I'm glad to see that you had already thought of it anyway.
Jesse
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Christoph LameterQuoted 31 lines
The page fault handler for anonymous pages can generate significant overhead apart from its essential function which is to clear and setup a new page table entry for a never accessed memory location. This overhead increases significantly in an SMP environment.
In the page table scalability patches, we addressed the issue by changing the locking scheme so that multiple fault handlers are able to be processed concurrently on multiple cpus. This patch attempts to aggregate multiple page faults into a single one. It does that by noting
anonymous page faults generated in sequence by an application.If a fault occurred for page x and is then followed by page x+1 then it may be reasonable to expect another page fault at x+2 in the future. If page table entries for x+1 and x+2 would be prepared in the fault handling for page x+1 then the overhead of taking a fault for x+2 is avoided. However page x+2 may never be used and thus we may have increased the rss of an application unnecessarily. The swapper will take care of removing that page if memory should get tight.
The following patch makes the anonymous fault handler anticipate future faults. For each fault a prediction is made where the fault would occur (assuming linear acccess by the application). If the prediction turns out to be right (next fault is where expected) then a number of pages is preallocated in order to avoid a series of future faults. The order of the preallocation increases by the power of two for each success in sequence.
The first successful prediction leads to an additional page being allocated. Second successful prediction leads to 2 additional pages being allocated. Third to 4 pages and so on. The max order is 3 by default. In a large continous allocation the number of faults is reduced by a factor of 8.
Quoted 8 lines
The patch may be combined with the page fault scalability patch (another edition of the patch is needed which will be forthcoming after the page fault scalability patch has been included). The combined patches will triple the possible page fault rate from ~1 mio faults sec to 3 mio faults sec.
Standard Kernel on a 512 Cpu machine allocating 32GB with an increasing number of threads (and thus increasing parallellism of page faults):
Mmmm ... we tried doing this before for filebacked pages by sniffing the pagecache, but it crippled forky workloads (like kernel compile) with the extra cost in zap_pte_range, etc.
Perhaps the locality is better for the anon stuff, but the cost is also higher. Exactly what benchmark were you running on this? If you just run a microbenchmark that allocates memory, then it will definitely be faster. On other things, I suspect not ...
M.
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Christoph LameterQuoted 3 lines · On Wed, 8 Dec 2004 09:56:00 -0800 (PST) Christoph Lameter <[email protected]>…
A patch like this is important for applications that allocate and preset large amounts of memory on startup. It will drastically reduce the startup times.
I see. Yet I noticed that while the patch makes system time decrease, for some reason the wall time is increasing with the patch applied. Why is that, or am I misreading your tables?
Re: Anticipatory prefaulting in the page fault handler V1
Quoted 4 lines · David S. Miller
I see. Yet I noticed that while the patch makes system time decrease, for some reason the wall time is increasing with the patch applied. Why is that, or am I misreading your tables?
I assume that you're looking at the final "both patches applied" case.
It has ten repetitions, while the other two tables only have three. That would explain the discrepancy.
Linus
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Christoph LameterQuoted 11 lines
The page fault handler for anonymous pages can generate significant overhead apart from its essential function which is to clear and setup a new page table entry for a never accessed memory location. This overhead increases significantly in an SMP environment.
In the page table scalability patches, we addressed the issue by changing the locking scheme so that multiple fault handlers are able to be processed concurrently on multiple cpus. This patch attempts to aggregate multiple page faults into a single one. It does that by noting
anonymous page faults generated in sequence by an application.
Quoted 7 lines
If a fault occurred for page x and is then followed by page x+1 then it may be reasonable to expect another page fault at x+2 in the future. If page table entries for x+1 and x+2 would be prepared in the fault handling for page x+1 then the overhead of taking a fault for x+2 is avoided. However page x+2 may never be used and thus we may have increased the rss of an application unnecessarily. The swapper will take care of removing that page if memory should get tight.
I tried benchmarking it ... but processes just segfault all the time. Any chance you could try it out on SMP ia32 system?
M.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Christoph LameterQuoted 4 lines · Christoph Lameter
Changes from
V11->V12of this patch:
- dumpsloppy_rssin favor oflist_rss(Linus' proposal)
- keep up against current Linus tree (patch is based on 2.6.10-rc2-bk14)
[snip]
Quoted 3 lines
For more than 8 cpus the page fault rate increases by orders of magnitude. For more than 64 cpus the improvement in performace is 10 times better.
Those numbers are pretty impressive. I thought you'd said with earlier patches that performance was about doubled from 8 to 512 CPUS. Did I remember correctly? If so, where is the improvement coming from? The per-thread RSS I guess?
On another note, these patches are basically only helpful to new anonymous page faults. I guess this is the main thing you are concerned about at the moment, but I wonder if you would see improvements with my patch to remove the ptl from the other types of faults as well?
The downside of my patch - well the main downsides - compared to yours are its intrusiveness, and the extra cost involved in copy_page_range which yours appears not to require.
As I've said earlier though, I wouldn't mind your patches going in. At least they should probably get into -mm soon, when Andrew has time (and after the 4level patches are sorted out). That wouldn't stop my patch (possibly) being merged some time after that if and when it was found worthy...
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Christoph LameterHi!
Quoted 5 lines
Standard Kernel on a 512 Cpu machine allocating 32GB with an increasing number of threads (and thus increasing parallellism of page faults):
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.416s 138.165s 139.050s 45073.831 45097.498
...
Quoted 4 lines
Patched kernel:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.098s 138.544s 139.063s 45053.657 45057.920
...
Quoted 8 lines
These number are roughly equal to what can be accomplished with the page fault scalability patches.
Kernel patches with both the page fault scalability patches and prefaulting:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 10 1 4.103s 456.384s 460.046s 45541.992 45544.369
...
Quoted 2 lines
The fault rate doubles when both patches are applied.
...
Quoted 2 lines
We are getting into an almost linear scalability in the high end with both patches and end up with a fault rate > 3 mio faults per second.
Well, with both patches you also slow single-threaded case more than twice. What are the effects of this patch on UP system?
Pavel
Signature · 2 lines
People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!
Re: Anticipatory prefaulting in the page fault handler V1
Quoted 31 lines · Pavel Machek
Hi!
Quoted 5 lines
Standard Kernel on a 512 Cpu machine allocating 32GB with an increasing number of threads (and thus increasing parallellism of page faults):
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.416s 138.165s 139.050s 45073.831 45097.498...
Quoted 4 lines
Patched kernel:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.098s 138.544s 139.063s 45053.657 45057.920...
Quoted 8 lines
These number are roughly equal to what can be accomplished with the page fault scalability patches.
Kernel patches with both the page fault scalability patches and prefaulting:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 10 1 4.103s 456.384s 460.046s 45541.992 45544.369...
Quoted 1 line
The fault rate doubles when both patches are applied.
Quoted 8 lines
...
Quoted 2 lines
We are getting into an almost linear scalability in the high end with both patches and end up with a fault rate > 3 mio faults per second.
Well, with both patches you also slow single-threaded case more than twice. What are the effects of this patch on UP system?
fault/wsec is the important number.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Nick PigginQuoted 8 lines · Nick Piggin
Quoted 3 lines
For more than 8 cpus the page fault rate increases by orders of magnitude. For more than 64 cpus the improvement in performace is 10 times better.
Those numbers are pretty impressive. I thought you'd said with earlier patches that performance was about doubled from 8 to 512 CPUS. Did I remember correctly? If so, where is the improvement coming from? The per-thread RSS I guess?
Right. The per-thread RSS seems to have made a big difference for high CPU counts. Also I was conservative in the estimates in earlier post since I did not have the numbers for the very high cpu counts.
Quoted 4 lines
On another note, these patches are basically only helpful to new anonymous page faults. I guess this is the main thing you are concerned about at the moment, but I wonder if you would see improvements with my patch to remove the ptl from the other types of faults as well?
I can try that but I am frankly a bit sceptical since the ptl protects many other variables. It may be more efficient to have the ptl in these cases than doing the atomic ops all over the place. Do you have any number you could post? I believe I send you a copy of the code that I use for performance tests last week or so,
Quoted 3 lines
The downside of my patch - well the main downsides - compared to yours are its intrusiveness, and the extra cost involved in
copy_page_rangewhich yours appears not to require.
Is the patch known to be okay for ia64? I can try to see how it does.
Quoted 5 lines
As I've said earlier though, I wouldn't mind your patches going in. At least they should probably get into -mm soon, when Andrew has time (and after the 4level patches are sorted out). That wouldn't stop my patch (possibly) being merged some time after that if and when it was found worthy...
I'd certainly be willing to poke around and see how beneficial this is. If it turns out to accellerate other functionality of the vm then you have my full support.
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Pavel MachekQuoted 23 lines · Pavel Machek
Hi!
Quoted 5 lines
Standard Kernel on a 512 Cpu machine allocating 32GB with an increasing number of threads (and thus increasing parallellism of page faults):
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.416s 138.165s 139.050s 45073.831 45097.498...
Quoted 4 lines
Patched kernel:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.098s 138.544s 139.063s 45053.657 45057.920...
Quoted 8 lines
These number are roughly equal to what can be accomplished with the page fault scalability patches.
Kernel patches with both the page fault scalability patches and prefaulting:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 10 1 4.103s 456.384s 460.046s 45541.992 45544.369...
Quoted 1 line
Quoted 7 lines
Quoted 1 line
The fault rate doubles when both patches are applied.
...
Quoted 2 lines
We are getting into an almost linear scalability in the high end with both patches and end up with a fault rate > 3 mio faults per second.
Well, with both patches you also slow single-threaded case more than twice. What are the effects of this patch on UP system?
The faults per second are slightly increased, so its faster. The last numbers are 10 repetitions and not 3. Do not look at the wall time.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Christoph LameterQuoted 9 lines · Christoph Lameter
Changes from
V11->V12of this patch:
- dumpsloppy_rssin favor oflist_rss(Linus' proposal)
- keep up against current Linus tree (patch is based on 2.6.10-rc2-bk14)This is a series of patches that increases the scalability of the page fault handler for SMP. Here are some performance results on a machine with 512 processors allocating 32 GB with an increasing number of threads (that are assigned a processor each).
Your V12 patches would apply well to 2.6.10-rc3, except that (as noted before) your mailer or whatever is eating trailing whitespace: trivial patch attached to apply before yours, removing that whitespace so yours apply. But what your patches need to apply to would be 2.6.10-mm.
Your i386 HIGHMEM64G 3level ptep_cmpxchg forgets to use cmpxchg8b, would have tested out okay up to 4GB but not above: trivial patch attached.
Your scalability figures show a superb improvement. But they are (I presume) for the best case: intense initial faulting of distinct areas of anonymous memory by parallel cpus running a multithreaded process. This is not a common case: how much do what real-world apps benefit?
Since you also avoid taking the page_table_lock in handle_pte_fault, there should be some scalability benefit to all kinds of page fault:
do you have any results to show how much (perhaps hard to quantify, since even tmpfs file faults introduce other scalability issues)?
How do the scalability figures compare if you omit patch 7/7 i.e. revert the per-task rss complications you added in for Linus? I remain a fan of sloppy rss, which you earlier showed to be accurate enough (I'd say), though I guess should be checked on other architectures than your ia64. I can't see the point of all that added ugliness for numbers which don't need to be precise - but perhaps there's no way of rearranging fields, and the point at which mm->(anon_)rss is updated (near up of mmap_sem?), to avoid destructive cacheline bounce. What I'm asking is, do you have numbers to support 7/7? Perhaps it's the fact you showed up to 512 cpus this time, but only up to 32 with sloppy rss? The ratios do look better with the latest, but the numbers are altogether lower so we don't know.
The split rss patch, if it stays, needs some work. For example, task_statm uses "get_shared" to total up rss-anon_rss from the tasks, but assumes mm->rss is already accurate. Scrap the separate get_rss, get_anon_rss, get_shared functions: just one get_rss to make a single pass through the tasks adding up both rss and anon_rss at the same time.
I am bothered that every read of /proc/<pid>/status or /proc/<pid>/statm is going to reread through all of that task_list each time; yet in that massively parallel case that concerns you, there should be little change to rss after startup. Perhaps a later optimization would be to avoid task_list completely for singly threaded processes. I'd like get_rss to update mm->rss and mm->anon_rss and flag it uptodate to avoid subsequent task_list iterations, but the locking might defeat your whole purpose.
Updating current->rss in do_anonymous_page, current->anon_rss in page_add_anon_rmap, is not always correct: ptrace's access_process_vm uses get_user_pages on another task. You need check that current->mm == mm (or vma->vm_mm) before incrementing current->rss or current->anon_rss, fall back to mm (or vma->vm_mm) in rare case not (taking page_table_lock for that). You'll also need to check !(current->flags & PF_BORROWED_MM), to guard against use_mm. Or... just go back to sloppy rss.
Moving to the main patch, 1/7, the major issue I see there is the way do_anonymous_page does update_mmu_cache after setting the pte, without any page_table_lock to bracket them together. Obviously no problem on architectures where update_mmu_cache is a no-op! But although there's been plenty of discussion, particularly with Ben and Nick, I've not noticed anything to guarantee that as safe on all architectures. I do think it's fine for you to post your patches before completing hooks in all the arches, but isn't this a significant issue which needs to be sorted before your patches go into -mm? You hazily refer to such issues in 0/7, but now you need to work with arch maintainers to settle them and show the patches.
A lesser issue with the reordering in do_anonymous_page: don't you need to move the lru_cache_add_active after the page_add_anon_rmap, to avoid the very slight chance that vmscan will pick the page off the LRU and unmap it before you've counted it in, hitting page_remove_rmap's BUG_ON(page_mapcount(page) < 0)?
(I do wonder why do_anonymous_page calls mark_page_accessed as well as lru_cache_add_active. The other instances of lru_cache_add_active for an anonymous page don't mark_page_accessed i.e. SetPageReferenced too, why here? But that's nothing new with your patch, and although you've reordered the calls, the final page state is the same as before.)
Where handle_pte_fault does "entry = *pte" without page_table_lock:
you're quite right to passing down precisely that entry to the fault handlers below, but there's still a problem on the 32bit architectures supporting 64bit ptes (i386, mips, ppc), that the upper and lower ints of entry may be out of synch. Not a problem for do_anonymous_page, or anything else relying on ptep_cmpxchg to check; but a problem for do_wp_page (which could find !pfn_valid and kill the process) and probably others (harder to think through). Your 4/7 patch for i386 has an unused atomic get_64bit function from Nick, I think you'll have to define a get_pte_atomic macro and use get_64bit in its 64-on-32 cases.
Hmm, that will only work if you're using atomic set_64bit rather than relying on page_table_lock in the complementary places which matter. Which I believe you are indeed doing in your 3level set_pte. Shouldn't __set_64bit be using LOCK_PREFIX like __get_64bit, instead of lock?
But by making every set_pte use set_64bit, you are significantly slowing down many operations which do not need that atomicity. This is quite visible in the fork/exec/shell results from lmbench on i386 PAE (and is the only interesting difference, for good or bad, that I noticed with your patches in lmbench on 2*HT*P4), which run 5-20% slower. There are no faults on dst mm (nor on src mm) while copy_page_range is copying, so its set_ptes don't need to be atomic; likewise during zap_pte_range (either mmap_sem is held exclusively, or it's in the final exit_mmap). Probably revert set_pte and set_pte_atomic to what they were, and use set_pte_atomic where it's needed.
Hugh
include/asm-i386/system.h +2 -2
@@ -273,9 +273,9 @@ static inline unsigned long __cmpxchg(vo#define cmpxchg (ptr,o,n)\ ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\ (unsigned long)(n),sizeof(*(ptr)))) - + #ifdef __KERNEL__ -struct alt_instr { +struct alt_instr { __u8 *instr; /* original instruction */ __u8 *replacement; __u8 cpuid; /* cpuid bit set for replacement */
include/asm-s390/pgalloc.h +1 -1
@@ -99,7 +99,7 @@ static inline void pgd_populate(struct m#endif /* __s390x__ */ -static inline void +static inline void pmd_populate_kernel (struct mm_struct *mm,pmd_t *pmd,pte_t *pte) {#ifndef __s390x__
mm/memory.c +2 -2
@@ -1424,7 +1424,7 @@ out:/* * We are called with the MM semaphore and page_table_lock * spinlock held to protect against concurrent faults in -* multithreaded programs. +* multithreaded programs. */ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
@@ -1615,7 +1615,7 @@ static int do_file_page(struct mm_struct* Fall back to the linear mapping if the fs does not support * ->populate: */ -if (!vma->vm_ops || !vma->vm_ops->populate || +if (!vma->vm_ops || !vma->vm_ops->populate || (write_access && !(vma->vm_flags &VM_SHARED ))) {pte_clear (pte);return do_no_page (mm, vma, address, write_access, pte, pmd);
include/asm-i386/pgtable-3level.h +1 -1
@@ -147,7 +147,7 @@ static inline pmd_t pfn_pmd(unsigned lonstatic inline int ptep_cmpxchg (struct vm_area_struct *vma,unsigned long address,pte_t *ptep,pte_t oldval,pte_t newval) { -return cmpxchg ((unsigned int *)ptep,pte_val (oldval),pte_val (newval)) ==pte_val (oldval); +return cmpxchg8b ((unsigned long long *)ptep,pte_val (oldval),pte_val (newval)) ==pte_val (oldval); }
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Martin J. BlighQuoted 2 lines · Martin J. Bligh
I tried benchmarking it ... but processes just segfault all the time. Any chance you could try it out on SMP ia32 system?
I tried it on my i386 system and it works fine. Sorry about the puny memory sizes (the system is a PIII-450 with 384k memory)
clameter@schroedinger:~/pfault/code$ ./pft -t -b256000 -r3 -f1 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 0 3 1 0.000s 0.004s 0.000s 37407.481 29200.500 0 3 2 0.002s 0.002s 0.000s 31177.059 27227.723
clameter@schroedinger:~/pfault/code$ uname -a Linux schroedinger 2.6.10-rc3-bk3-prezero #8 SMP Wed Dec 8 15:22:28 PST 2004 i686 GNU/Linux
Could you send me your .config?
page fault scalability patch V12: rss tasklist vs sloppy rss
In reply to Hugh DickinsQuoted 11 lines · Hugh Dickins
How do the scalability figures compare if you omit patch 7/7 i.e. revert the per-task rss complications you added in for Linus? I remain a fan of sloppy rss, which you earlier showed to be accurate enough (I'd say), though I guess should be checked on other architectures than your ia64. I can't see the point of all that added ugliness for numbers which don't need to be precise - but perhaps there's no way of rearranging fields, and the point at which mm->(anon_)rss is updated (near up of
mmap_sem?), to avoid destructive cacheline bounce. What I'm asking is, do you have numbers to support 7/7? Perhaps it's the fact you showed up to 512 cpus this time, but only up to 32 with sloppy rss? The ratios do look better with the latest, but the numbers are altogether lower so we don't know.
Here is a full set of numbers for sloppy and tasklist. The sloppy version is 2.6.9-rc2-bk14 with the prefault patch also applied and the tasklist version is 2.6.9-rc2-bk12 w/o prefault (you can get the numbers of 2.6.9-rc2-bk12 w prefault in the post titled "anticipatory prefaulting in the page fault handler")). Even with this handicap tasklist is still slightly better! I would expect tasklist to increase in importance for combination patches which increase the fault rate even more. The tasklist is likely to be unavoidable once I get the prezeroing patch debugged and integrated which should at least give us a peak pulse performance for page faults > 5 mio faults /sec.
I was not also able to get the high numbers of > 3 mio faults with atomic rss + prefaulting but was able to get that with tasklist + prefault. The atomic version shares the locality problems with the sloppy approach.
sloppy (2.6.10-bk14-rss-sloppy-prefault):
Gb Rep Threads User System Wall flt/cpu/s fault/wsec 1 10 1 0.040s 6.505s 6.054s100117.616 100072.760 1 10 2 0.041s 7.394s 4.005s 88138.739 161535.358 1 10 4 0.049s 7.863s 2.049s 82819.743 262839.190 1 10 8 0.093s 8.657s 1.077s 74889.898 369606.184 1 10 16 0.621s 13.278s 1.076s 47150.165 371506.561 1 10 32 3.154s 35.337s 2.029s 17025.784 285469.956 1 10 64 11.602s 77.548s 2.086s 7351.089 228908.831 1 10 128 41.999s 217.106s 4.030s 2529.316 152087.458 1 10 256 40.482s 106.627s 3.022s 4454.885 203363.548 1 10 512 63.673s 61.361s 3.040s 5241.403 192528.941 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 4 10 1 0.176s 41.276s 41.045s 63238.628 63237.008 4 10 2 0.154s 31.074s 16.095s 83943.753 154606.489 4 10 4 0.193s 31.886s 9.096s 81715.471 263190.941 4 10 8 0.210s 33.577s 6.061s 77584.707 396402.083 4 10 16 0.473s 52.997s 6.036s 49025.701 411640.587 4 10 32 3.331s 142.296s 7.093s 18000.934 330197.326 4 10 64 10.820s 318.485s 8.088s 7960.503 295042.520 4 10 128 56.012s 928.004s 12.037s 2664.019 211812.600 4 10 256 46.197s 464.579s 7.026s 5132.263 360940.189 4 10 512 57.396s 225.876s 4.081s 9254.125 544185.485 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 16 10 1 0.948s 221.167s 222.009s 47208.624 47212.786 16 10 2 0.824s 205.021s 110.022s 50939.876 95134.456 16 10 4 0.689s 168.670s 53.055s 61914.226 195802.740 16 10 8 0.683s 137.278s 27.034s 76004.706 383471.968 16 10 16 0.969s 216.288s 24.031s 48264.109 431329.422 16 10 32 3.932s 587.987s 30.002s 17714.820 349219.905 16 10 64 13.542s 1253.834s 32.051s 8273.588 322528.516 16 10 128 54.197s 3161.896s 38.064s 3260.403 271357.849 16 10 256 57.610s 1668.913s 21.038s 6073.335 490410.386 16 10 512 36.721s 833.691s 11.069s 12046.872 896970.623 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 32 10 1 2.080s 470.722s 472.075s 44355.728 44360.409 32 10 2 1.836s 456.343s 242.088s 45771.267 86344.100 32 10 4 1.671s 432.569s 131.065s 48294.609 159291.360 32 10 8 1.457s 354.825s 71.027s 58862.070 294242.410 32 10 16 1.660s 431.057s 48.038s 48464.636 433466.055 32 10 32 3.639s 1190.388s 59.040s 17563.676 353012.708 32 10 64 14.623s 2490.393s 63.040s 8371.808 330750.309 32 10 128 68.481s 6415.265s 76.053s 3234.476 274023.655 32 10 256 63.428s 3216.337s 39.044s 6394.212 531665.931 32 10 512 50.693s 1644.307s 21.035s 12372.572 982183.559 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 64 10 1 4.457s 1021.948s1026.030s 40863.994 40868.119 64 10 2 3.929s 994.825s 525.030s 41995.308 79844.658 64 10 4 3.661s 931.523s 269.014s 44849.990 155838.443 64 10 8 3.355s 858.565s 153.098s 48662.260 272381.402 64 10 16 3.130s 904.485s 101.090s 46212.285 411581.778 64 10 32 5.007s 2366.494s 116.079s 17686.275 359107.203 64 10 64 17.472s 5195.222s 126.012s 8046.325 332545.646 64 10 128 65.249s 12515.845s 147.053s 3333.815 284290.928 64 10 256 61.328s 6706.566s 78.061s 6197.354 533523.711 64 10 512 60.656s 3201.068s 39.095s 12859.162 1049637.054 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 128 10 8 7.481s 1875.297s 318.049s 44554.389 263386.340 128 10 16 7.128s 2048.919s 230.060s 40799.672 363757.736 128 10 32 9.584s 4758.868s 241.094s 17591.883 346711.571 128 10 64 17.955s 10135.674s 249.025s 8261.684 336547.279 128 10 128 66.939s 25006.914s 287.019s 3345.560 292086.404 128 10 256 62.454s 12892.242s 149.035s 6475.341 561653.696 128 10 512 59.082s 6456.965s 77.002s 12873.768 1089026.647 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 256 10 8 17.201s 4672.781s 860.094s 35772.446 194870.225 256 10 16 16.641s 5071.433s 588.076s 32973.603 284954.772 256 10 32 17.745s 9193.335s 478.005s 18214.166 350950.045 256 10 64 25.474s 20440.137s 510.037s 8197.759 328725.189 256 10 128 65.451s 50015.195s 572.044s 3350.040 293079.914 256 10 256 61.296s 25191.675s 290.084s 6643.660 576852.282 256 10 512 58.911s 12589.530s 149.012s 13264.255 1125015.367
tasklist (2.6.10-rc2-bk12-rss-tasklist):
Gb Rep Threads User System Wall flt/cpu/s fault/wsec 1 3 1 0.045s 2.042s 2.009s 94121.837 94039.902 1 3 2 0.053s 2.217s 1.022s 86554.869 160093.661 1 3 4 0.036s 2.325s 0.074s 83261.622 265213.249 1 3 8 0.065s 2.507s 0.053s 76404.784 370587.422 1 3 16 0.168s 4.727s 0.057s 40152.877 341385.368 1 3 32 0.829s 11.408s 0.070s 16066.277 280690.973 1 3 64 4.324s 25.591s 0.093s 6571.995 209956.473 1 3 128 19.370s 81.568s 1.055s 1947.799 126774.712 1 3 256 13.042s 46.608s 1.009s 3295.950 179708.774 1 3 512 19.410s 28.085s 0.092s 4139.454 211823.959 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 4 3 1 0.161s 12.698s 12.086s 61156.292 61149.853 4 3 2 0.152s 10.469s 5.073s 74037.518 137039.041 4 3 4 0.179s 9.401s 2.098s 82081.949 263750.289 4 3 8 0.156s 10.194s 1.098s 75979.430 395361.526 4 3 16 0.407s 18.084s 2.010s 42527.778 373673.111 4 3 32 0.824s 44.316s 2.031s 17421.815 339975.566 4 3 64 4.706s 96.587s 2.066s 7763.856 295588.217 4 3 128 17.453s 259.672s 3.053s 2837.813 222395.530 4 3 256 17.090s 136.816s 2.017s 5109.777 361440.098 4 3 512 13.466s 78.242s 1.043s 8575.295 548859.306 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 16 3 1 0.678s 61.548s 62.023s 50551.998 50544.748 16 3 2 0.691s 63.381s 34.027s 49095.790 91791.474 16 3 4 0.663s 52.083s 16.086s 59639.041 186542.124 16 3 8 0.585s 43.339s 9.031s 71614.583 337721.897 16 3 16 0.744s 75.174s 8.003s 41435.328 391278.035 16 3 32 1.713s 171.942s 8.086s 18114.674 354760.887 16 3 64 4.720s 366.803s 9.055s 8467.079 329273.168 16 3 128 22.637s 849.059s 10.093s 3608.741 287572.764 16 3 256 15.849s 472.565s 6.009s 6440.683 515916.601 16 3 512 15.479s 245.305s 3.046s 12062.521 909147.611 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 32 3 1 1.451s 140.151s 141.060s 44430.367 44428.115 32 3 2 1.399s 136.349s 73.041s 45673.303 85699.793 32 3 4 1.321s 129.760s 39.027s 47996.303 160197.217 32 3 8 1.279s 100.648s 20.039s 61724.641 308454.557 32 3 16 1.414s 153.975s 15.090s 40488.236 395681.716 32 3 32 2.534s 337.021s 17.016s 18528.487 366445.400 32 3 64 4.271s 709.872s 18.057s 8809.787 338656.440 32 3 128 18.734s 1805.094s 21.084s 3449.586 288005.644 32 3 256 14.698s 963.787s 11.078s 6429.787 534077.540 32 3 512 15.299s 453.990s 5.098s 13406.321 1050416.414 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 64 3 1 3.018s 301.014s 304.004s 41386.617 41384.901 64 3 2 2.941s 296.780s 157.005s 41981.967 80116.179 64 3 4 2.810s 280.803s 82.047s 44366.266 152575.551 64 3 8 2.763s 268.745s 48.099s 46344.377 256813.576 64 3 16 2.764s 332.029s 34.030s 37584.030 366744.317 64 3 32 3.337s 704.321s 34.074s 17781.025 362195.710 64 3 64 7.395s 1475.497s 36.078s 8485.379 342026.888 64 3 128 22.227s 3188.934s 40.044s 3918.492 311115.971 64 3 256 18.004s 1834.246s 21.093s 6793.308 573753.797 64 3 512 19.367s 861.324s 10.099s 14287.531 1144168.224
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
128 3 4 5.857s 626.055s 189.010s 39824.798 133076.331 128 3 8 5.837s 592.587s 107.080s 42053.423 233443.791 128 3 16 5.852s 666.252s 71.008s 37443.301 354011.649 128 3 32 6.305s 1365.184s 69.075s 18349.259 360755.364 128 3 64 8.450s 2914.730s 72.046s 8609.057 347288.474 128 3 128 21.188s 6719.590s 79.078s 3733.370 315402.750 128 3 256 18.263s 3672.379s 43.049s 6818.817 578587.427 128 3 512 17.625s 1901.969s 22.082s 13109.967 1102629.479
128 3 256 24.035s 3392.117s 40.074s 7366.714 617628.607 128 3 512 17.000s 1820.242s 21.072s 13697.601 1158632.106
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
256 3 4 11.976s 1660.924s 514.023s 30086.443 97877.018 256 3 8 11.618s 1301.448s 223.063s 38331.361 225057.902 256 3 16 11.696s 1409.158s 148.074s 35423.488 338379.838 256 3 32 12.678s 2668.417s 140.042s 18772.788 358421.926 256 3 64 15.933s 5833.804s 145.068s 8604.085 345487.685 256 3 128 32.640s 13437.080s 159.079s 3736.651 314981.569 256 3 256 23.875s 6835.241s 81.007s 7337.919 620777.397 256 3 512 17.566s 3392.148s 41.003s 14761.249 1226507.319
256 3 256 21.314s 6648.629s 79.085s 7546.038 630270.726 256 3 512 15.994s 3400.378s 40.087s 14732.481 1231399.906
Re: page fault scalability patch V12: rss tasklist vs sloppy rss
Quoted 15 lines · Christoph Lameter
Quoted 11 lines · Hugh Dickins
How do the scalability figures compare if you omit patch 7/7 i.e. revert the per-task rss complications you added in for Linus? I remain a fan of sloppy rss, which you earlier showed to be accurate enough (I'd say), though I guess should be checked on other architectures than your ia64. I can't see the point of all that added ugliness for numbers which don't need to be precise - but perhaps there's no way of rearranging fields, and the point at which mm->(anon_)rss is updated (near up of
mmap_sem?), to avoid destructive cacheline bounce. What I'm asking is, do you have numbers to support 7/7? Perhaps it's the fact you showed up to 512 cpus this time, but only up to 32 with sloppy rss? The ratios do look better with the latest, but the numbers are altogether lower so we don't know.
Quoted 1 line
Here is a full set of numbers for sloppy and tasklist.
Yes, but that only tests the thing-which-you're-trying-to-improve. We also need to work out the impact of that tasklist walk on other people's worst cases.
Quoted 1 line
sloppy (2.6.10-bk14-rss-sloppy-prefault):
It would be helpful if you could generate a breif summary of benchmarking results as well as dumping the raw numbers, please.
Re: page fault scalability patch V12: rss tasklist vs sloppy rss
In reply to Christoph LameterQuoted 3 lines · Christoph Lameter
I was not also able to get the high numbers of > 3 mio faults with atomic rss + prefaulting but was able to get that with tasklist + prefault. The atomic version shares the locality problems with the sloppy approach.
The implementation of the atomic version at least improperly places the counter's cacheline, so the results for that are gibberish.
Unless the algorithms being compared are properly implemented, they're straw men, not valid comparisons.
-- wli
Re: page fault scalability patch V12: rss tasklist vs sloppy rss
Quoted 2 lines · William Lee Irwin III
Unless the algorithms being compared are properly implemented, they're straw men, not valid comparisons.
Sloppy rss left the rss in the section of mm that contained the counters. So that has a separate cacheline. The idea of putting the atomic ops in a group was to only have one exclusive cacheline for mmap_sem and the rss. Which could lead to more bouncing of a single cache line rather than bouncing multiple cache lines less. But it seems to me that the problem essentially remains the same if the rss counter is not split.
Re: page fault scalability patch V12: rss tasklist vs sloppy rss
Quoted 6 lines · Christoph Lameter
Sloppy rss left the rss in the section of mm that contained the counters. So that has a separate cacheline. The idea of putting the atomic ops in a group was to only have one exclusive cacheline for
mmap_semand the rss. Which could lead to more bouncing of a single cache line rather than bouncing multiple cache lines less. But it seems to me that the problem essentially remains the same if the rss counter is not split.
The prior results Robin Holt cited were that the counter needed to be in a different cacheline from the ->mmap_sem and ->page_table_lock. We shouldn't need to evaluate splitting for the atomic RSS algorithm.
A faithful implementation would just move the atomic counters away from the ->mmap_sem and ->page_table_lock (just shuffle some mm fields). Obviously a complete set of results won't be needed unless it's very surprisingly competitive with the stronger algorithms. Things should be fine just making sure that behaves similarly to the one with the shared cacheline with ->mmap_sem in the sense of having a curve of similar shape on smaller systems. The absolute difference probably doesn't matter, but there is something to prove, and the largest risk of not doing so is exaggerating the low-end performance benefits of stronger algorithms.
-- wli
Re: page fault scalability patch V12: rss tasklist vs sloppy rss
Quoted 11 lines · William Lee Irwin III
Quoted 6 lines · Christoph Lameter
Sloppy rss left the rss in the section of mm that contained the counters. So that has a separate cacheline. The idea of putting the atomic ops in a group was to only have one exclusive cacheline for
mmap_semand the rss. Which could lead to more bouncing of a single cache line rather than bouncing multiple cache lines less. But it seems to me that the problem essentially remains the same if the rss counter is not split.The prior results Robin Holt cited were that the counter needed to be in a different cacheline from the ->mmap_sem and ->page_table_lock. We shouldn't need to evaluate splitting for the atomic RSS algorithm.
Ok. Then we would need rss and rss_anon on two additional cache lines? Both rss and anon_rss on one line? mmap_sem and the page_table_lock also each on different cache lines?
Quoted 9 lines
A faithful implementation would just move the atomic counters away from the ->mmap_sem and ->page_table_lock (just shuffle some mm fields). Obviously a complete set of results won't be needed unless it's very surprisingly competitive with the stronger algorithms. Things should be fine just making sure that behaves similarly to the one with the shared cacheline with ->mmap_sem in the sense of having a curve of similar shape on smaller systems. The absolute difference probably doesn't matter, but there is something to prove, and the largest risk of not doing so is exaggerating the low-end performance benefits of stronger algorithms.
The advantage in the split rss solution is that it can be placed on the same cacheline as other stuff from task that is already needed. So there is minimal overhead involved. But I can certainly give it a spin and see what the results are.
[OT:HUMOR] Re: Anticipatory prefaulting in the page fault handler V1
In reply to Christoph LameterQuoted 7 lines · Christoph Lameter
Quoted 2 lines · Martin J. Bligh
I tried benchmarking it ... but processes just segfault all the time. Any chance you could try it out on SMP ia32 system?
I tried it on my i386 system and it works fine. Sorry about the puny memory sizes (the system is a PIII-450 with 384k memory)
You probably get such fast numbers, because I mean, how many pages can 384k of memory have? I only figure 96 total pages.
Quoted 8 lines
clameter@schroedinger:~/pfault/code$ ./pft -t -b256000 -r3 -f1 Gb Rep Threads User System Wall flt/cpu/s fault/wsec 0 3 1 0.000s 0.004s 0.000s 37407.481 29200.500 0 3 2 0.002s 0.002s 0.000s 31177.059 27227.723clameter@schroedinger:~/pfault/code$ uname -a Linux schroedinger 2.6.10-rc3-bk3-prezero #8 SMP Wed Dec 8 15:22:28 PST 2004 i686 GNU/Linux
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Hugh DickinsQuoted 12 lines · Hugh Dickins
Quoted 8 lines · Christoph Lameter
Changes from
V11->V12of this patch:
- dumpsloppy_rssin favor oflist_rss(Linus' proposal)
- keep up against current Linus tree (patch is based on 2.6.10-rc2-bk14)This is a series of patches that increases the scalability of the page fault handler for SMP. Here are some performance results on a machine with 512 processors allocating 32 GB with an increasing number of threads (that are assigned a processor each).
Quoted 8 lines
Your V12 patches would apply well to 2.6.10-rc3, except that (as noted before) your mailer or whatever is eating trailing whitespace: trivial patch attached to apply before yours, removing that whitespace so yours apply. But what your patches need to apply to would be 2.6.10-mm.
Your i386 HIGHMEM64G 3level
ptep_cmpxchgforgets to use cmpxchg8b, would have tested out okay up to 4GB but not above: trivial patch attached.
That looks obviously correct. Probably the reason why Martin was getting crashes.
[snip]
Quoted 12 lines
Moving to the main patch, 1/7, the major issue I see there is the way
do_anonymous_pagedoesupdate_mmu_cacheafter setting the pte, without anypage_table_lockto bracket them together. Obviously no problem on architectures whereupdate_mmu_cacheis a no-op! But although there's been plenty of discussion, particularly with Ben and Nick, I've not noticed anything to guarantee that as safe on all architectures. I do think it's fine for you to post your patches before completing hooks in all the arches, but isn't this a significant issue which needs to be sorted before your patches go into -mm? You hazily refer to such issues in 0/7, but now you need to work with arch maintainers to settle them and show the patches.
Yep, the update_mmu_cache issue is real. There is a parallel problem that is update_mmu_cache can be called on a pte who's page has since been evicted and reused. Again, that looks safe on IA64, but maybe not on other architectures.
It can be solved by moving lru_cache_add to after update_mmu_cache in all cases but the "update accessed bit" type fault. I solved that by simply defining that out for architectures that don't need it - a raced fault will simply get repeated if need be.
Quoted 6 lines
A lesser issue with the reordering in
do_anonymous_page: don't you need to move thelru_cache_add_activeafter thepage_add_anon_rmap, to avoid the very slight chance that vmscan will pick the page off the LRU and unmap it before you've counted it in, hitting page_remove_rmap'sBUG_ON(page_mapcount(page) < 0)?
That's what I had been doing too. Seems to be the right way to go.
Quoted 6 lines
(I do wonder why
do_anonymous_pagecallsmark_page_accessedas well aslru_cache_add_active. The other instances oflru_cache_add_activefor an anonymous page don'tmark_page_accessedi.e. SetPageReferenced too, why here? But that's nothing new with your patch, and although you've reordered the calls, the final page state is the same as before.)
Quoted 11 lines
Where
handle_pte_faultdoes "entry = *pte" withoutpage_table_lock:
you're quite right to passing down precisely that entry to the fault handlers below, but there's still a problem on the 32bit architectures supporting 64bit ptes (i386, mips, ppc), that the upper and lower ints of entry may be out of synch. Not a problem fordo_anonymous_page, or anything else relying onptep_cmpxchgto check; but a problem fordo_wp_page(which could find !pfn_valid and kill the process) and probably others (harder to think through). Your 4/7 patch for i386 has an unused atomicget_64bitfunction from Nick, I think you'll have to define aget_pte_atomicmacro and useget_64bitin its 64-on-32 cases.
Indeed. This was a real problem for my patch, definitely.
Quoted 5 lines
Hmm, that will only work if you're using atomic
set_64bitrather than relying onpage_table_lockin the complementary places which matter. Which I believe you are indeed doing in your 3levelset_pte. Shouldn't__set_64bitbe usingLOCK_PREFIXlike__get_64bit, instead of lock?
That's what I was wondering. It could be that the actual 64-bit store is still atomic without the lock prefix (just not the entire rmw), which I think would be sufficient.
In that case, get_64bit may be able to drop the lock prefix as well.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Christoph LameterQuoted 13 lines · Christoph Lameter
Quoted 8 lines · Nick Piggin
Quoted 3 lines
For more than 8 cpus the page fault rate increases by orders of magnitude. For more than 64 cpus the improvement in performace is 10 times better.
Those numbers are pretty impressive. I thought you'd said with earlier patches that performance was about doubled from 8 to 512 CPUS. Did I remember correctly? If so, where is the improvement coming from? The per-thread RSS I guess?
Quoted 4 lines
Right. The per-thread RSS seems to have made a big difference for high CPU counts. Also I was conservative in the estimates in earlier post since I did not have the numbers for the very high cpu counts.
Ah OK.
Quoted 7 lines
Quoted 5 lines
On another note, these patches are basically only helpful to new anonymous page faults. I guess this is the main thing you are concerned about at the moment, but I wonder if you would see improvements with my patch to remove the ptl from the other types of faults as well?
Quoted 6 lines
I can try that but I am frankly a bit sceptical since the ptl protects many other variables. It may be more efficient to have the ptl in these cases than doing the atomic ops all over the place. Do you have any number you could post? I believe I send you a copy of the code that I use for performance tests last week or so,
Yep I have your test program. No real numbers because the biggest thing I have to test on is a 4-way - there is improvement, but it is not so impressive as your 512 way tests! :)
Quoted 9 lines
Quoted 4 lines
The downside of my patch - well the main downsides - compared to yours are its intrusiveness, and the extra cost involved in
copy_page_rangewhich yours appears not to require.Is the patch known to be okay for ia64? I can try to see how it does.
I think it just needs one small fix to the swapping code, and it should be pretty stable. So in fact it would probably work for you as is (if you don't swap), but I'd rather have something more stable before I ask you to test. I'll try to find time to do that in the next few days.
Quoted 8 lines
Quoted 6 lines
As I've said earlier though, I wouldn't mind your patches going in. At least they should probably get into -mm soon, when Andrew has time (and after the 4level patches are sorted out). That wouldn't stop my patch (possibly) being merged some time after that if and when it was found worthy...
Quoted 4 lines
I'd certainly be willing to poke around and see how beneficial this is. If it turns out to accellerate other functionality of the vm then you have my full support.
Great, thanks.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Nick PigginQuoted 10 lines · Nick Piggin
Yep, the
update_mmu_cacheissue is real. There is a parallel problem that isupdate_mmu_cachecan be called on a pte who's page has since been evicted and reused. Again, that looks safe on IA64, but maybe not on other architectures.It can be solved by moving
lru_cache_addto afterupdate_mmu_cachein all cases but the "update accessed bit" type fault. I solved that by simply defining that out for architectures that don't need it - a raced fault will simply get repeated if need be.
The page-freed-before-update_mmu_cache issue can be solved in that way, not the set_pte and update_mmu_cache not performed under the same ptl section issue that you raised.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 13 lines · Nick Piggin
Quoted 10 lines · Nick Piggin
Yep, the
update_mmu_cacheissue is real. There is a parallel problem that isupdate_mmu_cachecan be called on a pte who's page has since been evicted and reused. Again, that looks safe on IA64, but maybe not on other architectures.It can be solved by moving
lru_cache_addto afterupdate_mmu_cachein all cases but the "update accessed bit" type fault. I solved that by simply defining that out for architectures that don't need it - a raced fault will simply get repeated if need be.
Quoted 3 lines
The page-freed-before-update_mmu_cache issue can be solved in that way, not the
set_pteandupdate_mmu_cachenot performed under the same ptl section issue that you raised.
What is the problem with update_mmu_cache ? It doesn't need to be done in the same lock section since it's approx. equivalent to a HW fault, which doesn't take the ptl...
Ben.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 2 lines · Nick Piggin
Nick Piggin wrote:
Quoted 9 lines
Quoted 3 lines
The page-freed-before-update_mmu_cache issue can be solved in that way, not the
set_pteandupdate_mmu_cachenot performed under the same ptl section issue that you raised.What is the problem with
update_mmu_cache? It doesn't need to be done in the same lock section since it's approx. equivalent to a HW fault, which doesn't take the ptl...
I don't think a problem has been observed, I think Hugh was just raising it as a general issue.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 7 lines · Nick Piggin
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Nick Piggin
The page-freed-before-update_mmu_cache issue can be solved in that way, not the
set_pteandupdate_mmu_cachenot performed under the same ptl section issue that you raised.
Quoted 6 lines
Quoted 3 lines
What is the problem with
update_mmu_cache? It doesn't need to be done in the same lock section since it's approx. equivalent to a HW fault, which doesn't take the ptl...I don't think a problem has been observed, I think Hugh was just raising it as a general issue.
That's right, I know little of the arches on which update_mmu_cache does something, so cannot say that separation is a problem. And I did see mail from Ben a month ago in which he arrived at the conclusion that it's not a problem - but assumed he was speaking for ppc and ppc64. (He was also writing in the context of your patches rather than Christoph's.)
Perhaps Ben has in mind a logical argument that if update_mmu_cache does just what its name implies, then doing it under a separate acquisition of page_table_lock cannot introduce incorrectness on any architecture. Maybe, but I'd still rather we heard that from an expert in each of the affected architectures.
As it stands in Christoph's patches, update_mmu_cache is sometimes called inside page_table_lock and sometimes outside: I'd be surprised if that doesn't require adjustment for some architecture.
Your idea to raise do_anonymous_page's update_mmu_cache before the lru_cache_add_active sounds just right; perhaps it should then even be subsumed into the architectural ptep_cmpxchg. But once we get this far, I do wonder again whether it's right to be changing the rules in do_anonymous_page alone (Christoph's patches) rather than all the other faults together (your patches).
But there's no doubt that the do_anonymous_page case is easier, or more obviously easy, to deal with - it helps a lot to know that the page cannot yet be exposed to vmscan.c and rmap.c.
Hugh
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Hugh DickinsThank you for the thorough review of my patches. Comments below
Quoted 4 lines · Hugh Dickins
Your V12 patches would apply well to 2.6.10-rc3, except that (as noted before) your mailer or whatever is eating trailing whitespace: trivial patch attached to apply before yours, removing that whitespace so yours apply. But what your patches need to apply to would be 2.6.10-mm.
I am still mystified as to why this is an issue at all. The patches apply just fine to the kernel sources as is. I have patched kernels numerous times with this patchset and never ran into any issue. quilt removes trailing whitespace from patches when they are generated as far as I can tell.
Patches will be made against mm after Nick's modifications to the 4 level patches are in.
Quoted 2 lines
Your i386 HIGHMEM64G 3level
ptep_cmpxchgforgets to use cmpxchg8b, would have tested out okay up to 4GB but not above: trivial patch attached.
Thanks for the patch.
Quoted 4 lines
Your scalability figures show a superb improvement. But they are (I presume) for the best case: intense initial faulting of distinct areas of anonymous memory by parallel cpus running a multithreaded process. This is not a common case: how much do what real-world apps benefit?
This is common during the startup of distributed applications on our large machines. They seem to freeze for minutes on bootup. I am not sure how much real-world apps benefit. The numbers show that the benefit would mostly be for SMP applications. UP has only very minor improvements.
Quoted 4 lines
Since you also avoid taking the
page_table_lockinhandle_pte_fault, there should be some scalability benefit to all kinds of page fault:
do you have any results to show how much (perhaps hard to quantify, since even tmpfs file faults introduce other scalability issues)?
I have not done such tests (yet).
Quoted 5 lines
The split rss patch, if it stays, needs some work. For example,
task_statmuses "get_shared" to total up rss-anon_rss from the tasks, but assumesmm->rssis already accurate. Scrap the separateget_rss,get_anon_rss,get_sharedfunctions: just oneget_rssto make a single pass through the tasks adding up both rss andanon_rssat the same time.
Next rev will have that.
Quoted 7 lines
Updating
current->rssindo_anonymous_page,current->anon_rssinpage_add_anon_rmap, is not always correct: ptrace'saccess_process_vmusesget_user_pageson another task. You need check thatcurrent->mm= mm (orvma->vm_mm) before incrementingcurrent->rssorcurrent->anon_rss, fall back to mm (orvma->vm_mm) in rare case not (takingpage_table_lockfor that). You'll also need to check !(current->flags &PF_BORROWED_MM), to guard againstuse_mm. Or... just go back to sloppy rss.
I will look into this issue.
Quoted 11 lines
Moving to the main patch, 1/7, the major issue I see there is the way
do_anonymous_pagedoesupdate_mmu_cacheafter setting the pte, without anypage_table_lockto bracket them together. Obviously no problem on architectures whereupdate_mmu_cacheis a no-op! But although there's been plenty of discussion, particularly with Ben and Nick, I've not noticed anything to guarantee that as safe on all architectures. I do think it's fine for you to post your patches before completing hooks in all the arches, but isn't this a significant issue which needs to be sorted before your patches go into -mm? You hazily refer to such issues in 0/7, but now you need to work with arch maintainers to settle them and show the patches.
I have worked with a couple of arches and received feedback that was integrated. I certainly welcome more feedback. A vague idea if there is more trouble on that front: One could take the ptl in the cmpxchg emulation and then unlock on update_mmu cache.
Quoted 5 lines
A lesser issue with the reordering in
do_anonymous_page: don't you need to move thelru_cache_add_activeafter thepage_add_anon_rmap, to avoid the very slight chance that vmscan will pick the page off the LRU and unmap it before you've counted it in, hitting page_remove_rmap'sBUG_ON(page_mapcount(page) < 0)?
Changed.
Quoted 5 lines
(I do wonder why
do_anonymous_pagecallsmark_page_accessedas well aslru_cache_add_active. The other instances oflru_cache_add_activefor an anonymous page don'tmark_page_accessedi.e. SetPageReferenced too, why here? But that's nothing new with your patch, and although you've reordered the calls, the final page state is the same as before.)
The mark_page_accessed is likely there avoid a future fault just to set the accessed bit.
Quoted 10 lines
Where
handle_pte_faultdoes "entry = *pte" withoutpage_table_lock:
you're quite right to passing down precisely that entry to the fault handlers below, but there's still a problem on the 32bit architectures supporting 64bit ptes (i386, mips, ppc), that the upper and lower ints of entry may be out of synch. Not a problem fordo_anonymous_page, or anything else relying onptep_cmpxchgto check; but a problem fordo_wp_page(which could find !pfn_valid and kill the process) and probably others (harder to think through). Your 4/7 patch for i386 has an unused atomicget_64bitfunction from Nick, I think you'll have to define aget_pte_atomicmacro and useget_64bitin its 64-on-32 cases.
That would be a performance issue.
Quoted 5 lines
Hmm, that will only work if you're using atomic
set_64bitrather than relying onpage_table_lockin the complementary places which matter. Which I believe you are indeed doing in your 3levelset_pte. Shouldn't__set_64bitbe usingLOCK_PREFIXlike__get_64bit, instead of lock?
Quoted 10 lines
But by making every
set_pteuseset_64bit, you are significantly slowing down many operations which do not need that atomicity. This is quite visible in the fork/exec/shell results from lmbench on i386 PAE (and is the only interesting difference, for good or bad, that I noticed with your patches in lmbench on 2*HT*P4), which run 5-20% slower. There are no faults on dst mm (nor on src mm) whilecopy_page_rangeis copying, so itsset_ptesdon't need to be atomic; likewise duringzap_pte_range(eithermmap_semis held exclusively, or it's in the finalexit_mmap). Probably revertset_pteandset_pte_atomicto what they were, and useset_pte_atomicwhere it's needed.
Good suggestions. Will see what I can do but I will need some assistence my main platform is ia64 and the hardware and opportunities for testing on i386 are limited.
Again thanks for the detailed review.
Re: pfault V12 : correction to tasklist rss
In reply to Hugh DickinsQuoted 7 lines · Hugh Dickins
Updating
current->rssindo_anonymous_page,current->anon_rssinpage_add_anon_rmap, is not always correct: ptrace'saccess_process_vmusesget_user_pageson another task. You need check thatcurrent->mm= mm (orvma->vm_mm) before incrementingcurrent->rssorcurrent->anon_rss, fall back to mm (orvma->vm_mm) in rare case not (takingpage_table_lockfor that). You'll also need to check !(current->flags &PF_BORROWED_MM), to guard againstuse_mm. Or... just go back to sloppy rss.
Use_mm can simply attach the kernel thread to the mm via mm_add_thread and will then update mm->rss when being detached again.
The issue with ptrace and get_user_pages is a bit thorny. I did the check for mm = current->mm in the following patch. If mm != current->mm then do the sloppy thing and increment mm->rss without the page table lock. This should be a very special rare case.
One could also set current to the target task in get_user_pages but then faults for the actual current task may increment the wrong counters. Could we live with that?
Or simply leave as is. The pages are after all allocated by the ptrace process and it should be held responsible for it.
My favorite rss solution is still just getting rid of rss and anon_rss and do the long loops in procfs. Whichever process wants to know better be willing to pay the price in cpu time and the code for incrementing rss can be removed from the page fault handler.
We have no real way of establishing the ownership of shared pages anyways. Its counted when allocated. But the page may live on afterwards in another process and then not be accounted for although its only user is the new process. IMHO vm scans may be the only way of really getting an accurate count.
But here is the improved list_rss patch:
Index: linux-2.6.9/include/linux/sched.h
=================================--- linux-2.6.9.orig/include/linux/sched.h 2004-12-06 17:23:55.000000000 -0800
+++ linux-2.6.9/include/linux/sched.h 2004-12-10 11:39:00.000000000 -0800
@@ -30,6 +30,7 @@
#include <linux/pid.h>
#include <linux/percpu.h>
#include <linux/topology.h>
+#include <linux/rcupdate.h>
struct exec_domain;
@@ -217,6 +218,7 @@
int map_count; /* number of VMAs */
struct rw_semaphore mmap_sem;
spinlock_t page_table_lock; /* Protects page tables, mm->rss, mm->anon_rss */
+ long rss, anon_rss;
struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung
* together off init_mm.mmlist, and are protected
@@ -226,7 +228,7 @@
unsigned long start_code, end_code, start_data, end_data;
unsigned long start_brk, brk, start_stack;
unsigned long arg_start, arg_end, env_start, env_end;
- unsigned long rss, anon_rss, total_vm, locked_vm, shared_vm;
+ unsigned long total_vm, locked_vm, shared_vm;
unsigned long exec_vm, stack_vm, reserved_vm, def_flags, nr_ptes;
unsigned long saved_auxv[42]; /* for /proc/PID/auxv */
@@ -236,6 +238,8 @@
/* Architecture-specific MM context */
mm_context_t context;
+ struct list_head task_list; /* Tasks using this mm */
+ struct rcu_head rcu_head; /* For freeing mm via rcu */
/* Token based thrashing protection. */
unsigned long swap_token_time;
@@ -545,6 +549,9 @@
struct list_head ptrace_list;
struct mm_struct *mm, *active_mm;
+ /* Split counters from mm */
+ long rss;
+ long anon_rss;
/* task state */
struct linux_binfmt *binfmt;
@@ -578,6 +585,9 @@
struct completion *vfork_done; /* for vfork() */
int __user *set_child_tid; /* CLONE_CHILD_SETTID */
int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
+
+ /* List of other tasks using the same mm */
+ struct list_head mm_tasks;
unsigned long rt_priority;
unsigned long it_real_value, it_prof_value, it_virt_value;
@@ -1124,6 +1134,12 @@
#endif
+void get_rss(struct mm_struct *mm, unsigned long *rss, unsigned long *anon_rss); +
+void mm_remove_thread(struct mm_struct *mm, struct task_struct *tsk); +void mm_add_thread(struct mm_struct *mm, struct task_struct *tsk); +
#endif /* __KERNEL__ */
#endif
+
Index: linux-2.6.9/fs/proc/task_mmu.c
=================================--- linux-2.6.9.orig/fs/proc/task_mmu.c 2004-12-06 17:23:54.000000000 -0800
+++ linux-2.6.9/fs/proc/task_mmu.c 2004-12-10 11:39:00.000000000 -0800
@@ -6,8 +6,9 @@
char *task_mem(struct mm_struct *mm, char *buffer) {
- unsigned long data, text, lib;
+ unsigned long data, text, lib, rss, anon_rss;
+ get_rss(mm, &rss, &anon_rss);
data = mm->total_vm - mm->shared_vm - mm->stack_vm;
text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10; lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text;
@@ -22,7 +23,7 @@
"VmPTE:\t%8lu kB\n",
(mm->total_vm - mm->reserved_vm) << (PAGE_SHIFT-10), mm->locked_vm << (PAGE_SHIFT-10),
- mm->rss << (PAGE_SHIFT-10),
+ rss << (PAGE_SHIFT-10),
data << (PAGE_SHIFT-10),
mm->stack_vm << (PAGE_SHIFT-10), text, lib, (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
@@ -37,11 +38,14 @@
int task_statm(struct mm_struct *mm, int *shared, int *text,
int *data, int *resident)
{
- *shared = mm->rss - mm->anon_rss;
+ unsigned long rss, anon_rss;
+
+ get_rss(mm, &rss, &anon_rss);
+ *shared = rss - anon_rss;
*text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK))
>> PAGE_SHIFT;
*data = mm->total_vm - mm->shared_vm;
- *resident = mm->rss;
+ *resident = rss;
return mm->total_vm;
}
Index: linux-2.6.9/fs/proc/array.c
=================================--- linux-2.6.9.orig/fs/proc/array.c 2004-12-06 17:23:54.000000000 -0800
+++ linux-2.6.9/fs/proc/array.c 2004-12-10 11:39:00.000000000 -0800
@@ -302,7 +302,7 @@
static int do_task_stat(struct task_struct *task, char * buffer, int whole) {
- unsigned long vsize, eip, esp, wchan = ~0UL;
+ unsigned long rss, anon_rss, vsize, eip, esp, wchan = ~0UL;
long priority, nice;
int tty_pgrp = -1, tty_nr = 0;
sigset_t sigign, sigcatch;
@@ -325,6 +325,7 @@
vsize = task_vsize(mm);
eip = KSTK_EIP(task);
esp = KSTK_ESP(task);
+ get_rss(mm, &rss, &anon_rss);
}
get_task_comm(tcomm, task);
@@ -420,7 +421,7 @@
jiffies_to_clock_t(task->it_real_value), start_time,
vsize,
- mm ? mm->rss : 0, /* you might want to shift this left 3 */
+ mm ? rss : 0, /* you might want to shift this left 3 */
rsslim,
mm ? mm->start_code : 0,
mm ? mm->end_code : 0,
Index: linux-2.6.9/mm/rmap.c
=================================--- linux-2.6.9.orig/mm/rmap.c 2004-12-10 11:11:26.000000000 -0800
+++ linux-2.6.9/mm/rmap.c 2004-12-10 11:46:07.000000000 -0800
@@ -263,8 +263,6 @@
pte_t *pte;
int referenced = 0;
- if (!mm->rss)
- goto out;
address = vma_address(page, vma);
if (address = -EFAULT)
goto out;
@@ -438,7 +436,10 @@
BUG_ON(PageReserved(page));
BUG_ON(!anon_vma);
- vma->vm_mm->anon_rss++;
+ if (current->mm = vma->vm_mm)
+ current->anon_rss++;
+ else
+ vma->vm_mm->anon_rss++;
anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON; index = (address - vma->vm_start) >> PAGE_SHIFT;
@@ -510,8 +511,6 @@
pte_t pteval;
int ret = SWAP_AGAIN;
- if (!mm->rss)
- goto out;
address = vma_address(page, vma);
if (address = -EFAULT)
goto out;
@@ -799,8 +798,7 @@
if (vma->vm_flags & (VM_LOCKED|VM_RESERVED))
continue;
cursor = (unsigned long) vma->vm_private_data;
- while (vma->vm_mm->rss &&
- cursor < max_nl_cursor &&
+ while (cursor < max_nl_cursor &&
cursor < vma->vm_end - vma->vm_start) { try_to_unmap_cluster(cursor, &mapcount, vma); cursor += CLUSTER_SIZE;
Index: linux-2.6.9/kernel/fork.c
=================================--- linux-2.6.9.orig/kernel/fork.c 2004-12-06 17:23:55.000000000 -0800
+++ linux-2.6.9/kernel/fork.c 2004-12-10 11:39:00.000000000 -0800
@@ -151,6 +151,7 @@
*tsk = *orig;
tsk->thread_info = ti;
ti->task = tsk;
+ tsk->rss = 0;
/* One for us, one for whoever does the "release_task()" (usually parent) */ atomic_set(&tsk->usage,2);
@@ -292,6 +293,7 @@
atomic_set(&mm->mm_count, 1);
init_rwsem(&mm->mmap_sem);
INIT_LIST_HEAD(&mm->mmlist);
+ INIT_LIST_HEAD(&mm->task_list);
mm->core_waiters = 0;
mm->nr_ptes = 0;
spin_lock_init(&mm->page_table_lock);
@@ -323,6 +325,13 @@
return mm;
}
+static void rcu_free_mm(struct rcu_head *head)
+{
+ struct mm_struct *mm = container_of(head ,struct mm_struct, rcu_head);
+
+ free_mm(mm);
+}
+
/*
* Called when the last reference to the mm
* is dropped: either by a lazy thread or by
@@ -333,7 +342,7 @@
BUG_ON(mm = &init_mm);
mm_free_pgd(mm);
destroy_context(mm);
- free_mm(mm);
+ call_rcu(&mm->rcu_head, rcu_free_mm);
}
/*
@@ -400,6 +409,8 @@
/* Get rid of any cached register state */ deactivate_mm(tsk, mm);
+ if (mm)
+ mm_remove_thread(mm, tsk);
/* notify parent sleeping on vfork() */
if (vfork_done) {
@@ -447,8 +458,8 @@
* new threads start up in user mode using an mm, which
* allows optimizing out ipis; the tlb_gather_mmu code
* is an example.
+ * (mm_add_thread does use the ptl .... )
*/
- spin_unlock_wait(&oldmm->page_table_lock);
goto good_mm;
}
@@ -470,6 +481,7 @@
goto free_pt;
good_mm:
+ mm_add_thread(mm, tsk);
tsk->mm = mm;
tsk->active_mm = mm;
return 0;
Index: linux-2.6.9/mm/memory.c
=================================--- linux-2.6.9.orig/mm/memory.c 2004-12-10 11:12:44.000000000 -0800
+++ linux-2.6.9/mm/memory.c 2004-12-10 11:45:00.000000000 -0800
@@ -1467,8 +1467,10 @@
*/
page_add_anon_rmap(page, vma, addr); lru_cache_add_active(page);
- mm->rss++;
-
+ if (current->mm = mm)
+ current->rss++;
+ else
+ mm->rss++;
}
pte_unmap(page_table);
@@ -1859,3 +1861,49 @@
}
#endif
+
+void get_rss(struct mm_struct *mm, unsigned long *rss, unsigned long *anon_rss) +{
+ struct list_head *y;
+ struct task_struct *t;
+ long rss_sum, anon_rss_sum;
+
+ rcu_read_lock();
+ rss_sum = mm->rss;
+ anon_rss_sum = mm->anon_rss;
+ list_for_each_rcu(y, &mm->task_list) {
+ t = list_entry(y, struct task_struct, mm_tasks);
+ rss_sum += t->rss;
+ anon_rss_sum += t->anon_rss;
+ }
+ if (rss_sum < 0)
+ rss_sum = 0;
+ if (anon_rss_sum < 0)
+ anon_rss_sum = 0;
+ rcu_read_unlock();
+ *rss = rss_sum;
+ *anon_rss = anon_rss_sum;
+}
+
+void mm_remove_thread(struct mm_struct *mm, struct task_struct *tsk) +{
+ if (!mm)
+ return;
+
+ spin_lock(&mm->page_table_lock);
+ mm->rss += tsk->rss;
+ mm->anon_rss += tsk->anon_rss;
+ list_del_rcu(&tsk->mm_tasks);
+ spin_unlock(&mm->page_table_lock);
+}
+
+void mm_add_thread(struct mm_struct *mm, struct task_struct *tsk) +{
+ spin_lock(&mm->page_table_lock);
+ tsk->rss = 0;
+ tsk->anon_rss = 0;
+ list_add_rcu(&tsk->mm_tasks, &mm->task_list);
+ spin_unlock(&mm->page_table_lock);
+}
+
+
Index: linux-2.6.9/include/linux/init_task.h
=================================--- linux-2.6.9.orig/include/linux/init_task.h 2004-12-06 17:23:55.000000000 -0800
+++ linux-2.6.9/include/linux/init_task.h 2004-12-10 11:39:00.000000000 -0800
@@ -42,6 +42,7 @@
.mmlist = LIST_HEAD_INIT(name.mmlist), \
.cpu_vm_mask = CPU_MASK_ALL, \
.default_kioctx = INIT_KIOCTX(name.default_kioctx, name), \
+ .task_list = LIST_HEAD_INIT(name.task_list), \
}
#define INIT_SIGNALS(sig) { \
@@ -112,6 +113,7 @@
.proc_lock = SPIN_LOCK_UNLOCKED, \
.switch_lock = SPIN_LOCK_UNLOCKED, \
.journal_info = NULL, \
+ .mm_tasks = LIST_HEAD_INIT(tsk.mm_tasks), \
}
Index: linux-2.6.9/fs/exec.c
=================================--- linux-2.6.9.orig/fs/exec.c 2004-12-06 17:23:54.000000000 -0800
+++ linux-2.6.9/fs/exec.c 2004-12-10 11:39:00.000000000 -0800
@@ -543,6 +543,7 @@
active_mm = tsk->active_mm;
tsk->mm = mm;
tsk->active_mm = mm;
+ mm_add_thread(mm, current);
activate_mm(active_mm, mm);
task_unlock(tsk);
arch_pick_mmap_layout(mm);
Index: linux-2.6.9/fs/aio.c
=================================--- linux-2.6.9.orig/fs/aio.c 2004-12-06 17:23:54.000000000 -0800
+++ linux-2.6.9/fs/aio.c 2004-12-10 11:39:00.000000000 -0800
@@ -575,6 +575,7 @@
atomic_inc(&mm->mm_count);
tsk->mm = mm;
tsk->active_mm = mm;
+ mm_add_thread(mm, tsk);
activate_mm(active_mm, mm);
task_unlock(tsk);
@@ -597,6 +598,7 @@
struct task_struct *tsk = current;
task_lock(tsk);
+ mm_remove_thread(mm,tsk);
tsk->flags &= ~PF_BORROWED_MM;
tsk->mm = NULL;
/* active_mm is still 'mm' */
Re: pfault V12 : correction to tasklist rss
Quoted 10 lines · Christoph Lameter
Quoted 7 lines · Hugh Dickins
Updating
current->rssindo_anonymous_page,current->anon_rssinpage_add_anon_rmap, is not always correct: ptrace'saccess_process_vmusesget_user_pageson another task. You need check thatcurrent->mm= mm (orvma->vm_mm) before incrementingcurrent->rssorcurrent->anon_rss, fall back to mm (orvma->vm_mm) in rare case not (takingpage_table_lockfor that). You'll also need to check !(current->flags &PF_BORROWED_MM), to guard againstuse_mm. Or... just go back to sloppy rss.
Quoted 2 lines
Use_mmcan simply attach the kernel thread to the mm viamm_add_threadand will then updatemm->rsswhen being detached again.
True. But please add and remove mm outside of the task_lock, there's no need to nest page_table_lock within it, is there?
Quoted 4 lines
The issue with ptrace and
get_user_pagesis a bit thorny. I did the check for mm =current->mmin the following patch. If mm !=current->mmthen do the sloppy thing and incrementmm->rsswithout the page table lock. This should be a very special rare case.
I don't understand why you want to avoid taking mm->page_table_lock in that special rare case. I do prefer the sloppy rss approach, but if you're trying to be exact then it's regrettable to leave sloppy corners.
Oh, is it because page_add_anon_rmap is usually called with page_table_lock, but without in your do_anonymous_page case? You'll have to move the anon_rss incrementation out of page_add_anon_rmap to its callsites (I was being a little bit lazy when I sited it in that one place, it's probably better to do it near mm->rss anyway.)
Quoted 3 lines
One could also set current to the target task in
get_user_pagesbut then faults for the actual current task may increment the wrong counters. Could we live with that?
No, "current" is not nearly so easy to play with as that. See i386. Even if it were, you might get burnt for heresy.
Quoted 2 lines
Or simply leave as is. The pages are after all allocated by the ptrace process and it should be held responsible for it.
No.
Quoted 4 lines
My favorite rss solution is still just getting rid of rss and
anon_rssand do the long loops in procfs. Whichever process wants to know better be willing to pay the price in cpu time and the code for incrementing rss can be removed from the page fault handler.
We all seem to have different favourites. Your favourite makes quite a few people very angry. We've been there, we've done that, we've no wish to return. It'd be fine if just the process which wants to know paid the price; but it's every other that has to pay.
Quoted 4 lines
We have no real way of establishing the ownership of shared pages anyways. Its counted when allocated. But the page may live on afterwards in another process and then not be accounted for although its only user is the new process.
I didn't understand that bit.
Quoted 3 lines
IMHO vm scans may be the only way of really getting an accurate count.
But here is the improved
list_rsspatch:
Not studied in depth, but... am I going mad, or is your impressive RCUing the wrong way round? While we're scanning the list of tasks sharing the mm, there's no danger of the mm vanishing, but there is a danger of the task vanishing. Isn't it therefore the task which needs to be freed via RCU, not the mm?
Hugh
Re: pfault V12 : correction to tasklist rss
Quoted 7 lines · Hugh Dickins
Quoted 5 lines
We have no real way of establishing the ownership of shared pages anyways. Its counted when allocated. But the page may live on afterwards in another process and then not be accounted for although its only user is the new process.
I didn't understand that bit.
We did lose some accounting accuracy when the pagetable walk and the big tasklist walks were removed. Bill would probably have more details. Given that the code as it stood was a complete showstopper, the tradeoff seemed reasonable.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Christoph LameterQuoted 11 lines · Christoph Lameter
Quoted 4 lines · Hugh Dickins
Your V12 patches would apply well to 2.6.10-rc3, except that (as noted before) your mailer or whatever is eating trailing whitespace: trivial patch attached to apply before yours, removing that whitespace so yours apply. But what your patches need to apply to would be 2.6.10-mm.
I am still mystified as to why this is an issue at all. The patches apply just fine to the kernel sources as is. I have patched kernels numerous times with this patchset and never ran into any issue. quilt removes trailing whitespace from patches when they are generated as far as I can tell.
Perhaps you've only tried applying your original patches, not the ones as received through the mail. It discourages people from trying them when "patch -p1" fails with rejects, however trivial. Or am I alone in seeing this? never had such a problem with other patches before.
Quoted 9 lines
Quoted 4 lines
Your scalability figures show a superb improvement. But they are (I presume) for the best case: intense initial faulting of distinct areas of anonymous memory by parallel cpus running a multithreaded process. This is not a common case: how much do what real-world apps benefit?
This is common during the startup of distributed applications on our large machines. They seem to freeze for minutes on bootup. I am not sure how much real-world apps benefit. The numbers show that the benefit would mostly be for SMP applications. UP has only very minor improvements.
How much do your patches speed the startup of these applications? Can you name them?
Quoted 4 lines
I have worked with a couple of arches and received feedback that was integrated. I certainly welcome more feedback. A vague idea if there is more trouble on that front: One could take the ptl in the cmpxchg emulation and then unlock on
update_mmucache.
Or move the update_mmu_cache into the ptep_cmpxchg emulation perhaps.
Quoted 8 lines
Quoted 5 lines
(I do wonder why
do_anonymous_pagecallsmark_page_accessedas well aslru_cache_add_active. The other instances oflru_cache_add_activefor an anonymous page don'tmark_page_accessedi.e. SetPageReferenced too, why here? But that's nothing new with your patch, and although you've reordered the calls, the final page state is the same as before.)The
mark_page_accessedis likely there avoid a future fault just to set the accessed bit.
No, mark_page_accessed is an operation on the struct page (and the accessed bit of the pte is preset too anyway).
Quoted 11 lines
Quoted 10 lines
Where
handle_pte_faultdoes "entry = *pte" withoutpage_table_lock:
you're quite right to passing down precisely that entry to the fault handlers below, but there's still a problem on the 32bit architectures supporting 64bit ptes (i386, mips, ppc), that the upper and lower ints of entry may be out of synch. Not a problem fordo_anonymous_page, or anything else relying onptep_cmpxchgto check; but a problem fordo_wp_page(which could find !pfn_valid and kill the process) and probably others (harder to think through). Your 4/7 patch for i386 has an unused atomicget_64bitfunction from Nick, I think you'll have to define aget_pte_atomicmacro and useget_64bitin its 64-on-32 cases.
Quoted 1 line
That would be a performance issue.
Sadly, yes, but correctness must take precedence over performance. It may be possible to avoid it in most cases, doing the atomic later when in doubt: but would need careful thought.
Quoted 3 lines
Good suggestions. Will see what I can do but I will need some assistence my main platform is ia64 and the hardware and opportunities for testing on i386 are limited.
There's plenty of us can be trying i386. It's other arches worrying me.
Hugh
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 7 lines · Hugh Dickins
Quoted 7 lines
Quoted 6 lines
(I do wonder why
do_anonymous_pagecallsmark_page_accessedas well aslru_cache_add_active. The other instances oflru_cache_add_activefor an anonymous page don'tmark_page_accessedi.e. SetPageReferenced too, why here? But that's nothing new with your patch, and although you've reordered the calls, the final page state is the same as before.)
Quoted 5 lines
Quoted 2 lines
The
mark_page_accessedis likely there avoid a future fault just to set the accessed bit.No,
mark_page_accessedis an operation on the struct page (and the accessed bit of the pte is preset too anyway).
The point is a good one - I guess that code is a holdover from earlier implementations.
This is equivalent, no?
mm/memory.c renamed from mm/memory.c~do_anonymous_page-use-setpagereferenced +1 -1
@@ -1464,7 +1464,7 @@ do_anonymous_page(struct mm_struct *mm, vma->vm_page_prot)), vma);lru_cache_add_active (page); -mark_page_accessed (page); +SetPageReferenced (page);page_add_anon_rmap (page, vma, addr); }
_
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 8 lines · Andrew Morton
Quoted 6 lines · Hugh Dickins
Quoted 6 lines
Quoted 6 lines
(I do wonder why
do_anonymous_pagecallsmark_page_accessedas well aslru_cache_add_active. The other instances oflru_cache_add_activefor an anonymous page don'tmark_page_accessedi.e. SetPageReferenced too, why here? But that's nothing new with your patch, and although you've reordered the calls, the final page state is the same as before.)
Quoted 4 lines
The point is a good one - I guess that code is a holdover from earlier implementations.
This is equivalent, no?
Yes, it is equivalent to use SetPageReferenced(page) there instead. But why is do_anonymous_page adding anything to lru_cache_add_active, when its other callers leave it at that? What's special about the do_anonymous_page case?
Hugh
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 13 lines · Hugh Dickins
Quoted 11 lines · Andrew Morton
Quoted 6 lines · Hugh Dickins
Quoted 6 lines
Quoted 6 lines
(I do wonder why
do_anonymous_pagecallsmark_page_accessedas well aslru_cache_add_active. The other instances oflru_cache_add_activefor an anonymous page don'tmark_page_accessedi.e. SetPageReferenced too, why here? But that's nothing new with your patch, and although you've reordered the calls, the final page state is the same as before.)The point is a good one - I guess that code is a holdover from earlier implementations.
Quoted 6 lines
Quoted 1 line
This is equivalent, no?
Yes, it is equivalent to use SetPageReferenced(page) there instead. But why is
do_anonymous_pageadding anything tolru_cache_add_active, when its other callers leave it at that? What's special about thedo_anonymous_pagecase?
do_swap_page() is effectively doing the same as do_anonymous_page(). do_wp_page() and do_no_page() appear to be errant.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 7 lines · Andrew Morton
Quoted 3 lines · Hugh Dickins
But why is
do_anonymous_pageadding anything tolru_cache_add_active, when its other callers leave it at that? What's special about thedo_anonymous_pagecase?
do_swap_page()is effectively doing the same asdo_anonymous_page().do_wp_page()anddo_no_page()appear to be errant.
Demur. do_swap_page has to mark_page_accessed because the page from the swap cache is already on the LRU, and for who knows how long. The others (and count in fs/exec.c's install_arg_page) are dealing with a freshly allocated page they are putting onto the active LRU.
My inclination would be simply to remove the mark_page_accessed from do_anonymous_page; but I have no numbers to back that hunch.
Hugh
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 7 lines · Hugh Dickins
Quoted 5 lines · Andrew Morton
Quoted 3 lines · Hugh Dickins
But why is
do_anonymous_pageadding anything tolru_cache_add_active, when its other callers leave it at that? What's special about thedo_anonymous_pagecase?
Quoted 5 lines
Quoted 2 lines
do_swap_page()is effectively doing the same asdo_anonymous_page().do_wp_page()anddo_no_page()appear to be errant.Demur.
do_swap_pagehas tomark_page_accessedbecause the page from the swap cache is already on the LRU, and for who knows how long.
Well. Some of the time. If the page was just read from swap, it's known to be on the active list.
Quoted 6 lines
The others (and count in fs/exec.c's
install_arg_page) are dealing with a freshly allocated page they are putting onto the active LRU.My inclination would be simply to remove the
mark_page_accessedfromdo_anonymous_page; but I have no numbers to back that hunch.
With the current implementation of page_referenced() the software-referenced bit doesn't matter anyway, as long as the pte's referenced bit got set. So as long as the thing is on the active list, we can simply remove the mark_page_accessed() call.
Except one day the VM might get smarter about pages which are both software-referenced and pte-referenced.
Re: pfault V12 : correction to tasklist rss
In reply to Andrew MortonQuoted 4 lines · Hugh Dickins
Quoted 4 lines
Quoted 4 lines
We have no real way of establishing the ownership of shared pages anyways. Its counted when allocated. But the page may live on afterwards in another process and then not be accounted for although its only user is the new process.
Quoted 4 lines · Andrew Morton
We did lose some accounting accuracy when the pagetable walk and the big tasklist walks were removed. Bill would probably have more details. Given that the code as it stood was a complete showstopper, the tradeoff seemed reasonable.
There are several issues, not listed in order of importance here:
(1) Workload monitoring with high multiprogramming levels was infeasible.
(2) The long address space walks interfered with mmap() and page faults in the monitored processes, disturbing cluster membership and exceeding maximum response times in monitored workloads.
(3) There's a general long-running ongoing effort to take on various places tasklist_lock is abused one-by-one to incrementally resolve or otherwise mitigate the rwlock starvation issues.
-- wli
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Andrew MortonQuoted 9 lines · Andrew Morton
Quoted 3 lines · Hugh Dickins
My inclination would be simply to remove the
mark_page_accessedfromdo_anonymous_page; but I have no numbers to back that hunch.With the current implementation of
page_referenced()the software-referenced bit doesn't matter anyway, as long as the pte's referenced bit got set. So as long as the thing is on the active list, we can simply remove themark_page_accessed()call.
Yes, you're right. So we don't need numbers, can just delete that line.
Quoted 2 lines
Except one day the VM might get smarter about pages which are both software-referenced and pte-referenced.
And on that day, we'd be making other changes, which might well involve restoring the mark_page_accessed to do_anonymous_page and adding it in the similar places which currently lack it.
But for now...
mm/memory.c +0 -1
@@ -1464,7 +1464,6 @@ do_anonymous_page(struct mm_struct *mm, vma->vm_page_prot)), vma);lru_cache_add_active (page); -mark_page_accessed (page);page_add_anon_rmap (page, vma, addr); }
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Christoph LameterQuoted 11 lines · Christoph Lameter
Thank you for the thorough review of my patches. Comments below
Quoted 4 lines · Hugh Dickins
Your V12 patches would apply well to 2.6.10-rc3, except that (as noted before) your mailer or whatever is eating trailing whitespace: trivial patch attached to apply before yours, removing that whitespace so yours apply. But what your patches need to apply to would be 2.6.10-mm.
Quoted 8 lines
I am still mystified as to why this is an issue at all. The patches apply just fine to the kernel sources as is. I have patched kernels numerous times with this patchset and never ran into any issue. quilt removes trailing whitespace from patches when they are generated as far as I can tell.
Patches will be made against mm after Nick's modifications to the 4 level patches are in.
I've been a bit slow with them, sorry.... but there hasn't been a hard decision to go one way or the other with the 4level patches yet. Fortunately, it looks like 2.6.10 is having a longish drying out period, so I should have something before it is released.
I would just sit on them for a while, and submit them to -mm when the 4level patches get merged / ready to merge into 2.6. It shouldn't slow down the progress of your patch too much - they'll may have to wait until after 2.6.11 anyway I'd say (probably depends on the progress of other changes going in).
Quoted 8 lines
Quoted 3 lines
probably others (harder to think through). Your 4/7 patch for i386 has an unused atomic
get_64bitfunction from Nick, I think you'll have to define aget_pte_atomicmacro and useget_64bitin its 64-on-32 cases.That would be a performance issue.
Problems were pretty trivial to reproduce here with non atomic 64-bit loads being cut in half by atomic 64 bit stores. I don't see a way around them, unfortunately.
Test case is to run with CONFIG_HIGHMEM (you needn't have > 4 GB of memory in the system, of course), and run 2-4 threads on a dual CPU system, doing parallel faulting of the *same* anonymous pages.
What happens is that the load (entry = *pte) in handle_pte_fault gets cut in half, and handle_pte_fault drops down to do_swap_page, and you get an infinite loop trying to read in a non existant swap entry IIRC.
Quoted 18 lines
Quoted 6 lines
Hmm, that will only work if you're using atomic
set_64bitrather than relying onpage_table_lockin the complementary places which matter. Which I believe you are indeed doing in your 3levelset_pte. Shouldn't__set_64bitbe usingLOCK_PREFIXlike__get_64bit, instead of lock?Quoted 10 lines
But by making every
set_pteuseset_64bit, you are significantly slowing down many operations which do not need that atomicity. This is quite visible in the fork/exec/shell results from lmbench on i386 PAE (and is the only interesting difference, for good or bad, that I noticed with your patches in lmbench on 2*HT*P4), which run 5-20% slower. There are no faults on dst mm (nor on src mm) whilecopy_page_rangeis copying, so itsset_ptesdon't need to be atomic; likewise duringzap_pte_range(eithermmap_semis held exclusively, or it's in the finalexit_mmap). Probably revertset_pteandset_pte_atomicto what they were, and useset_pte_atomicwhere it's needed.
Quoted 4 lines
Good suggestions. Will see what I can do but I will need some assistence my main platform is ia64 and the hardware and opportunities for testing on i386 are limited.
I think I (and/or others) should be able to help with i386 if you are having trouble :)
Nick
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 7 lines · Nick Piggin
Quoted 6 lines · Christoph Lameter
Quoted 3 lines · Hugh Dickins
probably others (harder to think through). Your 4/7 patch for i386 has an unused atomic
get_64bitfunction from Nick, I think you'll have to define aget_pte_atomicmacro and useget_64bitin its 64-on-32 cases.
Quoted 5 lines
Quoted 1 line
That would be a performance issue.
Problems were pretty trivial to reproduce here with non atomic 64-bit loads being cut in half by atomic 64 bit stores. I don't see a way around them, unfortunately.
Of course, it'll only be a performance issue in the 64-on-32 cases:
the 64-on-64 and 32-on-32 macro should reduce to exactly the present "entry = *pte".
I've had the impression that Christoph and SGI have to care a great deal more about ia64 than the others; and as x86_64 advances, so i386 PAE grows less important. Just so long as a get_64bit there isn't a serious degradation from present behaviour, it's okay.
Oh, hold on, isn't handle_mm_fault's pmd without page_table_lock similarly racy, in both the 64-on-32 cases, and on architectures which have a more complex pmd_t (sparc, m68k, h8300)? Sigh.
Hugh
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
Quoted 12 lines · Hugh Dickins
Quoted 10 lines · Nick Piggin
Quoted 7 lines · Christoph Lameter
Quoted 3 lines · Hugh Dickins
probably others (harder to think through). Your 4/7 patch for i386 has an unused atomic
get_64bitfunction from Nick, I think you'll have to define aget_pte_atomicmacro and useget_64bitin its 64-on-32 cases.That would be a performance issue.
Quoted 9 lines
Quoted 3 lines
Problems were pretty trivial to reproduce here with non atomic 64-bit loads being cut in half by atomic 64 bit stores. I don't see a way around them, unfortunately.
Of course, it'll only be a performance issue in the 64-on-32 cases:
the 64-on-64 and 32-on-32 macro should reduce to exactly the present "entry = *pte".
That's right, yep. There is no ordering requirement, only that the actual store and load be atomic.
Quoted 5 lines
I've had the impression that Christoph and SGI have to care a great deal more about ia64 than the others; and as
x86_64advances, so i386 PAE grows less important. Just so long as aget_64bitthere isn't a serious degradation from present behaviour, it's okay.
I don't think it was particularly serious for PAE. Probably not worth holding off until 2.7. We'll see.
Quoted 4 lines
Oh, hold on, isn't handle_mm_fault's pmd without
page_table_locksimilarly racy, in both the 64-on-32 cases, and on architectures which have a more complexpmd_t(sparc, m68k, h8300)? Sigh.
Can't comment on a specific architecture... some may have problems. I think i386 prepopulates pmds, so it is no problem; but generally:
I think you can get away with it if you write the "unimportant" word(s) first, do a wmb(), then write the word containing the present bit. I guess this has to be done this way otherwise the hardware walker will blow up...
Of course, the hardware walker would be doing either atomic or correctly ordered reads, while a plain dereference doesn't guarantee anything.
I'm not sure of the history behind the code, but I would be in favour of making _all_ pagetable access go through accessor functions, even if nobody quite needs them yet.
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to Hugh DickinsQuoted 3 lines · Hugh Dickins
Oh, hold on, isn't handle_mm_fault's pmd without
page_table_locksimilarly racy, in both the 64-on-32 cases, and on architectures which have a more complexpmd_t(sparc, m68k, h8300)? Sigh.
yes.
-- wli
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Christoph LameterQuoted 7 lines · Christoph Lameter
Quoted 2 lines · Martin J. Bligh
I tried benchmarking it ... but processes just segfault all the time. Any chance you could try it out on SMP ia32 system?
I tried it on my i386 system and it works fine. Sorry about the puny memory sizes (the system is a PIII-450 with 384k memory)
I also encountered processes segfault.
Below patch fix several problems.
1) if no pages could allocated, returns VM_FAULT_OOM
2) fix duplicated pte_offset_map() call
3) don't set_pte() for the entry which already have been set
Acutually, 3) fixes my segfault problem.
mm/memory.c renamed from mm/memory.c.orig +12 -1
@@ -1483,6 +1483,8 @@ do_anonymous_page(struct mm_struct *mm, }else break ; } +if (a == addr) + goto no_mem; end_addr = a;spin_lock (&mm->page_table_lock);
@@ -1514,8 +1516,17 @@ do_anonymous_page(struct mm_struct *mm, } }else {/* Read */ +int first =1 ; +for (;addr < end_addr; addr +=PAGE_SIZE ) { - page_table =pte_offset_map (pmd, addr); +if (!first) + page_table =pte_offset_map (pmd, addr); + first =0 ; +if (!pte_none (*page_table)) { +/* Someone else got there first */ +pte_unmap (page_table); +continue ; + } entry =pte_wrprotect (mk_pte (ZERO_PAGE (addr), vma->vm_page_prot));set_pte (page_table, entry);pte_unmap (page_table);
Re: Anticipatory prefaulting in the page fault handler V1
Quoted 5 lines · Akinobu Mita
I also encountered processes segfault.
Below patch fix several problems.1) if no pages could allocated, returns
VM_FAULT_OOM
2) fix duplicatedpte_offset_map()call
I also saw these two issues and I think I dealt with them in a forthcoming patch.
Quoted 1 line
3) don't
set_pte()for the entry which already have been set
Not sure how this could have happened in the patch.
Could you try my updated version:
Index: linux-2.6.9/include/linux/sched.h
=================================--- linux-2.6.9.orig/include/linux/sched.h 2004-12-08 15:01:48.801457702 -0800
+++ linux-2.6.9/include/linux/sched.h 2004-12-08 15:02:04.286479345 -0800
@@ -537,6 +537,8 @@
#endif
struct list_head tasks;
+ unsigned long anon_fault_next_addr; /* Predicted sequential fault address */
+ int anon_fault_order; /* Last order of allocation on fault */
/*
* ptrace_list/ptrace_children forms the list of my children
* that were stolen by a ptracer.
Index: linux-2.6.9/mm/memory.c
=================================--- linux-2.6.9.orig/mm/memory.c 2004-12-08 15:01:50.668339751 -0800
+++ linux-2.6.9/mm/memory.c 2004-12-09 14:21:17.090061608 -0800
@@ -55,6 +55,7 @@
#include <linux/swapops.h>
#include <linux/elf.h>
+#include <linux/pagevec.h>
#ifndef CONFIG_DISCONTIGMEM
/* use the per-pgdat data instead for discontigmem - mbligh */
@@ -1432,52 +1433,99 @@
unsigned long addr)
{
pte_t entry;
- struct page * page = ZERO_PAGE(addr);
-
- /* Read-only mapping of ZERO_PAGE. */
- entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot));
+ unsigned long end_addr;
+
+ addr &= PAGE_MASK;
+
+ if (likely((vma->vm_flags & VM_RAND_READ) || current->anon_fault_next_addr != addr)) {
+ /* Single page */
+ current->anon_fault_order = 0;
+ end_addr = addr + PAGE_SIZE;
+ } else {
+ /* Sequence of faults detect. Perform preallocation */
+ int order = ++current->anon_fault_order;
+
+ if ((1 << order) < PAGEVEC_SIZE)
+ end_addr = addr + (PAGE_SIZE << order);
+ else
+ end_addr = addr + PAGEVEC_SIZE * PAGE_SIZE;
- /* ..except if it's a write access */
+ if (end_addr > vma->vm_end)
+ end_addr = vma->vm_end;
+ if ((addr & PMD_MASK) != (end_addr & PMD_MASK))
+ end_addr &= PMD_MASK;
+ }
if (write_access) {
- /* Allocate our own private page. */
+
+ unsigned long a;
+ struct page **p;
+ struct pagevec pv;
+
pte_unmap(page_table); spin_unlock(&mm->page_table_lock);
+ pagevec_init(&pv, 0);
+
if (unlikely(anon_vma_prepare(vma)))
- goto no_mem;
- page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
- if (!page)
- goto no_mem;
- clear_user_highpage(page, addr);
+ return VM_FAULT_OOM;
+
+ /* Allocate the necessary pages */
+ for(a = addr; a < end_addr ; a += PAGE_SIZE) {
+ struct page *p = alloc_page_vma(GFP_HIGHUSER, vma, a);
+
+ if (likely(p)) {
+ clear_user_highpage(p, a);
+ pagevec_add(&pv, p);
+ } else {
+ if (a = addr)
+ return VM_FAULT_OOM;
+ break;
+ }
+ }
spin_lock(&mm->page_table_lock);
- page_table = pte_offset_map(pmd, addr);
- if (!pte_none(*page_table)) {
+ for(p = pv.pages; addr < a; addr += PAGE_SIZE, p++) {
+
+ page_table = pte_offset_map(pmd, addr);
+ if (unlikely(!pte_none(*page_table))) {
+ /* Someone else got there first */
+ pte_unmap(page_table);
+ page_cache_release(*p);
+ continue;
+ }
+
+ entry = maybe_mkwrite(pte_mkdirty(mk_pte(*p,
+ vma->vm_page_prot)),
+ vma);
+
+ mm->rss++;
+ lru_cache_add_active(*p);
+ mark_page_accessed(*p);
+ page_add_anon_rmap(*p, vma, addr);
+
+ set_pte(page_table, entry);
pte_unmap(page_table);
- page_cache_release(page);
- spin_unlock(&mm->page_table_lock);
- goto out;
+
+ /* No need to invalidate - it was non-present before */
+ update_mmu_cache(vma, addr, entry);
+ }
+ } else {
+ /* Read */
+ entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot));
+nextread:
+ set_pte(page_table, entry);
+ pte_unmap(page_table);
+ update_mmu_cache(vma, addr, entry);
+ addr += PAGE_SIZE;
+ if (unlikely(addr < end_addr)) {
+ pte_offset_map(pmd, addr);
+ goto nextread;
}
- mm->rss++;
- entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
- vma->vm_page_prot)),
- vma);
- lru_cache_add_active(page);
- mark_page_accessed(page);
- page_add_anon_rmap(page, vma, addr);
}
-
- set_pte(page_table, entry);
- pte_unmap(page_table);
-
- /* No need to invalidate - it was non-present before */
- update_mmu_cache(vma, addr, entry);
+ current->anon_fault_next_addr = addr;
spin_unlock(&mm->page_table_lock);
-out:
return VM_FAULT_MINOR;
-no_mem:
- return VM_FAULT_OOM;
}
/*
Re: Anticipatory prefaulting in the page fault handler V1
Quoted 6 lines
Quoted 5 lines
I also encountered processes segfault.
Below patch fix several problems.1) if no pages could allocated, returns
VM_FAULT_OOM
2) fix duplicatedpte_offset_map()call
Quoted 8 lines
I also saw these two issues and I think I dealt with them in a forthcoming patch.
Quoted 1 line
3) don't
set_pte()for the entry which already have been setNot sure how this could have happened in the patch.
Could you try my updated version:
Urgle. There was a fix from Hugh too ... any chance you could just stick a whole new patch somewhere? I'm too idle/stupid to work it out ;-)
M.
Anticipatory prefaulting in the page fault handler V2
Changes from V1 to V2:
- Eliminate duplicate code and reorganize things
- Use SetReferenced instead of mark_accessed (Hugh Dickins)
- Fix the problem of the preallocation order increasing out of bounds (leading to memory being overwritten with pointers to struct page)
- Return VM_FAULT_OOM if not able to allocate a single page
- Tested on i386 and ia64
- New performance test for low cpu counts (up to 8 so that this does not seem to be too exotic)
The page fault handler for anonymous pages can generate significant overhead apart from its essential function which is to clear and setup a new page table entry for a never accessed memory location. This overhead increases significantly in an SMP environment.
In the page table scalability patches, we addressed the issue by changing the locking scheme so that multiple fault handlers are able to be processed concurrently on multiple cpus. This patch attempts to aggregate multiple page faults into a single one. It does that by noting
anonymous page faults generated in sequence by an application.
If a fault occurred for page x and is then followed by page x+1 then it may be reasonable to expect another page fault at x+2 in the future. If page table entries for x+1 and x+2 would be prepared in the fault handling for page x+1 then the overhead of taking a fault for x+2 is avoided. However page x+2 may never be used and thus we may have increased the rss of an application unnecessarily. The swapper will take care of removing that page if memory should get tight.
The following patch makes the anonymous fault handler anticipate future faults. For each fault a prediction is made where the fault would occur (assuming linear acccess by the application). If the prediction turns out to be right (next fault is where expected) then a number of pages is preallocated in order to avoid a series of future faults. The order of the preallocation increases by the power of two for each success in sequence.
The first successful prediction leads to an additional page being allocated. Second successful prediction leads to 2 additional pages being allocated. Third to 4 pages and so on. The max order is 3 by default. In a large continous allocation the number of faults is reduced by a factor of 8.
Standard Kernel on a 8 Cpu machine allocating 1 and 4GB with an increasing number of threads (and thus increasing parallellism of page faults):
ia64 2.6.10-rc3-bk7
Gb Rep Threads User System Wall flt/cpu/s fault/wsec 1 3 1 0.047s 2.163s 2.021s 88925.153 88859.030 1 3 2 0.040s 3.215s 1.069s 60385.889 115677.685 1 3 4 0.041s 3.509s 1.023s 55370.338 158971.609 1 3 8 0.047s 4.130s 1.014s 47049.904 172405.990
Gb Rep Threads User System Wall flt/cpu/s fault/wsec 4 3 1 0.155s 11.277s 11.043s 68788.420 68747.223 4 3 2 0.161s 16.459s 8.061s 47315.277 91322.962 4 3 4 0.170s 14.708s 4.079s 52852.007 164043.773 4 3 8 0.171s 23.257s 4.028s 33565.604 183348.574
ia64 Patched kernel:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec 1 3 1 0.008s 2.080s 2.008s 94121.792 94101.359 1 3 2 0.015s 3.128s 1.064s 62523.771 119563.496 1 3 4 0.008s 2.714s 1.012s 72185.910 175020.971 1 3 8 0.016s 2.963s 0.087s 65965.457 223921.949
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
4 3 1 0.034s 10.861s 10.089s 72179.444 72181.353 4 3 2 0.050s 14.303s 7.072s 54786.447 101738.901 4 3 4 0.038s 13.478s 4.044s 58182.649 176913.840 4 3 8 0.063s 13.584s 3.007s 57620.638 256109.927
i386 2.6.10-rc3-bk3 256M allocation 2x Pentium III 500 Mhz
Gb Rep Threads User System Wall flt/cpu/s fault/wsec 0 3 1 0.020s 1.566s 1.058s123827.513 123842.098 0 3 2 0.017s 2.439s 1.043s 79999.154 136931.671
i386 2.6.10-rc3-bk3 patches
Gb Rep Threads User System Wall flt/cpu/s fault/wsec 0 3 1 0.020s 1.527s 1.039s126945.181 140930.664 0 3 2 0.016s 2.417s 1.026s 80754.809 155162.903
Patch against 2.6.10-rc3-bk7:
Index: linux-2.6.9/include/linux/sched.h
=================================--- linux-2.6.9.orig/include/linux/sched.h 2004-12-13 15:14:40.000000000 -0800
+++ linux-2.6.9/include/linux/sched.h 2004-12-13 15:15:55.000000000 -0800
@@ -537,6 +537,8 @@
#endif
struct list_head tasks;
+ unsigned long anon_fault_next_addr; /* Predicted sequential fault address */
+ int anon_fault_order; /* Last order of allocation on fault */
/*
* ptrace_list/ptrace_children forms the list of my children
* that were stolen by a ptracer.
Index: linux-2.6.9/mm/memory.c
=================================--- linux-2.6.9.orig/mm/memory.c 2004-12-13 15:14:40.000000000 -0800
+++ linux-2.6.9/mm/memory.c 2004-12-13 16:49:31.000000000 -0800
@@ -55,6 +55,7 @@
#include <linux/swapops.h>
#include <linux/elf.h>
+#include <linux/pagevec.h>
#ifndef CONFIG_DISCONTIGMEM
/* use the per-pgdat data instead for discontigmem - mbligh */
@@ -1432,52 +1433,102 @@
unsigned long addr)
{
pte_t entry;
- struct page * page = ZERO_PAGE(addr);
-
- /* Read-only mapping of ZERO_PAGE. */
- entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot));
+ unsigned long end_addr;
+
+ addr &= PAGE_MASK;
+
+ if (likely((vma->vm_flags & VM_RAND_READ) || current->anon_fault_next_addr != addr)) {
+ /* Single page */
+ current->anon_fault_order = 0;
+ end_addr = addr + PAGE_SIZE;
+ } else {
+ /* Sequence of faults detect. Perform preallocation */
+ int order = ++current->anon_fault_order;
+
+ if ((1 << order) < PAGEVEC_SIZE)
+ end_addr = addr + (PAGE_SIZE << order);
+ else {
+ end_addr = addr + PAGEVEC_SIZE * PAGE_SIZE;
+ current->anon_fault_order = 3;
+ }
- /* ..except if it's a write access */
+ if (end_addr > vma->vm_end)
+ end_addr = vma->vm_end;
+ if ((addr & PMD_MASK) != (end_addr & PMD_MASK))
+ end_addr &= PMD_MASK;
+ }
if (write_access) {
- /* Allocate our own private page. */
+
+ unsigned long a;
+ int i;
+ struct pagevec pv;
+
pte_unmap(page_table); spin_unlock(&mm->page_table_lock);
+ pagevec_init(&pv, 0);
+
if (unlikely(anon_vma_prepare(vma)))
- goto no_mem;
- page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
- if (!page)
- goto no_mem;
- clear_user_highpage(page, addr);
+ return VM_FAULT_OOM;
+
+ /* Allocate the necessary pages */
+ for(a = addr; a < end_addr ; a += PAGE_SIZE) {
+ struct page *p = alloc_page_vma(GFP_HIGHUSER, vma, a);
+
+ if (likely(p)) {
+ clear_user_highpage(p, a);
+ pagevec_add(&pv, p);
+ } else {
+ if (a = addr)
+ return VM_FAULT_OOM;
+ break;
+ }
+ }
spin_lock(&mm->page_table_lock);
- page_table = pte_offset_map(pmd, addr);
- if (!pte_none(*page_table)) {
+ for(i = 0; addr < a; addr += PAGE_SIZE, i++) {
+ struct page *p = pv.pages[i];
+
+ page_table = pte_offset_map(pmd, addr);
+ if (unlikely(!pte_none(*page_table))) {
+ /* Someone else got there first */
+ pte_unmap(page_table);
+ page_cache_release(p);
+ continue;
+ }
+
+ entry = maybe_mkwrite(pte_mkdirty(mk_pte(p,
+ vma->vm_page_prot)),
+ vma);
+
+ mm->rss++;
+ lru_cache_add_active(p);
+ SetPageReferenced(p);
+ page_add_anon_rmap(p, vma, addr);
+
+ set_pte(page_table, entry);
pte_unmap(page_table);
- page_cache_release(page);
- spin_unlock(&mm->page_table_lock);
- goto out;
+
+ /* No need to invalidate - it was non-present before */
+ update_mmu_cache(vma, addr, entry);
+ }
+ } else {
+ /* Read */
+ entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot));
+nextread:
+ set_pte(page_table, entry);
+ pte_unmap(page_table);
+ update_mmu_cache(vma, addr, entry);
+ addr += PAGE_SIZE;
+ if (unlikely(addr < end_addr)) {
+ pte_offset_map(pmd, addr);
+ goto nextread;
}
- mm->rss++;
- entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
- vma->vm_page_prot)),
- vma);
- lru_cache_add_active(page);
- mark_page_accessed(page);
- page_add_anon_rmap(page, vma, addr);
}
-
- set_pte(page_table, entry);
- pte_unmap(page_table);
-
- /* No need to invalidate - it was non-present before */
- update_mmu_cache(vma, addr, entry);
+ current->anon_fault_next_addr = addr;
spin_unlock(&mm->page_table_lock);
-out:
return VM_FAULT_MINOR;
-no_mem:
- return VM_FAULT_OOM;
}
/*
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Christoph LameterQuoted 5 lines · Christoph Lameter
Quoted 1 line · Akinobu Mita
3) don't
set_pte()for the entry which already have been setNot sure how this could have happened in the patch.
This is why I inserted pte_none() for each page_table in case of read fault too.
If read access fault occured for the address "addr".
It is completely unnecessary to check by pte_none() to the page_table for "addr". Because page_table_lock has never been released until do_anonymous_page returns (in case of read access fault)
But there is not any guarantee that the page_tables for addr+PAGE_SIZE, addr+2*PAGE_SIZE, ... have not been mapped yet.
Anyway, I will try your V2 patch.
Re: Anticipatory prefaulting in the page fault handler V1
Quoted 5 lines · Akinobu Mita
But there is not any guarantee that the
page_tablesfor addr+PAGE_SIZE, addr+2*PAGE_SIZE, ... have not been mapped yet.Anyway, I will try your V2 patch.
Below patch fixes V2 patch, and adds debug printk. The output coincides with segfaulted processes.
# dmesg | grep ^comm:
comm: xscreensaver, addr_orig: ccdc40, addr: cce000, pid: 2995
comm: rhn-applet-gui, addr_orig: b6fd8020, addr: b6fd9000, pid: 3029
comm: rhn-applet-gui, addr_orig: b6e95020, addr: b6e96000, pid: 3029
comm: rhn-applet-gui, addr_orig: b6fd8020, addr: b6fd9000, pid: 3029
comm: rhn-applet-gui, addr_orig: b6e95020, addr: b6e96000, pid: 3029
comm: rhn-applet-gui, addr_orig: b6fd8020, addr: b6fd9000, pid: 3029
comm: X, addr_orig: 87e8000, addr: 87e9000, pid: 2874
comm: X, addr_orig: 87ea000, addr: 87eb000, pid: 2874
---
The read access prefaulting may override the page_table which has been already mapped. this patch fixes it. and it shows which process might suffer this problem.
mm/memory.c renamed from mm/memory.c.orig +10 -3
@@ -1434,6 +1434,7 @@ do_anonymous_page(struct mm_struct *mm, {pte_t entry;unsigned long end_addr; +unsigned long addr_orig = addr; addr &=PAGE_MASK ;
@@ -1517,9 +1518,15 @@ do_anonymous_page(struct mm_struct *mm,/* Read */ entry =pte_wrprotect (mk_pte (ZERO_PAGE (addr), vma->vm_page_prot)); nextread: -set_pte (page_table, entry); -pte_unmap (page_table); -update_mmu_cache (vma, addr, entry); +if (!pte_none (*page_table)) { +printk ("comm: %s, addr_orig: %lx, addr: %lx, pid: %d\n" , + current->comm, addr_orig, addr, current->pid); +pte_unmap (page_table); + }else { +set_pte (page_table, entry); +pte_unmap (page_table); +update_mmu_cache (vma, addr, entry); + } addr +=PAGE_SIZE ;if (unlikely (addr < end_addr)) {pte_offset_map (pmd, addr);
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Christoph LameterWhat benchmark are you using to generate the following results? I'd like to run this on some of my hardware and see how the results compare.
Quoted 225 lines · Christoph Lameter
Standard Kernel on a 512 Cpu machine allocating 32GB with an increasing number of threads (and thus increasing parallellism of page faults):
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.416s 138.165s 139.050s 45073.831 45097.498 32 3 2 1.397s 148.523s 78.044s 41965.149 80201.646 32 3 4 1.390s 152.618s 44.044s 40851.258 141545.239 32 3 8 1.500s 374.008s 53.001s 16754.519 118671.950 32 3 16 1.415s 1051.759s 73.094s 5973.803 85087.358 32 3 32 1.867s 3400.417s 117.003s 1849.186 53754.928 32 3 64 5.361s 11633.040s 197.034s 540.577 31881.112 32 3 128 23.387s 39386.390s 332.055s 159.642 18918.599 32 3 256 15.409s 20031.450s 168.095s 313.837 37237.918 32 3 512 18.720s 10338.511s 86.047s 607.446 72752.686Patched kernel:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 3 1 1.098s 138.544s 139.063s 45053.657 45057.920 32 3 2 1.022s 127.770s 67.086s 48849.350 92707.085 32 3 4 0.995s 119.666s 37.045s 52141.503 167955.292 32 3 8 0.928s 87.400s 18.034s 71227.407 342934.242 32 3 16 1.067s 72.943s 11.035s 85007.293 553989.377 32 3 32 1.248s 133.753s 10.038s 46602.680 606062.151 32 3 64 5.557s 438.634s 13.093s 14163.802 451418.617 32 3 128 17.860s 1496.797s 19.048s 4153.714 322808.509 32 3 256 13.382s 766.063s 10.016s 8071.695 618816.838 32 3 512 17.067s 369.106s 5.041s 16291.764 1161285.521These number are roughly equal to what can be accomplished with the page fault scalability patches.
Kernel patches with both the page fault scalability patches and prefaulting:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
32 10 1 4.103s 456.384s 460.046s 45541.992 45544.369 32 10 2 4.005s 415.119s 221.095s 50036.407 94484.174 32 10 4 3.855s 371.317s 111.076s 55898.259 187635.724 32 10 8 3.902s 308.673s 67.094s 67092.476 308634.397 32 10 16 4.011s 224.213s 37.016s 91889.781 564241.062 32 10 32 5.483s 209.391s 27.046s 97598.647 763495.417 32 10 64 19.166s 219.925s 26.030s 87713.212 797286.395 32 10 128 53.482s 342.342s 27.024s 52981.744 769687.791 32 10 256 67.334s 180.321s 15.036s 84679.911 1364614.334 32 10 512 66.516s 93.098s 9.015s131387.893 2291548.865The fault rate doubles when both patches are applied.
And on the high end (512 processors allocating 256G) (No numbers for regular kernels because they are extremely slow, also no number for a low number of threads. Also very slow)
With prefaulting:
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
256 3 4 8.241s 1414.348s 449.016s 35380.301 112056.239 256 3 8 8.306s 1300.982s 247.025s 38441.977 203559.271 256 3 16 8.368s 1223.853s 154.089s 40846.272 324940.924 256 3 32 8.536s 1284.041s 110.097s 38938.970 453556.624 256 3 64 13.025s 3587.203s 110.010s 13980.123 457131.492 256 3 128 25.025s 11460.700s 145.071s 4382.104 345404.909 256 3 256 26.150s 6061.649s 75.086s 8267.625 663414.482 256 3 512 20.637s 3037.097s 38.062s 16460.435 1302993.019Page fault scalability patch and prefaulting. Max prefault order increased to 5 (max preallocation of 32 pages):
Gb Rep Threads User System Wall flt/cpu/s fault/wsec
256 10 8 33.571s 4516.293s 863.021s 36874.099 194356.930 256 10 16 33.103s 3737.688s 461.028s 44492.553 363704.484 256 10 32 35.094s 3436.561s 321.080s 48326.262 521352.840 256 10 64 46.675s 2899.997s 245.020s 56936.124 684214.256 256 10 128 85.493s 2890.198s 203.008s 56380.890 826122.524 256 10 256 74.299s 1374.973s 99.088s115762.963 1679630.272 256 10 512 62.760s 706.559s 53.027s218078.311 3149273.714We are getting into an almost linear scalability in the high end with both patches and end up with a fault rate > 3 mio faults per second.
The one thing that takes up a lot of time is still be the zeroing of pages in the page fault handler. There is a another set of patches that I am working on which will prezero pages and led to another an increase in performance by a factor of 2-4 (if prezeroed pages are available which may not always be the case). Maybe we can reach 10 mio fault /sec that way.
Patch against 2.6.10-rc3-bk3:
Index:
linux-2.6.9/include/linux/sched.h
=================================> ---linux-2.6.9.orig/include/linux/sched.h2004-12-01 10:37:31.000000000 -0800
+++linux-2.6.9/include/linux/sched.h2004-12-01 10:38:15.000000000 -0800(quoted diff) +2
-0@@ -537,6 +537,8 @@ #endif struct list_head tasks; + unsigned long anon_fault_next_addr; /* Predicted sequential fault address */ + int anon_fault_order; /* Last order of allocation on fault */ /* * ptrace_list/ptrace_children forms the list of my children * that were stolen by a ptracer.Index:
linux-2.6.9/mm/memory.c
=================================> ---linux-2.6.9.orig/mm/memory.c2004-12-01 10:38:11.000000000 -0800
+++linux-2.6.9/mm/memory.c2004-12-01 10:45:01.000000000 -0800(quoted diff) +100
-2@@ -55,6 +55,7 @@ #include <linux/swapops.h> #include <linux/elf.h> +#include <linux/pagevec.h> #ifndef CONFIG_DISCONTIGMEM /* use the per-pgdat data instead for discontigmem - mbligh */@@ -1432,8 +1433,106 @@ unsigned long addr) { pte_t entry; - struct page * page = ZERO_PAGE(addr); + struct page * page; + + addr &= PAGE_MASK; + + if (current->anon_fault_next_addr = addr) { + unsigned long end_addr; + int order = current->anon_fault_order; + + /* Sequence of page faults detected. Perform preallocation of pages */ + /* The order of preallocations increases with each successful prediction */ + order++; + + if ((1 << order) < PAGEVEC_SIZE) + end_addr = addr + (1 << (order + PAGE_SHIFT)); + else + end_addr = addr + PAGEVEC_SIZE * PAGE_SIZE; + + if (end_addr > vma->vm_end) + end_addr = vma->vm_end; + if ((addr & PMD_MASK) != (end_addr & PMD_MASK)) + end_addr &= PMD_MASK; + + current->anon_fault_next_addr = end_addr; + current->anon_fault_order = order; + + if (write_access) { + + struct pagevec pv; + unsigned long a; + struct page **p; + + pte_unmap(page_table); + spin_unlock(&mm->page_table_lock); + + pagevec_init(&pv, 0); + + if (unlikely(anon_vma_prepare(vma))) + return VM_FAULT_OOM; + + /* Allocate the necessary pages */ + for(a = addr;a < end_addr ; a += PAGE_SIZE) { + struct page *p = alloc_page_vma(GFP_HIGHUSER, vma, a); + + if (p) { + clear_user_highpage(p, a); + pagevec_add(&pv,p); + } else + break; + } + end_addr = a; + + spin_lock(&mm->page_table_lock); + + for(p = pv.pages; addr < end_addr; addr += PAGE_SIZE, p++) { + + page_table = pte_offset_map(pmd, addr); + if (!pte_none(*page_table)) { + /* Someone else got there first */ + page_cache_release(*p); + pte_unmap(page_table); + continue; + } + + entry = maybe_mkwrite(pte_mkdirty(mk_pte(*p, + vma->vm_page_prot)), + vma); + + mm->rss++; + lru_cache_add_active(*p); + mark_page_accessed(*p); + page_add_anon_rmap(*p, vma, addr); + + set_pte(page_table, entry); + pte_unmap(page_table); + + /* No need to invalidate - it was non-present before */ + update_mmu_cache(vma, addr, entry); + } + } else { + /* Read */ + for(;addr < end_addr; addr += PAGE_SIZE) { + page_table = pte_offset_map(pmd, addr); + entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot)); + set_pte(page_table, entry); + pte_unmap(page_table); + + /* No need to invalidate - it was non-present before */ + update_mmu_cache(vma, addr, entry); + + }; + } + spin_unlock(&mm->page_table_lock); + return VM_FAULT_MINOR; + } + + current->anon_fault_next_addr = addr + PAGE_SIZE; + current->anon_fault_order = 0; + + page = ZERO_PAGE(addr); /* Read-only mapping of ZERO_PAGE. */ entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot)); -To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Adam Litke - (agl at us.ibm.com) IBM Linux Technology Center
Re: Anticipatory prefaulting in the page fault handler V2
In reply to Christoph LameterJust to add another data point: This works on my 4-way ppc64 (Power4) box. I am seeing no degradation when running this on kernbench (which is expected). For the curious, here are the results:
Kernbench results with anon-prefault:
349.86user 49.64system 1:57.85elapsed 338%CPU (0avgtext+0avgdata 0maxresident)k 349.65user 49.81system 1:58.31elapsed 337%CPU (0avgtext+0avgdata 0maxresident)k 349.48user 50.00system 1:53.70elapsed 351%CPU (0avgtext+0avgdata 0maxresident)k 349.73user 49.69system 1:57.67elapsed 339%CPU (0avgtext+0avgdata 0maxresident)k 349.75user 49.85system 1:52.71elapsed 354%CPU (0avgtext+0avgdata 0maxresident)k
Elapsed: 116.048s User: 349.694s System: 49.798s CPU: 343.8%
Kernbench results without anon-prefault:
350.86user 52.54system 1:53.45elapsed 355%CPU (0avgtext+0avgdata 0maxresident)k 350.99user 52.36system 1:52.05elapsed 359%CPU (0avgtext+0avgdata 0maxresident)k 350.92user 52.68system 1:54.14elapsed 353%CPU (0avgtext+0avgdata 0maxresident)k 350.98user 52.38system 1:56.17elapsed 347%CPU (0avgtext+0avgdata 0maxresident)k 351.16user 52.31system 1:53.90elapsed 354%CPU (0avgtext+0avgdata 0maxresident)k
Elapsed: 113.942s User: 350.982s System: 52.454s CPU: 353.6%
Quoted 9 lines · Christoph Lameter
Changes from V1 to V2:
- Eliminate duplicate code and reorganize things
- Use SetReferenced instead ofmark_accessed(Hugh Dickins)
- Fix the problem of the preallocation order increasing out of bounds (leading to memory being overwritten with pointers to struct page)
- ReturnVM_FAULT_OOMif not able to allocate a single page
- Tested on i386 and ia64
- New performance test for low cpu counts (up to 8 so that this does not seem to be too exotic)
Signature · 2 lines
Adam Litke - (agl at us.ibm.com) IBM Linux Technology Center
Re: Anticipatory prefaulting in the page fault handler V1
In reply to Akinobu MitaQuoted 10 lines · Akinobu Mita
This is why I inserted
pte_none()for eachpage_tablein case of read fault too.If read access fault occured for the address "addr".
It is completely unnecessary to check bypte_none()to thepage_tablefor "addr". Becausepage_table_lockhas never been released untildo_anonymous_pagereturns (in case of read access fault)But there is not any guarantee that the
page_tablesfor addr+PAGE_SIZE, addr+2*PAGE_SIZE, ... have not been mapped yet.
Right. Thanks for pointing that out.
Anticipatory prefaulting in the page fault handler V3
In reply to Adam LitkeChanges from V2 to V3:
- check for empty pte before setting additional pte's in aggregate read
The page fault handler for anonymous pages can generate significant overhead apart from its essential function which is to clear and setup a new page table entry for a never accessed memory location. This overhead increases significantly in an SMP environment.
In the page table scalability patches, we addressed the issue by changing the locking scheme so that multiple fault handlers are able to be processed concurrently on multiple cpus. This patch attempts to aggregate multiple page faults into a single one. It does that by noting
anonymous page faults generated in sequence by an application.
If a fault occurred for page x and is then followed by page x+1 then it may be reasonable to expect another page fault at x+2 in the future. If page table entries for x+1 and x+2 would be prepared in the fault handling for page x+1 then the overhead of taking a fault for x+2 is avoided. However page x+2 may never be used and thus we may have increased the rss of an application unnecessarily. The swapper will take care of removing that page if memory should get tight.
The following patch makes the anonymous fault handler anticipate future faults. For each fault a prediction is made where the fault would occur (assuming linear acccess by the application). If the prediction turns out to be right (next fault is where expected) then a number of pages is preallocated in order to avoid a series of future faults. The order of the preallocation increases by the power of two for each success in sequence.
The first successful prediction leads to an additional page being allocated. Second successful prediction leads to 2 additional pages being allocated. Third to 4 pages and so on. The max order is 3 by default. In a large continous allocation the number of faults is reduced by a factor of 8.
Patch against 2.6.10-rc3-bk7:
Index: linux-2.6.9/include/linux/sched.h
=================================--- linux-2.6.9.orig/include/linux/sched.h 2004-12-13 15:14:40.000000000 -0800
+++ linux-2.6.9/include/linux/sched.h 2004-12-14 12:21:26.000000000 -0800
@@ -537,6 +537,8 @@
#endif
struct list_head tasks;
+ unsigned long anon_fault_next_addr; /* Predicted sequential fault address */
+ int anon_fault_order; /* Last order of allocation on fault */
/*
* ptrace_list/ptrace_children forms the list of my children
* that were stolen by a ptracer.
Index: linux-2.6.9/mm/memory.c
=================================--- linux-2.6.9.orig/mm/memory.c 2004-12-13 15:14:40.000000000 -0800
+++ linux-2.6.9/mm/memory.c 2004-12-14 12:23:36.000000000 -0800
@@ -55,6 +55,7 @@
#include <linux/swapops.h>
#include <linux/elf.h>
+#include <linux/pagevec.h>
#ifndef CONFIG_DISCONTIGMEM
/* use the per-pgdat data instead for discontigmem - mbligh */
@@ -1432,52 +1433,103 @@
unsigned long addr)
{
pte_t entry;
- struct page * page = ZERO_PAGE(addr);
-
- /* Read-only mapping of ZERO_PAGE. */
- entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot));
+ unsigned long end_addr;
+
+ addr &= PAGE_MASK;
+
+ if (likely((vma->vm_flags & VM_RAND_READ) || current->anon_fault_next_addr != addr)) {
+ /* Single page */
+ current->anon_fault_order = 0;
+ end_addr = addr + PAGE_SIZE;
+ } else {
+ /* Sequence of faults detect. Perform preallocation */
+ int order = ++current->anon_fault_order;
+
+ if ((1 << order) < PAGEVEC_SIZE)
+ end_addr = addr + (PAGE_SIZE << order);
+ else {
+ end_addr = addr + PAGEVEC_SIZE * PAGE_SIZE;
+ current->anon_fault_order = 3;
+ }
- /* ..except if it's a write access */
+ if (end_addr > vma->vm_end)
+ end_addr = vma->vm_end;
+ if ((addr & PMD_MASK) != (end_addr & PMD_MASK))
+ end_addr &= PMD_MASK;
+ }
if (write_access) {
- /* Allocate our own private page. */
+
+ unsigned long a;
+ int i;
+ struct pagevec pv;
+
pte_unmap(page_table); spin_unlock(&mm->page_table_lock);
+ pagevec_init(&pv, 0);
+
if (unlikely(anon_vma_prepare(vma)))
- goto no_mem;
- page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
- if (!page)
- goto no_mem;
- clear_user_highpage(page, addr);
+ return VM_FAULT_OOM;
+
+ /* Allocate the necessary pages */
+ for(a = addr; a < end_addr ; a += PAGE_SIZE) {
+ struct page *p = alloc_page_vma(GFP_HIGHUSER, vma, a);
+
+ if (likely(p)) {
+ clear_user_highpage(p, a);
+ pagevec_add(&pv, p);
+ } else {
+ if (a = addr)
+ return VM_FAULT_OOM;
+ break;
+ }
+ }
spin_lock(&mm->page_table_lock);
- page_table = pte_offset_map(pmd, addr);
- if (!pte_none(*page_table)) {
+ for(i = 0; addr < a; addr += PAGE_SIZE, i++) {
+ struct page *p = pv.pages[i];
+
+ page_table = pte_offset_map(pmd, addr);
+ if (unlikely(!pte_none(*page_table))) {
+ /* Someone else got there first */
+ pte_unmap(page_table);
+ page_cache_release(p);
+ continue;
+ }
+
+ entry = maybe_mkwrite(pte_mkdirty(mk_pte(p,
+ vma->vm_page_prot)),
+ vma);
+
+ mm->rss++;
+ lru_cache_add_active(p);
+ SetPageReferenced(p);
+ page_add_anon_rmap(p, vma, addr);
+
+ set_pte(page_table, entry);
pte_unmap(page_table);
- page_cache_release(page);
- spin_unlock(&mm->page_table_lock);
- goto out;
+
+ /* No need to invalidate - it was non-present before */
+ update_mmu_cache(vma, addr, entry);
+ }
+ } else {
+ /* Read */
+ entry = pte_wrprotect(mk_pte(ZERO_PAGE(addr), vma->vm_page_prot));
+nextread:
+ set_pte(page_table, entry);
+ pte_unmap(page_table);
+ update_mmu_cache(vma, addr, entry);
+ addr += PAGE_SIZE;
+ if (unlikely(addr < end_addr)) {
+ page_table = pte_offset_map(pmd, addr);
+ if (likely(pte_none(*page_table)))
+ goto nextread;
}
- mm->rss++;
- entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
- vma->vm_page_prot)),
- vma);
- lru_cache_add_active(page);
- mark_page_accessed(page);
- page_add_anon_rmap(page, vma, addr);
}
-
- set_pte(page_table, entry);
- pte_unmap(page_table);
-
- /* No need to invalidate - it was non-present before */
- update_mmu_cache(vma, addr, entry);
+ current->anon_fault_next_addr = addr;
spin_unlock(&mm->page_table_lock);
-out:
return VM_FAULT_MINOR;
-no_mem:
- return VM_FAULT_OOM;
}
/*
Re: page fault scalability patch V12 [0/7]: Overview and performance tests
In reply to William Lee Irwin IIIQuoted 6 lines · William Lee Irwin III
Quoted 3 lines · Hugh Dickins
Oh, hold on, isn't handle_mm_fault's pmd without
page_table_locksimilarly racy, in both the 64-on-32 cases, and on architectures which have a more complexpmd_t(sparc, m68k, h8300)? Sigh.yes.
Those may fall back to use the page_table_lock for individual operations that cannot be realized in an atomic way.