Operating system memory management, virtual memory, python garbage collection

What is the paging mechanism?

Definition: logical addresses and physical addresses of the memory allocation management scheme isolated

  • Program logic address is divided into fixed-size pages (Page)
  • Physical address is divided into the same size frame (Frame)
  • Logical addresses and physical addresses corresponding to the page table by

 

Segmentation mechanism

Objective: logic to meet the needs of the segment of code (more specifically recommended to search for the next)

  • Data sharing, data protection, dynamic links.
  • Implement the mapping relationship between logical addresses and physical addresses by the segment table.
  • Each segment is contiguous internal memory allocation, and between paragraphs are discrete distribution.

 

The difference between paging and segmentation

  • Page is a discrete distribution mechanism for memory utilization point of view put forward (for a more efficient use of memory, reducing memory fragmentation).
  • Section is for the user perspective, the management mechanism for data protection, isolation purposes.
  • The page size is fixed, determined by the operating system; segment size is not fixed, is determined by the user program.

What is virtual memory.

Definition: The part of temporarily unused memory information is stored on the hard disk.

  • The principle of locality, while the program is running only part of the necessary information into memory.
  • Memory temporary unwanted content on the hard disk.
  • The system seems to offer larger than the actual memory capacity and more memory, called virtual memory.

 

What is the memory jitter (bumps)

 

Definition: The nature of scheduling behavior is frequent page

  • Frequent scheduling page, the process continues to generate page fault.
  • After replacement (into virtual memory) a page, and continue to need this page.
  • Too many operational procedures; page replacement policy is not good. Terminate the process or increase physical memory.

 

Principle of python garbage collection. 

  • Just use reference counting (Cons: not a circular reference
    • Reference count: python when referencing the C language, and each object has several fields, one of which is representative of the ref field is the number of objects
    • a = [1] # At this time the object list [1] is the value of the ref 1
      b = a # [1] becomes the value of the ref 2
      a = [1,2,3] # this time [1] becomes 1 ref

      print (b) # Results: [1]

      At this time, only # [1] be a reference b
      del (b) # the object is not to eliminate, but to reduce the object's reference count.
      # Print (b) error, b is undefined
      # [1] becomes 0 ref, recovered,

      The following shows what with ipython

    • . 1 the In [. 1]: Import SYS                                                                               
       2  
      . 3 the In [2]: = A [1,2 ]                                                                                
       . 4  
      . 5 the In [. 3 ]: sys.getrefcount (A) # This is a function call reference.                                                         
      . 6 Out [. 3]: 2
       . 7  
      . 8 the In [. 4]: B = 1                                                                                    
       . 9  
      10 the In [. 5]: sys.getrefcount (1 ) there is a small integer # Python object pool, a lot of the internal implementation of the object references                                                                 
      11 Out[5]: 3337

      Circular reference, the following code, only if the reference count, then, a and b have been references 1, can not be eliminated.

    • a = [1]    
      b = [2]
      
      a.append(b)
      b.append(a)
      
      del a
      del b

       

  • Mark removal and recycling to address generational reference count (a more detailed search bar)
    •   Clear marker objects from a root object is simply an iterative query down can be achieved, unattainable object and are labeled, such as the above code, a and b are two isolated objects. Remove orphaned objects.
    •        Generational recovery: python target object has three generations of the life cycle, 0,1,2, each generation is a doubly linked list, generation 0 after deleting some nodes (not used), generated a new node to form a first generation, and so on, usually when the number of node passage 0 reaches a certain value the time points for generational collection.

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/dairuiquan/p/11785339.html