ovl: improving copy-up efficiency for big sparse file
authorChengguang Xu <cgxu519@mykernel.net>
Fri, 1 Nov 2019 12:35:51 +0000 (20:35 +0800)
committerMiklos Szeredi <mszeredi@redhat.com>
Wed, 22 Jan 2020 19:11:41 +0000 (20:11 +0100)
commitb504c6540d1752c73e16548062c49bc9f447cb12
tree4e18011188b62d98bcaa07164cd24dafc69338a3
parentb1f9d3858f724ed45b279b689fb5b400d91352e3
ovl: improving copy-up efficiency for big sparse file

Current copy-up is not efficient for big sparse file,
It's not only slow but also wasting more disk space
when the target lower file has huge hole inside.
This patch tries to recognize file hole and skip it
during copy-up.

Detail logic of hole detection as below:
When we detect next data position is larger than current
position we will skip that hole, otherwise we copy
data in the size of OVL_COPY_UP_CHUNK_SIZE. Actually,
it may not recognize all kind of holes and sometimes
only skips partial of hole area. However, it will be
enough for most of the use cases.

Additionally, this optimization relies on lseek(2)
SEEK_DATA implementation, so for some specific
filesystems which do not support this feature
will behave as before on copy-up.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/overlayfs/copy_up.c