shm: add memfd_create() syscall
authorDavid Herrmann <dh.herrmann@gmail.com>
Fri, 8 Aug 2014 21:25:29 +0000 (14:25 -0700)
committerGrazvydas Ignotas <notasas@gmail.com>
Sat, 16 Sep 2017 21:29:32 +0000 (00:29 +0300)
commit6ed432ff1bc0a1ef1f3f736038c687cb13d1f62b
tree0135d222d7056c8b2ae6d620619fefa4a8b5cc15
parent7dd6c1fc06e2c6464ed71f1ca82341462fe3b123
shm: add memfd_create() syscall

memfd_create() is similar to mmap(MAP_ANON), but returns a file-descriptor
that you can pass to mmap().  It can support sealing and avoids any
connection to user-visible mount-points.  Thus, it's not subject to quotas
on mounted file-systems, but can be used like malloc()'ed memory, but with
a file-descriptor to it.

memfd_create() returns the raw shmem file, so calls like ftruncate() can
be used to modify the underlying inode.  Also calls like fstat() will
return proper information and mark the file as regular file.  If you want
sealing, you can specify MFD_ALLOW_SEALING.  Otherwise, sealing is not
supported (like on all other regular files).

Compared to O_TMPFILE, it does not require a tmpfs mount-point and is not
subject to a filesystem size limit.  It is still properly accounted to
memcg limits, though, and to the same overcommit or no-overcommit
accounting as all user memory.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Acked-by: Hugh Dickins <hughd@google.com>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: Ryan Lortie <desrt@desrt.ca>
Cc: Lennart Poettering <lennart@poettering.net>
Cc: Daniel Mack <zonque@gmail.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/syscalls.h
include/uapi/linux/memfd.h [new file with mode: 0644]
kernel/sys_ni.c
mm/shmem.c