aboutsummaryrefslogtreecommitdiffstats
path: root/mm/shmem.c
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2009-01-08 14:05:59 -0500
committerDavid S. Miller <davem@davemloft.net>2009-01-08 14:05:59 -0500
commit7f46b1343f723f98634a5dcee47856b2000079ed (patch)
treeed22b6298c8dd2f687890a0d79abcd1d273b5f81 /mm/shmem.c
parentb8c31da64165b8566fc6e1c9c826f76e7b98ff02 (diff)
parent9e42d0cf5020aaf217433cad1a224745241d212a (diff)
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'mm/shmem.c')
-rw-r--r--mm/shmem.c82
1 files changed, 71 insertions, 11 deletions
diff --git a/mm/shmem.c b/mm/shmem.c
index f1b0d4871f3a..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>
@@ -1444,7 +1452,6 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1444 if (error) 1452 if (error)
1445 return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS); 1453 return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS);
1446 1454
1447 mark_page_accessed(vmf->page);
1448 return ret | VM_FAULT_LOCKED; 1455 return ret | VM_FAULT_LOCKED;
1449} 1456}
1450 1457
@@ -2486,7 +2493,6 @@ static struct file_system_type tmpfs_fs_type = {
2486 .get_sb = shmem_get_sb, 2493 .get_sb = shmem_get_sb,
2487 .kill_sb = kill_litter_super, 2494 .kill_sb = kill_litter_super,
2488}; 2495};
2489static struct vfsmount *shm_mnt;
2490 2496
2491static int __init init_tmpfs(void) 2497static int __init init_tmpfs(void)
2492{ 2498{
@@ -2525,7 +2531,51 @@ out4:
2525 shm_mnt = ERR_PTR(error); 2531 shm_mnt = ERR_PTR(error);
2526 return error; 2532 return error;
2527} 2533}
2528module_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 */
2529 2579
2530/** 2580/**
2531 * shmem_file_setup - get an unlinked file living in tmpfs 2581 * shmem_file_setup - get an unlinked file living in tmpfs
@@ -2569,12 +2619,20 @@ struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
2569 if (!inode) 2619 if (!inode)
2570 goto close_file; 2620 goto close_file;
2571 2621
2622#ifdef CONFIG_SHMEM
2572 SHMEM_I(inode)->flags = flags & VM_ACCOUNT; 2623 SHMEM_I(inode)->flags = flags & VM_ACCOUNT;
2624#endif
2573 d_instantiate(dentry, inode); 2625 d_instantiate(dentry, inode);
2574 inode->i_size = size; 2626 inode->i_size = size;
2575 inode->i_nlink = 0; /* It is unlinked */ 2627 inode->i_nlink = 0; /* It is unlinked */
2576 init_file(file, shm_mnt, dentry, FMODE_WRITE | FMODE_READ, 2628 init_file(file, shm_mnt, dentry, FMODE_WRITE | FMODE_READ,
2577 &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
2578 return file; 2636 return file;
2579 2637
2580close_file: 2638close_file:
@@ -2606,3 +2664,5 @@ int shmem_zero_setup(struct vm_area_struct *vma)
2606 vma->vm_ops = &shmem_vm_ops; 2664 vma->vm_ops = &shmem_vm_ops;
2607 return 0; 2665 return 0;
2608} 2666}
2667
2668module_init(init_tmpfs)