lkml.org 
[lkml]   [2012]   [Dec]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subjectecho 1 > /proc/sys/vm/compact_memory -> sh: write error: Bad address
Date
I met one error when does the following command:

sh/$ echo 1 > /proc/sys/vm/compact_memory
sh/$ sh: write error: Bad address

After using strace, I find the following:
...
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

From the code, we can see it will return COMPACT_COMPLETE = 3 always when write.

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

/* Flush pending updates to the LRU lists */
lru_add_drain_all();

for_each_online_node(nid)
compact_node(nid);

return COMPACT_COMPLETE;
}

/* The written value is actually unused, all memory is compacted */
int sysctl_compact_memory;

/* This is the entry point for compacting all nodes via /proc/sys/vm */
int sysctl_compaction_handler(struct ctl_table *table, int write,
void __user *buffer, size_t *length, loff_t *ppos)
{
if (write)
return compact_nodes();

return 0;
}

I think we can't simply return COMPACT_COMPLETE, instead, we need return *length.

The following patch can fix this issue:

diff --git a/mm/compaction.c b/mm/compaction.c
index c4bc5ac..d3cb27f 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -732,8 +732,10 @@ int sysctl_compact_memory;
int sysctl_compaction_handler(struct ctl_table *table, int write,
void __user *buffer, size_t *length, loff_t *ppos)
{
- if (write)
- return compact_nodes();
+ if (write) {
+ compact_nodes();
+ return *length;
+ }

return 0;
}

Anyone can comment on it? Thanks a lot.

Happy Holiday.

Best Regards,
Jason Liu





\
 
 \ /
  Last update: 2012-12-27 13:01    [W:0.292 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site