mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
fix(flashnode): optimize computeAllocSize when there is a hole in dataSources.#1000080725
Signed-off-by: baihailong <baihailong@oppo.com>
This commit is contained in:
parent
efeeea3dcd
commit
30f483b8a5
@ -507,17 +507,17 @@ func (cb *CacheBlock) notifyReady() {
|
||||
|
||||
// align AllocSize with PageSize-4KB
|
||||
func computeAllocSize(sources []*proto.DataSource) (alloc uint64) {
|
||||
for _, s := range sources {
|
||||
blockOffset := s.FileOffset & (proto.CACHE_BLOCK_SIZE - 1)
|
||||
blockEnd := blockOffset + s.Size_ - 1
|
||||
pageOffset := blockOffset / proto.PageSize
|
||||
pageEnd := blockEnd / proto.PageSize
|
||||
if blockEnd < blockOffset {
|
||||
return 0
|
||||
}
|
||||
for i := pageOffset; i <= pageEnd; i++ {
|
||||
alloc += proto.PageSize
|
||||
}
|
||||
if len(sources) == 0 {
|
||||
return
|
||||
}
|
||||
firstSource := sources[0]
|
||||
lastSource := sources[len(sources)-1]
|
||||
start := firstSource.FileOffset / proto.CACHE_BLOCK_SIZE * proto.CACHE_BLOCK_SIZE
|
||||
end := lastSource.FileOffset + lastSource.Size_
|
||||
|
||||
alloc = end - start
|
||||
if alloc%proto.PageSize != 0 {
|
||||
alloc = (alloc/proto.PageSize + 1) * proto.PageSize
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user