Skip to content

Commit 5d75260

Browse files
mjkravetztorvalds
authored andcommitted
mm: restructure memfd code
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/20180415182119.4517-4-mike.kravetz@oracle.com Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com> Reviewed-by: Khalid Aziz <khalid.aziz@oracle.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: David Herrmann <dh.herrmann@gmail.com> Cc: Hugh Dickins <hughd@google.com> Cc: Marc-Andr Lureau <marcandre.lureau@gmail.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Michal Hocko <mhocko@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c49fcfc commit 5d75260

7 files changed

Lines changed: 366 additions & 338 deletions

File tree

‎fs/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ config HUGETLBFS
203203
config HUGETLB_PAGE
204204
def_bool HUGETLBFS
205205

206+
config MEMFD_CREATE
207+
def_bool TMPFS || HUGETLBFS
208+
206209
config ARCH_HAS_GIGANTIC_PAGE
207210
bool
208211

‎fs/fcntl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <linux/rcupdate.h>
2424
#include <linux/pid_namespace.h>
2525
#include <linux/user_namespace.h>
26-
#include <linux/shmem_fs.h>
26+
#include <linux/memfd.h>
2727
#include <linux/compat.h>
2828

2929
#include <linux/poll.h>

‎include/linux/memfd.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __LINUX_MEMFD_H
3+
#define __LINUX_MEMFD_H
4+
5+
#include <linux/file.h>
6+
7+
#ifdef CONFIG_MEMFD_CREATE
8+
extern long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg);
9+
#else
10+
static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned long a)
11+
{
12+
return -EINVAL;
13+
}
14+
#endif
15+
16+
#endif /* __LINUX_MEMFD_H */

‎include/linux/shmem_fs.h‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,6 @@ static inline bool shmem_file(struct file *file)
110110
extern bool shmem_charge(struct inode *inode, long pages);
111111
extern void shmem_uncharge(struct inode *inode, long pages);
112112

113-
#ifdef CONFIG_TMPFS
114-
115-
extern long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg);
116-
117-
#else
118-
119-
static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned long a)
120-
{
121-
return -EINVAL;
122-
}
123-
124-
#endif
125-
126113
#ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE
127114
extern bool shmem_huge_enabled(struct vm_area_struct *vma);
128115
#else

‎mm/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,4 @@ obj-$(CONFIG_DEBUG_PAGE_REF) += debug_page_ref.o
105105
obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o
106106
obj-$(CONFIG_PERCPU_STATS) += percpu-stats.o
107107
obj-$(CONFIG_HMM) += hmm.o
108+
obj-$(CONFIG_MEMFD_CREATE) += memfd.o

0 commit comments

Comments
 (0)