]> git.hungrycats.org Git - linux/commitdiff
[PATCH] shmem: inodes and links need lowmem
authorHugh Dickins <hugh@veritas.com>
Tue, 14 Sep 2004 00:45:36 +0000 (17:45 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Tue, 14 Sep 2004 00:45:36 +0000 (17:45 -0700)
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: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Documentation/filesystems/tmpfs.txt
mm/shmem.c

index 177edbea9bf11b070cfa124c4237785c45257bb4..4a3dcbdd623362a8f45e8fe04703ea81dc4d7de4 100644 (file)
@@ -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.
 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
-           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
 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.
 Author:
    Christoph Rohland <cr@sap.com>, 1.12.01
 Updated:
-   Hugh Dickins <hugh@veritas.com>, 01 April 2003
+   Hugh Dickins <hugh@veritas.com>, 01 September 2004
index 3722aefae0244468284d6b46f7cccb2950d15c5c..5c5d30805bbccb509fb6a8bffb04574fb8dacff2 100644 (file)
@@ -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)
 {
        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;
        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)
 {
        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;
        inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME;
        inode->i_nlink--;
@@ -1818,9 +1839,12 @@ static int shmem_fill_super(struct super_block *sb,
 
        /*
         * 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
        if (shmem_parse_options(data, &mode, &uid, &gid, &blocks, &inodes)) {