aio: convert the ioctx list to radix tree
PATCH v2 1/1 aio: convert the ioctx list to radix tree
When using a large number of threads performing AIO operations the IOCTX list may get a significant number of entries which will cause significant overhead. For example, when running this fio script:
rw=randrw; size=256k ;directory=/mnt/fio; ioengine=libaio; iodepth=1 blocksize=1024; numjobs=512; thread; loops=100
on an EXT2 filesystem mounted on top of a ramdisk we can observe up to 30% CPU time spent by lookup_ioctx:
32.51% [guest.kernel] [g] lookup_ioctx 9.19% [guest.kernel] [g] __lock_acquire.isra.28 4.40% [guest.kernel] [g] lock_release 4.19% [guest.kernel] [g] sched_clock_local 3.86% [guest.kernel] [g] local_clock 3.68% [guest.kernel] [g] native_sched_clock 3.08% [guest.kernel] [g] sched_clock_cpu 2.64% [guest.kernel] [g] lock_release_holdtime.part.11 2.60% [guest.kernel] [g] memcpy 2.33% [guest.kernel] [g] lock_acquired 2.25% [guest.kernel] [g] lock_acquire 1.84% [guest.kernel] [g] do_io_submit
This patchs converts the ioctx list to a radix tree. For a performance comparison the above FIO script was run on a 2 sockets 8 core machine. This are the results for the original list based implementation and for the radix tree based implementation:
cores 1 2 4 8 16 32
list 111025 ms 62219 ms 34193 ms 22998 ms 19335 ms 15956 ms radix 75400 ms 42668 ms 23923 ms 17206 ms 15820 ms 13295 ms
% of radix
relative 68% 69% 70% 75% 82% 83%
to list
To consider the impact of the patch on the typical case of having only one ctx per process the following FIO script was run:
rw=randrw; size=100m ;directory=/mnt/fio; ioengine=libaio; iodepth=1 blocksize=1024; numjobs=1; thread; loops=100
on the same system and the results are the following:
list 65241 ms
radix 65402 ms
% of radix
relative 100.25%
to list
---
Changes since V1:
* add performance comparision for the typical case of having only one ctx per process
* use ARRAY_SIZE and drop tracking idx as it is not needed
arch/s390/mm/pgtable.c | 4 +- fs/aio.c | 95 +++++++++++++++++++++++++++------------------- include/linux/aio.h | 1 - include/linux/mm_types.h | 3 +- kernel/fork.c | 2 +- 5 files changed, 61 insertions(+), 44 deletions(-)
arch/s390/mm/pgtable.c +2 -2
@@ -831,7 +831,7 @@ int s390_enable_sie(void)task_lock (tsk); if (!tsk->mm || atomic_read(&tsk->mm->mm_users) > 1 ||#ifdef CONFIG_AIO - !hlist_empty(&tsk->mm->ioctx_list) || + tsk->mm->ioctx_rtree.rnode || #endif tsk->mm != tsk->active_mm) {task_unlock (tsk);
@@ -858,7 +858,7 @@ int s390_enable_sie(void)task_lock (tsk); if (!tsk->mm || atomic_read(&tsk->mm->mm_users) > 1 ||#ifdef CONFIG_AIO - !hlist_empty(&tsk->mm->ioctx_list) || + tsk->mm->ioctx_rtree.rnode || #endif tsk->mm != tsk->active_mm) {mmput (mm);
fs/aio.c +56 -39
135 lines not on this page · raw message
include/linux/aio.h +0 -1
@@ -186,7 +186,6 @@ struct kioctx {/* This needs improving */ unsigned long user_id; -struct hlist_node list;wait_queue_head_t wait;
include/linux/mm_types.h +2 -1
@@ -5,6 +5,7 @@#include <linux/types.h> #include <linux/threads.h> #include <linux/list.h> +#include <linux/radix-tree.h> #include <linux/spinlock.h> #include <linux/rbtree.h> #include <linux/rwsem.h>
@@ -386,7 +387,7 @@ struct mm_struct {struct core_state *core_state;/* coredumping support */ #ifdef CONFIG_AIO spinlock_t ioctx_lock; -struct hlist_head ioctx_list; +struct radix_tree_root ioctx_rtree;#endif #ifdef CONFIG_MM_OWNER /*
kernel/fork.c +1 -1
@@ -523,7 +523,7 @@ static void mm_init_aio(struct mm_struct *mm) {#ifdef CONFIG_AIO spin_lock_init (&mm->ioctx_lock); -INIT_HLIST_HEAD (&mm->ioctx_list); +INIT_RADIX_TREE (&mm->ioctx_rtree,GFP_KERNEL );#endif }
Signature · 1 line
1.7.10.4
Andrew Morton
maintainerQuoted 1 line · On Wed, 3 Apr 2013 16:20:48 +0300 Octavian Purdila…
This patchs converts the ioctx list to a radix tree.
This looks rather nice, but unfortunately all the pending aio work in -mm/linux-next totally messes it up.
Could you please redo and retest it over the pending work? Perhaps after 3.10-rc1 would be a convenient time.
Quoted 10 lines · Andrew Morton
Quoted 1 line · On Wed, 3 Apr 2013 16:20:48 +0300 Octavian Purdila…
This patchs converts the ioctx list to a radix tree.
This looks rather nice, but unfortunately all the pending aio work in -mm/linux-next totally messes it up.
Could you please redo and retest it over the pending work? Perhaps after 3.10-rc1 would be a convenient time.
Hi Andrew,
Thanks for taking a look at this. I did test it against next/akpm HEAD a couple of weeks ago to see how it perform vs the new aio work from Kent, and is still looking good :) I will redo it and test it for the current next-apkm head and resend it to you.
Tavi