📄 o_streaming.patch
字号:
This patch by Robert Love prevents files opened as O_STREAMING fromconsuming disk cache pages prior to the current file pointer. It has been ported to kernel 2.6 using the infrastructure of posix_fadvice system call which is now the default interface for achieving this kindof operation.--- linux26-cvs/include/asm-mips/fcntl.h Wed Mar 9 11:21:27 2005+++ linux26-tony/include/asm-mips/fcntl.h Tue Jun 28 13:48:26 2005@@ -27,6 +27,7 @@ #define O_DIRECTORY 0x10000 /* must be a directory */ #define O_NOFOLLOW 0x20000 /* don't follow links */ #define O_NOATIME 0x40000+#define O_STREAMING 0x400000 /* streaming access */ #define O_NDELAY O_NONBLOCK --- linux26-cvs/mm/filemap.c Wed Mar 9 11:38:28 2005+++ linux26-tony/mm/filemap.c Tue Jun 28 13:36:12 2005@@ -669,6 +669,32 @@ EXPORT_SYMBOL(grab_cache_page_nowait); +/**+ * 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;+ + /*+ * ensure we have a decent amount of work todo+ */+ if (mapping->nrpages < 256)+ return 0;++ invalidate_mapping_pages(mapping, 0, max_index);+ return 0;+}+ /* * This is a generic file read routine, and uses the * mapping->a_ops->readpage() function for the actual low-level@@ -886,6 +912,8 @@ *ppos = ((loff_t) index << PAGE_CACHE_SHIFT) + offset; if (cached_page) page_cache_release(cached_page);+ if (filp->f_flags & O_STREAMING)+ shrink_pagecache(filp, index); if (filp) file_accessed(filp); }@@ -1940,7 +1968,10 @@ filemap_set_next_iovec(&cur_iov, &iov_base, written); buf = iov->iov_base + iov_base; }-+ + if (file->f_flags & O_STREAMING)+ shrink_pagecache(file, pos >> PAGE_CACHE_SHIFT);+ do { unsigned long index; unsigned long offset;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -