-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xload prefetch initial code #1585
Open
souravgupta-msft
wants to merge
55
commits into
feature/xload
Choose a base branch
from
sourav/prefetch
base: feature/xload
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 50 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
7ed70c3
Creating component
vibhansa-msft 88ec516
Cleanup
vibhansa-msft 3cbfc73
cleanup'
vibhansa-msft 5019e96
Updating copyright statement
souravgupta-msft 1dc590e
Adding block
vibhansa-msft 0f14e2a
Adding block and blockpool
vibhansa-msft 1c7e914
Merge branch 'feature/xload' of https://github.com/Azure/azure-storag…
vibhansa-msft 4a54134
Adding threadpool
vibhansa-msft c309894
Base code
vibhansa-msft c60bad0
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
souravgupta-msft d0bfd1b
changing mode type to enum
souravgupta-msft cad5756
changing mode type to enum (#1386)
souravgupta-msft 141a549
Adding splitter logic
vibhansa-msft 741a0ca
local listing
souravgupta-msft 2329c4b
Added splitter logic
vibhansa-msft dc31b1e
Correct error handling
vibhansa-msft 3d9357f
Sync with lister
vibhansa-msft 0e90768
Updated
vibhansa-msft 84b562e
Error handling
vibhansa-msft 60cb00e
Adding remote lister
souravgupta-msft 68e4bd8
log correction
souravgupta-msft a7b545f
sample
souravgupta-msft 3faa5f2
lister
souravgupta-msft 360bbec
adding xlister
souravgupta-msft e153b3f
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
souravgupta-msft 73a444c
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
souravgupta-msft a5eca7a
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
souravgupta-msft 1f43c23
check
souravgupta-msft a840414
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
souravgupta-msft 93f0224
temp
souravgupta-msft 26d19c9
test
souravgupta-msft 9fb087e
code
souravgupta-msft 177a177
more code
souravgupta-msft 3243675
refactor
souravgupta-msft c27ed4b
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
souravgupta-msft 2aaca33
changes
souravgupta-msft 4c18f76
xload to azstorage
souravgupta-msft 3483983
sync with main
souravgupta-msft 20c4853
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
souravgupta-msft 96e0968
changes
souravgupta-msft 96a8e28
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
souravgupta-msft 9c054d3
more logs
souravgupta-msft 523b64b
changes
souravgupta-msft 2f9e8ec
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
souravgupta-msft 0f462cd
config
souravgupta-msft 6ed0cb3
add readonly check
souravgupta-msft 34e567e
Merge branch 'main' of https://github.com/Azure/azure-storage-fuse in…
souravgupta-msft a7c8fe2
Removing upload code
souravgupta-msft dd4840b
go version update
souravgupta-msft 6f5121b
copyright fix
souravgupta-msft 17a9985
Merge branch 'feature/xload' of https://github.com/Azure/azure-storag…
souravgupta-msft ce69c5e
refactoring
souravgupta-msft 16eb04c
refactor
souravgupta-msft db6ffcc
Merge branch 'feature/xload' of https://github.com/Azure/azure-storag…
souravgupta-msft 151a2fa
update copyright statements
souravgupta-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
_____ _____ _____ ____ ______ _____ ------ | ||
| | | | | | | | | | | | | | ||
| | | | | | | | | | | | | | ||
| --- | | | | |-----| |---- | | |-----| |----- ------ | ||
| | | | | | | | | | | | | | ||
| ____| |_____ | ____| | ____| | |_____| _____| |_____ |_____ | ||
|
||
|
||
Licensed under the MIT License <http://opensource.org/licenses/MIT>. | ||
|
||
Copyright © 2020-2024 Microsoft Corporation. All rights reserved. | ||
Author : <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE | ||
*/ | ||
|
||
package xload | ||
|
||
import ( | ||
"fmt" | ||
"syscall" | ||
) | ||
|
||
// Block is a memory mapped buffer with its state to hold data | ||
type Block struct { | ||
index int // Index of the block in the pool | ||
offset int64 // Start offset of the data this block holds | ||
length int64 // Length of data that this block holds | ||
id string // ID to represent this block in the blob | ||
data []byte // Data this block holds | ||
} | ||
|
||
// AllocateBlock creates a new memory mapped buffer for the given size | ||
func AllocateBlock(size uint64) (*Block, error) { | ||
if size == 0 { | ||
return nil, fmt.Errorf("invalid size") | ||
} | ||
|
||
prot, flags := syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE | ||
addr, err := syscall.Mmap(-1, 0, int(size), prot, flags) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("mmap error: %v", err) | ||
} | ||
|
||
block := &Block{ | ||
index: 0, | ||
data: addr, | ||
offset: 0, | ||
length: 0, | ||
id: "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we omit explicit assignments for default values ( |
||
} | ||
|
||
return block, nil | ||
} | ||
|
||
// Delete cleans up the memory mapped buffer | ||
func (b *Block) Delete() error { | ||
if b.data == nil { | ||
return fmt.Errorf("invalid buffer") | ||
} | ||
|
||
err := syscall.Munmap(b.data) | ||
b.data = nil | ||
if err != nil { | ||
// if we get here, there is likely memory corruption. | ||
return fmt.Errorf("munmap error: %v", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Clear the old data of this block | ||
func (b *Block) ReUse() { | ||
b.id = "" | ||
b.index = 0 | ||
b.offset = 0 | ||
b.length = 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
_____ _____ _____ ____ ______ _____ ------ | ||
| | | | | | | | | | | | | | ||
| | | | | | | | | | | | | | ||
| --- | | | | |-----| |---- | | |-----| |----- ------ | ||
| | | | | | | | | | | | | | ||
| ____| |_____ | ____| | ____| | |_____| _____| |_____ |_____ | ||
|
||
|
||
Licensed under the MIT License <http://opensource.org/licenses/MIT>. | ||
|
||
Copyright © 2020-2024 Microsoft Corporation. All rights reserved. | ||
Author : <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE | ||
*/ | ||
|
||
package xload | ||
|
||
import "github.com/Azure/azure-storage-fuse/v2/common/log" | ||
|
||
const _1MB uint64 = (1024 * 1024) | ||
|
||
// BlockPool is a pool of Blocks | ||
type BlockPool struct { | ||
// Channel holding free blocks | ||
blocksCh chan *Block | ||
|
||
// Size of each block this pool holds | ||
blockSize uint64 | ||
|
||
// Number of block that this pool can handle at max | ||
maxBlocks uint32 | ||
} | ||
|
||
// NewBlockPool allocates a new pool of blocks | ||
func NewBlockPool(blockSize uint64, blockCount uint32) *BlockPool { | ||
// Ignore if config is invalid | ||
if blockSize == 0 { | ||
log.Err("blockpool::NewBlockPool : blockSize : %v", blockSize) | ||
return nil | ||
} | ||
|
||
pool := &BlockPool{ | ||
blocksCh: make(chan *Block, blockCount), | ||
maxBlocks: uint32(blockCount), | ||
blockSize: blockSize, | ||
} | ||
|
||
// Preallocate all blocks so that during runtime we do not spend CPU cycles on this | ||
for i := (uint32)(0); i < blockCount; i++ { | ||
b, err := AllocateBlock(blockSize) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
pool.blocksCh <- b | ||
} | ||
|
||
return pool | ||
} | ||
|
||
// Terminate ends the block pool life | ||
func (pool *BlockPool) Terminate() { | ||
close(pool.blocksCh) | ||
|
||
// Release back the memory allocated to each block | ||
for { | ||
b := <-pool.blocksCh | ||
if b == nil { | ||
break | ||
} | ||
_ = b.Delete() | ||
} | ||
} | ||
|
||
// Usage provides % usage of this block pool | ||
func (pool *BlockPool) Usage() uint32 { | ||
return ((pool.maxBlocks - (uint32)(len(pool.blocksCh))) * 100) / pool.maxBlocks | ||
} | ||
|
||
// Get a Block from the pool, return back if nothing is available | ||
func (pool *BlockPool) Get() *Block { | ||
// getting a block from pool will be a blocking operation if the pool is empty | ||
b := <-pool.blocksCh | ||
|
||
// Mark the buffer ready for reuse now | ||
if b != nil { | ||
b.ReUse() | ||
} | ||
return b | ||
} | ||
|
||
// Release back the Block to the pool | ||
func (pool *BlockPool) Release(b *Block) { | ||
select { | ||
case pool.blocksCh <- b: | ||
break | ||
default: | ||
_ = b.Delete() | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider declaring
16
as a constant. This approach would make it easier to update the value in the future, as it would only need to be changed in one place. Additionally, assigning it to a well-named constant would enhance readability for developers.