Skip to content

Commit

Permalink
slub: make ->remote_node_defrag_ratio unsigned int
Browse files Browse the repository at this point in the history
->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/[email protected]
Signed-off-by: Alexey Dobriyan <[email protected]>
Acked-by: Christoph Lameter <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Alexey Dobriyan authored and torvalds committed Apr 6, 2018
1 parent ac914d0 commit eb7235e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/linux/slub_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit eb7235e

Please sign in to comment.