mm: move use_mm/unuse_mm from aio.c to mm/
Subsystems (7)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Michael S. Tsirkin
maintainerPATCH v3 1/2 mm: move use_mm/unuse_mm from aio.c to mm/
Anyone who wants to do copy to/from user from a kernel thread, needs use_mm (like what fs/aio has). Move that into mm/, to make reusing and exporting easier down the line, and make aio use it. Next intended user, besides aio, will be vhost-net.
--- fs/aio.c | 47 +------------------------------------ include/linux/mmu_context.h | 9 +++++++ mm/Makefile | 2 +- mm/mmu_context.c | 55 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 47 deletions(-) create mode 100644 include/linux/mmu_context.h create mode 100644 mm/mmu_context.c
fs/aio.c +1 -46
@@ -24,6 +24,7 @@#include <linux/file.h> #include <linux/mm.h> #include <linux/mman.h> +#include <linux/mmu_context.h> #include <linux/slab.h> #include <linux/timer.h> #include <linux/aio.h>
@@ -34,7 +35,6 @@#include <asm/kmap_types.h> #include <asm/uaccess.h> -#include <asm/mmu_context.h> #if DEBUG >1 #define dprintk printk
@@ -595,51 +595,6 @@ static struct kioctx *lookup_ioctx(unsigned long ctx_id) }/* -* use_mm -* Makes the calling kernel thread take on the specified -* mm context. -* Called by the retry thread execute retries within the -* iocb issuer's mm context, so that copy_from/to_user -* operations work seamlessly for aio. -* (Note: this routine is intended to be called only -* from a kernel thread context) -*/ -static void use_mm (struct mm_struct *mm) -{ -struct mm_struct *active_mm; -struct task_struct *tsk = current; - -task_lock (tsk); - active_mm = tsk->active_mm; -atomic_inc (&mm->mm_count); - tsk->mm = mm; - tsk->active_mm = mm; -switch_mm (active_mm, mm, tsk); -task_unlock (tsk); - -mmdrop (active_mm); -} - -/* -* unuse_mm -* Reverses the effect of use_mm, i.e. releases the -* specified mm context which was earlier taken on -* by the calling kernel thread -* (Note: this routine is intended to be called only -* from a kernel thread context) -*/ -static void unuse_mm (struct mm_struct *mm) -{ -struct task_struct *tsk = current; - -task_lock (tsk); - tsk->mm =NULL ; -/* active_mm is still 'mm' */ -enter_lazy_tlb (mm, tsk); -task_unlock (tsk); -} - -/* * Queue up a kiocb to be retried. Assumes that the kiocb * has already been marked as kicked, and places it on * the retry run list for the corresponding ioctx, if it
include/linux/mmu_context.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _LINUX_MMU_CONTEXT_H +#define _LINUX_MMU_CONTEXT_H + +struct mm_struct ; + +void use_mm (struct mm_struct *mm); +void unuse_mm (struct mm_struct *mm); + +#endif
mm/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-y := bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \ maccess.o page_alloc.o page-writeback.o pdflush.o \ readahead.o swap.o truncate.o vmscan.o shmem.o \ prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \ - page_isolation.o mm_init.o $(mmu-y) + page_isolation.o mm_init.o mmu_context.o $(mmu-y) obj-y += init-mm.o obj-$(CONFIG_PROC_PAGE_MONITOR) += pagewalk.o
mm/mmu_context.c new file +55 -0
55 lines not on this page · raw message
Signature · 7 lines
1.6.2.5 -- 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>
Michael S. Tsirkin
maintainerPATCH v3 1/2 mm: move use_mm/unuse_mm from aio.c to mm/
In reply to a message not in the archiveAnyone who wants to do copy to/from user from a kernel thread, needs use_mm (like what fs/aio has). Move that into mm/, to make reusing and exporting easier down the line, and make aio use it. Next intended user, besides aio, will be vhost-net.
--- fs/aio.c | 47 +------------------------------------ include/linux/mmu_context.h | 9 +++++++ mm/Makefile | 2 +- mm/mmu_context.c | 55 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 47 deletions(-) create mode 100644 include/linux/mmu_context.h create mode 100644 mm/mmu_context.c
fs/aio.c +1 -46
@@ -24,6 +24,7 @@#include <linux/file.h> #include <linux/mm.h> #include <linux/mman.h> +#include <linux/mmu_context.h> #include <linux/slab.h> #include <linux/timer.h> #include <linux/aio.h>
@@ -34,7 +35,6 @@#include <asm/kmap_types.h> #include <asm/uaccess.h> -#include <asm/mmu_context.h> #if DEBUG >1 #define dprintk printk
@@ -595,51 +595,6 @@ static struct kioctx *lookup_ioctx(unsigned long ctx_id) }/* -* use_mm -* Makes the calling kernel thread take on the specified -* mm context. -* Called by the retry thread execute retries within the -* iocb issuer's mm context, so that copy_from/to_user -* operations work seamlessly for aio. -* (Note: this routine is intended to be called only -* from a kernel thread context) -*/ -static void use_mm (struct mm_struct *mm) -{ -struct mm_struct *active_mm; -struct task_struct *tsk = current; - -task_lock (tsk); - active_mm = tsk->active_mm; -atomic_inc (&mm->mm_count); - tsk->mm = mm; - tsk->active_mm = mm; -switch_mm (active_mm, mm, tsk); -task_unlock (tsk); - -mmdrop (active_mm); -} - -/* -* unuse_mm -* Reverses the effect of use_mm, i.e. releases the -* specified mm context which was earlier taken on -* by the calling kernel thread -* (Note: this routine is intended to be called only -* from a kernel thread context) -*/ -static void unuse_mm (struct mm_struct *mm) -{ -struct task_struct *tsk = current; - -task_lock (tsk); - tsk->mm =NULL ; -/* active_mm is still 'mm' */ -enter_lazy_tlb (mm, tsk); -task_unlock (tsk); -} - -/* * Queue up a kiocb to be retried. Assumes that the kiocb * has already been marked as kicked, and places it on * the retry run list for the corresponding ioctx, if it
include/linux/mmu_context.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _LINUX_MMU_CONTEXT_H +#define _LINUX_MMU_CONTEXT_H + +struct mm_struct ; + +void use_mm (struct mm_struct *mm); +void unuse_mm (struct mm_struct *mm); + +#endif
mm/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-y := bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \ maccess.o page_alloc.o page-writeback.o pdflush.o \ readahead.o swap.o truncate.o vmscan.o shmem.o \ prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \ - page_isolation.o mm_init.o $(mmu-y) + page_isolation.o mm_init.o mmu_context.o $(mmu-y) obj-y += init-mm.o obj-$(CONFIG_PROC_PAGE_MONITOR) += pagewalk.o
mm/mmu_context.c new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
1.6.2.5
Michael S. Tsirkin
maintainerPATCH v3 2/2 mm: reduce atomic use on use_mm fast path
In reply to a message not in the archiveWhen mm switched to matches that of active mm, we don't need to increment and then drop the mm count. In a simple benchmark this happens in about 50% of time. Making that conditional reduces contention on that cache line on SMP systems.
--- mm/mmu_context.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
mm/mmu_context.c +6 -3
@@ -26,13 +26,16 @@ void use_mm(struct mm_struct *mm)task_lock (tsk); active_mm = tsk->active_mm; -atomic_inc (&mm->mm_count); +if (active_mm != mm) { +atomic_inc (&mm->mm_count); + tsk->active_mm = mm; + } tsk->mm = mm; - tsk->active_mm = mm;switch_mm (active_mm, mm, tsk);task_unlock (tsk); -mmdrop (active_mm); +if (active_mm != mm) +mmdrop (active_mm); }/*
Signature · 7 lines
1.6.2.5 -- 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>
Michael S. Tsirkin
maintainerPATCH v3 2/2 mm: reduce atomic use on use_mm fast path
In reply to a message not in the archiveWhen mm switched to matches that of active mm, we don't need to increment and then drop the mm count. In a simple benchmark this happens in about 50% of time. Making that conditional reduces contention on that cache line on SMP systems.
--- mm/mmu_context.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-)
mm/mmu_context.c +6 -3
@@ -26,13 +26,16 @@ void use_mm(struct mm_struct *mm)task_lock (tsk); active_mm = tsk->active_mm; -atomic_inc (&mm->mm_count); +if (active_mm != mm) { +atomic_inc (&mm->mm_count); + tsk->active_mm = mm; + } tsk->mm = mm; - tsk->active_mm = mm;switch_mm (active_mm, mm, tsk);task_unlock (tsk); -mmdrop (active_mm); +if (active_mm != mm) +mmdrop (active_mm); }/*
Signature · 1 line
1.6.2.5