Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 623
b: refs/heads/master
c: 119f657
h: refs/heads/master
i:
  621: de7d346
  619: a2bfd2a
  615: bbdc571
  607: 0860650
v: v3
  • Loading branch information
akpm@osdl.org authored and Linus Torvalds committed May 1, 2005
1 parent 0421616 commit 4506dff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f021e9210185b46e41ec3a0e78ec1621e168eacb
refs/heads/master: 119f657c72fc07d6fd28c61de59cfba1566970a9
1 change: 1 addition & 0 deletions trunk/include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ extern void __vma_link_rb(struct mm_struct *, struct vm_area_struct *,
extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
unsigned long addr, unsigned long len, pgoff_t pgoff);
extern void exit_mmap(struct mm_struct *);
extern int may_expand_vm(struct mm_struct *mm, unsigned long npages);

extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);

Expand Down
24 changes: 19 additions & 5 deletions trunk/mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,7 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
}

/* Check against address space limit. */
if ((mm->total_vm << PAGE_SHIFT) + len
> current->signal->rlim[RLIMIT_AS].rlim_cur)
if (!may_expand_vm(mm, len >> PAGE_SHIFT))
return -ENOMEM;

if (accountable && (!(flags & MAP_NORESERVE) ||
Expand Down Expand Up @@ -1421,7 +1420,7 @@ static int acct_stack_growth(struct vm_area_struct * vma, unsigned long size, un
struct rlimit *rlim = current->signal->rlim;

/* address space limit tests */
if (mm->total_vm + grow > rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT)
if (!may_expand_vm(mm, grow))
return -ENOMEM;

/* Stack limit test */
Expand Down Expand Up @@ -1848,8 +1847,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
}

/* Check against address space limits *after* clearing old maps... */
if ((mm->total_vm << PAGE_SHIFT) + len
> current->signal->rlim[RLIMIT_AS].rlim_cur)
if (!may_expand_vm(mm, len >> PAGE_SHIFT))
return -ENOMEM;

if (mm->map_count > sysctl_max_map_count)
Expand Down Expand Up @@ -2019,3 +2017,19 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
}
return new_vma;
}

/*
* Return true if the calling process may expand its vm space by the passed
* number of pages
*/
int may_expand_vm(struct mm_struct *mm, unsigned long npages)
{
unsigned long cur = mm->total_vm; /* pages */
unsigned long lim;

lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;

if (cur + npages > lim)
return 0;
return 1;
}
6 changes: 3 additions & 3 deletions trunk/mm/mremap.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ unsigned long do_mremap(unsigned long addr,
if (locked > lock_limit && !capable(CAP_IPC_LOCK))
goto out;
}
ret = -ENOMEM;
if ((current->mm->total_vm << PAGE_SHIFT) + (new_len - old_len)
> current->signal->rlim[RLIMIT_AS].rlim_cur)
if (!may_expand_vm(current->mm, (new_len - old_len) >> PAGE_SHIFT)) {
ret = -ENOMEM;
goto out;
}

if (vma->vm_flags & VM_ACCOUNT) {
charged = (new_len - old_len) >> PAGE_SHIFT;
Expand Down

0 comments on commit 4506dff

Please sign in to comment.