본문 바로가기
조회 수 39250 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
?

단축키

Prev이전 문서

Next다음 문서

+ - Up Down Comment Print
false false false EN-US KO X-NONE MicrosoftInternetExplorer4

인터넷에 있는 정보를 모아 따로 정리한 내용이다.

주요출처

http://cafe.naver.com/vinnylover.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=180

 

먼저 free 명령어에 의한 출력결과로 메모리 사용량을 분석하면 아래와 같다.

 

[root@hojung931:Active] config # free

             total       used       free     shared    buffers     cached

Mem:        380696     325192      55504          0       5588     161080

-/+ buffers/cache:     158524     222172

Swap:      2314956          0    2314956

 

전체 메모리는 total 380696 이며, 사용된 메모리는325192이나 사용자 입장에서 사용 가능한 메모리(free)55504 아닌 free+buffers+cached (55504 + 5588 + 161080 =) 222172이다. Mem: 행에서 used 수치는 리눅스 운영체제 입장에서 바라본 사용 메모리 수치이다. Beffers cached 수치는 리눅스의 효율적인사용을 위하여 전체 메모리에서 미리 buffers+caches 값을 자동으로 할당한 app 에서 메모리가 필요할 경우 cached 할당한 메모리를 자동으로 반환한다.

 

다시말해 캐시는 사용한 데이터를 완전히 지우지 않고 프로세스가 다시 사용할 경우 곧바로 돌려주기 위해 쓰는 메모리이다.  Mem: 행에서 cached 값이 사용한 걸로 표시되어 used 포함되지만 실제로는 사용하는 메모리가 아니다. free 메모리가 부족하면 캐시된 메모리를 쓰게된다.

 

따라서 실제 메모리의 사용량과 사용 가능한 메모리는 -/+ buffers/cache 행의 값을 체크하면 된다.

 

다음은 Swap메모리의 현황에 대한 설명

 

Swap메모리의 결정은 서버설치시에 설치하는 사람이 결정한 스왑메모리의 용량이다. 또한 스왑메모리는 윈도우시스템에서는 가상메모리(Virtual Memory)라는 개념으로 사용되고 있는 것이며 시스템운용중에 실제메모리가 부족할 경우에 스왑메모리를 사용하게 된다. 스왑메모리는 디스크의 일부분을 메모리로 잡아서 설정되기 때문에 스왑메모리가 많이 사용되고 있다는 것은 시스템의 전체적인 속도가 떨어진다는 것을 의미하며 지속적으로 스왑메모리가 많이 사용될 경우에는 실제메모리(RAM) 증설해야한다는 의미가 된다.

 

Swap행의 total 시스템의 전체 Swap메모리의 량을 표시한다.

Swap행의 used 전체 스왑메모리에서 현재 사용중인 스왑메모리의 량이다.

Swap행의 free 전체 스왑메모리중에서 사용되지 않고 남아 있는 메모리의 량이다.

 

top 명령의 결과는 free 동일하다. 아래의 결과는 시간차를 두고 실행된 것이므로 약간의 차이가 있을 있다.

 

[root@hojung931:Active] config # top

 11:41:02  up  2:36,  4 users,  load average: 1.00, 1.00, 0.96

96 processes: 95 sleeping, 1 running, 0 zombie, 0 stopped

CPU states:  cpu    user    nice  system    irq  softirq  iowait    idle

           total   70.6%    0.0%   29.3%   0.0%     0.0%    0.0%    0.0%

Mem:   380696k av,  325184k used,   55512k free,       0k shrd,    5588k buff

       239104k active,              48916k inactive

Swap: 2314956k av,       0k used, 2314956k free                  161080k cached


----------------------------------------------------------------------------------------------------------------------------

이하 출처 : http://gentoo-wiki.com/FAQ_Linux_Memory_Management

Overview of memory management

Traditional Unix tools like 'top' often report a surprisingly small amount of free memory after a system has been running for a while. For instance, after about 3 hours of uptime, the machine I'm writing this on reports under 60 MB of free memory, even though I have 512 MB of RAM on the system. Where does it all go?

The biggest place it's being used is in the disk cache, which is currently over 290 MB. This is reported by top as "cached". Cached memory is essentially free, in that it can be replaced quickly if a running (or newly starting) program needs the memory.

The reason Linux uses so much memory for disk cache is because the RAM is wasted if it isn't used. Keeping the cache means that if something needs the same data again, there's a good chance it will still be in the cache in memory. Fetching the information from there is around 1,000 times quicker than getting it from the hard disk. If it's not found in the cache, the hard disk needs to be read anyway, but in that case nothing has been lost in time.

To see a better estimation of how much memory is really free for applications to use, run the command free -m:

Code: free -m
             total       used       free     shared    buffers     cached 
Mem: 503 451 52 0 14 293
-/+ buffers/cache: 143 360
Swap: 1027 0 1027

The -/+ buffers/cache line shows how much memory is used and free from the perspective of the applications. Generally speaking, if little swap is being used, memory usage isn't impacting performance at all.

Notice that I have 512 MB of memory in my machine, but only 52 is listed as available by free. This is mainly because the kernel can't be swapped out, so the memory it occupies could never be freed. There may also be regions of memory reserved for/by the hardware for other purposes as well, depending on the system architecture. However, 360M are free for application consumption.

Virtual Memory Area

Virtual memory allows non-contiguous memory to be addressed as if it is contiguous. Each process has a memory map made up of (at least):

  • Program's executable code (called text)
  • Areas for data, that could be initialized (assigned value at the beginning of execution), uninitialized data (BSS), and the program stack.
  • One area for each active memory mapping

Let's see how we can see the memory area of a process. We first have to identify the process we want to look at. We can use ps -A for that:

# ps -A
PID TTY TIME CMD
1 ? 00:00:00 init
2 ? 00:00:00 ksoftirqd/0

We are going to look at init that has the pid 1. Looking at at /proc/<process pid>/maps we can see the memory area of a process. In this case:

# cat /proc/1/maps
08048000-08050000 r-xp 00000000 16:46 493923 /sbin/init (executable code)
08050000-08051000 rw-p 00007000 16:46 493923 /sbin/init (data)
08051000-08072000 rw-p 08051000 00:00 0 [heap]
b7e2b000-b7e2c000 rw-p b7e2b000 00:00 0
b7e2c000-b7f4c000 r-xp 00000000 16:46 3770390 /lib/libc-2.5.so
b7f4c000-b7f4d000 r--p 00120000 16:46 3770390 /lib/libc-2.5.so
b7f4d000-b7f4f000 rw-p 00121000 16:46 3770390 /lib/libc-2.5.so
b7f4f000-b7f53000 rw-p b7f4f000 00:00 0
b7f6f000-b7f70000 r-xp b7f6f000 00:00 0 [vdso]
b7f70000-b7f8a000 r-xp 00000000 16:46 3770498 /lib/ld-2.5.so
b7f8a000-b7f8b000 r--p 00019000 16:46 3770498 /lib/ld-2.5.so
b7f8b000-b7f8c000 rw-p 0001a000 16:46 3770498 /lib/ld-2.5.so
bf8fc000-bf911000 rw-p bf8fc000 00:00 0 [stack]

The columns correspond to:

start-end perm offset major:minor inode image

Meaning:

  • Start and end of virtual address.
  • Permissions (read, write, execute, private/shared).
  • Offset
  • Major and minor numbers holding the mapped file.
  • Inode number
  • Name of the mapped file.

We can look at the different memory regions by looking at /proc/iomem. In my AMD XP:

File: # cat /proc/iomem
00000000-0009fbff : System RAM
0009fc00-0009ffff : reserved
000a0000-000bffff : Video RAM area
000c0000-000ccfff : Video ROM
000f0000-000fffff : System ROM
00100000-5ffeffff : System RAM
00100000-00405770 : Kernel code
00405771-0054148b : Kernel data
5fff0000-5fff7fff : ACPI Tables
5fff8000-5fffffff : ACPI Non-volatile Storage
70000000-7001ffff : 0000:00:04.0
afa00000-cfbfffff : PCI Bus #01
b8000000-bfffffff : 0000:01:00.1
c0000000-c7ffffff : 0000:01:00.0
cfd00000-cfefffff : PCI Bus #01
cfec0000-cfedffff : 0000:01:00.0
cfee0000-cfeeffff : 0000:01:00.1
cfef0000-cfefffff : 0000:01:00.0
cfffb800-cfffbfff : 0000:00:0c.0
cfffb800-cfffbfff : ohci1394
cfffc000-cfffcfff : 0000:00:04.0
cfffc000-cfffcfff : sis900
cfffd000-cfffdfff : 0000:00:03.0
cfffd000-cfffdfff : ohci_hcd
cfffe000-cfffefff : 0000:00:03.1
cfffe000-cfffefff : ohci_hcd
cffff000-cfffffff : 0000:00:03.2
cffff000-cfffffff : ehci_hcd
d0000000-d3ffffff : 0000:00:00.0
fec00000-fec00fff : reserved
fee00000-fee00fff : reserved
ffee0000-ffefffff : reserved
fffc0000-ffffffff : reserved

We can look at how different devices are mapped into the memory. If we have a look at my video card:

# lspci -vvv
01:00.0 VGA compatible controller: ATI Technologies Inc RV280 [Radeon 9200] (rev 01) (prog-if 00 [VGA])
Region 0: Memory at c0000000 (32-bit, prefetchable) [size=128M]
Region 1: I/O ports at a800 [size=256]
Region 2: Memory at cfef0000 (32-bit, non-prefetchable) [size=64K]

We can see that /proc/iomem shows the card memory allocation.

The mysterious 880 MB limit on x86

By default, the Linux kernel runs in and manages only low memory. This makes managing the page tables slightly easier, which in turn makes memory accesses slightly faster. The downside is that it can't use all of the memory once the amount of total RAM reaches the neighborhood of 880 MB. This has historically not been a problem, especially for desktop machines.

To be able to use all the RAM on a 1GB machine or better, the kernel needs to be recompiled. Go into 'make menuconfig' (or whichever config is preferred) and set the following option:

Linux Kernel Configuration: Large amounts of memory
Processor Type and Features ---->
High Memory Support ---->
(*) 4GB

This applies both to 2.4 and 2.6 kernels. Turning on high memory support theoretically slows down accesses slightly, but according to Joseph_sys and log, there is no practical difference.

Also, the ck-sources kernel has a patch for 1gb high memory support.

The difference among VIRT, RES, and SHR in top output

VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card's RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.

RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library.

SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.

The difference between buffers and cache

Buffers are allocated by various processes to use as input queues, etc. Most of the time, buffers are some processes' output, and they are file buffers. A simplistic explanation of buffers is that they allow processes to temporarily store input in memory until the process can deal with it.

Cache is typically frequently requested disk I/O. If multiple processes are accessing the same files, much of those files will be cached to improve performance (RAM being so much faster than hard drives), it's disk cache.

Swappiness (2.6 kernels)

Since 2.6, there has been a way to tune how much Linux favors swapping out to disk compared to shrinking the caches when memory gets full.

When an application needs memory and all the RAM is fully occupied, the kernel has two ways to free some memory at its disposal: it can either reduce the disk cache in the RAM by eliminating the oldest data or it may swap some less used memory (anonymous pages) of processess out to the swap partition on disk. It is not easy to predict which method would be more efficient. The kernel makes a choice by roughly guessing the effectiveness of the two methods at a given instant, based on the recent history of activity.

Before the 2.6 kernels, the user had no possible means to influence the calculations and there could happen situations where the kernel often made the wrong choice, leading to thrashing and slow performance. The addition of swappiness in 2.6 changes this. Thanks, ghoti!

Swappiness takes a value between 0 and 100 to change the balance between swapping processess anonymous pages and freeing cache. At 100, the kernel will always prefer to find inactive pages and swap them out; in other cases, whether a swapout occurs depends on how much application memory is in use and how poorly the cache is doing at finding and releasing inactive items.

The default swappiness is 60. A value of 0 gives something close to the old behavior where applications that wanted memory could shrink the cache to a tiny fraction of RAM. For laptops which would prefer to let their disk spin down, a value of 20 or less is recommended.

As a sysctl, the swappiness can be set at runtime with either of the following commands:

sysctl -w vm.swappiness=30 
echo 30 >/proc/sys/vm/swappiness

The default when Gentoo boots can also be set in /etc/sysctl.conf:

File: /etc/sysctl.conf
# Control how much the kernel should favor swapping out applications (0-100)
vm.swappiness = 30

Some patchsets (e.g. Con Kolivas' ck-sources patchset) allow the kernel to auto-tune the swappiness level as it sees fit; they may not keep a user-set value.

Autoregulation

gentoo-sources (and probably other gentoo 2.6 kernels) prior to 2.6.7-gentoo contains the Con Kolivas autoregulated swappiness patch. This means that the kernel automatically adjusts the /proc/sys/vm/swappiness value as needed during runtime, so any changes you make will be clobbered next time it updates. A good explanation of this patch and how it works is on KernelTrap.

I repeat: With gentoo-sources (prior to 2.6.7-gentoo) it is neither necessary nor possible to permanently adjust the swappiness value. It's taken care of automatically, no need to worry.

gentoo-sources no longer contains this patch as of 2.6.7-gentoo. The maintainer of gentoo-sources, Greg, pulled the autoregulation patch from the ebuild. http://bugs.gentoo.org/show_bug.cgi?id=54560



Title
List of Articles
번호 제목 글쓴이 날짜 조회 수
448 nslookup and DNS Zone Transfers Hojung 2011.01.05 80510
447 리눅스 터미널에서 한글깨짐 해결 (terminal,euc-kr,putty,i18n) Hojung 2011.01.28 59603
446 코어덤프 분석가이드 (coredump) Hojung 2012.02.17 51853
445 Apaceh2 + SSL on Fedora Core Hojung 2007.12.14 46666
444 SNMP Manager Cacti 설치하기 Hojung 2008.03.24 46421
443 Using TCP keepalive under Linux (tcp_keepalive_time) Hojung 2011.05.13 43919
442 cURL 사용법 Hojung 2009.04.28 41967
» 메모리 사용에 대한 체크 포인트 (top, free) Hojung 2008.09.12 39250
440 zip/unzip 사용 예 Hojung 2010.12.30 38412
439 Linux Security Checklist Hojung 2009.04.15 37447
438 디바이스가 busy일 경우 강제 umount Hojung 2010.03.29 36605
437 시리얼 통신 프로그램 (minicom) file Hojung 2011.02.05 34982
436 여러개의 NIC으로 teaming/bonding 설정하기 (LACP) Hojung 2011.01.28 34108
435 MIB에서 OID 확인 및 해당 OID 로 SNMP Polling 하기 Hojung 2010.11.04 34074
434 cacti 설치 및 그래프 추가하기 Hojung 2010.11.25 33812
433 PPTP VPN 클라이언트 설정하기 Hojung 2009.12.15 33603
432 CIFS 마운트하기 (기본 및 부팅시 자동으로 마운트) Hojung 2010.02.05 32770
431 싱글모드 또는 rescue 모드에서 fsck Hojung 2011.01.14 31862
430 인터페이스 duplex 및 speed 확인 및 설정 변경 Hojung 2010.04.26 31726
429 Switching your Linux systems to the new DST Hojung 2008.04.04 31324
Board Pagination ‹ Prev 1 2 3 4 5 6 7 8 9 10 ... 23 Next ›
/ 23

Designed by sketchbooks.co.kr / sketchbook5 board skin

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5

Sketchbook5, 스케치북5