Improve du thread performance (#6849)

master
Nitish Tiwari 6 years ago committed by GitHub
parent dd8c2aa5c6
commit 2a810c7da2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      cmd/fs-v1.go
  2. 8
      cmd/posix.go

@ -187,14 +187,9 @@ func (fs *FSObjects) diskUsage(doneCh chan struct{}) {
case <-doneCh: case <-doneCh:
return errWalkAbort return errWalkAbort
default: default:
var fi os.FileInfo fi, err := os.Stat(entry)
var err error
if hasSuffix(entry, slashSeparator) {
fi, err = fsStatDir(ctx, entry)
} else {
fi, err = fsStatFile(ctx, entry)
}
if err != nil { if err != nil {
err = osErrToFSFileErr(err)
return err return err
} }
atomic.AddUint64(&fs.totalUsed, uint64(fi.Size())) atomic.AddUint64(&fs.totalUsed, uint64(fi.Size()))
@ -226,14 +221,9 @@ func (fs *FSObjects) diskUsage(doneCh chan struct{}) {
} }
} }
var fi os.FileInfo fi, err := os.Stat(entry)
var err error
if hasSuffix(entry, slashSeparator) {
fi, err = fsStatDir(ctx, entry)
} else {
fi, err = fsStatFile(ctx, entry)
}
if err != nil { if err != nil {
err = osErrToFSFileErr(err)
return err return err
} }
usage = usage + uint64(fi.Size()) usage = usage + uint64(fi.Size())

@ -83,8 +83,10 @@ func checkPathLength(pathName string) error {
return errFileNameTooLong return errFileNameTooLong
} }
// Convert any '\' to '/'. if runtime.GOOS == "windows" {
pathName = filepath.ToSlash(pathName) // Convert any '\' to '/'.
pathName = filepath.ToSlash(pathName)
}
// Check each path segment length is > 255 // Check each path segment length is > 255
for len(pathName) > 0 && pathName != "." && pathName != "/" { for len(pathName) > 0 && pathName != "." && pathName != "/" {
@ -374,6 +376,7 @@ func (s *posix) diskUsage(doneCh chan struct{}) {
default: default:
fi, err := os.Stat(entry) fi, err := os.Stat(entry)
if err != nil { if err != nil {
err = osErrToFSFileErr(err)
return err return err
} }
atomic.AddUint64(&s.totalUsed, uint64(fi.Size())) atomic.AddUint64(&s.totalUsed, uint64(fi.Size()))
@ -413,6 +416,7 @@ func (s *posix) diskUsage(doneCh chan struct{}) {
default: default:
fi, err := os.Stat(entry) fi, err := os.Stat(entry)
if err != nil { if err != nil {
err = osErrToFSFileErr(err)
return err return err
} }
usage = usage + uint64(fi.Size()) usage = usage + uint64(fi.Size())

Loading…
Cancel
Save