Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 130532
b: refs/heads/master
c: fc8744a
h: refs/heads/master
v: v3
  • Loading branch information
Linus Torvalds committed Jan 31, 2009
1 parent 0a6dbcc commit b7662b0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 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: 33bfad54b58cf05cfe6678c3ec9235d4bc8db4c2
refs/heads/master: fc8744adc870a8d4366908221508bb113d8b72ee
2 changes: 1 addition & 1 deletion trunk/drivers/gpu/drm/drm_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size)
obj = kcalloc(1, sizeof(*obj), GFP_KERNEL);

obj->dev = dev;
obj->filp = shmem_file_setup("drm mm object", size, 0);
obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
if (IS_ERR(obj->filp)) {
kfree(obj);
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions trunk/ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
file = hugetlb_file_setup(name, size);
shp->mlock_user = current_user();
} else {
int acctflag = VM_ACCOUNT;
int acctflag = 0;
/*
* Do not allow no accounting for OVERCOMMIT_NEVER, even
* if it's asked for.
*/
if ((shmflg & SHM_NORESERVE) &&
sysctl_overcommit_memory != OVERCOMMIT_NEVER)
acctflag = 0;
acctflag = VM_NORESERVE;
file = shmem_file_setup(name, size, acctflag);
}
error = PTR_ERR(file);
Expand Down
48 changes: 25 additions & 23 deletions trunk/mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,15 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
mapping_cap_account_dirty(vma->vm_file->f_mapping);
}

/*
* We account for memory if it's a private writeable mapping,
* and VM_NORESERVE wasn't set.
*/
static inline int accountable_mapping(unsigned int vm_flags)
{
return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) == VM_WRITE;
}

unsigned long mmap_region(struct file *file, unsigned long addr,
unsigned long len, unsigned long flags,
unsigned int vm_flags, unsigned long pgoff,
Expand Down Expand Up @@ -1117,23 +1126,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
if (!may_expand_vm(mm, len >> PAGE_SHIFT))
return -ENOMEM;

if (flags & MAP_NORESERVE)
/*
* Set 'VM_NORESERVE' if we should not account for the
* memory use of this mapping. We only honor MAP_NORESERVE
* if we're allowed to overcommit memory.
*/
if ((flags & MAP_NORESERVE) && sysctl_overcommit_memory != OVERCOMMIT_NEVER)
vm_flags |= VM_NORESERVE;
if (!accountable)
vm_flags |= VM_NORESERVE;

if (accountable && (!(flags & MAP_NORESERVE) ||
sysctl_overcommit_memory == OVERCOMMIT_NEVER)) {
if (vm_flags & VM_SHARED) {
/* Check memory availability in shmem_file_setup? */
vm_flags |= VM_ACCOUNT;
} else if (vm_flags & VM_WRITE) {
/*
* Private writable mapping: check memory availability
*/
charged = len >> PAGE_SHIFT;
if (security_vm_enough_memory(charged))
return -ENOMEM;
vm_flags |= VM_ACCOUNT;
}
/*
* Private writable mapping: check memory availability
*/
if (accountable_mapping(vm_flags)) {
charged = len >> PAGE_SHIFT;
if (security_vm_enough_memory(charged))
return -ENOMEM;
vm_flags |= VM_ACCOUNT;
}

/*
Expand Down Expand Up @@ -1184,14 +1194,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
goto free_vma;
}

/* We set VM_ACCOUNT in a shared mapping's vm_flags, to inform
* shmem_zero_setup (perhaps called through /dev/zero's ->mmap)
* that memory reservation must be checked; but that reservation
* belongs to shared memory object, not to vma: so now clear it.
*/
if ((vm_flags & (VM_SHARED|VM_ACCOUNT)) == (VM_SHARED|VM_ACCOUNT))
vma->vm_flags &= ~VM_ACCOUNT;

/* Can addr have changed??
*
* Answer: Yes, several device drivers can do it in their
Expand Down
2 changes: 1 addition & 1 deletion trunk/mm/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2628,7 +2628,7 @@ struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
goto close_file;

#ifdef CONFIG_SHMEM
SHMEM_I(inode)->flags = flags & VM_ACCOUNT;
SHMEM_I(inode)->flags = (flags & VM_NORESERVE) ? 0 : VM_ACCOUNT;
#endif
d_instantiate(dentry, inode);
inode->i_size = size;
Expand Down

0 comments on commit b7662b0

Please sign in to comment.