4

I'm trying to use Redis for production services and trying to avoiding swapping, which is bad for performance.

I had learn that swap is triggered by swap_tendency which is depending on

swap_tendency = mapped_ratio/2 + swappiness + distress

How can I get mapped_ratio/distress from /proc/meminfo for my monitor script?

Or anything parameter that can info me that system is going to swap pages?

Zhuo.M
  • 143

1 Answers1

3

mapped_ratio

mapped_ratio can be calculated like so:

mapped ratio = (nr mapped * 100) / total memory;

Source: https://www.cs.columbia.edu/~smb/classes/s06-4118/l19.pdf

nr_mapped

The value, nr_mapped can be read from /proc/vmstat:

$ grep nr_mapped /proc/vmstat
nr_mapped 47640

distress

According to this article, titled: Linux Memory - Implementation Notes

“This is a measurement of how much difficulty the VM is having reclaiming pages. Each time the VM tries to reclaim memory, it scans 1/nth of the inactive lists in each zone in an effort to reclaim pages. Each time a pass over the list is made, if the number of inactive clean + free pages in that zone is not over the low water mark, n is decreased by one. Distress is measured as 100 >> n” 5

In researching much of the docs make it sounds as though "distress" is a kernel counter but it is not. Rather it's a value that's used when each zone of memory is being scanned, that is progressively increased as page frames of memory are scanned by the kernel in an attempt to reclaim them. Discussion of this is beyond the scope of this Q&A but if you're curious the section of the book "Understanding the Linux Kernel", Chapter 17: Page Frame Reclaiming. The value of "distress" comes from the value "prev_priority" as the zones are scanned.

References

slm
  • 369,824
  • Thanks for the answer, I still have one more question about distress: It seems that distress is a counter in the kernel. How can I get distress? – Zhuo.M Jun 03 '14 at 07:16
  • @Zhuo.M - yes it read that way to me as well. I've been searching for it and have yet to find it exposed under /proc or /proc/sys which leads me to believe that it isn't exposed directly. Will take a cursory look at the source which might be more revealing. – slm Jun 03 '14 at 11:56
  • I had check the Linux 3.12 source code but I can't find anything about distress. Instead I found vmpressure, it appears that it will try to reclaim pages while alloc free pages. – Zhuo.M Jun 04 '14 at 09:52
  • @Zhuo.M - me neither. There is a VM pressure setting that you can get/set, I wonder if that's it? – slm Jun 04 '14 at 11:05
  • I got the answer from "Understanding the Linux Kernel", distress came from prev_priority – Zhuo.M Jun 09 '14 at 08:22
  • @Zhuo.M - I added a bit at the end describing your findings, thanks. – slm Jun 09 '14 at 11:55
  • Great! After this research, I found my question is about tuning the "Memory Management" in Linux. For Redis usage, simply put swappiness to 0 and monitor /proc/zoneinfo with "Pages free" and "Pages high" but I don't know how to re-organize my question with more preciser description. A little help, maybe? – Zhuo.M Jun 10 '14 at 02:23
  • @Zhuo.M - I would probably make that a separate Q and reference this one as a source to it. You can then self A it. – slm Jun 10 '14 at 05:05