Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

1,125 views
Skip to first unread message

Liu Hui-R64343

unread,
Dec 27, 2012, 6:30:01 AM12/27/12
to
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



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

David Rientjes

unread,
Dec 27, 2012, 5:40:02 PM12/27/12
to
On Thu, 27 Dec 2012, Liu Hui-R64343 wrote:

> 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;
> }

No need to return the length at all, simply change compact_nodes() to
return void, remove the return value, and do

if (write)
compact_nodes();
return 0;

and it should be fixed. Could you write a changelog that shows the before
and after behavior (not necessarily the implementation), sign-off the
patch as described in Documentation/SubmittingPatches, running
scripts/get_maintainer.pl on your new patch file, and sending it to
all addresses that are listed?

Liu Hui-R64343

unread,
Dec 28, 2012, 1:10:02 AM12/28/12
to
>-----Original Message-----
>From: David Rientjes [mailto:rien...@google.com]
>Sent: Friday, December 28, 2012 6:39 AM
>To: Liu Hui-R64343
>Cc: Mel Gorman; linux-...@vger.kernel.org
>Subject: Re: echo 1 > /proc/sys/vm/compact_memory -> sh: write error: Bad
>address
>
>On Thu, 27 Dec 2012, Liu Hui-R64343 wrote:
>
>> 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;
>> }
>
>No need to return the length at all, simply change compact_nodes() to return
>void, remove the return value, and do
>
> if (write)
> compact_nodes();
> return 0;
>
>and it should be fixed.

Yes, this works. Thanks,

> Could you write a changelog that shows the before
>and after behavior (not necessarily the implementation), sign-off the patch
>as described in Documentation/SubmittingPatches, running
>scripts/get_maintainer.pl on your new patch file, and sending it to all
>addresses that are listed?

OK, I will send out the patch as you suggested.

Happy holiday.

Jason Liu
0 new messages