Skip to content

Commit

Permalink
core: 'uname' is a pointer
Browse files Browse the repository at this point in the history
* fix lcache re-caching
* regression: e604545

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Aug 17, 2024
1 parent ad78fa1 commit 681e4c4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cmn/cos/log_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
SmoduleTransport = 1 << iota
SmoduleAIS
SmoduleMemsys
SmoduleCluster
SmoduleCore
SmoduleFS
SmoduleReb
SmoduleEC
Expand Down
27 changes: 14 additions & 13 deletions core/lcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ func UncacheMountpath(mi *fs.Mountpath) {
// lchk //
//////////

func (lchk *lchk) housekeep() (d time.Duration) {
var tag string
d, tag = lchk.mp()
func (lchk *lchk) housekeep() time.Duration {
d, tag := lchk.mp()
if !lchk.running.CAS(false, true) {
if tag != "" {
nlog.Infof("running now: memory pressure %q, next sched %v", tag, d)
}
return
nlog.Infoln("running now; memory pressure:", tag, "next HK:", d)
return d
}
go lchk.evictAll(d /*evict older than*/)
return

go func(d time.Duration) {
lchk.evictOlder(d)
lchk.running.Store(false)
}(d)

return d
}

const termDuration = time.Duration(-1)
Expand All @@ -124,7 +126,7 @@ func (*lchk) mp() (d time.Duration, tag string) {
return
}

func (lchk *lchk) evictAll(d time.Duration) {
func (lchk *lchk) evictOlder(d time.Duration) {
lchk.now = time.Now()
lchk.d = d

Expand All @@ -133,6 +135,7 @@ func (lchk *lchk) evictAll(d time.Duration) {
// single-threaded: one cache at a time
caches := lomCaches()
if lchk.terminating() {
nlog.Infoln("terminating -->")
for _, cache := range caches {
lchk.cache = cache
cache.Range(lchk.fterm)
Expand All @@ -146,14 +149,12 @@ func (lchk *lchk) evictAll(d time.Duration) {
}

if _, tag := lchk.mp(); tag != "" {
nlog.Infof("memory pressure %q, total %d, evicted %d", tag, lchk.totalCnt, lchk.evictedCnt)
nlog.Infoln("post-evict memory pressure:", tag, "total:", lchk.totalCnt, "evicted:", lchk.evictedCnt)
}

// stats
g.tstats.Add(LcacheEvictedCount, lchk.evictedCnt)
g.tstats.Add(LcacheFlushColdCount, lchk.flushColdCnt)

lchk.running.Store(false)
}

func (lchk *lchk) fterm(_, value any) bool {
Expand Down
24 changes: 16 additions & 8 deletions core/lom.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/NVIDIA/aistore/cmn/cos"
"github.com/NVIDIA/aistore/cmn/debug"
"github.com/NVIDIA/aistore/cmn/feat"
"github.com/NVIDIA/aistore/cmn/nlog"
"github.com/NVIDIA/aistore/core/meta"
"github.com/NVIDIA/aistore/fs"
"github.com/NVIDIA/aistore/ios"
Expand Down Expand Up @@ -117,7 +118,7 @@ func Term() {
for i := 0; i < 8 && !g.lchk.running.CAS(false, true); i++ {
time.Sleep(sleep)
}
g.lchk.evictAll(termDuration)
g.lchk.evictOlder(termDuration)
}

/////////
Expand Down Expand Up @@ -483,7 +484,7 @@ func (lom *LOM) LoadUnsafe() (err error) {
// store new or refresh existing
func (lom *LOM) Recache() {
debug.Assert(!lom.IsCopy())
lom.setbid(lom.Bprops().BID) // TODO -- FIXME: 52 bits
lom.setbid(lom.Bprops().BID)

md := lom.md

Expand All @@ -493,23 +494,30 @@ func (lom *LOM) Recache() {
return
}
lmd := val.(*lmeta)
if lmd.uname != lom.md.uname {
g.tstats.Inc(LcacheCollisionCount) // target stats
if *lmd.uname != *lom.md.uname {
lom._collide(lmd)
} else {
// updating the value that's already in the map (race extremely unlikely, benign anyway)
md.cpAtime(lmd)
}
}

func (lom *LOM) _collide(lmd *lmeta) {
if cmn.Rom.FastV(4, cos.SmoduleCore) || (lom.digest%17) == 5 {
nlog.InfoDepth(1, LcacheCollisionCount, lom.digest, "[", *lmd.uname, "]", *lom.md.uname, lom.Cname())
}
g.tstats.Inc(LcacheCollisionCount)
}

func (lom *LOM) Uncache() {
lcache := lom.lcache()
md, ok := lcache.LoadAndDelete(lom.digest)
if !ok {
return
}
lmd := md.(*lmeta)
if lmd.uname != lom.md.uname {
g.tstats.Inc(LcacheCollisionCount) // target stats
if *lmd.uname != *lom.md.uname {
lom._collide(lmd)
} else {
lom.md.cpAtime(lmd)
}
Expand All @@ -534,8 +542,8 @@ func (lom *LOM) fromCache() (lcache *sync.Map, lmd *lmeta) {
lcache = lom.lcache()
if md, ok := lcache.Load(lom.digest); ok {
lmd = md.(*lmeta)
if lmd.uname != lom.md.uname {
g.tstats.Inc(LcacheCollisionCount) // target stats
if *lmd.uname != *lom.md.uname {
lom._collide(lmd)
}
}
return
Expand Down
2 changes: 1 addition & 1 deletion core/lom_xattr.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (md *lmeta) unpack(buf []byte) error {
mpathInfo, _, err := fs.FQN2Mpath(copyFQN)
if err != nil {
// Mountpath with the copy is missing.
if cmn.Rom.FastV(4, cos.SmoduleCluster) {
if cmn.Rom.FastV(4, cos.SmoduleCore) {
nlog.Warningln(err)
}
// For utilities and tests: fill the map with mpath names always
Expand Down

0 comments on commit 681e4c4

Please sign in to comment.