Skip to content

Commit

Permalink
fix echo 1 > compact_memory return error issue
Browse files Browse the repository at this point in the history
when run the folloing command under shell, it will return error
sh/$ echo 1 > /proc/sys/vm/compact_memory
sh/$ sh: write error: Bad address

After strace, I found the following log:
...
write(1, "1\n", 2)               = 3
write(1, "", 4294967295)         = -1 EFAULT (Bad address)
write(2, "echo: write error: Bad address\n", 31echo: write error: Bad address
) = 31

This tells system return 3(COMPACT_COMPLETE) after write data to compact_memory.

The fix is to make the system just return 0 instead 3(COMPACT_COMPLETE) from
sysctl_compaction_handler after compaction_nodes finished.

Signed-off-by: Jason Liu <r64343@freescale.com>
Suggested-by: David Rientjes <rientjes@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Rik van Riel <riel@redhat.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
LiuHui-Jason committed Jan 8, 2013
1 parent d7c6674 commit 80ad41a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions mm/compaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,14 +715,12 @@ static int compact_node(int nid)
}

/* Compact all nodes in the system */
static int compact_nodes(void)
static void compact_nodes(void)
{
int nid;

for_each_online_node(nid)
compact_node(nid);

return COMPACT_COMPLETE;
}

/* The written value is actually unused, all memory is compacted */
Expand All @@ -733,7 +731,7 @@ int sysctl_compaction_handler(struct ctl_table *table, int write,
void __user *buffer, size_t *length, loff_t *ppos)
{
if (write)
return compact_nodes();
compact_nodes();

return 0;
}
Expand Down

0 comments on commit 80ad41a

Please sign in to comment.