From: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
To: linux-fsdevel <linux-fsdevel@vger.kernel.org>,
linux-mm <linux-mm@kvack.org>
Subject: [RFC:PATCH 08/09] generic_file_aio_read can read directly from the tail. No need to unpack
Date: Thu, 8 Nov 2007 12:48:01 -0700 [thread overview]
Message-ID: <20071108194759.17862.44869.sendpatchset@norville.austin.ibm.com> (raw)
In-Reply-To: <20071108194709.17862.16713.sendpatchset@norville.austin.ibm.com>
generic_file_aio_read can read directly from the tail. No need to unpack
Signed-off-by: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
---
include/linux/vm_file_tail.h | 13 ++++++++++
mm/file_tail.c | 54 +++++++++++++++++++++++++++++++++++++++++++
mm/filemap.c | 4 ++-
3 files changed, 70 insertions(+), 1 deletion(-)
diff -Nurp linux007/include/linux/vm_file_tail.h linux008/include/linux/vm_file_tail.h
--- linux007/include/linux/vm_file_tail.h 2007-11-08 10:49:46.000000000 -0600
+++ linux008/include/linux/vm_file_tail.h 2007-11-08 10:49:46.000000000 -0600
@@ -53,6 +53,18 @@ static inline void vm_file_tail_unpack_i
vm_file_tail_unpack(mapping);
}
+extern int __vm_file_tail_read(struct file *, loff_t *, read_descriptor_t *);
+
+static inline int vm_file_tail_read(struct file *filp, loff_t *ppos,
+ read_descriptor_t *desc)
+{
+ struct address_space *mapping = filp->f_mapping;
+ unsigned long index = *ppos >> PAGE_CACHE_SHIFT;
+
+ if (mapping->tail && index == vm_file_tail_index(mapping))
+ return __vm_file_tail_read(filp, ppos, desc);
+ return 0;
+}
#else /* !CONFIG_VM_FILE_TAILS */
#define vm_file_tail_packed(mapping) 0
@@ -60,6 +72,7 @@ static inline void vm_file_tail_unpack_i
#define vm_file_tail_pack(page) 0
#define vm_file_tail_unpack(mapping) do {} while (0)
#define vm_file_tail_unpack_index(mapping, index) do {} while (0)
+#define vm_file_tail_read(filp, ppos, desc) 0
#endif /* CONFIG_VM_FILE_TAILS */
diff -Nurp linux007/mm/file_tail.c linux008/mm/file_tail.c
--- linux007/mm/file_tail.c 2007-11-08 10:49:46.000000000 -0600
+++ linux008/mm/file_tail.c 2007-11-08 10:49:46.000000000 -0600
@@ -178,3 +178,57 @@ void __vm_file_tail_unpack_on_resize(str
vm_file_tail_free(inode->i_mapping);
}
EXPORT_SYMBOL(__vm_file_tail_unpack_on_resize);
+
+/*
+ * Copy tail data to user buffer
+ *
+ * Returns 1 on success
+ */
+int __vm_file_tail_read(struct file *filp, loff_t *ppos,
+ read_descriptor_t *desc)
+{
+ unsigned long count = desc->count;
+ unsigned int flags;
+ unsigned long left;
+ struct address_space *mapping = filp->f_mapping;
+ unsigned long offset;
+ unsigned long index = *ppos >> PAGE_CACHE_SHIFT;
+ unsigned long size;
+
+ if (fault_in_pages_writeable(desc->arg.buf, count))
+ /*
+ * Keep this simple since this path is an optimization. Let
+ * the tricky stuff get handled in the fallback path.
+ */
+ return 0;
+
+ spin_lock_irqsave(&mapping->tail_lock, flags);
+
+ offset = *ppos & ~PAGE_CACHE_MASK;
+ if (!mapping->tail || index != vm_file_tail_index(mapping) ||
+ offset >= vm_file_tail_length(mapping)) {
+ spin_unlock_irqrestore(&mapping->tail_lock, flags);
+ return 0;
+ }
+
+ size = vm_file_tail_length(mapping) - offset;
+ if (size > count)
+ size = count;
+
+ left = __copy_to_user_inatomic(desc->arg.buf,
+ (char *)mapping->tail + offset, size);
+
+ spin_unlock_irqrestore(&mapping->tail_lock, flags);
+
+ if (left) {
+ size -= left;
+ desc->error = -EFAULT;
+ }
+ desc->count = count - size;
+ desc->written += size;
+ desc->arg.buf += size;
+ *ppos += size;
+ file_accessed(filp);
+
+ return 1;
+}
diff -Nurp linux007/mm/filemap.c linux008/mm/filemap.c
--- linux007/mm/filemap.c 2007-11-08 10:49:46.000000000 -0600
+++ linux008/mm/filemap.c 2007-11-08 10:49:46.000000000 -0600
@@ -1195,7 +1195,9 @@ generic_file_aio_read(struct kiocb *iocb
if (desc.count == 0)
continue;
desc.error = 0;
- do_generic_file_read(filp,ppos,&desc,file_read_actor);
+ if (!vm_file_tail_read(filp, ppos, &desc))
+ do_generic_file_read(filp, ppos, &desc,
+ file_read_actor);
retval += desc.written;
if (desc.error) {
retval = retval ?: desc.error;
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2007-11-08 19:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-08 19:47 [RFC:PATCH 00/09] VM File Tails Dave Kleikamp
2007-11-08 19:47 ` [RFC:PATCH 01/09] Add tail to address space Dave Kleikamp
2007-11-08 19:47 ` [RFC:PATCH 02/09] Core function for packing, unpacking, and freeing file tails Dave Kleikamp
2007-11-08 19:47 ` [RFC:PATCH 03/09] Release tail when inode is freed Dave Kleikamp
2007-11-08 19:47 ` [RFC:PATCH 04/09] Unpack or remove file tail when inode is resized Dave Kleikamp
2007-11-08 19:47 ` [RFC:PATCH 05/09] find_get_page() and find_lock_page() need to unpack the tail Dave Kleikamp
2007-11-08 19:47 ` [RFC:PATCH 06/09] For readahead, leave data in tail Dave Kleikamp
2007-11-08 19:47 ` [RFC:PATCH 07/09] shrink_active_list: pack file tails rather than move to inactive list Dave Kleikamp
2007-11-08 19:48 ` Dave Kleikamp [this message]
2007-11-08 19:48 ` [RFC:PATCH 09/09] VM tail statistics support Dave Kleikamp, Luiz Fernando N. Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071108194759.17862.44869.sendpatchset@norville.austin.ibm.com \
--to=shaggy@linux.vnet.ibm.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox