aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Mackall <mpm@selenic.com>2009-01-06 17:40:20 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-06 18:59:08 -0500
commit853ac43ab194f5051b27a55060215d696dc9480d (patch)
tree1f60fd49d516b7b242781a77446993b1dfb5bb66
parent69e9930993cfd70d82c8d9dd96fc3a88854d06fc (diff)
shmem: unify regular and tiny shmem
tiny-shmem shares most of its 130 lines of code with shmem and tends to break when particular bits of shmem get modified. Unifying saves code and makes keeping these two in sync much easier. before: 14367 392 24 14783 39bf mm/shmem.o 396 72 8 476 1dc mm/tiny-shmem.o after: 14367 392 24 14783 39bf mm/shmem.o 412 72 8 492 1ec mm/shmem.o tiny Signed-off-by: Matt Mackall <mpm@selenic.com> Acked-by: Hugh Dickins <hugh@veritas.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--init/Kconfig4
-rw-r--r--mm/Makefile4
-rw-r--r--mm/shmem.c81
-rw-r--r--mm/tiny-shmem.c134
4 files changed, 72 insertions, 151 deletions
diff --git a/init/Kconfig b/init/Kconfig
index 52847eec7398..315a6114bf87 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -838,10 +838,6 @@ config RT_MUTEXES
838 boolean 838 boolean
839 select PLIST 839 select PLIST
840 840
841config TINY_SHMEM
842 default !SHMEM
843 bool
844
845config BASE_SMALL 841config BASE_SMALL
846 int 842 int
847 default 0 if BASE_FULL 843 default 0 if BASE_FULL
diff --git a/mm/Makefile b/mm/Makefile
index 51c27709cc7c..72255be57f89 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -9,7 +9,7 @@ mmu-$(CONFIG_MMU) := fremap.o highmem.o madvise.o memory.o mincore.o \
9 9
10obj-y := bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \ 10obj-y := bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \
11 maccess.o page_alloc.o page-writeback.o pdflush.o \ 11 maccess.o page_alloc.o page-writeback.o pdflush.o \
12 readahead.o swap.o truncate.o vmscan.o \ 12 readahead.o swap.o truncate.o vmscan.o shmem.o \
13 prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \ 13 prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \
14 page_isolation.o mm_init.o $(mmu-y) 14 page_isolation.o mm_init.o $(mmu-y)
15 15
@@ -21,9 +21,7 @@ obj-$(CONFIG_HUGETLBFS) += hugetlb.o
21obj-$(CONFIG_NUMA) += mempolicy.o 21obj-$(CONFIG_NUMA) += mempolicy.o
22obj-$(CONFIG_SPARSEMEM) += sparse.o 22obj-$(CONFIG_SPARSEMEM) += sparse.o
23obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o 23obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o
24obj-$(CONFIG_SHMEM) += shmem.o
25obj-$(CONFIG_TMPFS_POSIX_ACL) += shmem_acl.o 24obj-$(CONFIG_TMPFS_POSIX_ACL) += shmem_acl.o
26obj-$(CONFIG_TINY_SHMEM) += tiny-shmem.o
27obj-$(CONFIG_SLOB) += slob.o 25obj-$(CONFIG_SLOB) += slob.o
28obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o 26obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o
29obj-$(CONFIG_SLAB) += slab.o 27obj-$(CONFIG_SLAB) += slab.o
diff --git a/mm/shmem.c b/mm/shmem.c
index 24f18fdee6e3..5941f9801363 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -14,31 +14,39 @@
14 * Copyright (c) 2004, Luke Kenneth Casson Leighton <lkcl@lkcl.net> 14 * Copyright (c) 2004, Luke Kenneth Casson Leighton <lkcl@lkcl.net>
15 * Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com> 15 * Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
16 * 16 *
17 * tiny-shmem:
18 * Copyright (c) 2004, 2008 Matt Mackall <mpm@selenic.com>
19 *
17 * This file is released under the GPL. 20 * This file is released under the GPL.
18 */ 21 */
19 22
23#include <linux/fs.h>
24#include <linux/init.h>
25#include <linux/vfs.h>
26#include <linux/mount.h>
27#include <linux/file.h>
28#include <linux/mm.h>
29#include <linux/module.h>
30#include <linux/swap.h>
31
32static struct vfsmount *shm_mnt;
33
34#ifdef CONFIG_SHMEM
20/* 35/*
21 * This virtual memory filesystem is heavily based on the ramfs. It 36 * This virtual memory filesystem is heavily based on the ramfs. It
22 * extends ramfs by the ability to use swap and honor resource limits 37 * extends ramfs by the ability to use swap and honor resource limits
23 * which makes it a completely usable filesystem. 38 * which makes it a completely usable filesystem.
24 */ 39 */
25 40
26#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/fs.h>
29#include <linux/xattr.h> 41#include <linux/xattr.h>
30#include <linux/exportfs.h> 42#include <linux/exportfs.h>
31#include <linux/generic_acl.h> 43#include <linux/generic_acl.h>
32#include <linux/mm.h>
33#include <linux/mman.h> 44#include <linux/mman.h>
34#include <linux/file.h>
35#include <linux/swap.h>
36#include <linux/pagemap.h> 45#include <linux/pagemap.h>
37#include <linux/string.h> 46#include <linux/string.h>
38#include <linux/slab.h> 47#include <linux/slab.h>
39#include <linux/backing-dev.h> 48#include <linux/backing-dev.h>
40#include <linux/shmem_fs.h> 49#include <linux/shmem_fs.h>
41#include <linux/mount.h>
42#include <linux/writeback.h> 50#include <linux/writeback.h>
43#include <linux/vfs.h> 51#include <linux/vfs.h>
44#include <linux/blkdev.h> 52#include <linux/blkdev.h>
@@ -2485,7 +2493,6 @@ static struct file_system_type tmpfs_fs_type = {
2485 .get_sb = shmem_get_sb, 2493 .get_sb = shmem_get_sb,
2486 .kill_sb = kill_litter_super, 2494 .kill_sb = kill_litter_super,
2487}; 2495};
2488static struct vfsmount *shm_mnt;
2489 2496
2490static int __init init_tmpfs(void) 2497static int __init init_tmpfs(void)
2491{ 2498{
@@ -2524,7 +2531,51 @@ out4:
2524 shm_mnt = ERR_PTR(error); 2531 shm_mnt = ERR_PTR(error);
2525 return error; 2532 return error;
2526} 2533}
2527module_init(init_tmpfs) 2534
2535#else /* !CONFIG_SHMEM */
2536
2537/*
2538 * tiny-shmem: simple shmemfs and tmpfs using ramfs code
2539 *
2540 * This is intended for small system where the benefits of the full
2541 * shmem code (swap-backed and resource-limited) are outweighed by
2542 * their complexity. On systems without swap this code should be
2543 * effectively equivalent, but much lighter weight.
2544 */
2545
2546#include <linux/ramfs.h>
2547
2548static struct file_system_type tmpfs_fs_type = {
2549 .name = "tmpfs",
2550 .get_sb = ramfs_get_sb,
2551 .kill_sb = kill_litter_super,
2552};
2553
2554static int __init init_tmpfs(void)
2555{
2556 BUG_ON(register_filesystem(&tmpfs_fs_type) != 0);
2557
2558 shm_mnt = kern_mount(&tmpfs_fs_type);
2559 BUG_ON(IS_ERR(shm_mnt));
2560
2561 return 0;
2562}
2563
2564int shmem_unuse(swp_entry_t entry, struct page *page)
2565{
2566 return 0;
2567}
2568
2569#define shmem_file_operations ramfs_file_operations
2570#define shmem_vm_ops generic_file_vm_ops
2571#define shmem_get_inode ramfs_get_inode
2572#define shmem_acct_size(a, b) 0
2573#define shmem_unacct_size(a, b) do {} while (0)
2574#define SHMEM_MAX_BYTES LLONG_MAX
2575
2576#endif /* CONFIG_SHMEM */
2577
2578/* common code */
2528 2579
2529/** 2580/**
2530 * shmem_file_setup - get an unlinked file living in tmpfs 2581 * shmem_file_setup - get an unlinked file living in tmpfs
@@ -2568,12 +2619,20 @@ struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
2568 if (!inode) 2619 if (!inode)
2569 goto close_file; 2620 goto close_file;
2570 2621
2622#ifdef CONFIG_SHMEM
2571 SHMEM_I(inode)->flags = flags & VM_ACCOUNT; 2623 SHMEM_I(inode)->flags = flags & VM_ACCOUNT;
2624#endif
2572 d_instantiate(dentry, inode); 2625 d_instantiate(dentry, inode);
2573 inode->i_size = size; 2626 inode->i_size = size;
2574 inode->i_nlink = 0; /* It is unlinked */ 2627 inode->i_nlink = 0; /* It is unlinked */
2575 init_file(file, shm_mnt, dentry, FMODE_WRITE | FMODE_READ, 2628 init_file(file, shm_mnt, dentry, FMODE_WRITE | FMODE_READ,
2576 &shmem_file_operations); 2629 &shmem_file_operations);
2630
2631#ifndef CONFIG_MMU
2632 error = ramfs_nommu_expand_for_mapping(inode, size);
2633 if (error)
2634 goto close_file;
2635#endif
2577 return file; 2636 return file;
2578 2637
2579close_file: 2638close_file:
@@ -2605,3 +2664,5 @@ int shmem_zero_setup(struct vm_area_struct *vma)
2605 vma->vm_ops = &shmem_vm_ops; 2664 vma->vm_ops = &shmem_vm_ops;
2606 return 0; 2665 return 0;
2607} 2666}
2667
2668module_init(init_tmpfs)
diff --git a/mm/tiny-shmem.c b/mm/tiny-shmem.c
deleted file mode 100644
index 3e67d575ee6e..000000000000
--- a/mm/tiny-shmem.c
+++ /dev/null
@@ -1,134 +0,0 @@
1/*
2 * tiny-shmem.c: simple shmemfs and tmpfs using ramfs code
3 *
4 * Matt Mackall <mpm@selenic.com> January, 2004
5 * derived from mm/shmem.c and fs/ramfs/inode.c
6 *
7 * This is intended for small system where the benefits of the full
8 * shmem code (swap-backed and resource-limited) are outweighed by
9 * their complexity. On systems without swap this code should be
10 * effectively equivalent, but much lighter weight.
11 */
12
13#include <linux/fs.h>
14#include <linux/init.h>
15#include <linux/vfs.h>
16#include <linux/mount.h>
17#include <linux/file.h>
18#include <linux/mm.h>
19#include <linux/module.h>
20#include <linux/swap.h>
21#include <linux/ramfs.h>
22
23static struct file_system_type tmpfs_fs_type = {
24 .name = "tmpfs",
25 .get_sb = ramfs_get_sb,
26 .kill_sb = kill_litter_super,
27};
28
29static struct vfsmount *shm_mnt;
30
31static int __init init_tmpfs(void)
32{
33 BUG_ON(register_filesystem(&tmpfs_fs_type) != 0);
34
35 shm_mnt = kern_mount(&tmpfs_fs_type);
36 BUG_ON(IS_ERR(shm_mnt));
37
38 return 0;
39}
40module_init(init_tmpfs)
41
42/**
43 * shmem_file_setup - get an unlinked file living in tmpfs
44 * @name: name for dentry (to be seen in /proc/<pid>/maps
45 * @size: size to be set for the file
46 * @flags: vm_flags
47 */
48struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
49{
50 int error;
51 struct file *file;
52 struct inode *inode;
53 struct dentry *dentry, *root;
54 struct qstr this;
55
56 if (IS_ERR(shm_mnt))
57 return (void *)shm_mnt;
58
59 error = -ENOMEM;
60 this.name = name;
61 this.len = strlen(name);
62 this.hash = 0; /* will go */
63 root = shm_mnt->mnt_root;
64 dentry = d_alloc(root, &this);
65 if (!dentry)
66 goto put_memory;
67
68 error = -ENFILE;
69 file = get_empty_filp();
70 if (!file)
71 goto put_dentry;
72
73 error = -ENOSPC;
74 inode = ramfs_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0);
75 if (!inode)
76 goto close_file;
77
78 d_instantiate(dentry, inode);
79 inode->i_size = size;
80 inode->i_nlink = 0; /* It is unlinked */
81 init_file(file, shm_mnt, dentry, FMODE_WRITE | FMODE_READ,
82 &ramfs_file_operations);
83
84#ifndef CONFIG_MMU
85 error = ramfs_nommu_expand_for_mapping(inode, size);
86 if (error)
87 goto close_file;
88#endif
89 return file;
90
91close_file:
92 put_filp(file);
93put_dentry:
94 dput(dentry);
95put_memory:
96 return ERR_PTR(error);
97}
98EXPORT_SYMBOL_GPL(shmem_file_setup);
99
100/**
101 * shmem_zero_setup - setup a shared anonymous mapping
102 * @vma: the vma to be mmapped is prepared by do_mmap_pgoff
103 */
104int shmem_zero_setup(struct vm_area_struct *vma)
105{
106 struct file *file;
107 loff_t size = vma->vm_end - vma->vm_start;
108
109 file = shmem_file_setup("dev/zero", size, vma->vm_flags);
110 if (IS_ERR(file))
111 return PTR_ERR(file);
112
113 if (vma->vm_file)
114 fput(vma->vm_file);
115 vma->vm_file = file;
116 vma->vm_ops = &generic_file_vm_ops;
117 return 0;
118}
119
120int shmem_unuse(swp_entry_t entry, struct page *page)
121{
122 return 0;
123}
124
125#ifndef CONFIG_MMU
126unsigned long shmem_get_unmapped_area(struct file *file,
127 unsigned long addr,
128 unsigned long len,
129 unsigned long pgoff,
130 unsigned long flags)
131{
132 return ramfs_nommu_get_unmapped_area(file, addr, len, pgoff, flags);
133}
134#endif