Skip to content

Commit

Permalink
[PATCH] SHM_NORESERVE flags for shmget()
Browse files Browse the repository at this point in the history
Add SHM_NORESERVE functionality similar to MAP_NORESERVE for shared memory
segments.

This is mainly to avoid abuse of OVERCOMMIT_ALWAYS and this flag is ignored
for OVERCOMMIT_NEVER.

Signed-off-by: Badari Pulavarty <[email protected]>
Cc: Hugh Dickins <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Badari Pulavarty authored and Linus Torvalds committed Nov 7, 2005
1 parent d8ba3b7 commit bf8f972
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/linux/shm.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct shmid_kernel /* private to the kernel */
#define SHM_DEST 01000 /* segment will be destroyed on last detach */
#define SHM_LOCKED 02000 /* segment will not be swapped */
#define SHM_HUGETLB 04000 /* segment will use huge TLB pages */
#define SHM_NORESERVE 010000 /* don't check for reservations */

#ifdef CONFIG_SYSVIPC
long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr);
Expand Down
10 changes: 9 additions & 1 deletion ipc/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,16 @@ static int newseg (key_t key, int shmflg, size_t size)
file = hugetlb_zero_setup(size);
shp->mlock_user = current->user;
} else {
int acctflag = VM_ACCOUNT;
/*
* 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;
sprintf (name, "SYSV%08x", key);
file = shmem_file_setup(name, size, VM_ACCOUNT);
file = shmem_file_setup(name, size, acctflag);
}
error = PTR_ERR(file);
if (IS_ERR(file))
Expand Down

0 comments on commit bf8f972

Please sign in to comment.