Skip to content

Commit

Permalink
eCryptfs: Avoid unnecessary disk read and data decryption during writing
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
  • Loading branch information
Li Wang authored and Tyler Hicks committed Nov 8, 2012
1 parent 0e4a43e commit e4bc652
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions fs/ecryptfs/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e4bc652

Please sign in to comment.