NOWS/ULK

ulk-ch1. introduction

emzei 2014. 1. 13. 23:01

Understanding the Linux kernel (ed3) 
- 중요 부분 노트


▷  Linux vs. Other unix-like kernels

- monolithic kernel (cf. microkernel ... carnegie-mellon's Mach ... OS X, GNU Hurd)
- complied and statically linked traditional unix kernels : modules
- kernel threading : context switches between kernel threads are less expensive (linux uses kernel threads in a limited way)
- multithreaded application support : multithreaded application could be composed of light-weighted processes (LWP).
                                                  ( Linux's LWP is different from other systems' such as SVR4 and Solaris. )
                                                  ( LWP is basic execution context in Linux and that can be handled by (nonstandard) clone(). )
 - preemptive kernel 
 - multiprocessor support : symmetric multiprocessing (SMP)
 - filesystem :  Ext2, Ext3, ReiserFS(JFS+XFS)
 - STREAM : Linux has no analog to the STREAM I/O




▷ Hardware dependancy

 - arch, include




▷ Basic Operating System Concepts

 - multiuser systems : able to concurrently and independently execute several applications belonging to 2 or more users.
                                ( authentication / protection / accounting mechanism ) 

 - users and groups : User-id , Group-id, Root..

 - processes : an instance of a program in execution / execution context
    * address space
    * multi-user system must be preemptable

 - kernel architecture : 대부분의 unix 계열 커널은 monolithic.
                                반면, micro kernel은 적은 함수집합, 적은 동기화 함수, 단순 스케줄러, 그리고 IPC 매커니즘을 갖는다. 
                                리눅스에서는 microkernel의 이론적인 장점을 패널티 없이 도입하기 위해, module을 제공한다.
                                * module ... 일종의 객체 파일로, 코드가 런타임 중 커널에 link/unlink가 가능
                                ( modularized approach / platform independence / frugal main memory usage / no performance penalty )

 



▷ Overview of the Unix Filesystem

 - files : structured as a sequence of bytes. ( pathname... O : absolute, X : relative )

 - hard and soft links 
   * hard link's limitation (1) not possible to create links for directory. (2) can be created only among files included in the same FS)
   * soft(symbolic) link : short files. path name may refer to any file or directory located in any file system.
                                  even refer to nonexistent file.

 - file types : regular file / directory / symbolic link / block-oriented file / character-oriented file / pipe and FIFO / socket

 - file descriptor and i-node : i-node is a data structure and it has all information needed by the file system to handle a file

 - access rights and file mode : owner / same group / others
                                             * 3 types of access rights : read / write / execute
                                             * additional flags 
                                                - suid(set user id) : process gets the UID of the file owner
                                                - sgid(set group id) : process gets the user group ID of the file
                                                - sticky : an execution file with the sticky flag set corresponds to a request
                                                              to the kernel to keep the program in memory after its execution terminates
                                          

 - file-handling system calls
    * open(), read(), write(), lseek(), close(), rename(), unlink()...

 



▷ An Overview of Unix kernel

 - Process/Kernel Model
     * User Mode : 커널 데이터에 직접 접근 불가
     * Kernel Mode : 접근에 제한 없음
     커널에 의한 요청이 있을 때 User Mode에서 Kernel Mode로의 전환이 가능하고, 요청이 완료되면 User Mode로 복귀
       ---> system calls / timer interrupt / device interrupt
     * kernel threads 
        - kernel mode, kernel address space 내에서 실행
        - user와 상호작용하지 않으므로, 단말기를 필요로 하지 않음
        - system startup 때 생성되어 system 종료까지 살아있음.

 - Process Implementation
    커널이 프로세스들을 관리하기 위해, 각 프로세스들은 process descriptor로 표현됨. 
     (* process descriptor : 현재 상태의 프로세스에 관한 정보를 갖고 있음 . ex) program counter, stack pointer register ... )

 - Reentrant Kernels ( 나중에 다시 조사해봐야지... 너무  새로워서 자꾸 이거만 파고있음 )
    모든 유닉스 커널은 reentrant : 여러 프로세스들이 동시에 Kernel Mode에서 실행 가능
    reentrancy 보장하는 방법 (in 책) : 전역 데이터는 변경하지않고,, 지역 변수만 수정할 수 있도록 함수 작성.
    * kernel control path : kernel이 system call, exception, interrupt 등을 처리할 때의 명령 순서

 - Process Address Space
    모든 프로세스는 개별적인 주소 공간을 갖는다. 
    User Mode에서 실행되는 프로세스는  해당 프로세스의 stack, data, code 영역을 가리킴.
    Kernel Mode에서 실행되는 프로세스는 kernel 데이터와 코드 영역을 다루며, 별도의 개별 스택을 가리킴.
    Kernel은 Reentrant이기 때문에 여러 프로세스와 연관된 kernel control paths는 순차적으로 실행된다.
    * shared memory
    * mmap() : 파일의 일부분이나 블록 장치에 저장된 정보를 process address space의 일부에 매핑할 수 있도록 해줌.

 - Synchronization and Critical Regions
    reentrant kernel을 위해서는 반드시 동기화가 필요함.
    critical regions (임계영역)
    * kernel preemption disabling 
    * interrupt disabling
    * semaphores
    * spin locks
    * avoiding deadlocks

 - Signals and Interprocess Communication 
    * signals
    (1) Asynchronous notifications
    (2) Synchronous notifications
    * IPC ... shmget(), semget(), msgget() ... shmget()-shmat()-shmdt()
    * Message ... msgsnd(), msgrcv()




▷ Process Management
    fork() and _exit() : create new process and terminate it  vs. exec() : load a new program
    * fork() : 부모의 데이터와 코드를 복사하여 child에게 제공하는 것은 상당한 시간 낭비. (naive approach)
                 Copy-on-write : 내용에 변경이 있기전까지는 복제하지 않고 가리키다가 변경이 있으면 그때 복사.
    - zombie process
        : 종료된 child process. 부모 프로세스가 거둬가기전까진 좀비...
    - process groups and login session
        * process groups ... PGID(process group ID)
        * login sessions




▷ Memory management
    - Virtual memory : logical layer between app memory requests and hardware MMU(memory management unit)
        * Virtual(logical) address space * how virtual addresses correspond to physical addresses!
    - RAM Usage
        * problem on virtual memory system --> memory fragmentation
    - Kernel Memory Allocator (KMA)
        resource map allocator, buddy system... etc.
    - Process virtual address space handling
        커널은 process virtual address space를 memory area descriptor 목록으로 저장함.
        요즘 memory allocation 정책은 demand paging 
            --> 프로그램 실행 시 물리 메모리에 아무것도 적재하지 않음.
                  존재하지 않는 페이지에 접근시 MMU는 예외를 생성하며 exception handler는 해당 메모리 영역을 찾아
                  빈 페이지를 할당하여 적절한 데이터와 함께 초기화.

    - Caching
         hard drive는 RAM과 비교했을 때 매우 느림. disks는 병목현상이 발생하기 쉽기때문에, UNIX 시스템에서는 디스크 쓰기를
        가능한한 늦게하도록 하는 정책을 사용. 
         sync() 시스템콜 ... 버퍼를 강제로 쓰게하여 disk 동기화.

   



▷ Device Drivers
    각 드라이버는 정해진 인터페이스에 따라 커널의 다른 부분(심지어 다른 드라이버)와 상호작용함






!! 서론 끝 !!



'NOWS > ULK' 카테고리의 다른 글

ulk-ch3. processes  (0) 2014.01.29
ulk-ch2. memory addressing  (0) 2014.01.17