swap cache patch and page cache patch for pre-2.0.31-4

Krzysztof Strasburger (strasbur@chkw386.ch.pwr.wroc.pl)
Tue, 12 Aug 97 14:21


Hi all!
Here is my swap cache patch for pre-2.0.31-4. It was present in pre-1 and 2,
but not in 3 and 4. Additionally, I'm posting slightly updated version
of the page cache patch, which makes freeing of page cache pages more
aggressive. As some people did not like it, it is a config option now.
Krzysztof Strasburger

------ begin of swap cache patch (search for ------)

diff -u -r linux.orig/include/linux/swap.h linux/include/linux/swap.h
--- linux.orig/include/linux/swap.h Mon Jun 3 14:38:37 1996
+++ linux/include/linux/swap.h Fri Apr 18 17:11:22 1997
@@ -34,6 +34,7 @@

extern int nr_swap_pages;
extern int nr_free_pages;
+extern int nr_swap_cache_pages;
extern atomic_t nr_async_pages;
extern int min_free_pages;
extern int free_pages_low;
@@ -113,10 +114,12 @@
swap_cache_find_total++;
#endif
entry = xchg(swap_cache + index, 0);
+ if (entry) {
#ifdef SWAP_CACHE_INFO
- if (entry)
swap_cache_find_success++;
#endif
+ nr_swap_cache_pages--;
+ }
return entry;
}

@@ -133,6 +136,7 @@
swap_cache_del_success++;
#endif
swap_free(entry);
+ nr_swap_cache_pages--;
return 1;
}
return 0;
diff -u -r linux.orig/mm/mmap.c linux/mm/mmap.c
--- linux.orig/mm/mmap.c Fri Dec 6 22:09:24 1996
+++ linux/mm/mmap.c Fri Apr 18 17:12:08 1997
@@ -55,9 +55,10 @@
long freepages;
freepages = buffermem >> PAGE_SHIFT;
freepages += page_cache_size;
- freepages >>= 1;
+/* freepages >>= 1;*/
freepages += nr_free_pages;
freepages += nr_swap_pages;
+ freepages += nr_swap_cache_pages;
freepages -= MAP_NR(high_memory) >> 4;
return freepages > pages;
}
diff -u -r linux.orig/mm/swap_state.c linux/mm/swap_state.c
--- linux.orig/mm/swap_state.c Wed Mar 13 14:17:23 1996
+++ linux/mm/swap_state.c Fri Apr 18 17:12:11 1997
@@ -32,6 +32,8 @@
*/
unsigned long *swap_cache;

+int nr_swap_cache_pages = 0;
+
#ifdef SWAP_CACHE_INFO
unsigned long swap_cache_add_total = 0;
unsigned long swap_cache_add_success = 0;
@@ -64,6 +66,7 @@
#ifdef SWAP_CACHE_INFO
swap_cache_add_success++;
#endif
+ nr_swap_cache_pages++;
return 1;
}
return 0;
diff -u -r linux.orig/mm/swapfile.c linux/mm/swapfile.c
--- linux.orig/mm/swapfile.c Thu Apr 10 23:47:14 1997
+++ linux/mm/swapfile.c Fri Apr 18 17:12:12 1997
@@ -570,6 +570,7 @@
++val->totalswap;
}
}
+ val->freeswap += nr_swap_cache_pages;
val->freeswap <<= PAGE_SHIFT;
val->totalswap <<= PAGE_SHIFT;
return;

------ end of swap cache patch
------ begin of page cache patch

--- linux.orig/mm/filemap.c.orig Thu Aug 7 11:25:00 1997
+++ linux/mm/filemap.c Thu Aug 7 12:04:02 1997
@@ -157,6 +157,15 @@

switch (page->count) {
case 1:
+#ifdef CONFIG_FREE_PAGE_CACHE
+ /* is it a page cache page? */
+ if (page->inode) {
+ remove_page_from_hash_queue(page);
+ remove_page_from_inode_queue(page);
+ __free_page(page);
+ return 1;
+ }
+#endif
/* If it has been referenced recently, don't free it */
if (clear_bit(PG_referenced, &page->flags)) {
/* age this page potential used */
@@ -165,6 +174,7 @@
break;
}

+#ifndef CONFIG_FREE_PAGE_CACHE
/* is it a page cache page? */
if (page->inode) {
remove_page_from_hash_queue(page);
@@ -172,6 +182,7 @@
__free_page(page);
return 1;
}
+#endif

/* is it a buffer cache page? */
if (bh && try_to_free_buffer(bh, &bh, 6))
@@ -180,7 +191,12 @@

default:
/* more than one users: we can't throw it away */
+#ifdef CONFIG_FREE_PAGE_CACHE
+ if (!clear_bit(PG_referenced, &page->flags))
+ age_page(page);
+#else
set_bit(PG_referenced, &page->flags);
+#endif
/* fall through */
case 0:
/* nothing */
diff -u --recursive --unidirectional-new-file linux.orig/mm/Config.in linux/mm/Config.in
--- linux.orig/mm/Config.in Thu Jan 1 00:00:00 1970
+++ linux/mm/Config.in Thu Aug 7 12:22:14 1997
@@ -0,0 +1,7 @@
+# Memory management configuration
+mainmenu_option next_comment
+comment 'Memory management configuration'
+
+bool 'Free page cache pages aggressively' CONFIG_FREE_PAGE_CACHE
+
+endmenu
--- linux.orig/arch/i386/config.in Mon May 13 04:17:23 1996
+++ linux/arch/i386/config.in Thu Aug 7 12:13:39 1997
@@ -45,6 +45,8 @@
PPro CONFIG_M686" Pentium
endmenu

+source mm/Config.in
+
source drivers/block/Config.in

if [ "$CONFIG_NET" = "y" ]; then
--- linux.orig/arch/alpha/config.in Mon Aug 5 07:13:50 1996
+++ linux/arch/alpha/config.in Thu Aug 7 12:34:23 1997
@@ -96,6 +96,8 @@
tristate 'Kernel support for ELF binaries' CONFIG_BINFMT_ELF
endmenu

+source mm/Config.in
+
source drivers/block/Config.in

if [ "$CONFIG_NET" = "y" ]; then
--- linux.orig/arch/m68k/config.in Mon May 20 04:54:26 1996
+++ linux/arch/m68k/config.in Thu Aug 7 12:34:21 1997
@@ -33,6 +33,8 @@
fi
endmenu

+source mm/Config.in
+
#
# Block device driver configuration
#
--- linux.orig/arch/mips/config.in Sun May 5 06:05:58 1996
+++ linux/arch/mips/config.in Thu Aug 7 12:34:25 1997
@@ -57,6 +57,8 @@
bool 'Set version information on all symbols for modules' CONFIG_MODVERSIONS
endmenu

+source mm/Config.in
+
source drivers/block/Config.in

if [ "$CONFIG_NET" = "y" ]; then
--- linux.orig/arch/ppc/config.in Mon May 27 09:00:57 1996
+++ linux/arch/ppc/config.in Thu Aug 7 12:34:20 1997
@@ -38,6 +38,8 @@
bool 'Compile kernel as ELF - if your GCC is ELF-GCC' CONFIG_KERNEL_ELF
fi

+source mm/Config.in
+
source drivers/block/Config.in

if [ "$CONFIG_NET" = "y" ]; then
--- linux.orig/arch/sparc/config.in Thu Apr 25 10:22:05 1996
+++ linux/arch/sparc/config.in Thu Aug 7 12:34:24 1997
@@ -31,6 +31,8 @@
tristate 'Kernel support for ELF binaries' CONFIG_BINFMT_ELF
endmenu

+source mm/Config.in
+
mainmenu_option next_comment
comment 'Floppy, IDE, and other block devices'

--- linux.orig/Documentation/Configure.help Tue Aug 5 09:01:41 1997
+++ linux/Documentation/Configure.help Thu Aug 7 12:51:21 1997
@@ -79,6 +79,16 @@
arch/i386/math-emu/README. If you are not sure, say Y; apart from
resulting in a 45kB bigger kernel, it won't hurt.

+Free page cache pages aggressively
+CONFIG_FREE_PAGE_CACHE
+ By default shared page cache and buffer pages are marked as referenced.
+ It makes freeing them very difficult (especially for the page cache).
+ If this option is enabled, shared pages are not marked. Additionally,
+ non referenced pages are aged. It may make low memory machines more
+ usable, as non referenced code pages (which are in most situations
+ the main component of the page cache) are freed aggressively and
+ swapping out of data pages is avoided.
+
Normal floppy disk support
CONFIG_BLK_DEV_FD
If you want to use your floppy disk drive(s) under Linux, say