Skip to content

Commit

Permalink
mm: restructure memfd code
Browse files Browse the repository at this point in the history
With the addition of memfd hugetlbfs support, we now have the situation
where memfd depends on TMPFS -or- HUGETLBFS.  Previously, memfd was only
supported on tmpfs, so it made sense that the code resided in shmem.c.
In the current code, memfd is only functional if TMPFS is defined.  If
HUGETLFS is defined and TMPFS is not defined, then memfd functionality
will not be available for hugetlbfs.  This does not cause BUGs, just a
lack of potentially desired functionality.

Code is restructured in the following way:
- include/linux/memfd.h is a new file containing memfd specific
  definitions previously contained in shmem_fs.h.
- mm/memfd.c is a new file containing memfd specific code previously
  contained in shmem.c.
- memfd specific code is removed from shmem_fs.h and shmem.c.
- A new config option MEMFD_CREATE is added that is defined if TMPFS
  or HUGETLBFS is defined.

No functional changes are made to the code: restructuring only.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Mike Kravetz <[email protected]>
Reviewed-by: Khalid Aziz <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: David Herrmann <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Marc-Andr Lureau <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Michal Hocko <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
mjkravetz authored and torvalds committed Jun 8, 2018
1 parent c49fcfc commit 5d75260
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 338 deletions.
3 changes: 3 additions & 0 deletions fs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ config HUGETLBFS
config HUGETLB_PAGE
def_bool HUGETLBFS

config MEMFD_CREATE
def_bool TMPFS || HUGETLBFS

config ARCH_HAS_GIGANTIC_PAGE
bool

Expand Down
2 changes: 1 addition & 1 deletion fs/fcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <linux/rcupdate.h>
#include <linux/pid_namespace.h>
#include <linux/user_namespace.h>
#include <linux/shmem_fs.h>
#include <linux/memfd.h>
#include <linux/compat.h>

#include <linux/poll.h>
Expand Down
16 changes: 16 additions & 0 deletions include/linux/memfd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __LINUX_MEMFD_H
#define __LINUX_MEMFD_H

#include <linux/file.h>

#ifdef CONFIG_MEMFD_CREATE
extern long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg);
#else
static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned long a)
{
return -EINVAL;
}
#endif

#endif /* __LINUX_MEMFD_H */
13 changes: 0 additions & 13 deletions include/linux/shmem_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,6 @@ static inline bool shmem_file(struct file *file)
extern bool shmem_charge(struct inode *inode, long pages);
extern void shmem_uncharge(struct inode *inode, long pages);

#ifdef CONFIG_TMPFS

extern long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg);

#else

static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned long a)
{
return -EINVAL;
}

#endif

#ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE
extern bool shmem_huge_enabled(struct vm_area_struct *vma);
#else
Expand Down
1 change: 1 addition & 0 deletions mm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ obj-$(CONFIG_DEBUG_PAGE_REF) += debug_page_ref.o
obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o
obj-$(CONFIG_PERCPU_STATS) += percpu-stats.o
obj-$(CONFIG_HMM) += hmm.o
obj-$(CONFIG_MEMFD_CREATE) += memfd.o
Loading

0 comments on commit 5d75260

Please sign in to comment.