Information Security Design System 14th Week study Summary

Source: Internet
Author: User

Information Security System Design Foundation 14th Week study Summary

"Learning Time: 5 hours"

"Learning content: The Nineth chapter--Virtual Memory"

I. Textbook content carding 1. Virtual memory
  • Role:

    1. The main memory is considered as a cache of the address space stored on disk, only the active area is protected in main memory, and the data is transmitted back and forth between the disk and main memory as needed;
    2. simplifies memory management by providing a consistent address space for each process;
    3. Protects the address space of each process from being destroyed by other processes
  • Status:

    1. Virtual memory is central: it is hardware exception, hardware address translation, main memory, disk file and kernel software interaction Center;
    2. Virtual memory is powerful: it can create and destroy memory slices, can map memory slices to a portion of a disk, and so on;
    3. Virtual memory is dangerous if it is not properly operated
2. Basic idea of virtual memory

Each data object is allowed to have multiple independent addresses, each of which is selected from a different address space (for example, virtual address space or physical address space).

3. How does virtual storage work as a caching tool?
  • concept:

    • second, the VM system splits the virtual memory into a fixed-size virtual page with a size of p=2^p bytes per virtual page; Similarly, The physical memory is split into a physical page (also called a page frame), and the size is P-byte
  • Virtual Memory Page Collection

    • Unassigned: The VM system does not associate them with any data and takes up no disk space;
    • Cached: The allocated pages in the physical memory are currently being slowed;
    • Not cached: No more allocated pages exist in physical memory
4. Page Table
    • Effect: Maps a virtual page to a physical page. Each time the address translation hardware translates a virtual address into a physical address, the page table is read. The operating system is responsible for maintaining the contents of the page table.
    • Structure: A page table is an array of page table entries (PTEs); Each page in the virtual address space has a PTE at a fixed offset in the page table. For our purposes, we assume that each PTE consists of a valid bit and an n-bit address field. A valid bit indicates the starting position of the physical page in which the virtual page is cached.
5. Missing pages
  • DRAM cache misses are called missing pages.
  • Concept:
    • In the customary parlance of memory, blocks are called pages;
    • The activity of transferring pages between disk and storage is called switching or paging;
    • The page is swapped into DRAM and swapped out of the disk from the DRAM, and has been waiting until a hit occurs before swapping in the page; This strategy is called on-demand page scheduling
  • Processing process:
    • The page fault is called by the kernel to call the fault handler, the program will select a sacrifice, and swap it out of memory;
    • The kernel copies the required entries from the disk to the location before the page is sacrificed, and then returns;
    • When the exception handler returns, it restarts the instruction that caused the missing pages, which re-sends the virtual address that caused the missing pages to the address translation hardware;
    • At this point, the page hits
6. Address Translation
    • Formally speaking, address translation is a mapping between an element in the virtual address space (VAS) of an n element and the Physical address space (PAS) of an M element.
    • Process:
      • A control register in the CPU, and the page table base register points to the current page table;
      • The virtual address of N-bit consists of the following two parts: a virtual page offset of P-bit and a virtual page number of (n-p) bit;
      • The MMU chooses the appropriate PTE with the latter, and then concatenates the physical page number and the VPO in the virtual address to get the physical address;
      • Because both physical and virtual pages are P-bytes, the physical page offsets and VPO are the same
7.linux Virtual Memory System
  • Linux maintains a separate virtual address space for each process, where the kernel virtual memory resides on the user stack;
  • Linux organizes virtual storage into a collection of areas (also called segments). An area is a continuous slice of the already existing (allocated) virtual memory;
    • Meaning: Allow the virtual address space to have gaps, the kernel does not have to record those pages that do not exist, such pages do not occupy memory;
    • Regional structure
      • Vm_start: Point at the beginning of the area;
      • Vm_end: Point at the end of the area;
      • Vm_prot: Describes the read and Write permission permissions for all pages contained within this area;
      • Vm_fags: Describes whether the pages in this area are shared with other processes, whether the process is private, and so on;
      • Vm_next: The next structure that points to the list
8. Comparison of shared objects & private objects
  • Introduction: An object can be mapped to an area of the virtual storage, either as a shared object or as a private object.

    • If a process maps a shared object to a region of its virtual address space, then any write to this zone by the process is also visible to other processes that also map the shared object to its own virtual address space "regardless of how many shared areas the object is mapped to, Only one copy of the object is needed in physical memory ";
    • a change to a zone that is mapped to a private object, is not visible to other processes, and any writes that the process makes to this zone are not reflected in objects on disk
  • Depth:

    • Private objects are mapped to virtual memory through clever techniques of copy-on-write, and for each process that maps private objects, page table entries for the corresponding private areas are marked as read-only, and the zone structure is marked as a write-time copy of the private object;
    • As long as no process attempts to write its own private area, they can continue to share;
    • Whenever a process tries to write a page in a private area, the write action triggers a protection failure, and when the fault handler notices that the protection exception is caused by the process trying to write a page in the private copy area of the write, it creates a new copy of the page in the physical storage area, The Update page table entry points to this new copy and then restores its writable permissions
9. Garbage collection
    • Concept: The garbage collector is a dynamic storage allocator that automatically frees allocated blocks that are no longer needed by the program. These blocks are called garbage. The process of automatic recycling is called garbage collection. The garbage collector periodically identifies the garbage blocks and calls free accordingly, putting the blocks back into the idle list
    • Process:
      • The garbage collector treats the entire memory as an accessible graph, and the node of the graph is divided into a set of root nodes and a set of heap nodes, each of which corresponds to an allocated block in the heap.
      • When there is any one from the root node division and reached the direction of the P path, we say that P is reachable, at any time, the non-reachable node corresponding to the garbage, is no longer recyclable.
      • The role of the garbage collector is to maintain some representation of the graph, and to recycle them periodically by releasing the unreachable nodes and returning them to the free list.
      • Whenever a heap space is required, the application invokes the malloc function in the usual way, and if malloc cannot find a suitable free block, it calls the garbage collector, hoping to reclaim some garbage to the idle list
Second, after-school exercises 1. Exercises 9.3

Given a 32-bit virtual address space and a 24-bit physical address, for the following page size p, determine the number of bits of Vpn,vpo,ppn,ppo

"Supplement: vpn--virtual page number; vpo--virtual page offset; ppn--physical page number; ppo--physical page offset"

"Understanding: We have 32 virtual address bits and 24 physical address bits, and the page size is 1KB, which means that for VPO and PPO, 10 bits are required (to differentiate the 2^10 specific units within each page); then the rest is Vpn,ppn"

P = 1kb-->vpn = 22,vpo = 10,ppn = 14,ppo = 10

P = 4kb-->vpn = 20,vpo = 12,ppn = 12,ppo = 12

2. Exercises 9.5

Write a C language program MMAPCOPY.C, use mmap to copy any size of the disk file to stdout, the input file name must be passed as a command line parameter

"The Answer:"

#include "csapp.h"void mmapcopy(int fd,int size){    char *bufp;    bufp = Mmap(NULL,size,PROT_READ,MAP_PRIVATE,fd,0);    Write(1,bufp,size);    return;}int main(int argc,char **argv){    struct stat stat;    int fd;    if(argc !=2)//因为传进来的参数应该有两个,一个是文件名(题目要求用命令行传递);第二个是    {        printf("usage:%s ,<filename>\n",argv[0]);        exit(0);    }    fd = Open(argv[0],O_RDONLY,0);    fstat(fd,&stat);    mmapcopy(fd,stat.st_size);    exit(0);}
Iii. Summary

This chapter reveals many of the "secrets" of previous learning, so it is often read to compare the contents of the previous content.

Information Security Design System 14th Week study Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.