Skip to contentSkip to conversation

shmem: unify regular and tiny shmem

PATCH In review Matt Mackall 2 participants 6 messages Dec 4, 2008 – Dec 5, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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
init/Kconfig +0 -4
diff -r 8a9f1e9c46e8 -r 3fd7e399e034 init/Kconfig
@@ -830,10 +830,6 @@
 	boolean
 	select PLIST
 
-config TINY_SHMEM
-	default !SHMEM
-	bool
-
 config BASE_SMALL
 	int
 	default 0 if BASE_FULL
mm/Makefile +1 -3
diff -r 8a9f1e9c46e8 -r 3fd7e399e034 mm/Makefile
@@ -9,7 +9,7 @@
 
 obj-y			:= bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \
 			   maccess.o page_alloc.o page-writeback.o pdflush.o \
-			   readahead.o swap.o truncate.o vmscan.o \
+			   readahead.o swap.o truncate.o vmscan.o shmem.o \
 			   prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \
 			   page_isolation.o mm_init.o $(mmu-y)
 
@@ -21,9 +21,7 @@
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
 obj-$(CONFIG_SPARSEMEM)	+= sparse.o
 obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o
-obj-$(CONFIG_SHMEM) += shmem.o
 obj-$(CONFIG_TMPFS_POSIX_ACL) += shmem_acl.o
-obj-$(CONFIG_TINY_SHMEM) += tiny-shmem.o
 obj-$(CONFIG_SLOB) += slob.o
 obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o
 obj-$(CONFIG_SLAB) += slab.o
mm/shmem.c +71 -10

131 lines not on this page · raw message

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#1 lore raw
Quoted 6 lines · Matt Mackall

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

Quoted 7 lines
    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

I agree with where you're going (surrendering your empire to mine! or perhaps you don't you see it quite that way?), but I think this isn't quite the patch you meant to send: it shouldn't contain that

mm/shmem.c line 2636

Quoted 8 lines
mm/shmem.c +7 -1
-			&shmem_file_operations);
+		  &shmem_file_operations);
+
+#ifndef CONFIG_MMU
+	error = ramfs_nommu_expand_for_mapping(inode, size);
+	if (error)
+		goto close_file;
+#endif

hunk in mm/shmem.c, and it should be deleting mm/tiny-shmem.c?

Hugh

Quoted 178 lines

diff -r 8a9f1e9c46e8 -r 3fd7e399e034 init/Kconfig

init/Kconfig +0 -4
@@ -830,10 +830,6 @@
 	boolean
 	select PLIST
 
-config TINY_SHMEM
-	default !SHMEM
-	bool
-
 config BASE_SMALL
 	int
 	default 0 if BASE_FULL

diff -r 8a9f1e9c46e8 -r 3fd7e399e034 mm/Makefile

mm/Makefile +1 -3
@@ -9,7 +9,7 @@
 
 obj-y			:= bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \
 			   maccess.o page_alloc.o page-writeback.o pdflush.o \
-			   readahead.o swap.o truncate.o vmscan.o \
+			   readahead.o swap.o truncate.o vmscan.o shmem.o \
 			   prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \
 			   page_isolation.o mm_init.o $(mmu-y)
 
@@ -21,9 +21,7 @@
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
 obj-$(CONFIG_SPARSEMEM)	+= sparse.o
 obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o
-obj-$(CONFIG_SHMEM) += shmem.o
 obj-$(CONFIG_TMPFS_POSIX_ACL) += shmem_acl.o
-obj-$(CONFIG_TINY_SHMEM) += tiny-shmem.o
 obj-$(CONFIG_SLOB) += slob.o
 obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o
 obj-$(CONFIG_SLAB) += slab.o

diff -r 8a9f1e9c46e8 -r 3fd7e399e034 mm/shmem.c

mm/shmem.c +71 -10
@@ -14,31 +14,39 @@
  * Copyright (c) 2004, Luke Kenneth Casson Leighton <[email protected]>
  * Copyright (c) 2004 Red Hat, Inc., James Morris <[email protected]>
  *
+ * tiny-shmem:
+ * Copyright (c) 2004, 2008 Matt Mackall <[email protected]>
+ *
  * This file is released under the GPL.
  */
 
+#include <linux/fs.h>
+#include <linux/init.h>
+#include <linux/vfs.h>
+#include <linux/mount.h>
+#include <linux/file.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/swap.h>
+
+static struct vfsmount *shm_mnt;
+
+#ifdef CONFIG_SHMEM
 /*
  * This virtual memory filesystem is heavily based on the ramfs. It
  * extends ramfs by the ability to use swap and honor resource limits
  * which makes it a completely usable filesystem.
  */
 
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/fs.h>
 #include <linux/xattr.h>
 #include <linux/exportfs.h>
 #include <linux/generic_acl.h>
-#include <linux/mm.h>
 #include <linux/mman.h>
-#include <linux/file.h>
-#include <linux/swap.h>
 #include <linux/pagemap.h>
 #include <linux/string.h>
 #include <linux/slab.h>
 #include <linux/backing-dev.h>
 #include <linux/shmem_fs.h>
-#include <linux/mount.h>
 #include <linux/writeback.h>
 #include <linux/vfs.h>
 #include <linux/blkdev.h>
@@ -2486,7 +2494,6 @@
 	.get_sb		= shmem_get_sb,
 	.kill_sb	= kill_litter_super,
 };
-static struct vfsmount *shm_mnt;
 
 static int __init init_tmpfs(void)
 {
@@ -2525,7 +2532,51 @@
 	shm_mnt = ERR_PTR(error);
 	return error;
 }
-module_init(init_tmpfs)
+
+#else /* !CONFIG_SHMEM */
+
+/*
+ * tiny-shmem: simple shmemfs and tmpfs using ramfs code
+ *
+ * This is intended for small system where the benefits of the full
+ * shmem code (swap-backed and resource-limited) are outweighed by
+ * their complexity. On systems without swap this code should be
+ * effectively equivalent, but much lighter weight.
+ */
+
+#include <linux/ramfs.h>
+
+static struct file_system_type tmpfs_fs_type = {
+	.name		= "tmpfs",
+	.get_sb		= ramfs_get_sb,
+	.kill_sb	= kill_litter_super,
+};
+
+static int __init init_tmpfs(void)
+{
+	BUG_ON(register_filesystem(&tmpfs_fs_type) != 0);
+
+	shm_mnt = kern_mount(&tmpfs_fs_type);
+	BUG_ON(IS_ERR(shm_mnt));
+
+	return 0;
+}
+
+int shmem_unuse(swp_entry_t entry, struct page *page)
+{
+	return 0;
+}
+
+#define shmem_file_operations ramfs_file_operations
+#define shmem_vm_ops generic_file_vm_ops
+#define shmem_get_inode ramfs_get_inode
+#define shmem_acct_size(a, b) 0
+#define shmem_unacct_size(a, b) do {} while (0)
+#define SHMEM_MAX_BYTES LLONG_MAX
+
+#endif /* CONFIG_SHMEM */
+
+/* common code */
 
 /**
  * shmem_file_setup - get an unlinked file living in tmpfs
@@ -2569,12 +2620,20 @@
 	if (!inode)
 		goto close_file;
 
+#ifdef CONFIG_SHMEM
 	SHMEM_I(inode)->flags = flags & VM_ACCOUNT;
+#endif
 	d_instantiate(dentry, inode);
 	inode->i_size = size;
 	inode->i_nlink = 0;	/* It is unlinked */
 	init_file(file, shm_mnt, dentry, FMODE_WRITE | FMODE_READ,
-			&shmem_file_operations);
+		  &shmem_file_operations);
+
+#ifndef CONFIG_MMU
+	error = ramfs_nommu_expand_for_mapping(inode, size);
+	if (error)
+		goto close_file;
+#endif
 	return file;
 
 close_file:
@@ -2606,3 +2665,5 @@
 	vma->vm_ops = &shmem_vm_ops;
 	return 0;
 }
+
+module_init(init_tmpfs)
Signature · 2 lines
-- 
Mathematics is the supreme nostalgia of our time.
#2 lore raw
Quoted 4 lines · Hugh Dickins

I agree with where you're going (surrendering your empire to mine! or perhaps you don't you see it quite that way?), but I think this isn't quite the patch you meant to send: it shouldn't contain that

Quoted 10 lines

mm/shmem.c line 2636

Quoted 8 lines
mm/shmem.c +7 -1
-			&shmem_file_operations);
+		  &shmem_file_operations);
+
+#ifndef CONFIG_MMU
+	error = ramfs_nommu_expand_for_mapping(inode, size);
+	if (error)
+		goto close_file;
+#endif

hunk in mm/shmem.c

I'm staring at the source and I'm at a loss as to why not? SHMEM depends on MMU, so this only gets done when !SHMEM && !MMU, which makes it the same as the tiny-shmem.c code it's unifying, no?

Quoted 1 line

and it should be deleting mm/tiny-shmem.c?

Not sure how that bit fell off, yes.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#3 lore raw
Quoted 16 lines · Matt Mackall
Quoted 4 lines · Hugh Dickins

I agree with where you're going (surrendering your empire to mine! or perhaps you don't you see it quite that way?), but I think this isn't quite the patch you meant to send: it shouldn't contain that

Quoted 10 lines

mm/shmem.c line 2636

Quoted 8 lines
mm/shmem.c +7 -1
-			&shmem_file_operations);
+		  &shmem_file_operations);
+
+#ifndef CONFIG_MMU
+	error = ramfs_nommu_expand_for_mapping(inode, size);
+	if (error)
+		goto close_file;
+#endif

hunk in mm/shmem.c

Quoted 3 lines

I'm staring at the source and I'm at a loss as to why not? SHMEM depends on MMU, so this only gets done when !SHMEM && !MMU, which makes it the same as the tiny-shmem.c code it's unifying, no?

Sorry for wasting your time puzzling over that, it was just me getting confused with the ramfs_nommu_get_unmapped_area() bit which does vanish:
this part is fine.

Hugh

Quoted 4 lines
Quoted 2 lines

and it should be deleting mm/tiny-shmem.c?

Not sure how that bit fell off, yes.

#4 lore raw
Quoted 21 lines · Hugh Dickins
Quoted 16 lines · Matt Mackall
Quoted 4 lines · Hugh Dickins

I agree with where you're going (surrendering your empire to mine! or perhaps you don't you see it quite that way?), but I think this isn't quite the patch you meant to send: it shouldn't contain that

Quoted 10 lines

Review

Quoted 8 lines
(quoted diff) +7 -1
-			&shmem_file_operations);
+		  &shmem_file_operations);
+
+#ifndef CONFIG_MMU
+	error = ramfs_nommu_expand_for_mapping(inode, size);
+	if (error)
+		goto close_file;
+#endif

hunk in mm/shmem.c

Quoted 3 lines

I'm staring at the source and I'm at a loss as to why not? SHMEM depends on MMU, so this only gets done when !SHMEM && !MMU, which makes it the same as the tiny-shmem.c code it's unifying, no?

Quoted 5 lines

Sorry for wasting your time puzzling over that, it was just me getting confused with the ramfs_nommu_get_unmapped_area() bit which does vanish:
this part is fine.

Hugh

Ok, here's a version with the rm of tiny-shmem restored. Andrew, please apply.

 a/mm/tiny-shmem.c |  123 ------------------------------------------------------
 init/Kconfig      |    4 -
 mm/Makefile       |    4 -
 mm/shmem.c        |   81 +++++++++++++++++++++++++++++++----
 4 files changed, 72 insertions(+), 140 deletions(-)

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
init/Kconfig +0 -4
diff -r 03b1e5320279 -r 4d7f11d413c3 init/Kconfig
@@ -830,10 +830,6 @@
 	boolean
 	select PLIST
 
-config TINY_SHMEM
-	default !SHMEM
-	bool
-
 config BASE_SMALL
 	int
 	default 0 if BASE_FULL
mm/Makefile +1 -3
diff -r 03b1e5320279 -r 4d7f11d413c3 mm/Makefile
@@ -9,7 +9,7 @@
 
 obj-y			:= bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \
 			   maccess.o page_alloc.o page-writeback.o pdflush.o \
-			   readahead.o swap.o truncate.o vmscan.o \
+			   readahead.o swap.o truncate.o vmscan.o shmem.o \
 			   prio_tree.o util.o mmzone.o vmstat.o backing-dev.o \
 			   page_isolation.o mm_init.o $(mmu-y)
 
@@ -21,9 +21,7 @@
 obj-$(CONFIG_NUMA) 	+= mempolicy.o
 obj-$(CONFIG_SPARSEMEM)	+= sparse.o
 obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o
-obj-$(CONFIG_SHMEM) += shmem.o
 obj-$(CONFIG_TMPFS_POSIX_ACL) += shmem_acl.o
-obj-$(CONFIG_TINY_SHMEM) += tiny-shmem.o
 obj-$(CONFIG_SLOB) += slob.o
 obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o
 obj-$(CONFIG_SLAB) += slab.o
mm/shmem.c +71 -10

131 lines not on this page · raw message

mm/tiny-shmem.c deleted +0 -123

123 lines not on this page · raw message

Signature · 1 line
Mathematics is the supreme nostalgia of our time.