Skip to content
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

bug: memory.memsw.usage_in_bytes : no such file or directory #5

Closed
ivan-kiselev opened this issue Jan 26, 2017 · 6 comments
Closed

Comments

@ivan-kiselev
Copy link

ivan-kiselev commented Jan 26, 2017

Hi there!

I have a problems with Stat() function in cgroups package:

Code example(approximately):

control, err = cgroups.New(cgroups.V1, cgroups.StaticPath(cgroupName), &specs.LinuxResources {})
err := control.Add(cgroups.Process{Pid:int(pid)})
stats, err := control.Stat()
usage := stats.Cpu.Usage.Total
fmt.Printf("\n%v", usage)

It's just a part of a code, but its quite simple for seeing the logic I go through.

But when I try to run it:

  • Process that I expect to be moved into cgroupName is moved, it's ok.
  • My code falls into panic with /sys/fs/cgroup/memory/somecgroupname/memory.memsw.usage_in_bytes: no such file or directory

So, what have I found: memory.memsw.usage_in_bytes file isnt always present in system because its optionaly cgroups feature that could be activated by passing swapaccount=1 into kernel (actualy, I'm using Ubunt/Debian systems in my environment, so I have the same situation as I linked you to)

Additional links about kernel parameters that has impackt to file existing factor:

http://cateee.net/lkddb/web-lkddb/MEMCG_SWAP.html
http://cateee.net/lkddb/web-lkddb/MEMCG_SWAP_ENABLED.html.

So, it looks like we need some check about if the file exists or it doesnt to prevent that kind of panic.
May be I will try to figure it out by myself and create PR then, but if you have enough time and see quite easy way to do it, it would be nice.

Anyway, thank you for opensourcing that again!

@crosbymichael
Copy link
Member

First is the panic coming from your code or this cgroups package? If its coming from the package can you post the stack and I can fix it or you can submit a PR if you have time.

To fix this fast you should be able to pass an error handler for the stats function. This is one already in this package to ignore isnotexist errors.

control.Stats(cgroups.IgnoreNotExists)

You could also make your own ErrorHander func and pass to that method if you want it to do other things.

@ivan-kiselev
Copy link
Author

oh, control.Stat(cgroups.ErrorHandler(cgroups.IgnoreNotExist)) did the trick! Thx, and sorry for taking your time with my inattention: didnt open errors.go file before.

@ivan-kiselev
Copy link
Author

P.S. May be it's worthy to be noticed in README.md?

@crosbymichael
Copy link
Member

Ya, we can put an example in the readme

@point-free
Copy link

I'm running into the same issue. If you pass cgroups.ErrorHandler(cgroups.IgnoreNotExist), won't that prevent the rest of the memory stats from being read (e.g. kmem and kmem.tcp)? It seems like we'll return as soon as we hit a single error: https://github.com/containerd/cgroups/blob/master/memory.go#L163

@mariomac
Copy link
Contributor

The changes introduced in this PR should help dealing with this issue: #98

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants