UML - Speed up exec
PATCH 2/2 UML - Speed up exec
flush_thread doesn't need to do a full page table walk in order to clear the address space. It knows what the end result needs to be, so it can call unmap directly.
This results in a 10-20% speedup in an exec from bash.
--
arch/um/kernel/skas/exec.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
arch/um/kernel/skas/exec.c +11 -1
@@ -17,7 +17,17 @@void flush_thread_skas (void ) { -force_flush_all (); +void *data =NULL ; +unsigned long end = proc_mm ? task_size :CONFIG_STUB_START ; +int ret; + + ret =unmap (¤t->mm->context.skas.id,0 , end,1 , &data); +if (ret){ +printk ("flush_thread_skas - clearing address space failed, " +"err = %d\n" , ret); +force_sig (SIGKILL , current); + } +switch_mm_skas (¤t->mm->context.skas.id); }
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 5 lines · Jeff Dike
flush_threaddoesn't need to do a full page table walk in order to clear the address space. It knows what the end result needs to be, so it can call unmap directly.This results in a 10-20% speedup in an exec from bash.
Oh, yeah!
When porting part of Ingo's work, I realized that a similar thing can be done for fork().
If the whole address space is unmapped in init_new_context_skas(), the first fix_range_common() call won't need to call unmap at all. He did this with remap_file_pages(), where init_new_context_skas() must "unmap" everything anyway.
This is giving some speedup in lmbench (5% better in fork proc, 2% better in exec proc), but the results are still controversial, there is one benchmark with a 2% slowdown (called 'mmap latency').
In a loop, it maps, touches a byte per page and unmaps a region with growing size (up to 32MB).
However, since results aren't yet stable for some other benchmark (context switching benchmark is crazy), I'm still studying on this.
Quoted 28 lines
Signed-off-by Jeff Dike <[email protected]>--
arch/um/kernel/skas/exec.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)Index:
linux-2.6.21-mm/arch/um/kernel/skas/exec.c
===================================================================
---linux-2.6.21-mm.orig/arch/um/kernel/skas/exec.c2007-03-30
10:28:24.000000000 -0400 +++linux-2.6.21-mm/arch/um/kernel/skas/exec.c2007-03-30 10:30:15.000000000
-0400 @@ -17,7 +17,17 @@void
flush_thread_skas(void)
{(quoted diff) +11
-1- force_flush_all(); + void *data = NULL; + unsigned long end = proc_mm ? task_size : CONFIG_STUB_START; + int ret; + + ret = unmap(¤t->mm->context.skas.id, 0, end, 1, &data); + if(ret){ + printk("flush_thread_skas - clearing address space failed, " + "err = %d\n", ret); + force_sig(SIGKILL, current); + } + switch_mm_skas(¤t->mm->context.skas.id); }
Signature · 3 lines
Inform me of my mistakes, so I can add them to my list! Paolo Giarrusso, aka Blaisorblade http://www.user-mode-linux.org/~blaisorblade
arch/um/include/skas/mmu-skas.h +1 -0
@@ -16,6 +16,7 @@ struct mmu_context_skas {unsigned long last_pmd;#endif uml_ldt_t ldt; +int first_flush; };extern void switch_mm_skas (struct mm_id * mm_idp);
arch/um/kernel/skas/mmu.c +9 -0
@@ -77,6 +77,7 @@ int init_new_context_skas(struct task_ststruct mmu_context_skas *to_mm = &mm->context.skas;unsigned long stack =0 ;int ret = -ENOMEM ; +void *unused =NULL ;if (skas_needs_stub){ stack =get_zeroed_page (GFP_KERNEL );
@@ -121,6 +122,14 @@ int init_new_context_skas(struct task_stelse to_mm->id.u.pid =start_userspace (stack); } + mm->context.skas.first_flush =1 ; + ret =unmap (&mm->context.skas.id,0 ,TASK_SIZE ,1 , &unused); +if (ret <0 ) { +printk ("init_new_context_skas - unmap failed, " +"errno = %d; continuing\n" , ret); + mm->context.skas.first_flush =0 ; + } + ret =init_new_ldt (to_mm, from_mm);if (ret <0 ){ printk("init_new_context_skas - init_ldt"
arch/um/kernel/tlb.c +22 -11
@@ -139,10 +139,17 @@ void fix_range_common(struct mm_struct *void *flush =NULL ;int op_index =-1 , last_op =ARRAY_SIZE (ops) -1 ;int ret =0 ; +int first_flush;if (mm ==NULL )return ; +/* Nothing is mapped in this address space, so no call to add_munmap() +* must be done */ + first_flush = mm->context.skas.first_flush; + + mm->context.skas.first_flush =0 ; + ops[0 ].type =NONE ;for (addr = start_addr; addr < end_addr && !ret;){ npgd =pgd_offset (mm, addr);
@@ -151,9 +158,10 @@ void fix_range_common(struct mm_struct *if (end > end_addr) end = end_addr;if (force ||pgd_newpage (*npgd)){ - ret =add_munmap (addr, end - addr, ops, - &op_index, last_op, mmu, - &flush, do_ops); +if (!first_flush) + ret =add_munmap (addr, end - addr, ops, + &op_index, last_op, mmu, + &flush, do_ops);pgd_mkuptodate (*npgd); } addr = end;
@@ -166,9 +174,10 @@ void fix_range_common(struct mm_struct *if (end > end_addr) end = end_addr;if (force ||pud_newpage (*npud)){ - ret =add_munmap (addr, end - addr, ops, - &op_index, last_op, mmu, - &flush, do_ops); +if (!first_flush) + ret =add_munmap (addr, end - addr, ops, + &op_index, last_op, mmu, + &flush, do_ops);pud_mkuptodate (*npud); } addr = end;
@@ -181,9 +190,10 @@ void fix_range_common(struct mm_struct *if (end > end_addr) end = end_addr;if (force ||pmd_newpage (*npmd)){ - ret =add_munmap (addr, end - addr, ops, - &op_index, last_op, mmu, - &flush, do_ops); +if (!first_flush) + ret =add_munmap (addr, end - addr, ops, + &op_index, last_op, mmu, + &flush, do_ops);pmd_mkuptodate (*npmd); } addr = end;
@@ -207,7 +217,8 @@ void fix_range_common(struct mm_struct *PAGE_SIZE , r, w, x, ops, &op_index, last_op, mmu, &flush, do_ops); - else ret = add_munmap(addr, PAGE_SIZE, ops, + else if (!first_flush) + ret =add_munmap (addr,PAGE_SIZE , ops, &op_index, last_op, mmu, &flush, do_ops); }
@@ -219,7 +230,7 @@ void fix_range_common(struct mm_struct * *npte =pte_mkuptodate (*npte); addr +=PAGE_SIZE ; } -if (!ret) +if (!ret && op_index >-1 ) ret = (*do_ops)(mmu, ops, op_index,1 , &flush);/* This is not an else because ret is modified above */