Virtual memory Flashcards

1
Q

Why processes need memory

A

Every process needs memory for:

  • Instructions (“code” or”text” segments)
  • Static data (in program - not changing)
  • Dynamic data (heap and stack)
  • AND memory for OS instructions and data
  • Multiprogramming system has many processes in memory simultaneously
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Issue of relocation

A
  1. Sharing => programmer no longer knows runtime address of process on a specific machine / other processes.
  2. Swapping running/waiting processes into / out of memory to reuse space for other processes => silly to require swapped process to always go to same place in memory after being swapped back from HDD. Irritating constraint…
  3. Process may incorporate addresses (branching, pointers) and OS must sanity check the logical addresses generated by the process, without confusion e.g. process branching to instruction in another process’s address space.
    Conclusion : need to translate LOGICAL (program generated) to PHYSICAL addresses (machine dependent). OS manages translation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Issues of allocation

A

Where does the OS put the process in memory? How does it find a large enough chunk of memory so that the process can do something useful. No use loading half the process into memory - not all instructions / data.

  1. OS has to place data/ instructions in memory to make linking or relocation easier
  2. Related to sharing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Issues of protection

A

Multiple processes in memory

  • Ensure a given process cannot interfere with the memory of another process.
  • One process should not be able to write the memory of another process unless under specific circumstances e.g. communication, OS needs to prevent accidental accesses (e.g. buggy processes).

(Protection between processes)
1. OS needs to protect one process from others

(RWX protection)
2. OS may implement RWX protection on small memory units - designate readable / writable / executable chunks of memory.

(Self modifying code - malware target)
3. OS should prevent process modifying its own code (why - confusing, bugs, possibility to attacks/malware. If the OS knows that the program’s instructions CANNOT be changed while it executes, then nobody can try and change that to inject bad instructions. )

(Dynamically generated addresses)
4. OS should sanity check dynamically computed addresses (e.g. array subscripts) - ensure that invalid memory is not accessed (e.g. EDSAC … sparse instruction set => fails fast, most bit patterns not valid instruction, fails near bug).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Issues of sharing

A

Efficiency argument

  1. Multiple processes executing same binary - would like to keep only one copy in memory.
  2. Data can be shipped between processes by passing shared data segment references
  3. Operating on same data concurrently requires sharing locks with other processes.
  4. OS has to multiplex memory in a reasonably fair way
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Issues of logical organisation

A

(Physical memory)

  1. Physical memory : linear address space from 0 to max.

But,

(Contrast between physical memory and programmer view of memory)
2. Physical memory doesn’t correspond to modular structure of programs : want segments.

(Modules - locating modifiable data and code which modifies it)
Previously was useful to structure process into modules.
3. Modules can contain modifiable data or just code - locate modifiable data with data that can modify it - reduces chance of unwarranted modification.

(Independently compiled modules)
4. Would be useful if the OS could deal with modules, written and compiled independently.

(Protection and sharing of modular units of code rather than whole process data)
5. Can give different modules different protection and can be shared, thus easy for user to specify sharing model.

e.g. put heap in one segment, make it readable / writable to facilitate IPC

But, put stack and instructions / static data
in another segment and make it non-readable / non-writable

Specificity ???????

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

issues of physical organisation

A

There is a storage hierarchy …

  1. Main memory - single linear address space, volatile, more expensive
  2. Secondary storage : cheap, non-volatile, can be arbitrarily structured.
  3. OS should organise flow between main memory and secondary store (buffering using a cache - need to manage what should be kept in the cache).
  4. Programmer may not know beforehand how much space will be available.
  5. Programmer does not want to deal with cache associativity, 4-way / 2-way, etc… complexity - would like OS to abstract away the cache and management.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the address binding problem

A
  1. Logical variables and data are compiled to addresses in assembly code - contain relocatable addresses passed to instructions e.g. LOAD, STORE, ADD … which take memory address arguments.
  2. Problem : What physical addresses do you assign the abstract memory locations in the compiled code?

cannot assign addresses before loading, because compiler does not know where in memory the program will be loaded (otherwise would know where the program would be loaded, specify offset from loading address for each required memory location).

Conclusion : translate between program addresses and real addresses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Outline solutions to address binding problem

A

Solution : translate between program addresses and real addresses.

Can be done at
1. Compile time (simple but very old systems)

  1. Load time : Load code, find the position it was put into memory by the OS, OS fixes up references.
  2. Run time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Evaluate : address binding at compile time

A
  • Requires knowledge of absolute addresses (e.g. DOS .exe files).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Evaluate: address binding at load time

A
  • Find position in memory after loading, update code with correct addresses
  • Must be done every time program loaded
  • OK for embedded systems (processes run forever) / boot loaders (once at start of day)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Evaluate: address binding at run time

A

Perform relocation as the program is executing

  • Hardware automatically translates between program and real addresses.
    => Need hardware support : too slow with software because have to translate EVERY logical address generated by CPU / every variable access …
  • No changes required to program itself
  • Given MMU hardware - the most popular and flexible scheme.
  • Hardware support also nice because reduces complexity of memory management software / transparent to programmer / MMU can be hardware specific removing need for OS to consider platform-dependent parameters.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

MMU purpose

A

Memory management unit,

MMU, maps logical to physical addresses at run time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

MMU - how relocation occurs (scheme:= base relocation, simple system)

A

CPU generates logical addresses
MMU converts those to physical addresses.

  1. Relocation register holds value of base address owned by process
  2. Relocation register contents are added to each memory address before sent to main memory
    - Instruction may reference some areas in memory - control bits to memory / IO bus (recap buses) - hardware enters data from bus into CPU registers, available to process.
  3. e.g.MS DOS on 80x86 - 4 relocation registers, logical address is a tuple (segment, offset)
  4. Process never sees physical address, simply manipulates logical addresses
  5. OS has privilege to update relocation register : guarantees process cannot access memory it is not allowed to do so by OS (limit register - how far it can go through memory).
  6. Diagram CPU =LA=> MMU => PA => MM, or translation fault to OS.
  7. If no corresponding memory location exists, a translation fault / hardware exception sent to OS, OS catches the fault, OS works out what to do e.g. location of an object may have changed, update segmentation table.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Problem of contiguous allocation

A

How do we support multiple virtual processors in a single
address space?

Where do we put processes in memory?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Explain contiguous allocation issues

A
  1. OS typically in low memory due to location of interrupt vectors (why - backwards compatibility, eg if hardware can only put a relatively small address in the interrupt so OS has to be in low memory. )
  2. Easiest way : STATICALLY divide memory into multiple fixed size partitions.
  3. Bottom partition contains OS, remainder each contain exactly one process.
  • Every process knows which partition it operates in
  • Relocation by base and limit registers
  • Straightforward
  • Used in older systems e.g. OS360
  1. When a process terminates, its partition becomes available to new processes. e.g. OS/360 MFT.
    - and a process swapped to HDD can be loaded into a different partition, with OS having privilege to update its base register.
  2. Need to protect OS and user processes from malicious programs by using base and limit registers in MMU, updating values when a new process is scheduled, solving both relocation and protection problems at the same time.
    - Limit registers prevent process accessing memory beyond the range allocated to it.
    => Deals with relocation and protection simultaneously.
17
Q

Explain how STATIC multiprogramming works **

A
  1. Partition memory when installing OS
  2. Allocate partitions to different job
    queues. (different partitions with different process states)
  3. Associate jobs to a job queue according to size.
    - e.g. ready queue gets different partitions for processes of different queues.
  4. Swap job back to HDD when either (a) blocked on IO (assuming IO slower than backing store) - e.g. blocked queue can be kept on HDD

or (b) Time sliced, larger the job, larger the time slice. Go between jobs in the queue according to the scheduling algorithm.

Swap things to disk when device IO is slower than the backing store. (so while a processes is blocked waiting for IO, it is swapped out to the HDD).
=> Run job from another queue while swapping jobs e.g. IBM OS/360 MVT ICL system 4.
=> Does something useful with the machine while swapping processes out

18
Q

Problems with static multiprogramming

A

Fragmentation

=> Swapping something out, chunk of free memory,
=> Processes may not fill their partition - leaving fragments of non-contiguous memory which in total are large enough to hold additional processes, but individually cannot because they are non-contiguous.
=> Fragments of memory cannot be used usefully since non-contiguous.

Cannot grow partitions
=> Static allocation, fixed, cannot be changed.

19
Q

Explain how dynamic partitioning works

A
  1. More flexibility allow partition sizes to be dynamically chosen (e.g.OS/360 MVT):
  2. OS keeps track of which areas of memory are available and which are occupied e.g. use one or more linked lists:
  3. For a new process,OS searches for a hole large enough to fit it - strategies : First, Best, worst fit.
20
Q

What are First, Best, Worst fit and why

A

Strategy used by OS in a dynamic partitioning memory management system to allocate a partition
First fit: stop searching list as soon as big enough hole is found
Best fit: search entire list to find “best” fitting hole
Worst fit: counterintuitively allocate largest hole (again, search entire list)

21
Q

Compare strategies for dynamic partitioning ???????????????

A
  1. First and Best fit perform better statistically both in time and space utilisation —
    typically for allocated blocks have another 0.5 in wasted space using first fit
  2. Which is better depends on pattern of process swapping
  3. Can use buddy system to make allocation faster
  4. When process terminates its memory returns onto the free list, coalescing holes
    where appropriate
22
Q

Difference between heap and stack

A
  1. Memory allocated on heap and may be garbage collected, objects on heap can grow dynamically.
  2. Stack - local variables store data which is of fixed size,
23
Q

What problems are introduced by multiprogramming with respect to memory management

A
  1. Relocation
  2. Allocation
  3. Protection
  4. Sharing
  5. Logical organisation
  6. Physical organisation
24
Q

External fragmentation

A

Dynamic partitioning algorithms suffer external fragmentation
WHY
1 - as processes are loaded they leave little fragments which may not be used.
2 - Processes may eventually block due to insufficient memory to swap in ( new memory cannot be fit into a fragment available)
3 - External fragmentation exists when the total available memory is sufficient for a request, but is unusable as it is split into many holes. => absolute sense enough memory available but not enough contiguously / in a particular partition.
4 - Can also have problems with tiny holes when keeping track of hole costs more memory than the hole.
5 - Requires periodic compaction
(Example in notes - entry / exit of processes => fragmentation)
=> Quicker to find an appropriately sized hole
=> Enable use of free memory

25
Q

How is compaction performed?

A

WHY
- Reduce external fragmentation

HOW

1 - Runtime relocation : system has to support taking a running process and moving it in memory (dynamic relocation) …. otherwise would have to be re-loaded / recompiled.

2 - If cannot be done at runtime, then may do it more efficiently when a process is moved into memory from a swap.
=> Even if cannot be done during execution, may be feasible to do this nonetheless…

3 - May have hardware support - make finding and changing all the addresses easier, or change tables being used to access memory addresses.

4 - May also get fragmentation in backing store