[patch] shrink inode fs-lowlevel memory when low on memory

Andrea Arcangeli (andrea@e-mind.com)
Thu, 11 Feb 1999 12:06:07 +0100 (CET)


On Thu, 11 Feb 1999, Andrea Arcangeli wrote:

>>called by shrink_dcache() and be invisible for VM - after all, it's VFS
>>business what to trim and what kind of balance should be kept between
>>dcache, icache and fs-specific parts.
>
>Agreed, better to do the work in shrink_dcache(). Once you shrunk the

I looked at the code and (even if I don't think it's a big issue for high
memory machines) it's very simple to fix cleanly the lowlevel fs memory
issue.

We can simply clear the inode at iput() time.

I checked that this works fine here:

Index: inode.c
===================================================================
RCS file: /var/cvs/linux/fs/inode.c,v
retrieving revision 1.1.2.11
diff -u -r1.1.2.11 inode.c
--- inode.c 1999/02/09 21:46:03 1.1.2.11
+++ linux/fs/inode.c 1999/02/11 10:55:00
@@ -725,16 +725,23 @@
spin_lock(&inode_lock);
}
}
- if (list_empty(&inode->i_hash)) {
+ if (!inode->i_state) {
list_del(&inode->i_list);
+ list_del(&inode->i_hash);
INIT_LIST_HEAD(&inode->i_list);
+ INIT_LIST_HEAD(&inode->i_hash);
+ dispose:
spin_unlock(&inode_lock);
clear_inode(inode);
spin_lock(&inode_lock);
list_add(&inode->i_list, &inode_unused);
inodes_stat.nr_free_inodes++;
- }
- else if (!(inode->i_state & I_DIRTY)) {
+ } else if (list_empty(&inode->i_hash)) {
+ list_del(&inode->i_list);
+ INIT_LIST_HEAD(&inode->i_list);
+ goto dispose;
+ } else if (!(inode->i_state & I_DIRTY)) {
+ printk(KERN_WARNING "iput: inode under I/O\n");
list_del(&inode->i_list);
list_add(&inode->i_list, &inode_in_use);
}

I finished now a `find /'. The inode/dcache looks like this:

andrea@laser:/proc/sys/fs$ cat inode-nr
8205 3
andrea@laser:/proc/sys/fs$ cat dentry-state
0 7895 45 0 0 0

Now I run a trashing proggy:

andrea@laser:/proc/sys/fs$ swap-bench &
[1] 169
andrea@laser:/proc/sys/fs$ free
total used free shared buffers cached
Mem: 127360 118384 8976 7944 16940 13660
-/+ buffers/cache: 87784 39576
Swap: 72256 0 72256
andrea@laser:/proc/sys/fs$ free
total used free shared buffers cached
Mem: 127360 124848 2512 7576 108 4308
-/+ buffers/cache: 120432 6928
Swap: 72256 12104 60152
andrea@laser:/proc/sys/fs$ free
total used free shared buffers cached
Mem: 127360 124692 2668 7576 88 3904
-/+ buffers/cache: 120700 6660
Swap: 72256 29608 42648
andrea@laser:/proc/sys/fs$ free
total used free shared buffers cached
Mem: 127360 124908 2452 7576 84 3852
-/+ buffers/cache: 120972 6388
Swap: 72256 42724 29532
andrea@laser:/proc/sys/fs$ fg
swap-bench

andrea@laser:/proc/sys/fs$ cat inode-nr
8205 8075
andrea@laser:/proc/sys/fs$ cat dentry-state
0 12 45 0 0 0
andrea@laser:/proc/sys/fs$

So every inode get cleared when the system gone low on memory.

Comments?

Andrea Arcangeli

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/