diff -urN linux-2.4.17/include/asm-arm/fcntl.h linux/include/asm-arm/fcntl.h --- linux-2.4.17/include/asm-arm/fcntl.h 2002-10-07 16:45:43.000000000 -0400 +++ linux/include/asm-arm/fcntl.h 2002-10-07 17:19:33.000000000 -0400 @@ -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 -urN linux-2.4.17/include/asm-i386/fcntl.h linux/include/asm-i386/fcntl.h --- linux-2.4.17/include/asm-i386/fcntl.h 2002-10-07 16:45:38.000000000 -0400 +++ linux/include/asm-i386/fcntl.h 2002-10-07 17:18:22.000000000 -0400 @@ -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 -urN linux-2.4.17/include/asm-mips/fcntl.h linux/include/asm-mips/fcntl.h --- linux-2.4.17/include/asm-mips/fcntl.h 2002-10-07 16:45:39.000000000 -0400 +++ linux/include/asm-mips/fcntl.h 2002-10-07 17:20:38.000000000 -0400 @@ -26,6 +26,7 @@ #define O_DIRECT 0x8000 /* direct disk access hint - currently ignored */ #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 -urN linux-2.4.17/include/asm-ppc/fcntl.h linux/include/asm-ppc/fcntl.h --- linux-2.4.17/include/asm-ppc/fcntl.h 2002-10-07 16:45:42.000000000 -0400 +++ linux/include/asm-ppc/fcntl.h 2002-10-07 17:20:49.000000000 -0400 @@ -23,6 +23,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 -urN linux-2.4.17/include/asm-sh/fcntl.h linux/include/asm-sh/fcntl.h --- linux-2.4.17/include/asm-sh/fcntl.h 2002-10-07 16:45:45.000000000 -0400 +++ linux/include/asm-sh/fcntl.h 2002-10-07 17:19:19.000000000 -0400 @@ -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 -urN linux-2.4.17/mm/filemap.c linux/mm/filemap.c --- linux-2.4.17/mm/filemap.c 2002-10-07 16:45:37.000000000 -0400 +++ linux/mm/filemap.c 2002-10-07 18:26:48.000000000 -0400 @@ -1268,6 +1268,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 @@ -1484,6 +1568,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); } @@ -2966,6 +3053,9 @@ if (file->f_flags & O_DIRECT) goto o_direct; + if (file->f_flags & O_STREAMING) + shrink_pagecache(file, pos >> PAGE_CACHE_SHIFT); + do { unsigned long index, offset; long page_fault;