aboutsummaryrefslogtreecommitdiffstats
path: root/mm/shmem.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/shmem.c')
-rw-r--r--mm/shmem.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/mm/shmem.c b/mm/shmem.c
index 8135fac294ee..7ec78e24a30d 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -170,13 +170,13 @@ static inline struct shmem_sb_info *SHMEM_SB(struct super_block *sb)
170 */ 170 */
171static inline int shmem_acct_size(unsigned long flags, loff_t size) 171static inline int shmem_acct_size(unsigned long flags, loff_t size)
172{ 172{
173 return (flags & VM_ACCOUNT) ? 173 return (flags & VM_NORESERVE) ?
174 security_vm_enough_memory_kern(VM_ACCT(size)) : 0; 174 0 : security_vm_enough_memory_kern(VM_ACCT(size));
175} 175}
176 176
177static inline void shmem_unacct_size(unsigned long flags, loff_t size) 177static inline void shmem_unacct_size(unsigned long flags, loff_t size)
178{ 178{
179 if (flags & VM_ACCOUNT) 179 if (!(flags & VM_NORESERVE))
180 vm_unacct_memory(VM_ACCT(size)); 180 vm_unacct_memory(VM_ACCT(size));
181} 181}
182 182
@@ -188,13 +188,13 @@ static inline void shmem_unacct_size(unsigned long flags, loff_t size)
188 */ 188 */
189static inline int shmem_acct_block(unsigned long flags) 189static inline int shmem_acct_block(unsigned long flags)
190{ 190{
191 return (flags & VM_ACCOUNT) ? 191 return (flags & VM_NORESERVE) ?
192 0 : security_vm_enough_memory_kern(VM_ACCT(PAGE_CACHE_SIZE)); 192 security_vm_enough_memory_kern(VM_ACCT(PAGE_CACHE_SIZE)) : 0;
193} 193}
194 194
195static inline void shmem_unacct_blocks(unsigned long flags, long pages) 195static inline void shmem_unacct_blocks(unsigned long flags, long pages)
196{ 196{
197 if (!(flags & VM_ACCOUNT)) 197 if (flags & VM_NORESERVE)
198 vm_unacct_memory(pages * VM_ACCT(PAGE_CACHE_SIZE)); 198 vm_unacct_memory(pages * VM_ACCT(PAGE_CACHE_SIZE));
199} 199}
200 200
@@ -1516,8 +1516,8 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma)
1516 return 0; 1516 return 0;
1517} 1517}
1518 1518
1519static struct inode * 1519static struct inode *shmem_get_inode(struct super_block *sb, int mode,
1520shmem_get_inode(struct super_block *sb, int mode, dev_t dev) 1520 dev_t dev, unsigned long flags)
1521{ 1521{
1522 struct inode *inode; 1522 struct inode *inode;
1523 struct shmem_inode_info *info; 1523 struct shmem_inode_info *info;
@@ -1538,6 +1538,7 @@ shmem_get_inode(struct super_block *sb, int mode, dev_t dev)
1538 info = SHMEM_I(inode); 1538 info = SHMEM_I(inode);
1539 memset(info, 0, (char *)inode - (char *)info); 1539 memset(info, 0, (char *)inode - (char *)info);
1540 spin_lock_init(&info->lock); 1540 spin_lock_init(&info->lock);
1541 info->flags = flags & VM_NORESERVE;
1541 INIT_LIST_HEAD(&info->swaplist); 1542 INIT_LIST_HEAD(&info->swaplist);
1542 1543
1543 switch (mode & S_IFMT) { 1544 switch (mode & S_IFMT) {
@@ -1780,9 +1781,10 @@ static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf)
1780static int 1781static int
1781shmem_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) 1782shmem_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
1782{ 1783{
1783 struct inode *inode = shmem_get_inode(dir->i_sb, mode, dev); 1784 struct inode *inode;
1784 int error = -ENOSPC; 1785 int error = -ENOSPC;
1785 1786
1787 inode = shmem_get_inode(dir->i_sb, mode, dev, VM_NORESERVE);
1786 if (inode) { 1788 if (inode) {
1787 error = security_inode_init_security(inode, dir, NULL, NULL, 1789 error = security_inode_init_security(inode, dir, NULL, NULL,
1788 NULL); 1790 NULL);
@@ -1921,7 +1923,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
1921 if (len > PAGE_CACHE_SIZE) 1923 if (len > PAGE_CACHE_SIZE)
1922 return -ENAMETOOLONG; 1924 return -ENAMETOOLONG;
1923 1925
1924 inode = shmem_get_inode(dir->i_sb, S_IFLNK|S_IRWXUGO, 0); 1926 inode = shmem_get_inode(dir->i_sb, S_IFLNK|S_IRWXUGO, 0, VM_NORESERVE);
1925 if (!inode) 1927 if (!inode)
1926 return -ENOSPC; 1928 return -ENOSPC;
1927 1929
@@ -2333,7 +2335,7 @@ static int shmem_fill_super(struct super_block *sb,
2333 sb->s_flags |= MS_POSIXACL; 2335 sb->s_flags |= MS_POSIXACL;
2334#endif 2336#endif
2335 2337
2336 inode = shmem_get_inode(sb, S_IFDIR | sbinfo->mode, 0); 2338 inode = shmem_get_inode(sb, S_IFDIR | sbinfo->mode, 0, VM_NORESERVE);
2337 if (!inode) 2339 if (!inode)
2338 goto failed; 2340 goto failed;
2339 inode->i_uid = sbinfo->uid; 2341 inode->i_uid = sbinfo->uid;
@@ -2575,12 +2577,12 @@ int shmem_unuse(swp_entry_t entry, struct page *page)
2575 return 0; 2577 return 0;
2576} 2578}
2577 2579
2578#define shmem_file_operations ramfs_file_operations 2580#define shmem_vm_ops generic_file_vm_ops
2579#define shmem_vm_ops generic_file_vm_ops 2581#define shmem_file_operations ramfs_file_operations
2580#define shmem_get_inode ramfs_get_inode 2582#define shmem_get_inode(sb, mode, dev, flags) ramfs_get_inode(sb, mode, dev)
2581#define shmem_acct_size(a, b) 0 2583#define shmem_acct_size(flags, size) 0
2582#define shmem_unacct_size(a, b) do {} while (0) 2584#define shmem_unacct_size(flags, size) do {} while (0)
2583#define SHMEM_MAX_BYTES LLONG_MAX 2585#define SHMEM_MAX_BYTES LLONG_MAX
2584 2586
2585#endif /* CONFIG_SHMEM */ 2587#endif /* CONFIG_SHMEM */
2586 2588
@@ -2590,7 +2592,7 @@ int shmem_unuse(swp_entry_t entry, struct page *page)
2590 * shmem_file_setup - get an unlinked file living in tmpfs 2592 * shmem_file_setup - get an unlinked file living in tmpfs
2591 * @name: name for dentry (to be seen in /proc/<pid>/maps 2593 * @name: name for dentry (to be seen in /proc/<pid>/maps
2592 * @size: size to be set for the file 2594 * @size: size to be set for the file
2593 * @flags: vm_flags 2595 * @flags: VM_NORESERVE suppresses pre-accounting of the entire object size
2594 */ 2596 */
2595struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags) 2597struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
2596{ 2598{
@@ -2624,13 +2626,10 @@ struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
2624 goto put_dentry; 2626 goto put_dentry;
2625 2627
2626 error = -ENOSPC; 2628 error = -ENOSPC;
2627 inode = shmem_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0); 2629 inode = shmem_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0, flags);
2628 if (!inode) 2630 if (!inode)
2629 goto close_file; 2631 goto close_file;
2630 2632
2631#ifdef CONFIG_SHMEM
2632 SHMEM_I(inode)->flags = (flags & VM_NORESERVE) ? 0 : VM_ACCOUNT;
2633#endif
2634 d_instantiate(dentry, inode); 2633 d_instantiate(dentry, inode);
2635 inode->i_size = size; 2634 inode->i_size = size;
2636 inode->i_nlink = 0; /* It is unlinked */ 2635 inode->i_nlink = 0; /* It is unlinked */