forked from TrueCloudLab/restic
Reduce memory usage for fuse mount
This changes `repository.LoadBlob()` so that a destination buffer must be provided, which enables the fuse code to use a buffer from a `sync.Pool`. In addition, release the buffers when the file is closed. At the moment, the max memory usage is defined by the max file size that is read in one go (e.g. with `cat`). It could be further optimized by implementing a LRU caching scheme.
This commit is contained in:
parent
90ed679e88
commit
55ddd5317d
5 changed files with 101 additions and 39 deletions
13
node.go
13
node.go
|
@ -209,8 +209,19 @@ func (node Node) createFileAt(path string, repo *repository.Repository) error {
|
|||
return errors.Annotate(err, "OpenFile")
|
||||
}
|
||||
|
||||
var buf []byte
|
||||
for _, id := range node.Content {
|
||||
buf, err := repo.LoadBlob(pack.Data, id)
|
||||
_, _, _, length, err := repo.Index().Lookup(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
buf = buf[:cap(buf)]
|
||||
if uint(len(buf)) < length {
|
||||
buf = make([]byte, length)
|
||||
}
|
||||
|
||||
buf, err := repo.LoadBlob(pack.Data, id, buf)
|
||||
if err != nil {
|
||||
return errors.Annotate(err, "Load")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue