<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi Weiwen, Xiang,<br>
</p>
<div class="moz-cite-prefix">在 2021/1/22 21:21, Gao Xiang 写道:<br>
</div>
<blockquote type="cite"
cite="mid:20210122132118.GC3105292@xiangao.remote.csb">
<pre class="moz-quote-pre" wrap="">On Fri, Jan 22, 2021 at 09:14:08PM +0800, Gao Xiang wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">Hi Weiwen,
On Tue, Jan 19, 2021 at 01:49:51PM +0800, Hu Weiwen wrote:
...
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap=""> bb = NULL;
- list_for_each_entry(cur, &blkh.list, list) {
- unsigned int used_before, used;
+ if (!used0 || alignsize == EROFS_BLKSIZ)
+ goto alloc;
+
+ /* try to find a most-fit mapped buffer block first */
+ used_before = EROFS_BLKSIZ -
+ round_up(size + required_ext + inline_ext, alignsize);
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
Honestly, after seen above I feel I'm not good at math now
since I smell somewhat strange of this, apart from the pending
patch you raised [1], the algebra is
/* since all buffers should be aligned with alignsize */
erofs_off_t alignedoffset = roundup(used_before, alignsize);
and (alignedoffset + size + required_ext + inline_ext <= EROFS_BLKSIZ)
and why it can be equal to
used_before = EROFS_BLKSIZ - round_up(size + required_ext + inline_ext, alignsize);
Could you explain this in detail if possible? for example,
size = 3
inline_ext = 62
alignsize = 32
so 4096 - roundup(3 + 62, 32) = 4096 - 96 = 4000
but, the real used_before can be even started at 4032, since
alignedoffset = roundup(4032, 32) = 4032
4032 + 62 = 4094 <= EROFS_BLKSIZ.
Am I stll missing something?
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
Oh, the example itself is wrong, yet I still feel no good at
this formula, e.g I'm not sure if it works for alignsize which
cannot be divided by EROFS_BLKSIZ (although currently alignsize =
4 or 32)
Thanks,
Gao Xiang
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
We can divide several parts of data in EROFS_BLKSIZ as follows:
</pre>
<p
style="margin:0in;margin-left:.375in;font-family:微软雅黑;font-size:11.0pt"><span
style="mso-spacerun:yes"> </span><span style="mso-spacerun:yes">
</span>____________________________________________________________________________________</p>
<p
style="margin:0in;margin-left:.375in;font-family:微软雅黑;font-size:11.0pt"><span
lang="zh-CN"><span style="mso-spacerun:yes"> </span> |<span
style="mso-spacerun:yes"> </span><span
style="mso-spacerun:yes"> </span></span><span lang="en-US"><span
style="mso-spacerun:yes"> </span></span><span
lang="zh-CN"><span style="mso-spacerun:yes"></span>|<span
style="mso-spacerun:yes"> </span></span><span
lang="zh-CN"><span style="mso-spacerun:yes"></span>|</span><span
lang="zh-CN"><span style="mso-spacerun:yes">
</span></span><span
lang="zh-CN"><span style="mso-spacerun:yes"></span>|</span><span
lang="zh-CN"><span style="mso-spacerun:yes"> </span></span><span
lang="zh-CN"><span style="mso-spacerun:yes"></span>|</span></p>
<p
style="margin:0in;margin-left:.375in;font-family:微软雅黑;font-size:11.0pt"><span
lang="zh-CN"><span style="mso-spacerun:yes"> </span> |<span
style="mso-spacerun:yes"> used_before </span></span><span
lang="en-US"><span style="mso-spacerun:yes"> </span></span><span
lang="zh-CN"><span style="mso-spacerun:yes"> </span>|<span
style="mso-spacerun:yes"> </span>alignedoffset</span><span
lang="en-US"><span style="mso-spacerun:yes"> </span></span><span
lang="zh-CN">|</span><span lang="en-US"><span
style="mso-spacerun:yes"></span></span><span lang="zh-CN"><span
style="mso-spacerun:yes"> size + required_ext + inline_ext
</span></span><span lang="en-US"><span style="mso-spacerun:yes"></span></span><span
lang="zh-CN">|</span><span lang="en-US"><span
style="mso-spacerun:yes"></span></span><span lang="zh-CN"><span
style="mso-spacerun:yes"> </span>tail_data <span
style="mso-spacerun:yes"> </span></span><span lang="en-US"><span
style="mso-spacerun:yes"></span></span><span lang="zh-CN">|</span><span
lang="en-US"><span style="mso-spacerun:yes"></span></span><span
lang="zh-CN"></span></p>
<p
style="margin:0in;margin-left:.375in;font-family:微软雅黑;font-size:11.0pt"><span
style="mso-spacerun:yes"> </span>
|________________ |_________________|_____________________________________|___________|</p>
<pre class="moz-quote-pre" wrap="">Use alignsize to represent these data:
1) alignsize * num_x = used_before + alignedoffset
2) alignsize * num_y = size + required_ext + inline_ext + tail_data
3) alignsize * num_z = EROFS_BLKSIZ
So we can get,
4) num_x + num_y = num_z
If we use
used_before = EROFS_BLKSIZ - round_up(size + required_ext + inline_ext, alignsize);
here, num_y should be an integer.
Consider the following two situations:
</pre>
<pre class="moz-quote-pre" wrap="">1) If EROFS_BLKSIZ can be divisible by alignsize, num_z is an integer. so num_x is an integer.
The following formula can be satisfied:
erofs_off_t alignedoffset = roundup(used_before, alignsize);
2)If EROFS_BLKSIZ can't be divisible by alignsize, num_z isn't an integer and num_x won't be an integer.
The formula can't be satisfied.
So I think it should be
used_before = round_down(EROFS_BLKSIZ - size-required_ext - inline_ext , alignsize);
here.
Sorry for my poor english and figure. . .
Thanks,
Jianan
</pre>
<blockquote type="cite"
cite="mid:20210122132118.GC3105292@xiangao.remote.csb">
<pre class="moz-quote-pre" wrap="">
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">IMO, I don't want too hard on such math, I'd like to just use
used_before = EROFS_BLKSIZ - (size + required_ext + inline_ext);
and simply skip the bb if __erofs_battach is fail (as I said before,
the internal __erofs_battach can be changed, and I don't want to
imply that always succeed.)
If you also agree that, I'll send out a revised version along
with a cleanup patch to clean up erofs_balloc() as well, which
is more complicated than before.
[1] <a class="moz-txt-link-freetext" href="https://lore.kernel.org/r/20210121162606.8168-1-sehuww@mail.scut.edu.cn/">https://lore.kernel.org/r/20210121162606.8168-1-sehuww@mail.scut.edu.cn/</a>
Thanks,
Gao Xiang
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
</pre>
</blockquote>
</body>
</html>