Skip to content

Commit e4bc652

Browse files
Li Wangtyhicks
authored andcommitted
eCryptfs: Avoid unnecessary disk read and data decryption during writing
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>
1 parent 0e4a43e commit e4bc652

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎fs/ecryptfs/mmap.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ static int ecryptfs_write_begin(struct file *file,
338338
if (prev_page_end_size
339339
>= i_size_read(page->mapping->host)) {
340340
zero_user(page, 0, PAGE_CACHE_SIZE);
341-
} else {
341+
SetPageUptodate(page);
342+
} else if (len < PAGE_CACHE_SIZE) {
342343
rc = ecryptfs_decrypt_page(page);
343344
if (rc) {
344345
printk(KERN_ERR "%s: Error decrypting "
@@ -348,8 +349,8 @@ static int ecryptfs_write_begin(struct file *file,
348349
ClearPageUptodate(page);
349350
goto out;
350351
}
352+
SetPageUptodate(page);
351353
}
352-
SetPageUptodate(page);
353354
}
354355
}
355356
/* 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,
499500
}
500501
goto out;
501502
}
503+
if (!PageUptodate(page)) {
504+
if (copied < PAGE_CACHE_SIZE) {
505+
rc = 0;
506+
goto out;
507+
}
508+
SetPageUptodate(page);
509+
}
502510
/* Fills in zeros if 'to' goes beyond inode size */
503511
rc = fill_zeros_to_end_of_page(page, to);
504512
if (rc) {

0 commit comments

Comments
 (0)