linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH mm] limit the mm->map_count not greater than sysctl_max_map_count
@ 2012-04-18  9:27 Li Zhong
  2012-04-18 13:28 ` Cong Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Li Zhong @ 2012-04-18  9:27 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-mm, akpm

When reading the mmap codes, I found the checking of mm->map_count
against sysctl_max_map_count is not consistent. At some places, ">" is
used; at some other places, ">=" is used.

This patch changes ">" to ">=", so they are consistent, and makes sure
the value is not greater (one more) than sysctl_max_map_count.

Signed-off-by: Li Zhong <zhong@linux.vnet.ibm.com>
---
 mm/mmap.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index a7bf6a3..85f4816 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -987,7 +987,7 @@ unsigned long do_mmap_pgoff(struct file *file,
unsigned long addr,
                return -EOVERFLOW;
 
 	/* Too many mappings? */
-	if (mm->map_count > sysctl_max_map_count)
+	if (mm->map_count >= sysctl_max_map_count)
 		return -ENOMEM;
 
 	/* Obtain the address to map to. we verify (or select) it and ensure
@@ -2193,7 +2193,7 @@ unsigned long do_brk(unsigned long addr, unsigned
long len)
 	if (!may_expand_vm(mm, len >> PAGE_SHIFT))
 		return -ENOMEM;
 
-	if (mm->map_count > sysctl_max_map_count)
+	if (mm->map_count >= sysctl_max_map_count)
 		return -ENOMEM;
 
 	if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
-- 
1.7.6.5




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

* Re: [PATCH mm] limit the mm->map_count not greater than sysctl_max_map_count
  2012-04-18  9:27 [PATCH mm] limit the mm->map_count not greater than sysctl_max_map_count Li Zhong
@ 2012-04-18 13:28 ` Cong Wang
  2012-04-19  1:40   ` Li Zhong
  0 siblings, 1 reply; 3+ messages in thread
From: Cong Wang @ 2012-04-18 13:28 UTC (permalink / raw)
  To: Li Zhong; +Cc: linux-kernel, linux-mm, akpm

On 04/18/2012 05:27 PM, Li Zhong wrote:
> When reading the mmap codes, I found the checking of mm->map_count
> against sysctl_max_map_count is not consistent. At some places, ">" is
> used; at some other places, ">=" is used.
>
> This patch changes ">" to">=", so they are consistent, and makes sure
> the value is not greater (one more) than sysctl_max_map_count.
>

Well, according to Documentation/sysctl/vm.txt,

max_map_count:

This file contains the maximum number of memory map areas a process
may have. [...]

I think ->map_count == sysctl_max_map_count should be allowed, so using 
'>' is correct.

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

* Re: [PATCH mm] limit the mm->map_count not greater than sysctl_max_map_count
  2012-04-18 13:28 ` Cong Wang
@ 2012-04-19  1:40   ` Li Zhong
  0 siblings, 0 replies; 3+ messages in thread
From: Li Zhong @ 2012-04-19  1:40 UTC (permalink / raw)
  To: Cong Wang; +Cc: linux-kernel, linux-mm, akpm

On Wed, 2012-04-18 at 21:28 +0800, Cong Wang wrote:
> On 04/18/2012 05:27 PM, Li Zhong wrote:
> > When reading the mmap codes, I found the checking of mm->map_count
> > against sysctl_max_map_count is not consistent. At some places, ">" is
> > used; at some other places, ">=" is used.
> >
> > This patch changes ">" to">=", so they are consistent, and makes sure
> > the value is not greater (one more) than sysctl_max_map_count.
> >
> 
> Well, according to Documentation/sysctl/vm.txt,
> 
> max_map_count:
> 
> This file contains the maximum number of memory map areas a process
> may have. [...]
> 
> I think ->map_count == sysctl_max_map_count should be allowed, so using 
> '>' is correct.
> 
Yes, I agree that ->map_count == sysctl_max_map_count should be allowed.
However, with '>' used. The ->map_count could be sysctl_max_map_count+1.
It could be seen with a simple program doing continuously mmaping of a
file. 

( Still it is possible, as stated in the comments of do_munmap code, if
the VMA is going to be divided into two, the map_count could temporarily
be sysctl_max_map_count+1, after the original vma split into two, and
before one of the two vmas removed. ) 



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

end of thread, other threads:[~2012-04-19  1:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-18  9:27 [PATCH mm] limit the mm->map_count not greater than sysctl_max_map_count Li Zhong
2012-04-18 13:28 ` Cong Wang
2012-04-19  1:40   ` Li Zhong

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).