리눅스의 메모리 사용량의 경우 항상 물리적인 메모리 대비 Cache 와 Buffer의 사용량에 대해서 논쟁이도고는 한다.
물론 운영중에 갑자기 물리적인 메모리의 사용량이 늘어서 SWAP을 사용하는 경우라면 달라지겠지만 실질적으로  어플리케이션이 동작하지 않는 가운데 메모리의 사용량이 터무니 없이 나타나는건 , Buffer나 Cache에 대한 용량적인 계산에 대해서 잘못 인식하고 있는 경우가 많기 때문이다..
아래는 /proc/meminfo에 대한 항목에 대한 내용인데.. 메모리 관련 부분에 있어서 설명할때 필요한 부분인듯 하다..
/proc/meminfo 내용

This is one of the more commonly used files in the /proc/ directory, as it reports a large amount of valuable information about the systems RAM usage.

The following sample /proc/meminfo virtual file is from a system with 256 MB of RAM and 512 MB of swap space:

         MemTotal: 255908 kB MemFree: 69936 kB Buffers: 15812 kB Cached: 115124 kB SwapCached: 0 kB Active: 92700 kB Inactive: 63792 kB HighTotal: 0 kB HighFree: 0 kB LowTotal: 255908 kB LowFree: 69936 kB SwapTotal: 524280 kB SwapFree: 524280 kB Dirty: 4 kB Writeback: 0 kB Mapped: 42236 kB Slab: 25912 kB Committed_AS: 118680 kB PageTables: 1236 kB VmallocTotal: 3874808 kB VmallocUsed: 1416 kB VmallocChunk: 3872908 kB HugePages_Total: 0 HugePages_Free: 0 Hugepagesize: 4096 kB       

Much of the information here is used by the free, top, and ps commands. In fact, the output of the free command is similar in appearance to the contents and structure of /proc/meminfo. But by looking directly at /proc/meminfo, more details are revealed:

  • MemTotal — Total amount of physical RAM, in kilobytes.

  • MemFree — The amount of physical RAM, in kilobytes, left unused by the system.

  • Buffers — The amount of physical RAM, in kilobytes, used for file buffers.

  • Cached — The amount of physical RAM, in kilobytes, used as cache memory.

  • SwapCached — The amount of swap, in kilobytes, used as cache memory.

  • Active
    — The total amount of buffer or page cache memory, in kilobytes, that
    is in active use. This is memory that has been recently used and is
    usually not reclaimed for other purposes.

  • Inactive
    — The total amount of buffer or page cache memory, in kilobytes, that
    are free and available. This is memory that has not been recently used
    and can be reclaimed for other purposes.

  • HighTotal and HighFree — The total and free amount of memory, in kilobytes, that is not directly mapped into kernel space. The HighTotal value can vary based on the type of kernel used.

  • LowTotal and LowFree — The total and free amount of memory, in kilobytes, that is directly mapped into kernel space. The LowTotal value can vary based on the type of kernel used.

  • SwapTotal — The total amount of swap available, in kilobytes.

  • SwapFree — The total amount of swap free, in kilobytes.

  • Dirty — The total amount of memory, in kilobytes, waiting to be written back to the disk.

  • Writeback — The total amount of memory, in kilobytes, actively being written back to the disk.

  • Mapped — The total amount of memory, in kilobytes, which have been used to map devices, files, or libraries using the mmap command.

  • Slab — The total amount of memory, in kilobytes, used by the kernel to cache data structures for its own use.

  • Committed_AS
    — The total amount of memory, in kilobytes, estimated to complete the
    workload. This value represents the worst case scenario value, and also
    includes swap memory.

  • PageTables — The total amount of memory, in kilobytes, dedicated to the lowest page table level.

  • VMallocTotal — The total amount of memory, in kilobytes, of total allocated virtual address space.

  • VMallocUsed — The total amount of memory, in kilobytes, of used virtual address space.

  • VMallocChunk — The largest contiguous block of memory, in kilobytes, of available virtual address space.

  • HugePages_Total — The total number of hugepages for the system. The number is derived by dividing Hugepagesize by the megabytes set aside for hugepages specified in /proc/sys/vm/hugetlb_pool. This statistic only appears on the x86, Itanium, and AMD64 architectures.

  • HugePages_Free — The total number of hugepages available for the system. This statistic only appears on the x86, Itanium, and AMD64 architectures.

  • Hugepagesize
    — The size for each hugepages unit in kilobytes. By default, the value
    is 4096 KB on uniprocessor kernels for 32 bit architectures. For SMP,
    hugemem kernels, and AMD64, the default is 2048 KB. For Itanium
    architectures, the default is 262144 KB. This statistic only appears on the x86, Itanium, and AMD64 architectures.


정보는 최고사용량과 최저사용량으로 표현되며, 먼저 최고사용량에 대해 살펴보면 다음과 같다.

- MemoryTotal :
사용 가능한 최대 메모리(RAM)량
( Physical RAM - a few reserved bits - kernel binary code )

- MemFree :
LowFree + HighFree

- MemShared :
호환성을 위한 값이며 항상 0임

- Buffers :
버퍼 캐시 메모리로 최근에는 거의 쓸모없는 값

- Cached :
pagecache(diskcache) - SwapCache

- SwapCache :
스와핑 아웃되었던 메모리로, 스와핑 인되었지만 여전히 스왑 파일에 존재하는
메모리(메모리가 다시 필요하다면 이미 스왑파일에 존재하므로 또 다시 스와핑
아웃될 필요가 없음. 이는 I/O를 절약할 수 있음)
가상 메모리 통계는 다음과 같다.
가상 메모리는 캐시 페이지를 active와 inactive 메모리로 나누고,
The idea is that if you need memory and some cache needs to be sacrificed for that, you take it from inactive since that's expected to be not used. The vm checks what is used on a regular basis and moves stuff around.
When you use memory, the CPU sets a bit in the pagetable and the VM checks that bit occasionally, and based on that, it can move pages back to active. And within active there's an order of "longest ago not used" (roughly, it's a little more complex in reality). The longest-ago used ones can get moved to inactive. Inactive is split into two in the above kernel (2.4.18-24.8.0). Some have it three.

- Active : 가장 최근에 사용되었던 메모리로 완전히 불필요하지 않은 경우를 제외하고서는
반환되지 않음

- Inact_dirty :
여기서 dirty의 의미는 "디스크나 스왑 공간으로 기록될 필요가 있음"을 의미하며,
빈 공간으로 반환되기 위해서는 몇가지 작업이 필요하다. 아직 기록되지 않은
파일이 예가 될 것이다. 너무 일찍 메모리에 기록하여 I/O의 성능을 떨어뜨릴
필요가 없기 때문이다. 예를 들어 log를 기록한다고 할 때 완벽한 로그가 구성될
때까지 디스크에 기록하지 않는 것이 성능에 도움이 된다.

- Inact_clean :
쉽게 빈 공간으로 반환될 수 있음을 의미한다. 커널은 항상 일정한 양의 빈 공간을
확보하고 있는데, 이는 움직일 수 있는 여유를 가지기 위함이다.

- Inact_target :
Just a goal metric the kernel uses for making sure there are enough inactive pages around. When exceeded, the kernel will not do work to move pages from active to inactive. A page can also get inactive in a few other ways, e.g. if you do a long sequential I/O, the kernel assumes you're not going to use that memory and makes it inactive preventively. So you can get more inactive pages than the target because the kernel marks some cache as "more likely to be never used" and lets it cheat in the "last used" order.
메모리 통계

- HighTotal :
상위 영역(high region)에 존재하는 메모리의 전체 양으로, Highmem은
physical RAM에서 대략 860MB 위의 메모리를 의미한다. 커널은 상위 영역의
메모리 메모리에 접근하기 위해 간접적인 트릭(indirect tricks)을 사용한다.
데이터 캐시가 이 메모리 영역에 포함될 수 있다.

- LowTotal :
비상위메모리(non-highmem) 영역에 대한 총량

- LowFree :
하위메모리 영역(low memory region)의 빈 공간. 커널이 직접적으로 접근할 수
있는 메모리 영역으로, 모든 커널 데이터구조(datastructures)가 이 메모리 영역에
저장된다.

- SwapTotal :
물리적인 스왑 메모리(physical swap memory)의 총량

- SwapFree :
스왑 공간의 빈 영역의 총량

- Committed_AS :
99.99%의 보장(이러한 부하에서는 OOM[Out of Memory]를 결코 발생시키지
않음)을 위해 필요로 하는 RAM의 추측값으로, 일반적인 상황에서는 커널이 메모리를
지나치게 낭비하는 경우이다. 즉, 1GB malloc를 사용한다고 할 때 실제적으로는
아무런 일도 발생하지 않는다. 단지 메모리를 실제로 사용하기 시작할 때 malloc에
의해 필요로 하는 메모리가 요구된다. 즉 저당을 잡히고 은행이 망하지 않기만을
바라는 상황이 된다. 또 다른 경우에는 mmap 파일을 이용해서 두 프로세스 간에
공유할 경우가 포함된다. Committed_AS는 최악의 상황에서 필요로 하는

RAM/swap의 추측값이다.

참고url
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-proc-meminfo.html
http://blog.daum.net/_blog/BlogTypeView.do?blogid=05S77&articleno=86&_bloghome_menu=recenttext#ajax_history_home


==================


'Linux 이야기. > LInux Article.' 카테고리의 다른 글

Linux Shared Memory에 대한 Handling  (0) 2012.05.25
Linux Memory 매니지먼트  (0) 2012.05.14
OpenStack RedHat Contribution  (0) 2012.04.19
RHEL6에서 Bonding 하기  (0) 2012.02.29
RHEL6 UDP Communicate 에러관련  (0) 2012.02.13

+ Recent posts