From 2e38a0f2950ec8884385fe0f484fce0892af5a15 Mon Sep 17 00:00:00 2001 From: Xiaoguang Wang Date: Mon, 9 Mar 2020 10:18:05 +0800 Subject: [PATCH] alinux: mm: add proc interface to control context readahead For some workloads whose io activities are mostly random, context readahead feature can introduce unnecessary io read operations, which will impact app's performance. Context readahead's algorithm is straightforward and not that smart. This patch adds "/proc/sys/vm/enable_context_readahead" to control whether to disable or enable this feature. Currently we enable context readahead default, user can echo 0 to /proc/sys/vm/enable_context_readahead to disable context readahead. We also have tested mongodb's performance in 'random point select' case, With context readahead enabled: mongodb eps 12409 With context readahead disabled: mongodb eps 14443 About 16% performance improvement. Signed-off-by: Xiaoguang Wang Reviewed-by: Joseph Qi --- Documentation/sysctl/vm.txt | 17 +++++++++++++++++ kernel/sysctl.c | 11 +++++++++++ mm/readahead.c | 10 ++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Documentation/sysctl/vm.txt b/Documentation/sysctl/vm.txt index 7d73882e2c27..c0cf24ba4797 100644 --- a/Documentation/sysctl/vm.txt +++ b/Documentation/sysctl/vm.txt @@ -65,6 +65,7 @@ Currently, these files are in /proc/sys/vm: - vfs_cache_pressure - watermark_scale_factor - zone_reclaim_mode +- enable_context_readahead ============================================================== @@ -910,4 +911,20 @@ Allowing regular swap effectively restricts allocations to the local node unless explicitly overridden by memory policies or cpuset configurations. +============================================================== + +enable_context_readahead: + +Specific workloads whose io activities are mostly random, context readahead +feature may introduce unnecessary io read operations, which will impact app's +performance. + +Default it is enabled. + +To disable context readahead: + echo 0 > /proc/sys/vm/enable_context_readahead + +To enable context readahead again: + echo 1 > /proc/sys/vm/enable_context_readahead + ============ End of Document ================================= diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 8a5f85651ba6..8482670ebed1 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -262,6 +262,8 @@ extern struct ctl_table epoll_table[]; extern struct ctl_table firmware_config_table[]; #endif +extern int sysctl_enable_context_readahead; + #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT int sysctl_legacy_va_layout; #endif @@ -1666,6 +1668,15 @@ static struct ctl_table vm_table[] = { .extra2 = (void *)&mmap_rnd_compat_bits_max, }, #endif + { + .procname = "enable_context_readahead", + .data = &sysctl_enable_context_readahead, + .maxlen = sizeof(sysctl_enable_context_readahead), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = &zero, + .extra2 = &one, + }, { } }; diff --git a/mm/readahead.c b/mm/readahead.c index 4e630143a0ba..8491fde016e9 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -24,6 +24,9 @@ #include "internal.h" +/* enable context readahead default */ +int sysctl_enable_context_readahead = 1; + /* * Initialise a struct file's readahead state. Assumes that the caller has * memset *ra to zero. @@ -458,8 +461,11 @@ ondemand_readahead(struct address_space *mapping, * Query the page cache and look for the traces(cached history pages) * that a sequential stream would leave behind. */ - if (try_context_readahead(mapping, ra, offset, req_size, max_pages)) - goto readit; + if (sysctl_enable_context_readahead) { + if (try_context_readahead(mapping, ra, offset, req_size, + max_pages)) + goto readit; + } /* * standalone, small random read -- GitLab