diff -Naur linux-2.4.22-ppc-dev.orig/include/asm-arm/fcntl.h linux-2.4.22-ppc-dev/include/asm-arm/fcntl.h --- linux-2.4.22-ppc-dev.orig/include/asm-arm/fcntl.h 2003-09-05 16:22:51.000000000 +0200 +++ linux-2.4.22-ppc-dev/include/asm-arm/fcntl.h 2003-09-05 17:22:03.000000000 +0200 @@ -20,6 +20,7 @@ #define O_NOFOLLOW 0100000 /* don't follow links */ #define O_DIRECT 0200000 /* direct disk access hint - currently ignored */ #define O_LARGEFILE 0400000 +#define O_STREAMING 04000000 /* streaming access */ #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get close_on_exec */ diff -Naur linux-2.4.22-ppc-dev.orig/include/asm-i386/fcntl.h linux-2.4.22-ppc-dev/include/asm-i386/fcntl.h --- linux-2.4.22-ppc-dev.orig/include/asm-i386/fcntl.h 2003-09-05 16:22:47.000000000 +0200 +++ linux-2.4.22-ppc-dev/include/asm-i386/fcntl.h 2003-09-05 17:22:03.000000000 +0200 @@ -20,6 +20,7 @@ #define O_LARGEFILE 0100000 #define O_DIRECTORY 0200000 /* must be a directory */ #define O_NOFOLLOW 0400000 /* don't follow links */ +#define O_STREAMING 04000000 /* streaming access */ #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get close_on_exec */ diff -Naur linux-2.4.22-ppc-dev.orig/include/asm-mips/fcntl.h linux-2.4.22-ppc-dev/include/asm-mips/fcntl.h --- linux-2.4.22-ppc-dev.orig/include/asm-mips/fcntl.h 2003-09-05 16:22:48.000000000 +0200 +++ linux-2.4.22-ppc-dev/include/asm-mips/fcntl.h 2003-09-05 17:22:03.000000000 +0200 @@ -26,6 +26,7 @@ #define O_DIRECT 0x8000 /* direct disk access hint */ #define O_DIRECTORY 0x10000 /* must be a directory */ #define O_NOFOLLOW 0x20000 /* don't follow links */ +#define O_STREAMING 0x400000 /* streaming access */ #define O_NDELAY O_NONBLOCK diff -Naur linux-2.4.22-ppc-dev.orig/include/asm-ppc/fcntl.h linux-2.4.22-ppc-dev/include/asm-ppc/fcntl.h --- linux-2.4.22-ppc-dev.orig/include/asm-ppc/fcntl.h 2003-09-05 16:22:51.000000000 +0200 +++ linux-2.4.22-ppc-dev/include/asm-ppc/fcntl.h 2003-09-05 17:22:03.000000000 +0200 @@ -20,6 +20,7 @@ #define O_NOFOLLOW 0100000 /* don't follow links */ #define O_LARGEFILE 0200000 #define O_DIRECT 0400000 /* direct disk access hint */ +#define O_STREAMING 04000000 /* streaming access */ #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get close_on_exec */ diff -Naur linux-2.4.22-ppc-dev.orig/include/asm-sh/fcntl.h linux-2.4.22-ppc-dev/include/asm-sh/fcntl.h --- linux-2.4.22-ppc-dev.orig/include/asm-sh/fcntl.h 2003-09-05 16:22:53.000000000 +0200 +++ linux-2.4.22-ppc-dev/include/asm-sh/fcntl.h 2003-09-05 17:22:03.000000000 +0200 @@ -20,6 +20,7 @@ #define O_LARGEFILE 0100000 #define O_DIRECTORY 0200000 /* must be a directory */ #define O_NOFOLLOW 0400000 /* don't follow links */ +#define O_STREAMING 04000000 /* streaming access */ #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get close_on_exec */ diff -Naur linux-2.4.22-ppc-dev.orig/mm/filemap.c linux-2.4.22-ppc-dev/mm/filemap.c --- linux-2.4.22-ppc-dev.orig/mm/filemap.c 2003-09-05 16:45:43.000000000 +0200 +++ linux-2.4.22-ppc-dev/mm/filemap.c 2003-09-05 17:22:03.000000000 +0200 @@ -1340,6 +1340,90 @@ SetPageReferenced(page); } +/** + * shrink_list - non-blockingly drop pages from the given cache list + * @mapping: the mapping from which we want to drop pages + * @list: which list (e.g. locked, dirty, clean)? + * @max_index: greatest index from which we will drop pages + */ +static unsigned long shrink_list(struct address_space *mapping, + struct list_head *list, + unsigned long max_index) +{ + struct list_head *curr = list->prev; + unsigned long nr_shrunk = 0; + + spin_lock(&pagemap_lru_lock); + spin_lock(&pagecache_lock); + + while ((curr != list)) { + struct page *page = list_entry(curr, struct page, list); + + curr = curr->prev; + + if (page->index > max_index) + continue; + + if (PageDirty(page)) + continue; + + if (TryLockPage(page)) + break; + + if (page->buffers && !try_to_release_page(page, 0)) { + /* probably dirty buffers */ + unlock_page(page); + break; + } + + if (page_count(page) != 1) { + unlock_page(page); + continue; + } + + __lru_cache_del(page); + __remove_inode_page(page); + unlock_page(page); + page_cache_release(page); + nr_shrunk++; + } + + spin_unlock(&pagecache_lock); + spin_unlock(&pagemap_lru_lock); + + return nr_shrunk; +} + +/** + * shrink_pagecache - nonblockingly drop pages from the mapping. + * @file: the file we are doing I/O on + * @max_index: the maximum index from which we are willing to drop pages + * + * This is for O_STREAMING, which says "I am streaming data, I know I will not + * revisit this; do not cache anything". + * + * max_index allows us to only drop pages which are behind `index', to avoid + * trashing readahead. + */ +static unsigned long shrink_pagecache(struct file *file, + unsigned long max_index) +{ + struct address_space *mapping = file->f_dentry->d_inode->i_mapping; + unsigned long nr_locked, nr_clean, nr_dirty; + + /* + * ensure we have a decent amount of work todo + */ + if (mapping->nrpages < 256) + return 0; + + nr_locked = shrink_list(mapping, &mapping->locked_pages, max_index); + nr_clean = shrink_list(mapping, &mapping->clean_pages, max_index); + nr_dirty = shrink_list(mapping, &mapping->dirty_pages, max_index); + + return nr_locked + nr_clean + nr_dirty; +} + /* * This is a generic file read routine, and uses the * inode->i_op->readpage() function for the actual low-level @@ -1556,6 +1640,8 @@ filp->f_reada = 1; if (cached_page) page_cache_release(cached_page); + if (filp->f_flags & O_STREAMING) + shrink_pagecache(filp, index); UPDATE_ATIME(inode); } @@ -3125,6 +3211,9 @@ inode->i_ctime = inode->i_mtime = CURRENT_TIME; mark_inode_dirty_sync(inode); + if (file->f_flags & O_STREAMING) + shrink_pagecache(file, pos >> PAGE_CACHE_SHIFT); + do { unsigned long index, offset; long page_fault;