]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
slub: make ->remote_node_defrag_ratio unsigned int
authorAlexey Dobriyan <adobriyan@gmail.com>
Thu, 5 Apr 2018 23:20:48 +0000 (16:20 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 6 Apr 2018 04:36:23 +0000 (21:36 -0700)
->remote_node_defrag_ratio is in range 0..1000.

This also adds a check and modifies the behavior to return an error
code.  Before this patch invalid values were ignored.

Link: http://lkml.kernel.org/r/20180305200730.15812-9-adobriyan@gmail.com
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Acked-by: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/slub_def.h
mm/slub.c

index 8ad99c47b19cde22e4a4fdab0ad71e054817e9b4..f6548083fe0fbd2e1b8bbc61c6c2aab0a53ed42e 100644 (file)
@@ -124,7 +124,7 @@ struct kmem_cache {
        /*
         * Defragmentation by allocating from a remote node.
         */
-       int remote_node_defrag_ratio;
+       unsigned int remote_node_defrag_ratio;
 #endif
 
 #ifdef CONFIG_SLAB_FREELIST_RANDOM
index 495c785c8d7e75988e252e21257e069ead22943b..97dd2db30acbf2774a07c38ebf77307cd3e19f5d 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -5289,21 +5289,22 @@ SLAB_ATTR(shrink);
 #ifdef CONFIG_NUMA
 static ssize_t remote_node_defrag_ratio_show(struct kmem_cache *s, char *buf)
 {
-       return sprintf(buf, "%d\n", s->remote_node_defrag_ratio / 10);
+       return sprintf(buf, "%u\n", s->remote_node_defrag_ratio / 10);
 }
 
 static ssize_t remote_node_defrag_ratio_store(struct kmem_cache *s,
                                const char *buf, size_t length)
 {
-       unsigned long ratio;
+       unsigned int ratio;
        int err;
 
-       err = kstrtoul(buf, 10, &ratio);
+       err = kstrtouint(buf, 10, &ratio);
        if (err)
                return err;
+       if (ratio > 100)
+               return -ERANGE;
 
-       if (ratio <= 100)
-               s->remote_node_defrag_ratio = ratio * 10;
+       s->remote_node_defrag_ratio = ratio * 10;
 
        return length;
 }