<div dir="auto">Gao,<div dir="auto"><br></div><div dir="auto">just returned from holidays. Let me rethink about this approach.</div><div dir="auto"><br></div><div dir="auto">--Pratik</div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 11, 2019, 11:14 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">On Mon, Dec 09, 2019 at 03:18:17PM +0800, Gao Xiang wrote:<br>
> Hi Pratik,<br>
> <br>
> On Mon, Dec 09, 2019 at 12:34:50PM +0530, Pratik Shinde wrote:<br>
> > Hello Gao,<br>
> > <br>
> > Did you get any chance to look at this in detail.<br>
> <br>
> I looked into your implementation weeks before.<br>
> <br>
> As my reply in the previous email, did you see it and could you check it out?<br>
> <br>
> Kernel emails are not top-posting so you could scroll down to the end.<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<br>
> > > variable-sized<br>
> > > extent array at the time of writing inode metadata (The order is firstly<br>
> > > data<br>
> > > and then metadata in erofs-utils so it looks practical.)<br>
<br>
<br>
Some feedback words here? Do you think it is unnecessary to use such<br>
array for limited fragmented holes (either in-memory or ondisk) as well?<br>
<br>
Thanks,<br>
Gao Xiang<br>
<br>
<br>
> <br>
> Thanks,<br>
> Gao Xiang<br>
> <br>
> > <br>
> > --Pratik.<br>
> > <br>
> > On Wed, Dec 4, 2019, 7:52 AM Gao Xiang <<a href="mailto:gaoxiang25@huawei.com" target="_blank" rel="noreferrer">gaoxiang25@huawei.com</a>> wrote:<br>
> > <br>
> > > 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 /<br>
> > > blocksize)<br>
> > > > The array basically tracks number of holes before a particular logical<br>
> > > 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<br>
> > > block in which offset falls)<br>
> > > ><br>
> > > > 3) If a read offset falls inside a hole (which can be found using above<br>
> > > 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<br>
> > > tracking<br>
> > > > array for every file to the disk.Which doesn't seems to be practical.we<br>
> > > 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<br>
> > > variable-sized<br>
> > > extent array at the time of writing inode metadata (The order is firstly<br>
> > > 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>
> > > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-<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 >><br>
> > > 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>
> > > \<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<br>
> > > 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<br>
> > > *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>
> > ><br>
</blockquote></div>