Commit 77cdadab authored by Hugh Dickins's avatar Hugh Dickins Committed by Linus Torvalds

[PATCH] shmem: inodes and links need lowmem

Keith Mannthey's Bugzilla #3268 drew attention to how tmpfs inodes and
dentries and long names and radix-tree nodes pin lowmem.  Assuming about 1k of
lowmem per inode, we need to lower the default nr_inodes limit on machines
with significant highmem.

Be conservative, but more generous than in the original patch to Keith: limit
to number of lowmem pages, which works out around 200,000 on i386.  Easily
overridden by giving the nr_inodes= mount option: those who want to sail
closer to the rocks should be allowed to do so.

Notice how tmpfs dentries cannot be reclaimed in the way that disk-based
dentries can: so even hard links need to be costed.  They are cheaper than
inodes, but easier all round to charge the same.  This way, the limit for hard
links is equally visible through "df -i": but expect occasional bugreports
that tmpfs links are being treated like this.

Would have been simpler just to move the free_inodes accounting from
shmem_delete_inode to shmem_unlink; but that would lose the charge on unlinked
but open files.
Signed-off-by: default avatarHugh Dickins <hugh@veritas.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent fe658b15
...@@ -62,7 +62,9 @@ size: The limit of allocated bytes for this tmpfs instance. The ...@@ -62,7 +62,9 @@ size: The limit of allocated bytes for this tmpfs instance. The
since the OOM handler will not be able to free that memory. since the OOM handler will not be able to free that memory.
nr_blocks: The same as size, but in blocks of PAGE_CACHE_SIZE. nr_blocks: The same as size, but in blocks of PAGE_CACHE_SIZE.
nr_inodes: The maximum number of inodes for this instance. The default nr_inodes: The maximum number of inodes for this instance. The default
is half of the number of your physical RAM pages. is half of the number of your physical RAM pages, or (on a
a machine with highmem) the number of lowmem RAM pages,
whichever is the lower.
These parameters accept a suffix k, m or g for kilo, mega and giga and These parameters accept a suffix k, m or g for kilo, mega and giga and
can be changed on remount. The size parameter also accepts a suffix % can be changed on remount. The size parameter also accepts a suffix %
...@@ -89,4 +91,4 @@ RAM/SWAP in 10240 inodes and it is only accessible by root. ...@@ -89,4 +91,4 @@ RAM/SWAP in 10240 inodes and it is only accessible by root.
Author: Author:
Christoph Rohland <cr@sap.com>, 1.12.01 Christoph Rohland <cr@sap.com>, 1.12.01
Updated: Updated:
Hugh Dickins <hugh@veritas.com>, 01 April 2003 Hugh Dickins <hugh@veritas.com>, 01 September 2004
...@@ -1567,6 +1567,20 @@ static int shmem_create(struct inode *dir, struct dentry *dentry, int mode, ...@@ -1567,6 +1567,20 @@ static int shmem_create(struct inode *dir, struct dentry *dentry, int mode,
static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) static int shmem_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)
{ {
struct inode *inode = old_dentry->d_inode; struct inode *inode = old_dentry->d_inode;
struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
/*
* No ordinary (disk based) filesystem counts links as inodes;
* but each new link needs a new dentry, pinning lowmem, and
* tmpfs dentries cannot be pruned until they are unlinked.
*/
spin_lock(&sbinfo->stat_lock);
if (!sbinfo->free_inodes) {
spin_unlock(&sbinfo->stat_lock);
return -ENOSPC;
}
sbinfo->free_inodes--;
spin_unlock(&sbinfo->stat_lock);
dir->i_size += BOGO_DIRENT_SIZE; dir->i_size += BOGO_DIRENT_SIZE;
inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
...@@ -1581,6 +1595,13 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry) ...@@ -1581,6 +1595,13 @@ static int shmem_unlink(struct inode *dir, struct dentry *dentry)
{ {
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
if (inode->i_nlink > 1 && !S_ISDIR(inode->i_mode)) {
struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
spin_lock(&sbinfo->stat_lock);
sbinfo->free_inodes++;
spin_unlock(&sbinfo->stat_lock);
}
dir->i_size -= BOGO_DIRENT_SIZE; dir->i_size -= BOGO_DIRENT_SIZE;
inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME; inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
inode->i_nlink--; inode->i_nlink--;
...@@ -1818,9 +1839,12 @@ static int shmem_fill_super(struct super_block *sb, ...@@ -1818,9 +1839,12 @@ static int shmem_fill_super(struct super_block *sb,
/* /*
* Per default we only allow half of the physical ram per * Per default we only allow half of the physical ram per
* tmpfs instance * tmpfs instance, limiting inodes to one per page of lowmem.
*/ */
blocks = inodes = totalram_pages / 2; blocks = totalram_pages / 2;
inodes = totalram_pages - totalhigh_pages;
if (inodes > blocks)
inodes = blocks;
#ifdef CONFIG_TMPFS #ifdef CONFIG_TMPFS
if (shmem_parse_options(data, &mode, &uid, &gid, &blocks, &inodes)) { if (shmem_parse_options(data, &mode, &uid, &gid, &blocks, &inodes)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment