linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages
@ 2011-02-22 20:17 Petr Holasek
  2011-02-22 20:32 ` David Rientjes
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Petr Holasek @ 2011-02-22 20:17 UTC (permalink / raw)
  To: linux-kernel
  Cc: Petr Holasek, Andi Kleen, Naoya Horiguchi, Mel Gorman,
	Andrew Morton, Wu Fengguang, linux-mm

When user insert negative value into /proc/sys/vm/nr_hugepages it will 
result
in the setting a random number of HugePages in system (can be easily showed
at /proc/meminfo output). This patch fixes the wrong behavior so that the
negative input will result in nr_hugepages value unchanged.

v2: same fix was also done in hugetlb_overcommit_handler function
     as suggested by reviewers.

Signed-off-by: Petr Holasek <pholasek@redhat.com>
Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
---
  mm/hugetlb.c |    6 ++----
  1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index bb0b7c1..06de5aa 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1872,8 +1872,7 @@ static int hugetlb_sysctl_handler_common(bool 
obey_mempolicy,
      unsigned long tmp;
      int ret;

-    if (!write)
-        tmp = h->max_huge_pages;
+    tmp = h->max_huge_pages;

      if (write && h->order >= MAX_ORDER)
          return -EINVAL;
@@ -1938,8 +1937,7 @@ int hugetlb_overcommit_handler(struct ctl_table 
*table, int write,
      unsigned long tmp;
      int ret;

-    if (!write)
-        tmp = h->nr_overcommit_huge_pages;
+    tmp = h->nr_overcommit_huge_pages;

      if (write && h->order >= MAX_ORDER)
          return -EINVAL;
-- 
1.7.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages
  2011-02-22 20:17 [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages Petr Holasek
@ 2011-02-22 20:32 ` David Rientjes
  2011-02-23  9:01 ` Mel Gorman
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: David Rientjes @ 2011-02-22 20:32 UTC (permalink / raw)
  To: Petr Holasek
  Cc: linux-kernel, Andi Kleen, Naoya Horiguchi, Mel Gorman,
	Andrew Morton, Wu Fengguang, linux-mm

On Tue, 22 Feb 2011, Petr Holasek wrote:

> When user insert negative value into /proc/sys/vm/nr_hugepages it will result
> in the setting a random number of HugePages in system (can be easily showed
> at /proc/meminfo output). This patch fixes the wrong behavior so that the
> negative input will result in nr_hugepages value unchanged.
> 
> v2: same fix was also done in hugetlb_overcommit_handler function
>     as suggested by reviewers.
> 
> Signed-off-by: Petr Holasek <pholasek@redhat.com>
> Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>

Acked-by: David Rientjes <rientjes@google.com>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages
  2011-02-22 20:17 [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages Petr Holasek
  2011-02-22 20:32 ` David Rientjes
@ 2011-02-23  9:01 ` Mel Gorman
  2011-02-23 15:33 ` Eric B Munson
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Mel Gorman @ 2011-02-23  9:01 UTC (permalink / raw)
  To: Petr Holasek
  Cc: linux-kernel, Andi Kleen, Naoya Horiguchi, Andrew Morton,
	Wu Fengguang, linux-mm

On Tue, Feb 22, 2011 at 09:17:04PM +0100, Petr Holasek wrote:
> When user insert negative value into /proc/sys/vm/nr_hugepages it will  
> result
> in the setting a random number of HugePages in system (can be easily showed
> at /proc/meminfo output). This patch fixes the wrong behavior so that the
> negative input will result in nr_hugepages value unchanged.
>
> v2: same fix was also done in hugetlb_overcommit_handler function
>     as suggested by reviewers.
>
> Signed-off-by: Petr Holasek <pholasek@redhat.com>
> Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>

Thanks

Acked-by: Mel Gorman <mel@csn.ul.ie>

-- 
Mel Gorman
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages
  2011-02-22 20:17 [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages Petr Holasek
  2011-02-22 20:32 ` David Rientjes
  2011-02-23  9:01 ` Mel Gorman
@ 2011-02-23 15:33 ` Eric B Munson
  2011-02-24  8:16 ` Anton Arapov
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Eric B Munson @ 2011-02-23 15:33 UTC (permalink / raw)
  To: Petr Holasek
  Cc: linux-kernel, Andi Kleen, Naoya Horiguchi, Mel Gorman,
	Andrew Morton, Wu Fengguang, linux-mm

[-- Attachment #1: Type: text/plain, Size: 618 bytes --]

On Tue, 22 Feb 2011, Petr Holasek wrote:

> When user insert negative value into /proc/sys/vm/nr_hugepages it
> will result
> in the setting a random number of HugePages in system (can be easily showed
> at /proc/meminfo output). This patch fixes the wrong behavior so that the
> negative input will result in nr_hugepages value unchanged.
> 
> v2: same fix was also done in hugetlb_overcommit_handler function
>     as suggested by reviewers.
> 
> Signed-off-by: Petr Holasek <pholasek@redhat.com>
> Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>

Acked-by: Eric B Munson <emunson@mgebm.net>

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages
  2011-02-22 20:17 [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages Petr Holasek
                   ` (2 preceding siblings ...)
  2011-02-23 15:33 ` Eric B Munson
@ 2011-02-24  8:16 ` Anton Arapov
  2011-02-24 17:02 ` Petr Holasek
  2011-02-24 22:10 ` Andrew Morton
  5 siblings, 0 replies; 9+ messages in thread
From: Anton Arapov @ 2011-02-24  8:16 UTC (permalink / raw)
  To: Petr Holasek
  Cc: linux-kernel, Andi Kleen, Naoya Horiguchi, Mel Gorman,
	Andrew Morton, Wu Fengguang, linux-mm

On Tue, Feb 22, 2011 at 09:17:04PM +0100, Petr Holasek wrote:
> When user insert negative value into /proc/sys/vm/nr_hugepages it
> will result
> in the setting a random number of HugePages in system (can be easily showed
> at /proc/meminfo output). This patch fixes the wrong behavior so that the
> negative input will result in nr_hugepages value unchanged.
> 
> v2: same fix was also done in hugetlb_overcommit_handler function
>     as suggested by reviewers.
> 
> Signed-off-by: Petr Holasek <pholasek@redhat.com>
> Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> ---
>  mm/hugetlb.c |    6 ++----
>  1 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index bb0b7c1..06de5aa 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1872,8 +1872,7 @@ static int hugetlb_sysctl_handler_common(bool
> obey_mempolicy,
>      unsigned long tmp;
>      int ret;
> 
> -    if (!write)
> -        tmp = h->max_huge_pages;
> +    tmp = h->max_huge_pages;
> 
>      if (write && h->order >= MAX_ORDER)
>          return -EINVAL;
> @@ -1938,8 +1937,7 @@ int hugetlb_overcommit_handler(struct
> ctl_table *table, int write,
>      unsigned long tmp;
>      int ret;
> 
> -    if (!write)
> -        tmp = h->nr_overcommit_huge_pages;
> +    tmp = h->nr_overcommit_huge_pages;
> 
>      if (write && h->order >= MAX_ORDER)
>          return -EINVAL;
> -- 
> 1.7.1
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 
 
Signed-off-by: Anton Arapov <anton@redhat.com>

-- 
Anton

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages
  2011-02-22 20:17 [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages Petr Holasek
                   ` (3 preceding siblings ...)
  2011-02-24  8:16 ` Anton Arapov
@ 2011-02-24 17:02 ` Petr Holasek
  2011-02-24 22:10 ` Andrew Morton
  5 siblings, 0 replies; 9+ messages in thread
From: Petr Holasek @ 2011-02-24 17:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andi Kleen, Naoya Horiguchi, Mel Gorman, Andrew Morton,
	Wu Fengguang, linux-mm

----- Original Message -----
> From: "Petr Holasek" <pholasek@redhat.com>
> To: linux-kernel@vger.kernel.org
> Cc: "Petr Holasek" <pholasek@redhat.com>, "Andi Kleen" <ak@linux.intel.com>, "Naoya Horiguchi"
> <n-horiguchi@ah.jp.nec.com>, "Mel Gorman" <mel@csn.ul.ie>, "Andrew Morton" <akpm@linux-foundation.org>, "Wu Fengguang"
> <fengguang.wu@intel.com>, linux-mm@kvack.org
> Sent: Tuesday, February 22, 2011 9:17:04 PM
> Subject: [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages
> When user insert negative value into /proc/sys/vm/nr_hugepages it will
> result
> in the setting a random number of HugePages in system (can be easily
> showed
> at /proc/meminfo output). This patch fixes the wrong behavior so that
> the
> negative input will result in nr_hugepages value unchanged.
> 
> v2: same fix was also done in hugetlb_overcommit_handler function
> as suggested by reviewers.
> 
> Signed-off-by: Petr Holasek <pholasek@redhat.com>
> Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> ---
> mm/hugetlb.c | 6 ++----
> 1 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index bb0b7c1..06de5aa 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1872,8 +1872,7 @@ static int hugetlb_sysctl_handler_common(bool
> obey_mempolicy,
> unsigned long tmp;
> int ret;
> 
> - if (!write)
> - tmp = h->max_huge_pages;
> + tmp = h->max_huge_pages;
> 
> if (write && h->order >= MAX_ORDER)
> return -EINVAL;
> @@ -1938,8 +1937,7 @@ int hugetlb_overcommit_handler(struct ctl_table
> *table, int write,
> unsigned long tmp;
> int ret;
> 
> - if (!write)
> - tmp = h->nr_overcommit_huge_pages;
> + tmp = h->nr_overcommit_huge_pages;
> 
> if (write && h->order >= MAX_ORDER)
> return -EINVAL;
> --
> 1.7.1
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

I am really sorry, but tabs were broken up into spaces during posting,
here is the right version:

thanks,
Petr

---
 mm/hugetlb.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index bb0b7c1..06de5aa 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1872,8 +1872,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
 	unsigned long tmp;
 	int ret;
 
-	if (!write)
-		tmp = h->max_huge_pages;
+	tmp = h->max_huge_pages;
 
 	if (write && h->order >= MAX_ORDER)
 		return -EINVAL;
@@ -1938,8 +1937,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
 	unsigned long tmp;
 	int ret;
 
-	if (!write)
-		tmp = h->nr_overcommit_huge_pages;
+	tmp = h->nr_overcommit_huge_pages;
 
 	if (write && h->order >= MAX_ORDER)
 		return -EINVAL;
-- 
1.7.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages
  2011-02-22 20:17 [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages Petr Holasek
                   ` (4 preceding siblings ...)
  2011-02-24 17:02 ` Petr Holasek
@ 2011-02-24 22:10 ` Andrew Morton
  2011-02-24 22:13   ` Andrew Morton
  5 siblings, 1 reply; 9+ messages in thread
From: Andrew Morton @ 2011-02-24 22:10 UTC (permalink / raw)
  To: Petr Holasek
  Cc: linux-kernel, Andi Kleen, Naoya Horiguchi, Mel Gorman,
	Wu Fengguang, linux-mm

On Tue, 22 Feb 2011 21:17:04 +0100
Petr Holasek <pholasek@redhat.com> wrote:

> When user insert negative value into /proc/sys/vm/nr_hugepages it will 
> result
> in the setting a random number of HugePages in system

Is this true?  afacit the kernel will allocate as many pages as it can
and will then set /proc/sys/vm/nr_hugepages to reflect the result. 
That's not random.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages
  2011-02-24 22:10 ` Andrew Morton
@ 2011-02-24 22:13   ` Andrew Morton
  2011-02-25 17:30     ` Mel Gorman
  0 siblings, 1 reply; 9+ messages in thread
From: Andrew Morton @ 2011-02-24 22:13 UTC (permalink / raw)
  To: Petr Holasek, linux-kernel, Andi Kleen, Naoya Horiguchi,
	Mel Gorman, Wu Fengguang, linux-mm

On Thu, 24 Feb 2011 14:10:34 -0800
Andrew Morton <akpm@linux-foundation.org> wrote:

> On Tue, 22 Feb 2011 21:17:04 +0100
> Petr Holasek <pholasek@redhat.com> wrote:
> 
> > When user insert negative value into /proc/sys/vm/nr_hugepages it will 
> > result
> > in the setting a random number of HugePages in system
> 
> Is this true?  afacit the kernel will allocate as many pages as it can
> and will then set /proc/sys/vm/nr_hugepages to reflect the result. 
> That's not random.
> 

Assuming the above to be correct, I altered the changelog thusly:

: When the user inserts a negative value into /proc/sys/vm/nr_hugepages it
: will cause the kernel to allocate as many hugepages as possible and to
: then update /proc/meminfo to reflect this.
:
: This changes the behavior so that the negative input will result in
: nr_hugepages value being unchanged.

and given that, I don't really see why we should change the existing behaviour.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages
  2011-02-24 22:13   ` Andrew Morton
@ 2011-02-25 17:30     ` Mel Gorman
  0 siblings, 0 replies; 9+ messages in thread
From: Mel Gorman @ 2011-02-25 17:30 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Petr Holasek, linux-kernel, Andi Kleen, Naoya Horiguchi,
	Wu Fengguang, linux-mm

On Thu, Feb 24, 2011 at 02:13:35PM -0800, Andrew Morton wrote:
> On Thu, 24 Feb 2011 14:10:34 -0800
> Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> > On Tue, 22 Feb 2011 21:17:04 +0100
> > Petr Holasek <pholasek@redhat.com> wrote:
> > 
> > > When user insert negative value into /proc/sys/vm/nr_hugepages it will 
> > > result
> > > in the setting a random number of HugePages in system
> > 
> > Is this true?  afacit the kernel will allocate as many pages as it can
> > and will then set /proc/sys/vm/nr_hugepages to reflect the result. 
> > That's not random.
> > 
> 
> Assuming the above to be correct, I altered the changelog thusly:
> 

AFAIK, it's correct.

> : When the user inserts a negative value into /proc/sys/vm/nr_hugepages it
> : will cause the kernel to allocate as many hugepages as possible and to
> : then update /proc/meminfo to reflect this.
> :
> : This changes the behavior so that the negative input will result in
> : nr_hugepages value being unchanged.
> 
> and given that, I don't really see why we should change the existing behaviour.
> 

The main motivation is that asking the kernel for -1 pages and getting a
sensible response just feels wrong. The second reason I'd guess is that an
administrator script that was buggy (or raced with a second) instance that
accidentally wrote a negative number to the proc interface would try allocating
all memory as huge pages instead of reducing the number of hugepages as
was probably intended. Totally hypothetical case of course, I haven't
actually heard of this happening to anyone.

-- 
Mel Gorman
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-02-25 17:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-22 20:17 [PATCH v2] hugetlbfs: correct handling of negative input to /proc/sys/vm/nr_hugepages Petr Holasek
2011-02-22 20:32 ` David Rientjes
2011-02-23  9:01 ` Mel Gorman
2011-02-23 15:33 ` Eric B Munson
2011-02-24  8:16 ` Anton Arapov
2011-02-24 17:02 ` Petr Holasek
2011-02-24 22:10 ` Andrew Morton
2011-02-24 22:13   ` Andrew Morton
2011-02-25 17:30     ` Mel Gorman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).