<div dir="auto">Hello Gao,<div dir="auto"><br></div><div dir="auto">Did you get any chance to look at this in detail.</div><div dir="auto"><br></div><div dir="auto">--Pratik.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 4, 2019, 7:52 AM Gao Xiang <<a href="mailto:gaoxiang25@huawei.com">gaoxiang25@huawei.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Pratik,<br>
<br>
I'll give detailed words this weekend if you have more questions<br>
since I'm busying in other stupid intra-company stuffs now...<br>
<br>
On Tue, Dec 03, 2019 at 07:32:50PM +0530, Pratik Shinde wrote:<br>
> NOTE: The patch is not fully complete yet, with this patch I just want to<br>
> present rough idea of what I am trying to achieve.<br>
> <br>
> The patch does following :<br>
> 1) Detect holes (of size EROFS_BLKSIZ) in uncompressed files.<br>
> 2) Keep track of holes per file.<br>
> <br>
> In-order to track holes, I used an array of size = (file_size / blocksize)<br>
> The array basically tracks number of holes before a particular logical file block.<br>
> e.g blks[i] = 10 meaning ith block has 10 holes before it.<br>
> If a particular block is a hole we set the index to '-1'.<br>
> <br>
> how read logic will change:<br>
> 1) currently we simply map read offset to a fs block.<br>
> 2) with holes in place the calculation of block number would be:<br>
> <br>
> blkno = start_block + (offset >> block_size_shift) - (number of <br>
> holes before block in which offset falls)<br>
> <br>
> 3) If a read offset falls inside a hole (which can be found using above array). We<br>
> fill the user buffer with '\0' on the fly.<br>
> <br>
> through this,block no. lookup would still be performed in constant time.<br>
> <br>
> The biggest problem with this approach is - we have to store the hole tracking<br>
> array for every file to the disk.Which doesn't seems to be practical.we can use a linkedlist,<br>
> but that will make size of inode variable.<br>
<br>
"variable-sized inode" isn't a problem here, which can be handled<br>
similar to the case of "compress indexes".<br>
<br>
Probably no need to write linked list to the disk but generate linked list<br>
in memory when writing data on the fly, and then transfer to a variable-sized<br>
extent array at the time of writing inode metadata (The order is firstly data<br>
and then metadata in erofs-utils so it looks practical.)<br>
<br>
Thanks,<br>
Gao Xiang<br>
<br>
> <br>
> Signed-off-by: Pratik Shinde <<a href="mailto:pratikshinde320@gmail.com" target="_blank" rel="noreferrer">pratikshinde320@gmail.com</a>><br>
> ---<br>
> lib/inode.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-<br>
> 1 file changed, 66 insertions(+), 1 deletion(-)<br>
> <br>
> diff --git a/lib/inode.c b/lib/inode.c<br>
> index 0e19b11..af31949 100644<br>
> --- a/lib/inode.c<br>
> +++ b/lib/inode.c<br>
> @@ -38,6 +38,61 @@ static unsigned char erofs_type_by_mode[S_IFMT >> S_SHIFT] = {<br>
> <br>
> struct list_head inode_hashtable[NR_INODE_HASHTABLE];<br>
> <br>
> +<br>
> +#define IS_HOLE(start, end) (roundup(start, EROFS_BLKSIZ) == start && \<br>
> + roundup(end, EROFS_BLKSIZ) == end && \<br>
> + (end - start) % EROFS_BLKSIZ == 0)<br>
> +#define HOLE_BLK -1<br>
> +unsigned int erofs_detect_holes(struct erofs_inode *inode, int *blks)<br>
> +{<br>
> + int i, fd, st, en;<br>
> + unsigned int nblocks;<br>
> + erofs_off_t data, hole, len;<br>
> +<br>
> + nblocks = inode->i_size / EROFS_BLKSIZ;<br>
> + for (i = 0; i < nblocks; i++)<br>
> + blks[i] = 0;<br>
> + fd = open(inode->i_srcpath, O_RDONLY);<br>
> + if (fd < 0) {<br>
> + return -errno;<br>
> + }<br>
> + len = lseek(fd, 0, SEEK_END);<br>
> + if (lseek(fd, 0, SEEK_SET) == -1)<br>
> + return -errno;<br>
> + data = 0;<br>
> + while (data < len) {<br>
> + hole = lseek(fd, data, SEEK_HOLE);<br>
> + if (hole == len)<br>
> + break;<br>
> + data = lseek(fd, hole, SEEK_DATA);<br>
> + if (data < 0 || hole > data) {<br>
> + return -EINVAL;<br>
> + }<br>
> + if (IS_HOLE(hole, data)) {<br>
> + st = hole >> S_SHIFT;<br>
> + en = data >> S_SHIFT;<br>
> + nblocks -= (en - st);<br>
> + for (i = st; i < en; i++)<br>
> + blks[i] = HOLE_BLK;<br>
> + }<br>
> + }<br>
> + return nblocks;<br>
> +}<br>
> +<br>
> +int erofs_fill_holedata(int *blks, unsigned int nblocks) {<br>
> + int i, nholes = 0;<br>
> + for (i = 0; i < nblocks; i++) {<br>
> + if (blks[i] == -1)<br>
> + nholes++;<br>
> + else {<br>
> + blks[i] = nholes;<br>
> + if (nholes >= (i + 1))<br>
> + return -EINVAL;<br>
> + }<br>
> + }<br>
> + return 0;<br>
> +}<br>
> +<br>
> void erofs_inode_manager_init(void)<br>
> {<br>
> unsigned int i;<br>
> @@ -305,6 +360,7 @@ static bool erofs_file_is_compressible(struct erofs_inode *inode)<br>
> int erofs_write_file(struct erofs_inode *inode)<br>
> {<br>
> unsigned int nblocks, i;<br>
> + int *blks;<br>
> int ret, fd;<br>
> <br>
> if (!inode->i_size) {<br>
> @@ -322,7 +378,13 @@ int erofs_write_file(struct erofs_inode *inode)<br>
> /* fallback to all data uncompressed */<br>
> inode->datalayout = EROFS_INODE_FLAT_INLINE;<br>
> nblocks = inode->i_size / EROFS_BLKSIZ;<br>
> -<br>
> + blks = malloc(sizeof(int) * nblocks);<br>
> + nblocks = erofs_detect_holes(inode, blks);<br>
> + if (nblocks < 0)<br>
> + return nblocks;<br>
> + if ((ret = erofs_fill_holedata(blks, nblocks)) != 0) {<br>
> + return ret;<br>
> + }<br>
> ret = __allocate_inode_bh_data(inode, nblocks);<br>
> if (ret)<br>
> return ret;<br>
> @@ -332,6 +394,8 @@ int erofs_write_file(struct erofs_inode *inode)<br>
> return -errno;<br>
> <br>
> for (i = 0; i < nblocks; ++i) {<br>
> + if (blks[i] == HOLE_BLK)<br>
> + continue;<br>
> char buf[EROFS_BLKSIZ];<br>
> <br>
> ret = read(fd, buf, EROFS_BLKSIZ);<br>
> @@ -962,3 +1026,4 @@ struct erofs_inode *erofs_mkfs_build_tree_from_path(struct erofs_inode *parent,<br>
> return erofs_mkfs_build_tree(inode);<br>
> }<br>
> <br>
> +<br>
> -- <br>
> 2.9.3<br>
> <br>
</blockquote></div>