가상 메모리 개념
낮은 수준의 관점에서 가상 메모리, 메모리 분할, 페이징의 원리를 이해합니다.
가상 메모리 개념은(는) CoddyKit의 무료 Assembly Language & x86 Low-Level Systems Programming 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Assembly Language & x86 Low-Level Systems Programming 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Virtual Memory's Role
Welcome to the world of Virtual Memory! This concept is fundamental to how modern operating systems manage memory, enabling powerful features like multitasking and memory protection.
It allows programs to use a continuous, private memory space, even if the physical RAM is fragmented or smaller than the program's needs.
Limits of Physical Memory
In early computing, programs directly accessed physical RAM. This led to several challenges:
- Limited RAM: Programs had to fit entirely into physical memory.
- No Isolation: One program could overwrite another's memory, causing crashes.
- Relocation Issues: Programs needed to be loaded at specific physical addresses, complicating multitasking.
Virtual Memory was designed to solve these problems by introducing an abstraction layer.
Addresses: Virtual & Physical
The core idea is a distinction between two types of addresses:
- Virtual Address: The address seen and used by the CPU and your program. Each program gets its own unique, isolated virtual address space.
- Physical Address: The actual address in the computer's RAM chips. This is what the hardware truly understands and where data is physically stored.
Think of it like a house number (virtual) versus its GPS coordinates (physical).
MMU: The Address Translator
The magic behind this translation is performed by a dedicated hardware component inside the CPU called the Memory Management Unit (MMU).
When the CPU requests data from a virtual address, the MMU intercepts this request and instantly translates it into the corresponding physical address before accessing the RAM. This process is transparent to the running program.
Paging for Flexibility
One of the most common ways the MMU handles translation is through paging. In paging, both virtual and physical memory are divided into fixed-size blocks:
- Pages: Blocks of virtual memory.
- Frames (or Page Frames): Blocks of physical memory.
These blocks are typically 4KB (4096 bytes) in size, though larger sizes exist. Paging allows non-contiguous physical memory to appear contiguous to a program.
Page Tables: The Lookup
How does the MMU know which physical frame corresponds to which virtual page? It uses Page Tables.
Page tables are special data structures stored in physical RAM. They contain entries that map virtual page numbers to their corresponding physical frame numbers. The operating system creates and manages these tables for each running process.
Multi-Level Paging Simplified
For modern 64-bit systems with huge virtual address spaces, a single, flat page table would consume an impractical amount of memory. To save space, x86-64 uses multi-level paging.
This means there's a hierarchy of page tables. A top-level table (like PML4) points to lower-level tables, and so on, until the final page table points to a physical frame. This structure ensures that only necessary parts of the address space have page tables allocated.
CR3: The Root Pointer
The CPU needs to know where the top-level page table (the PML4 in 64-bit mode) is located in physical memory. This critical physical base address is stored in the CR3 register (Control Register 3).
Each process typically has its own set of page tables. When the operating system switches between processes, it updates the value of CR3 to point to the new process's page tables, effectively switching virtual address spaces.
An Assembly Memory Access
When your assembly program accesses a memory location, it's always using a virtual address. The MMU handles the translation transparently, so your code doesn't need to know the physical address.
Try running this simple assembly program. The my_var label refers to a virtual address, which the MMU translates to a physical address before the data is fetched.
section .data
my_var db 42 ; A byte variable at a virtual address
section .text
global _start
_start:
; Load the value from my_var into AL register
mov al, byte [my_var]
; At this point, AL contains the value 42.
; The address of 'my_var' was a virtual one,
; translated by the MMU to a physical address.
; Exit syscall (Linux specific)
mov eax, 60
xor edi, edi
syscallQuick Check: Memory Concepts
Which of the following components is primarily responsible for translating virtual addresses to physical addresses in an x86 system?
Recap: Virtual Memory Essentials
In this lesson, we explored the crucial concept of Virtual Memory in x86 systems. We learned:
- Virtual memory provides programs with a private, large address space, abstracting physical RAM.
- The MMU is the hardware unit that translates virtual addresses to physical addresses.
- Paging divides memory into fixed-size blocks (pages/frames) and uses page tables for mapping.
- Multi-level paging efficiently manages large address spaces in modern systems.
- The CR3 register points to the base of the top-level page table, changing with process context.
Understanding virtual memory is key to grasping how operating systems manage processes and memory protection at a low level.
자주 묻는 질문
“가상 메모리 개념” 강의는 무료인가요?
네 — “가상 메모리 개념” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Assembly Language & x86 Low-Level Systems Programming 강의 전체를 잠금 해제할 수 있습니다. Assembly Language & x86 Low-Level Systems Programming 강의에는 총 4개의 강의가 포함되어 있습니다.
“가상 메모리 개념”에서 뭘 배우나요?
낮은 수준의 관점에서 가상 메모리, 메모리 분할, 페이징의 원리를 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Assembly Language & x86 Low-Level Systems Programming을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Assembly Language & x86 Low-Level Systems Programming을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Assembly Language & x86 Low-Level Systems Programming은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“가상 메모리 개념” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Assembly Language & x86 Low-Level Systems Programming 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Assembly Language & x86 Low-Level Systems Programming 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.