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

Procfs is not support process share memory monitoring #685

Open
SilenceAdele opened this issue Dec 9, 2024 · 4 comments
Open

Procfs is not support process share memory monitoring #685

SilenceAdele opened this issue Dec 9, 2024 · 4 comments

Comments

@SilenceAdele
Copy link

SilenceAdele commented Dec 9, 2024

  • In the top command, the size of the process's shared memory can be obtained through SHR.
PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
58984 diag      20   0 2119424 185436  35180 S   1.0   0.1 234:02.02 qemu-kvm
  • The role of shared memory monitoring of processes in actual production
  1. In a virtualized or containerized environment, multiple virtual machines or containers may share the host machine's memory. If a virtual machine or container occupies too much shared memory, it may affect the memory resources of other virtual machines or containers, resulting in limited memory access, delays or crashes.
  2. If a long-running virtual machine or container does not release shared memory correctly, it may cause the shared memory to continue to grow, eventually affecting the stability of the entire system.

Looking forward to your reply!

@SilenceAdele
Copy link
Author

ping...

@discordianfish
Copy link
Member

Are you sure its not part of the MemInfo struct? https://pkg.go.dev/github.com/prometheus/procfs#Meminfo

@SilenceAdele
Copy link
Author

SilenceAdele commented Dec 20, 2024

// Meminfo returns an information about current kernel/system memory statistics.
// See https://www.kernel.org/doc/Documentation/filesystems/proc.txt
func (fs FS) Meminfo() (Meminfo, error) {
	b, err := util.ReadFileNoStat(fs.proc.Path("meminfo"))
	if err != nil {
		return Meminfo{}, err
	}

	m, err := parseMemInfo(bytes.NewReader(b))
	if err != nil {
		return Meminfo{}, fmt.Errorf("%w: %w", ErrFileParse, err)
	}

	return *m, nil
}
  • https://github.com/prometheus/procfs/blob/v0.15.1/meminfo.go#L195 From the meminfo.go code, we can see that Procfs obtains the system memory information in the /proc/meminfo directory. Shmem here is the size of the system shared memory, rather than the shared memory of a specific process.
  • I want to get the shared memory of each pid. It should be obtained from /proc/pid/statm.Therefore, Procfs has not yet achieved all process sharing of memory monitoring. @discordianfish

@discordianfish
Copy link
Member

Ah I see, well yeah than this seems reasonable. PRs welcome! :)

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

2 participants