Browse Source

reduce memory usage

pull/769/head
Chris Lu 6 years ago
parent
commit
2e6a3c7b16
  1. 6
      weed/command/mount.go
  2. 2
      weed/command/mount_std.go
  3. 8
      weed/filesys/dirty_page.go
  4. 9
      weed/filesys/filehandle.go
  5. 5
      weed/filesys/wfs.go

6
weed/command/mount.go

@ -20,7 +20,9 @@ type MountOptions struct {
}
var (
mountOptions MountOptions
mountOptions MountOptions
mountCpuProfile *string
mountMemProfile *string
)
func init() {
@ -35,6 +37,8 @@ func init() {
mountOptions.ttlSec = cmdMount.Flag.Int("ttl", 0, "file ttl in seconds")
mountOptions.chunkSizeLimitMB = cmdMount.Flag.Int("chunkSizeLimitMB", 16, "local write buffer size, also chunk large files")
mountOptions.dataCenter = cmdMount.Flag.String("dataCenter", "", "prefer to write to the data center")
mountCpuProfile = cmdMount.Flag.String("cpuprofile", "", "cpu profile output file")
mountMemProfile = cmdMount.Flag.String("memprofile", "", "memory profile output file")
}
var cmdMount = &Command{

2
weed/command/mount_std.go

@ -28,6 +28,8 @@ func runMount(cmd *Command, args []string) bool {
fuse.Unmount(*mountOptions.dir)
util.SetupProfiling(*mountCpuProfile, *mountMemProfile)
c, err := fuse.Mount(
*mountOptions.dir,
fuse.VolumeName("SeaweedFS"),

8
weed/filesys/dirty_page.go

@ -28,6 +28,14 @@ func newDirtyPages(file *File) *ContinuousDirtyPages {
}
}
func (pages *ContinuousDirtyPages) InitializeToFile(file *File) *ContinuousDirtyPages {
if len(pages.Data) != int(file.wfs.option.ChunkSizeLimit) {
pages.Data = make([]byte, file.wfs.option.ChunkSizeLimit)
}
pages.f = file
return pages
}
func (pages *ContinuousDirtyPages) AddPage(ctx context.Context, offset int64, data []byte) (chunks []*filer_pb.FileChunk, err error) {
pages.lock.Lock()

9
weed/filesys/filehandle.go

@ -37,6 +37,15 @@ func newFileHandle(file *File, uid, gid uint32) *FileHandle {
}
}
func (fh *FileHandle) InitializeToFile(file *File, uid, gid uint32) *FileHandle {
newHandle := &FileHandle{
f: file,
dirtyPages: fh.dirtyPages.InitializeToFile(file),
Uid: uid,
Gid: gid,
}
return newHandle
}
var _ = fs.Handle(&FileHandle{})
// var _ = fs.HandleReadAller(&FileHandle{})

5
weed/filesys/wfs.go

@ -72,15 +72,14 @@ func (wfs *WFS) AcquireHandle(file *File, uid, gid uint32) (fileHandle *FileHand
return wfs.handles[index]
}
fileHandle = newFileHandle(file, uid, gid)
if found && wfs.handles[index] != nil {
glog.V(4).Infoln(fullpath, "reuse previous fileHandle id", index)
wfs.handles[index] = fileHandle
wfs.handles[index].InitializeToFile(file, uid, gid)
fileHandle.handle = uint64(index)
return
}
fileHandle = newFileHandle(file, uid, gid)
for i, h := range wfs.handles {
if h == nil {
wfs.handles[i] = fileHandle

Loading…
Cancel
Save