CS695 Topics in Virtualization and Cloud Computing Spring 2019 Lecture 6 23.1.2019 -------------------- 0. Exercise #2 due 30th January 2019 https://www.cse.iitb.ac.in/~puru/ https://www.cse.iitb.ac.in/~puru/courses/spring19/cs695/exercises/ex2.html references for this lecture: [lkd] ... Linux Kernel Development, Robert Lowe (book) [ulk] ... Understanding the Linux Kernel, Daniel P. Bovet and Marco Cesati (book) 1. Recap - techniques for CPU virtualization, 0. trap and emulate 1. scan and patch 2. para-virtualization 3. hardware-assisted CPU virtualziation 2. Linux digression (a) a basic unit for control and management of execution and resources is a process. - what is a process for an OS? - state (metadata): required to identify entities, to tag resoures, for controlling runtime execution - actions: process specific actions, actions for processes etc. scheduling, context switching, allocating memory, file operations, delivering signals etc. - all (process) state and actions managed by the OS as part of providing the process abstraction - OS representation (state) of a process exists in a task_struct structure struct task_struct pid, ppid, tgid status, priority mm_struct fs_struct signal_struct thread_info pointer to tasklist ... * Homework: look inside task_struct and mm_struct and understant important fields. - kernel threads (ps -ef) - special processes - have a task_struct and hence schedulable - mm_struct = NULL (no address space of its own) - do non-user intiated work for the kernel page cache flush to disk, CPU runqueue migration, interrupt processing, watchdog timers ... * Homework: How do kernel threads work with no address space? (mm_struct == NULL) - process creation fork->clone->do_fork->copy_process->dup_task_struct fork + exec ... create a process, replace process with new program copy-on-write memory optimization used by fork * What does the call 'current' do? What is its return value? How is it implemented? (b) memory mamanagement - protected mode of operation of the CPU (as opposed to real mode) enables support for virtual address space via paging (and MMU based hardware translation) - per process virtual address space - isolation, sharing, swapping, physical memory mutliplexing, memory protection, file mapping ... - terminology: mapped address, pte, pmd, pud, ... - Linux specifics: mm_struct in task_struct holds state/metadata of memory allocation and manangement of a process task mm_struct pgd_t pgd; // page directory pointer struct vm_area_struct* mmap; // list of VMAs - memory layout (example for 32-bit arch.) for each process, the following virtual address space ranges hold - 0x0000 0000 to 0xbfff ffff: user addresses (user space) - 0xc000 0000 to 0xffff ffff: kernel addresses (kernel space) - the kernel space mappings are same across all processes, hence all processes share/have the same kernel. - kernel space holds the kernel state and code for actions - all, kernel addressing is via the virtual address space - linux keywords: __pa, kmalloc, vmalloc, virt_to_page, pgd_offset, pte_present, page_address ... - paging and PTE flags - 32-bit virtual to physical address mapping v2p mapping and translation - PTE_FLAGs: LSB 12-bits of PTE - PAGE_PRESENT, PAGE_PROTNONE, PAGE_RW, PAGER_USER, PAGE_DIRTY, PAGE_ACCESSED ... - Note: On a virtual address issue, the MMU in hardware attempts a translation and access. Interventions are possible only on exceptions!