mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [patch 1/1] uml: fixes performance regression in activate_mm and thus exec()
@ 2005-08-12 17:59 blaisorblade
       [not found] ` <20050812201145.GA10796@kvack.org>
  0 siblings, 1 reply; 2+ messages in thread
From: blaisorblade @ 2005-08-12 17:59 UTC (permalink / raw)
  To: akpm; +Cc: jdike, linux-kernel, user-mode-linux-devel, blaisorblade, bcrl


From: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
CC: Benjamin LaHaise <bcrl@kvack.org>

Normally, activate_mm() is called from exec(), and thus it used to be a no-op
because we use a completely new "MM context" on the host (for instance, a new
process), and so we didn't need to flush any "TLB entries" (which for us are
the set of memory mappings for the host process from the virtual "RAM" file).

Kernel threads, instead, are usually handled in a different way. So, when for
AIO we call use_mm(), things used to break and so Benjamin implemented
activate_mm(). However, that is only needed for AIO, and could slow down
exec() inside UML, so be smart: detect being called for AIO (via PF_BORROWED_MM)
and do the full flush only in that situation.

Comment also the caller so that people won't go breaking UML without noticing.
I also rely on the caller's locks for testing current->flags.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 linux-2.6.git-paolo/fs/aio.c                     |    2 ++
 linux-2.6.git-paolo/include/asm-um/mmu_context.h |    8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff -puN include/asm-um/mmu_context.h~uml-optimize-activate-mm include/asm-um/mmu_context.h
--- linux-2.6.git/include/asm-um/mmu_context.h~uml-optimize-activate-mm	2005-08-06 12:53:30.141344264 +0200
+++ linux-2.6.git-paolo/include/asm-um/mmu_context.h	2005-08-06 12:58:49.682766584 +0200
@@ -20,7 +20,13 @@ extern void force_flush_all(void);
 
 static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)
 {
-	if (old != new)
+	/* This is called by fs/exec.c and fs/aio.c. In the first case, for an
+	 * exec, we don't need to do anything as we're called from userspace
+	 * and thus going to use a new host PID. In the second, we're called
+	 * from a kernel thread, and thus need to go doing the mmap's on the
+	 * host. Since they're very expensive, we want to avoid that as far as
+	 * possible. */
+	if (old != new && (current->flags & PF_BORROWED_MM))
 		force_flush_all();
 }
 
diff -puN fs/aio.c~uml-optimize-activate-mm fs/aio.c
--- linux-2.6.git/fs/aio.c~uml-optimize-activate-mm	2005-08-06 12:59:14.393010056 +0200
+++ linux-2.6.git-paolo/fs/aio.c	2005-08-06 13:03:07.163623544 +0200
@@ -567,6 +567,8 @@ static void use_mm(struct mm_struct *mm)
 	atomic_inc(&mm->mm_count);
 	tsk->mm = mm;
 	tsk->active_mm = mm;
+	/* Note that on UML this *requires* PF_BORROWED_MM to be set, otherwise
+	 * it won't work. Update it accordingly if you change it here. */
 	activate_mm(active_mm, mm);
 	task_unlock(tsk);
 
_

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch 1/1] uml: fixes performance regression in activate_mm and thus exec()
       [not found] ` <20050812201145.GA10796@kvack.org>
@ 2005-08-23  9:57   ` Blaisorblade
  0 siblings, 0 replies; 2+ messages in thread
From: Blaisorblade @ 2005-08-23  9:57 UTC (permalink / raw)
  To: Benjamin LaHaise; +Cc: LKML, Jeff Dike

On Friday 12 August 2005 22:11, Benjamin LaHaise wrote:
> Is it possible to get an optimization for this case where uml can execute
> the kernel thread in the same process as it normally executes kernel mode
> for the given mm?  AIO performance on uml is pretty bad when it has to
> access userspace.
I thought to another solution to that, i.e. use get_user_pages() and kmap() 
the resulting pages, like other kernel threads do when accessing userspace 
context.

However, by looking at the code (starting from aio_pread), maybe AIO reuses 
too much normal I/O code to do this.

Actually, the changes wouldn't maybe be so intrusive, they're limited to 
__generic_file_aio_read (conditionalize access_ok, and change the setup of 
read_descriptor_t) and file_read_actor, plus the write side, plus anything 
not using  pagecache - generic_file_aio_read.

Having a different actor for AIO would work. The real problem is adding a 
field to iovec to specify whether we're passing in a page array (given by 
get_user_pages) rather than a void __user *, or passing an iovec "wrapper" 
structure, which can carry either a normal iovec or the new kind of 
descriptor.

However, this does not sound like too much added complexity. Instead, allowing 
to move a kernel thread elsewhere on the host is a lot more difficult.
-- 
Inform me of my mistakes, so I can keep imitating Homer Simpson's "Doh!".
Paolo Giarrusso, aka Blaisorblade (Skype ID "PaoloGiarrusso", ICQ 215621894)
http://www.user-mode-linux.org/~blaisorblade


	

	
		
___________________________________ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-08-26 15:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-12 17:59 [patch 1/1] uml: fixes performance regression in activate_mm and thus exec() blaisorblade
     [not found] ` <20050812201145.GA10796@kvack.org>
2005-08-23  9:57   ` Blaisorblade

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®