* [PATCH 1/2] mm: Fix overcommit overflow
@ 2008-04-30 20:42 Alan Cox
2008-04-30 21:09 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Alan Cox @ 2008-04-30 20:42 UTC (permalink / raw)
To: akpm, linux-kernel, linux-mm
Sami Farin reported an overflow in the overcommit handling on 64bit boxes.
We use atomic_t for page counting which is fine on 32bit but on 64bit
overflows. We can use atomic64_t but there is a problem - most heavy
users of zero overcommit are embedded people whose 64bit atomics are
really slow and expensive operations. Thus we use a few defines to flip
32 or 64bit according to the size of a long
(Split into two diffs to keep ownership correct)
Signed-off-by: Alan Cox <alan@redhat.com>
diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.25-mm1/include/linux/mman.h linux-2.6.25-mm1/include/linux/mman.h
--- linux.vanilla-2.6.25-mm1/include/linux/mman.h 2008-04-28 11:35:21.000000000 +0100
+++ linux-2.6.25-mm1/include/linux/mman.h 2008-04-30 11:21:10.000000000 +0100
@@ -15,16 +15,31 @@
#include <asm/atomic.h>
+/* 32bit platforms have a virtual address space in pages we
+ can fit into an atomic_t. We want to avoid atomic64_t on
+ such boxes as it is often expensive and most strict overcommit
+ users turn out to be embedded low power processors */
+
+#if (BITS_PER_LONG == 32)
+#define vm_atomic_t atomic_t
+#define vm_atomic_read atomic_read
+#define vm_atomic_add atomic_add
+#else
+#define vm_atomic_t atomic64_t
+#define vm_atomic_read atomic64_read
+#define vm_atomic_add atomic64_add
+#endif
+
extern int sysctl_overcommit_memory;
extern int sysctl_overcommit_ratio;
-extern atomic_t vm_committed_space;
+extern vm_atomic_t vm_committed_space;
#ifdef CONFIG_SMP
extern void vm_acct_memory(long pages);
#else
static inline void vm_acct_memory(long pages)
{
- atomic_add(pages, &vm_committed_space);
+ vm_atomic_add(pages, &vm_committed_space);
}
#endif
diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.25-mm1/mm/mmap.c linux-2.6.25-mm1/mm/mmap.c
--- linux.vanilla-2.6.25-mm1/mm/mmap.c 2008-04-28 11:36:52.000000000 +0100
+++ linux-2.6.25-mm1/mm/mmap.c 2008-04-30 11:17:03.000000000 +0100
@@ -80,7 +80,7 @@
int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
int sysctl_overcommit_ratio = 50; /* default is 50% */
int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
-atomic_t vm_committed_space = ATOMIC_INIT(0);
+vm_atomic_t vm_committed_space = ATOMIC_INIT(0);
/*
* Check that a process has enough memory to allocate a new virtual
@@ -177,7 +177,7 @@
* cast `allowed' as a signed long because vm_committed_space
* sometimes has a negative value
*/
- if (atomic_read(&vm_committed_space) < (long)allowed)
+ if (vm_atomic_read(&vm_committed_space) < (long)allowed)
return 0;
error:
vm_unacct_memory(pages);
diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.25-mm1/mm/swap.c linux-2.6.25-mm1/mm/swap.c
--- linux.vanilla-2.6.25-mm1/mm/swap.c 2008-04-28 11:36:52.000000000 +0100
+++ linux-2.6.25-mm1/mm/swap.c 2008-04-30 11:18:05.000000000 +0100
@@ -503,7 +503,7 @@
local = &__get_cpu_var(committed_space);
*local += pages;
if (*local > ACCT_THRESHOLD || *local < -ACCT_THRESHOLD) {
- atomic_add(*local, &vm_committed_space);
+ vm_atomic_add(*local, &vm_committed_space);
*local = 0;
}
preempt_enable();
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] mm: Fix overcommit overflow
2008-04-30 20:42 [PATCH 1/2] mm: Fix overcommit overflow Alan Cox
@ 2008-04-30 21:09 ` Andrew Morton
2008-04-30 21:14 ` Alan Cox
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2008-04-30 21:09 UTC (permalink / raw)
To: Alan Cox; +Cc: linux-kernel, linux-mm
On Wed, 30 Apr 2008 21:42:41 +0100
Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> Sami Farin reported an overflow in the overcommit handling on 64bit boxes.
>
> We use atomic_t for page counting which is fine on 32bit but on 64bit
> overflows. We can use atomic64_t but there is a problem - most heavy
> users of zero overcommit are embedded people whose 64bit atomics are
> really slow and expensive operations. Thus we use a few defines to flip
> 32 or 64bit according to the size of a long
>
> (Split into two diffs to keep ownership correct)
>
> Signed-off-by: Alan Cox <alan@redhat.com>
>
> diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.25-mm1/include/linux/mman.h linux-2.6.25-mm1/include/linux/mman.h
> --- linux.vanilla-2.6.25-mm1/include/linux/mman.h 2008-04-28 11:35:21.000000000 +0100
> +++ linux-2.6.25-mm1/include/linux/mman.h 2008-04-30 11:21:10.000000000 +0100
> @@ -15,16 +15,31 @@
>
> #include <asm/atomic.h>
>
> +/* 32bit platforms have a virtual address space in pages we
> + can fit into an atomic_t. We want to avoid atomic64_t on
> + such boxes as it is often expensive and most strict overcommit
> + users turn out to be embedded low power processors */
> +
> +#if (BITS_PER_LONG == 32)
> +#define vm_atomic_t atomic_t
> +#define vm_atomic_read atomic_read
> +#define vm_atomic_add atomic_add
> +#else
> +#define vm_atomic_t atomic64_t
> +#define vm_atomic_read atomic64_read
> +#define vm_atomic_add atomic64_add
> +#endif
ew.
> extern int sysctl_overcommit_memory;
> extern int sysctl_overcommit_ratio;
> -extern atomic_t vm_committed_space;
> +extern vm_atomic_t vm_committed_space;
>
> #ifdef CONFIG_SMP
> extern void vm_acct_memory(long pages);
> #else
> static inline void vm_acct_memory(long pages)
> {
> - atomic_add(pages, &vm_committed_space);
> + vm_atomic_add(pages, &vm_committed_space);
> }
> #endif
>
> diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.25-mm1/mm/mmap.c linux-2.6.25-mm1/mm/mmap.c
> --- linux.vanilla-2.6.25-mm1/mm/mmap.c 2008-04-28 11:36:52.000000000 +0100
> +++ linux-2.6.25-mm1/mm/mmap.c 2008-04-30 11:17:03.000000000 +0100
> @@ -80,7 +80,7 @@
> int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
> int sysctl_overcommit_ratio = 50; /* default is 50% */
> int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
> -atomic_t vm_committed_space = ATOMIC_INIT(0);
> +vm_atomic_t vm_committed_space = ATOMIC_INIT(0);
That'll need to be ATOMIC64_INIT on 64-bit.
>
> /*
> * Check that a process has enough memory to allocate a new virtual
> @@ -177,7 +177,7 @@
> * cast `allowed' as a signed long because vm_committed_space
> * sometimes has a negative value
> */
> - if (atomic_read(&vm_committed_space) < (long)allowed)
> + if (vm_atomic_read(&vm_committed_space) < (long)allowed)
> return 0;
> error:
> vm_unacct_memory(pages);
> diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.vanilla-2.6.25-mm1/mm/swap.c linux-2.6.25-mm1/mm/swap.c
> --- linux.vanilla-2.6.25-mm1/mm/swap.c 2008-04-28 11:36:52.000000000 +0100
> +++ linux-2.6.25-mm1/mm/swap.c 2008-04-30 11:18:05.000000000 +0100
> @@ -503,7 +503,7 @@
> local = &__get_cpu_var(committed_space);
> *local += pages;
> if (*local > ACCT_THRESHOLD || *local < -ACCT_THRESHOLD) {
> - atomic_add(*local, &vm_committed_space);
> + vm_atomic_add(*local, &vm_committed_space);
> *local = 0;
> }
> preempt_enable();
But afacit the existing atomic_long_t does exactly what you want?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] mm: Fix overcommit overflow
2008-04-30 21:09 ` Andrew Morton
@ 2008-04-30 21:14 ` Alan Cox
0 siblings, 0 replies; 3+ messages in thread
From: Alan Cox @ 2008-04-30 21:14 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, linux-mm
> > preempt_enable();
>
> But afacit the existing atomic_long_t does exactly what you want?
We have a portable atomic_long_t .. oooh scratch that patch then...
Alan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-04-30 21:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-30 20:42 [PATCH 1/2] mm: Fix overcommit overflow Alan Cox
2008-04-30 21:09 ` Andrew Morton
2008-04-30 21:14 ` Alan Cox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox