diff options
Diffstat (limited to 'mm/shmem.c')
-rw-r--r-- | mm/shmem.c | 81 |
1 files changed, 71 insertions, 10 deletions
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 | |||
32 | static 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 | }; |
2488 | static struct vfsmount *shm_mnt; | ||
2489 | 2496 | ||
2490 | static int __init init_tmpfs(void) | 2497 | static 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 | } |
2527 | module_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 | |||
2548 | static struct file_system_type tmpfs_fs_type = { | ||
2549 | .name = "tmpfs", | ||
2550 | .get_sb = ramfs_get_sb, | ||
2551 | .kill_sb = kill_litter_super, | ||
2552 | }; | ||
2553 | |||
2554 | static 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 | |||
2564 | int 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 | ||
2579 | close_file: | 2638 | close_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 | |||
2668 | module_init(init_tmpfs) | ||