[Ch6]optimizing makfile for docker, fix data blocks allocation #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
optimizing makefile
原来的docker makefile,每次执行都会删除原来的镜像重建:
将
build,run,attach,rebuild拆分开来,按需rebuild。fix data blocks allocation
计算 data_bitmap 需要的 blocks 数量,这里的算法逻辑是:
我们期望:
定义:
核心目标:
让 blocks_used 尽可能接近 data_total_blocks(data_total_blocks 是 data_bitmap + data_areas 的总块数),
既保证所有 bitmap 的 bit 都有对应 data_areas 块,又保证绝大多数 data_areas 块都有对应 bit。
又因为:
blocks_used = n + n * 4096 = n * 4097 ≈ data_total_blocks
推导出:
n ≈ data_total_blocks / 4097
为了保证,bitmap 中每个 bit 都有有效 block 可以分配,这里我们需要
向下取整。那么:n = data_total_blocks / 4097
这样,我们在最好情况下正好用完全部的 blocks,最差情况下浪费 4096 个 blocks。
最差情况:假设有 8193 个 blocks 可用,那么最终是 1 个 bitmap,4096 个 data_area_blocks,剩余的4096个blocks没办法满足我们的需求
最好情况:假设有 8194 个 blocks 可用,那么最终是 2 个 bitmap,8192 个 data_area_blocks,正好用完全部的 blocks