* [PATCH] eCryptfs: Avoid unnecessary disk read and data decryption during writing
@ 2012-10-30 11:52 Li Wang
2012-11-08 5:10 ` Tyler Hicks
0 siblings, 1 reply; 2+ messages in thread
From: Li Wang @ 2012-10-30 11:52 UTC (permalink / raw)
To: Tyler Hicks, Dustin Kirkland
Cc: ecryptfs, linux-fsdevel, linux-kernel, Li Wang, Yunchuan Wen
ecryptfs_write_begin grabs a page from page cache for writing.
If the page contains invalid data, or data older than the
counterpart on the disk, eCryptfs will read out the
corresponing data from the disk into the page, decrypt them,
then perform writing. However, for this page, if the length
of the data to be written into is equal to page size,
that means the whole page of data will be overwritten,
in which case, it does not matter whatever the data were before,
it is beneficial to perform writing directly rather than bothering
to read and decrypt first.
With this optimization, according to our test on a machine with
Intel Core 2 Duo processor, iozone 'write' operation on an existing
file with write size being multiple of page size will enjoy a steady
3x speedup.
Signed-off-by: Li Wang <wangli@kylinos.com.cn>
Signed-off-by: Yunchuan Wen <wenyunchuan@kylinos.com.cn>
Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
---
fs/ecryptfs/mmap.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index bd1d57f..564a1fa 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -338,7 +338,8 @@ static int ecryptfs_write_begin(struct file *file,
if (prev_page_end_size
>= i_size_read(page->mapping->host)) {
zero_user(page, 0, PAGE_CACHE_SIZE);
- } else {
+ SetPageUptodate(page);
+ } else if (len < PAGE_CACHE_SIZE) {
rc = ecryptfs_decrypt_page(page);
if (rc) {
printk(KERN_ERR "%s: Error decrypting "
@@ -348,8 +349,8 @@ static int ecryptfs_write_begin(struct file *file,
ClearPageUptodate(page);
goto out;
}
+ SetPageUptodate(page);
}
- SetPageUptodate(page);
}
}
/* If creating a page or more of holes, zero them out via truncate.
@@ -499,6 +500,13 @@ static int ecryptfs_write_end(struct file *file,
}
goto out;
}
+ if (!PageUptodate(page)) {
+ if (copied < PAGE_CACHE_SIZE) {
+ rc = 0;
+ goto out;
+ }
+ SetPageUptodate(page);
+ }
/* Fills in zeros if 'to' goes beyond inode size */
rc = fill_zeros_to_end_of_page(page, to);
if (rc) {
--
1.7.6.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] eCryptfs: Avoid unnecessary disk read and data decryption during writing
2012-10-30 11:52 [PATCH] eCryptfs: Avoid unnecessary disk read and data decryption during writing Li Wang
@ 2012-11-08 5:10 ` Tyler Hicks
0 siblings, 0 replies; 2+ messages in thread
From: Tyler Hicks @ 2012-11-08 5:10 UTC (permalink / raw)
To: Li Wang
Cc: Dustin Kirkland, ecryptfs, linux-fsdevel, linux-kernel,
Yunchuan Wen
[-- Attachment #1: Type: text/plain, Size: 2687 bytes --]
On 2012-10-30 19:52:40, Li Wang wrote:
> ecryptfs_write_begin grabs a page from page cache for writing.
> If the page contains invalid data, or data older than the
> counterpart on the disk, eCryptfs will read out the
> corresponing data from the disk into the page, decrypt them,
> then perform writing. However, for this page, if the length
> of the data to be written into is equal to page size,
> that means the whole page of data will be overwritten,
> in which case, it does not matter whatever the data were before,
> it is beneficial to perform writing directly rather than bothering
> to read and decrypt first.
>
> With this optimization, according to our test on a machine with
> Intel Core 2 Duo processor, iozone 'write' operation on an existing
> file with write size being multiple of page size will enjoy a steady
> 3x speedup.
>
> Signed-off-by: Li Wang <wangli@kylinos.com.cn>
> Signed-off-by: Yunchuan Wen <wenyunchuan@kylinos.com.cn>
> Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
Thanks again, Li. I've pushed this to my next branch.
I lost track of it last time. Sorry about that!
Tyler
> ---
> fs/ecryptfs/mmap.c | 12 ++++++++++--
> 1 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
> index bd1d57f..564a1fa 100644
> --- a/fs/ecryptfs/mmap.c
> +++ b/fs/ecryptfs/mmap.c
> @@ -338,7 +338,8 @@ static int ecryptfs_write_begin(struct file *file,
> if (prev_page_end_size
> >= i_size_read(page->mapping->host)) {
> zero_user(page, 0, PAGE_CACHE_SIZE);
> - } else {
> + SetPageUptodate(page);
> + } else if (len < PAGE_CACHE_SIZE) {
> rc = ecryptfs_decrypt_page(page);
> if (rc) {
> printk(KERN_ERR "%s: Error decrypting "
> @@ -348,8 +349,8 @@ static int ecryptfs_write_begin(struct file *file,
> ClearPageUptodate(page);
> goto out;
> }
> + SetPageUptodate(page);
> }
> - SetPageUptodate(page);
> }
> }
> /* If creating a page or more of holes, zero them out via truncate.
> @@ -499,6 +500,13 @@ static int ecryptfs_write_end(struct file *file,
> }
> goto out;
> }
> + if (!PageUptodate(page)) {
> + if (copied < PAGE_CACHE_SIZE) {
> + rc = 0;
> + goto out;
> + }
> + SetPageUptodate(page);
> + }
> /* Fills in zeros if 'to' goes beyond inode size */
> rc = fill_zeros_to_end_of_page(page, to);
> if (rc) {
> --
> 1.7.6.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe ecryptfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-11-08 5:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-30 11:52 [PATCH] eCryptfs: Avoid unnecessary disk read and data decryption during writing Li Wang
2012-11-08 5:10 ` Tyler Hicks
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).