Skip to contentSkip to conversation

the /proc/filecache interface

RFC New Fengguang Wu 1 participant 1 message Jun 12, 2006

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

RFC 1/1 the /proc/filecache interface

Hello,

The /proc/filecache support has been half done. And I'd like to hear early comments on the interface.

(The patch is not quite ready for code reviews. It is attached in case someone are interested to have it a try.)

NOTES

- Devices are shown as MAJOR:MINOR numbers(03:00), rather than device files(/dev/hda).

- The query is atomic in a single read() context. So if you need consistent result, prepare a large enough read buffer.

- Parameters(only one for now: the file name) are stored in two kind of
places: one as the global default, and the others inside each opened /proc/filecache file. They are set according to the following rules:
- on opening up a new /proc/filecache fd, it's associated parameters are initialized by the global one;
- on writing to a /proc/filecache file to set new value for a parameter, both the file's associated parameters and the global one are updated.
The rules imply that:
- one can normally query the filecache use simple echo/cat command sequences.
- for scripts that don't want to be disturbed by concurrent queries, always reuse one single fd to expect a consistent set of private parameters.

TODO

1) sort the inode list
a) dirty inodes for each partition
b) in use inodes(newest at top)
c) unused inodes
2) security concerns
3) split up the patch
4) documents

5) breakup the page attribute 'location' into section/node/zone
6) allow users to specify which attrs to show, examples:
file.attr = cached% dev file # show only the three attrs
file.attr = ALL -uid -gid # all attrs but uid/gid
page.attr = NONE # report only idx/len
page.state = referenced active # show only two page flags
page.state = RF AC # use acronyms

Note that (6) is necessary only if we want to do (5) and provide support for the section/node/zone attributes. If ever these attrs should be supported, they must be optional ones: For systems with interleaved memory policies, the page location differs for every successive pages, thus can make the output rather tedious and huge.

I guess the location attrs might be useful for someone. However I need strong confirmation on this, to make sure that I'm not wasting time when doing (6).

If you thinks a lot of the page location attrs, please voice it now, thanks.

SAMPLE OUTPUT

root ~# echo -n ALL > /proc/filecache
root ~# head /proc/filecache

# file ALL
#      ino       size   cached cached%  state   refcnt  uid     gid     dev             file
    413605         23       24    100   --      0       0       0       03:00(hda)      /sbin/modprobe
    381701         17       20    100   --      1       0       0       03:00(hda)      /bin/cat
    398088          1        4    100   --      0       0       0       03:00(hda)      /root/bin/checkpath
    381698        611      612    100   --      1       0       0       03:00(hda)      /bin/bash
    159498          1        4    100   --      0       0       0       03:00(hda)      /etc/mtab
    381719         30       32    100   --      0       0       0       03:00(hda)      /bin/rm
    335993          4        4    100   --      0       0       43      03:00(hda)      /var/run/utmp
         0    3687424      828      0   --      0       0       0       00:02(bdev)     03:00
    159701          5        8    100   --      0       0       0       03:00(hda)      /etc/modprobe.d/aliases
     31866       1238     1240    100   --      4       0       0       03:00(hda)      /lib/tls/libc-2.3.5.so
    381705         51       52    100   --      0       0       0       03:00(hda)      /bin/cp
     31814         27       28    100   --      0       0       0       03:00(hda)      /lib/libblkid.so.1.0
    159534         17       20    100   --      0       0       0       03:00(hda)      /etc/ld.so.cache
[...]

root ~# echo -n /lib/tls/libc-2.3.5.so > /proc/filecache root ~# head /proc/filecache

# file /lib/tls/libc-2.3.5.so
# flags LK:locked ER:error RF:referenced UD:uptodate DT:dirty AC:active SL:slab CK:checked A1:arch_1 RS:reserved PV:private WB:writeback NS:nosave CP:compound SC:swapcache MD:mappedtodisk RC:reclaim ns:nosave_free RA:readahead MM:mmap
# idx   len                     state                   	refcnt  location
0       21      ____RFUD__AC__________________MD______MM        4       0.0.Normal
21      1       ____RFUD__AC__________________MD______MM        3       0.0.Normal
22      3       ______UD______________________MD________        1       0.0.Normal
25      1       ____RFUD__AC__________________MD______MM        2       0.0.Normal
26      2       ______UD______________________MD________        1       0.0.Normal
28      1       ______UD______________________MD____RA__        1       0.0.Normal
29      2       ______UD______________________MD________        1       0.0.Normal

root ~# echo -n /dev/hda > /proc/filecache
root ~# head /proc/filecache

# file /dev/hda
# flags LK:locked ER:error RF:referenced UD:uptodate DT:dirty AC:active SL:slab CK:checked A1:arch_1 RS:reserved PV:private WB:writeback NS:nosave CP:compound SC:swapcache MD:mappedtodisk RC:reclaim ns:nosave_free RA:readahead MM:mmap
# idx   len                     state                   	refcnt  location
0       2       ______UDDTAC________PV__________________        2       0.0.Normal
4       1       ____RF____AC________PV__________________        2       0.0.Normal
501     1       ____RF____AC________PV__________________        2       0.0.Normal
506     1       ____RFUD____________PV__________________        2       0.0.Normal
507     1       ____RF______________PV__________________        2       0.0.Normal
518     1       ____RF____AC________PV__________________        2       0.0.Normal
571     2       ____RF______________PV__________________        2       0.0.Normal

---

 fs/Kconfig          |   10 
 fs/dcache.c         |   17 +
 fs/inode.c          |    9 
 fs/proc/Makefile    |    1 
 fs/proc/filecache.c |  535 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h  |    1 
 include/linux/mm.h  |    1 
 mm/page_alloc.c     |    2 
 8 files changed, 574 insertions(+), 2 deletions(-)
fs/Kconfig +10 -0
@@ -894,6 +894,16 @@ config CONFIGFS_FS
 	  Both sysfs and configfs can and should exist together on the
 	  same system. One is not a replacement for the other.
 
+config PROC_FILECACHE
+	tristate "/proc/filecache support"
+	default m
+	depends on PROC_FS
+	help
+	  This option creates a file /proc/filecache which enables one to
+	  get the listing of cached files/pages.
+
+	  It can be a handy tool for sysadms and desktop users.
+
 endmenu
 
 menu "Miscellaneous filesystems"
fs/proc/filecache.c new file +524 -0

524 lines not on this page · raw message

fs/inode.c +9 -0
@@ -1328,6 +1328,15 @@ void wake_up_inode(struct inode *inode)
 	wake_up_bit(&inode->i_state, __I_LOCK);
 }
 
+struct hlist_head * get_inode_hash_budget(unsigned long index)
+{
+	if (index >= (1 << i_hash_shift))
+		return NULL;
+
+	return inode_hashtable + index;
+}
+EXPORT_SYMBOL_GPL(get_inode_hash_budget);
+
 static __initdata unsigned long ihash_entries;
 static int __init set_ihash_entries(char *str)
 {
include/linux/fs.h +1 -0
@@ -1674,6 +1674,7 @@ extern void remove_inode_hash(struct ino
 static inline void insert_inode_hash(struct inode *inode) {
 	__insert_inode_hash(inode, inode->i_ino);
 }
+struct hlist_head * get_inode_hash_budget(unsigned long index);
 
 extern struct file * get_empty_filp(void);
 extern void file_move(struct file *f, struct list_head *list);
fs/dcache.c +4 -1
@@ -1478,7 +1478,10 @@ static char * __d_path( struct dentry *d
 
 		if (dentry == root && vfsmnt == rootmnt)
 			break;
-		if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
+		if (unlikely(!vfsmnt)) {
+			if (IS_ROOT(dentry))
+				break;
+		} else if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
 			/* Global root? */
 			spin_lock(&vfsmount_lock);
 			if (vfsmnt->mnt_parent == vfsmnt) {
fs/proc/Makefile +1 -0
@@ -13,3 +13,4 @@ proc-y       += inode.o root.o base.o ge
 proc-$(CONFIG_PROC_KCORE)	+= kcore.o
 proc-$(CONFIG_PROC_VMCORE)	+= vmcore.o
 proc-$(CONFIG_PROC_DEVICETREE)	+= proc_devtree.o
+proc-$(CONFIG_PROC_FILECACHE)	+= filecache.o
include/linux/mm.h +1 -0
@@ -483,6 +483,7 @@ static inline unsigned long page_zonenum
 
 struct zone;
 extern struct zone *zone_table[];
+extern char *zone_names[];
 
 static inline int page_zone_id(struct page *page)
 {
mm/page_alloc.c +1 -1
@@ -81,7 +81,7 @@ EXPORT_SYMBOL(totalram_pages);
 struct zone *zone_table[1 << ZONETABLE_SHIFT] __read_mostly;
 EXPORT_SYMBOL(zone_table);
 
-static char *zone_names[MAX_NR_ZONES] = { "DMA", "DMA32", "Normal", "HighMem" };
+char *zone_names[MAX_NR_ZONES] = { "DMA", "DMA32", "Normal", "HighMem" };
 int min_free_kbytes = 1024;
 
 unsigned long __meminitdata nr_kernel_pages;