Skip to contentSkip to conversation

mm-filesize_dependant_lru_cache_add.patch

PATCH In review Con Kolivas 1 participant 1 message Jun 18, 2006

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

PATCH 27/29 mm-filesize_dependant_lru_cache_add.patch

When reading from large files through the generic file read functions into page cache we can detect when a file is so large that it is unlikely to be fully cached in ram.

Add a tunable /proc/sys/vm/tail_largefiles that puts them at the tail of the inactive list to minimise their harm on present mapped pages and pagecache and enable it by default.

---
 Documentation/filesystems/proc.txt |    8 ++++++
 Documentation/sysctl/vm.txt        |    2 -
 include/linux/sysctl.h             |    1 
 include/linux/writeback.h          |    2 +
 kernel/sysctl.c                    |    9 +++++++
 mm/filemap.c                       |   47 +++++++++++++++++++++++++++++++++++--
 mm/page-writeback.c                |    2 -
 mm/swap.c                          |    3 --
 8 files changed, 68 insertions(+), 6 deletions(-)
include/linux/writeback.h +2 -0
Index: linux-ck-dev/include/linux/writeback.h
===================================================================
@@ -85,6 +85,8 @@ void laptop_io_completion(void);
 void laptop_sync_completion(void);
 void throttle_vm_writeout(void);
 
+extern long total_pages;
+
 /* These are exported to sysctl. */
 extern int dirty_background_ratio;
 extern int vm_dirty_ratio;
mm/filemap.c +45 -2

65 lines not on this page · raw message

mm/page-writeback.c +1 -1
Index: linux-ck-dev/mm/page-writeback.c
===================================================================
@@ -45,7 +45,7 @@
  */
 static long ratelimit_pages = 32;
 
-static long total_pages;	/* The total number of pages in the machine. */
+long total_pages __read_mostly;	/* The total number of pages in the machine. */
 static int dirty_exceeded __cacheline_aligned_in_smp;	/* Dirty mem may be over limit */
 
 /*
mm/swap.c +1 -2
Index: linux-ck-dev/mm/swap.c
===================================================================
@@ -416,8 +416,7 @@ void __pagevec_lru_add_active(struct pag
 
 /*
  * Function used uniquely to put pages back to the lru at the end of the
- * inactive list to preserve the lru order. Currently only used by swap
- * prefetch.
+ * inactive list to preserve the lru order.
  */
 void fastcall lru_cache_add_tail(struct page *page)
 {
include/linux/sysctl.h +1 -0
Index: linux-ck-dev/include/linux/sysctl.h
===================================================================
@@ -191,6 +191,7 @@ enum
 	VM_ZONE_RECLAIM_INTERVAL=32, /* time period to wait after reclaim failure */
 	VM_SWAP_PREFETCH=33,	/* swap prefetch */
 	VM_HARDMAPLIMIT=34,	/* Make mapped a hard limit */
+	VM_TAIL_LARGEFILES=35,	/* Read large files to lru tail */
 };
 
 
kernel/sysctl.c +9 -0
Index: linux-ck-dev/kernel/sysctl.c
===================================================================
@@ -73,6 +73,7 @@ extern int printk_ratelimit_burst;
 extern int pid_max_min, pid_max_max;
 extern int sysctl_drop_caches;
 extern int percpu_pagelist_fraction;
+extern int vm_tail_largefiles;
 
 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
 int unknown_nmi_panic;
@@ -809,6 +810,14 @@ static ctl_table vm_table[] = {
 		.mode		= 0644,
 		.proc_handler	= &proc_dointvec,
 	},
+	{
+		.ctl_name	= VM_TAIL_LARGEFILES,
+		.procname	= "tail_largefiles",
+		.data		= &vm_tail_largefiles,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= &proc_dointvec,
+	},
 #ifdef CONFIG_HUGETLB_PAGE
 	 {
 		.ctl_name	= VM_HUGETLB_PAGES,
Documentation/filesystems/proc.txt +8 -0
Index: linux-ck-dev/Documentation/filesystems/proc.txt
===================================================================
@@ -1318,6 +1318,14 @@ To free pagecache, dentries and inodes:
 As this is a non-destructive operation and dirty objects are not freeable, the
 user should run `sync' first.
 
+tail_largefiles
+---------------
+
+When enabled reads from large files to the tail end of the inactive lru list.
+This means that any cache from reading large files is dropped very quickly,
+preventing loss of mapped ram and useful pagecache when large files are read.
+This does, however, make caching less effective when working with large files.
+
 
 2.5 /proc/sys/dev - Device specific parameters
 ----------------------------------------------
Documentation/sysctl/vm.txt +1 -1
Index: linux-ck-dev/Documentation/sysctl/vm.txt
===================================================================
@@ -37,7 +37,7 @@ Currently, these files are in /proc/sys/
 
 dirty_ratio, dirty_background_ratio, dirty_expire_centisecs,
 dirty_writeback_centisecs, vfs_cache_pressure, laptop_mode,
-block_dump, swap_token_timeout, drop-caches:
+block_dump, swap_token_timeout, drop-caches, tail_largefiles:
 
 See Documentation/filesystems/proc.txt
 
Signature · 1 line
-ck