summaryrefslogtreecommitdiffstats
path: root/mm/swap_state.c
diff options
context:
space:
mode:
authorHuang Ying <ying.huang@intel.com>2017-09-06 19:24:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-09-06 20:27:29 -0400
commitd9bfcfdc41e8e5d80f7591f95a09ccce7cb8ad05 (patch)
treec0844737c2d37eab327d6dfb0c446ef111b92d4f /mm/swap_state.c
parentec560175c0b6fce86994bdf036754d48122c5c87 (diff)
mm, swap: add sysfs interface for VMA based swap readahead
The sysfs interface to control the VMA based swap readahead is added as follow, /sys/kernel/mm/swap/vma_ra_enabled Enable the VMA based swap readahead algorithm, or use the original global swap readahead algorithm. /sys/kernel/mm/swap/vma_ra_max_order Set the max order of the readahead window size for the VMA based swap readahead algorithm. The corresponding ABI documentation is added too. Link: http://lkml.kernel.org/r/20170807054038.1843-5-ying.huang@intel.com Signed-off-by: "Huang, Ying" <ying.huang@intel.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Rik van Riel <riel@redhat.com> Cc: Shaohua Li <shli@kernel.org> Cc: Hugh Dickins <hughd@google.com> Cc: Fengguang Wu <fengguang.wu@intel.com> Cc: Tim Chen <tim.c.chen@intel.com> Cc: Dave Hansen <dave.hansen@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/swap_state.c')
-rw-r--r--mm/swap_state.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 3885fef7bdf5..71ce2d1ccbf7 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -751,3 +751,83 @@ skip:
751 return read_swap_cache_async(fentry, gfp_mask, vma, vmf->address, 751 return read_swap_cache_async(fentry, gfp_mask, vma, vmf->address,
752 swap_ra->win == 1); 752 swap_ra->win == 1);
753} 753}
754
755#ifdef CONFIG_SYSFS
756static ssize_t vma_ra_enabled_show(struct kobject *kobj,
757 struct kobj_attribute *attr, char *buf)
758{
759 return sprintf(buf, "%s\n", swap_vma_readahead ? "true" : "false");
760}
761static ssize_t vma_ra_enabled_store(struct kobject *kobj,
762 struct kobj_attribute *attr,
763 const char *buf, size_t count)
764{
765 if (!strncmp(buf, "true", 4) || !strncmp(buf, "1", 1))
766 swap_vma_readahead = true;
767 else if (!strncmp(buf, "false", 5) || !strncmp(buf, "0", 1))
768 swap_vma_readahead = false;
769 else
770 return -EINVAL;
771
772 return count;
773}
774static struct kobj_attribute vma_ra_enabled_attr =
775 __ATTR(vma_ra_enabled, 0644, vma_ra_enabled_show,
776 vma_ra_enabled_store);
777
778static ssize_t vma_ra_max_order_show(struct kobject *kobj,
779 struct kobj_attribute *attr, char *buf)
780{
781 return sprintf(buf, "%d\n", swap_ra_max_order);
782}
783static ssize_t vma_ra_max_order_store(struct kobject *kobj,
784 struct kobj_attribute *attr,
785 const char *buf, size_t count)
786{
787 int err, v;
788
789 err = kstrtoint(buf, 10, &v);
790 if (err || v > SWAP_RA_ORDER_CEILING || v <= 0)
791 return -EINVAL;
792
793 swap_ra_max_order = v;
794
795 return count;
796}
797static struct kobj_attribute vma_ra_max_order_attr =
798 __ATTR(vma_ra_max_order, 0644, vma_ra_max_order_show,
799 vma_ra_max_order_store);
800
801static struct attribute *swap_attrs[] = {
802 &vma_ra_enabled_attr.attr,
803 &vma_ra_max_order_attr.attr,
804 NULL,
805};
806
807static struct attribute_group swap_attr_group = {
808 .attrs = swap_attrs,
809};
810
811static int __init swap_init_sysfs(void)
812{
813 int err;
814 struct kobject *swap_kobj;
815
816 swap_kobj = kobject_create_and_add("swap", mm_kobj);
817 if (!swap_kobj) {
818 pr_err("failed to create swap kobject\n");
819 return -ENOMEM;
820 }
821 err = sysfs_create_group(swap_kobj, &swap_attr_group);
822 if (err) {
823 pr_err("failed to register swap group\n");
824 goto delete_obj;
825 }
826 return 0;
827
828delete_obj:
829 kobject_put(swap_kobj);
830 return err;
831}
832subsys_initcall(swap_init_sysfs);
833#endif