Memory Management in windows

ESHAN KOUL
9 min readJun 20, 2022

--

How windows manage the data?

information that’s stored in or used by a computer is called an data. An example of data is information collected for a research paper. So how this data is stored and managed in the windows operating system. Are you curious about it?

Memory Management :

Operating structures take care of or control number one reminiscence in addition to circulate methods among essential reminiscence and disk in the course of execution. Every unmarried reminiscence vicinity is tracked with the aid of using reminiscence control, irrespective of whether or not it’s miles allotted to a few method or if it’s miles free. Memory control makes a decision how a lot reminiscence every method gets at a given time. It tracks every time a few reminiscence receives freed or unallocated and correspondingly it updates the status.

Process Address Space

The process address space is the set of logical addresses that a process references in your code. For example, if 32-bit addressing is used, the range of addresses is 0 to 0x7fffffff. This is a possible number of 2 ^ 31 for a theoretical total size of 2 gigabytes.

The operating system handles the mapping from logical addresses to physical addresses when memory is allocated to the program. There are three types of addresses used by programs before and after memory allocation-

S.N.

Memory Addresses & Description

1

Symbolic addresses

The addresses used in a source code. The variable names, constants, and instruction labels are the basic elements of the symbolic address space.

2

Relative addresses

At the time of compilation, a compiler converts symbolic addresses into relative addresses.

3

Physical addresses

The loader generates these addresses at the time when a program is loaded into main memory.

Virtual and physical addresses are the same in compile time and load time address binding schemes. Virtual and physical addresses differ in execution time address binding scheme.

The set of all logical addresses generated by a program is referred to as a logical address space. The set of all physical addresses corresponding to these logical addresses is referred to as a physical address space.

Runtime assignments from virtual addresses to physical addresses are performed by the memory management unit (MMU), which is a hardware device. The MMU uses the following mechanism to translate virtual addresses to physical addresses.

The value of the base register is added to each address generated by the user process and treated as an offset when sent to memory. For example, if the base register value is 1000, the user’s attempt to use address space 100 is dynamically reassigned to space 10100.

The user program handles virtual addresses. The actual physical address is not displayed.

Static vs Dynamic Loading

The choice between static and dynamic loads is made during computer program development. If the program needs to be loaded statically, the complete program will be compiled and linked during compilation without leaving any external program or module dependencies. The linker combines the object program with other required object modules into an absolute program that also contains logical addresses.

When you create a dynamically loaded program, the compiler compiles the program and provides only references for the modules you want to include dynamically, and the rest of the work is done at run time.

Static vs Dynamic Linking

As explained above, when static linking is used, the linker combines all other modules needed by a program into a single executable program to avoid any runtime dependency.

When dynamic linking is used, it is not required to link the actual module or library with the program, rather a reference to the dynamic module is provided at the time of compilation and linking. Dynamic Link Libraries (DLL) in Windows and Shared Objects in Unix are good examples of dynamic libraries.

Swapping

Swapping is a mechanism that temporarily swaps out (or moves) a process from main memory to secondary memory (hard disk) so that this memory can be used by other processes. At a later point, the system relocates the process from secondary storage to main storage.

The paging process usually degrades performance, but it is useful when you want to run multiple large processes in parallel. For this reason, offload is also known as storage compression technology.

The overall time taken with the aid of using swapping manner consists of the time it takes to transport the complete manner to a secondary disk after which to duplicate the manner again to reminiscence, in addition to the time the manner takes to regain principal reminiscence.

Let us expect that the consumer manner is of length 2048KB and on a well-known difficult disk in which swapping will take region has a records switch charge round 1 MB in step with second. The real switch of the 1000K manner to or from reminiscence will take

2048KB / 1024KB per second= 2 seconds= 2000 milliseconds

Now considering in and out time, it will take complete 4000 milliseconds plus other overhead where the process competes to regain main memory.

Memory Allocation

Main memory usually has two partitions −

· Low Memory − Operating system resides in this memory.

· High Memory − User processes are held in high memory.

Operating system uses the following memory allocation mechanism.

S.N.

Memory Allocation & Description

1

Single-partition allocation

In this form of allocation, relocation-check in scheme is used to guard consumer tactics from every other, and from converting operating-device code and data. Relocation check in consists of cost of smallest bodily cope with while restrict check in consists of variety of logical addresses. Each logical cope with have to be much less than the restrict check in.

2

Multiple-partition allocation

In this type of allocation, main memory is divided into a number of fixed-sized partitions where each partition should contain only one process. When a partition is free, a process is selected from the input queue and is loaded into the free partition. When the process terminates, the partition becomes available for another process.

Fragmentation

As strategies are loaded and eliminated from reminiscence, the loose reminiscence area is damaged into little pieces. It takes place after every so often that strategies can not be allotted to reminiscence blocks thinking about their small length and reminiscence blocks stays unused. This trouble is referred to as Fragmentation.

Fragmentation is of two types −

S.N.

Fragmentation & Description

1

External fragmentation

Total memory space is enough to satisfy a request or to reside a process in it, but it is not contiguous, so it cannot be used.

2

Internal fragmentation

Memory block assigned to process is bigger. Some portion of memory is left unused, as it cannot be used by another process.

The following diagram shows how fragmentation can cause waste of memory and a compaction technique can be used to create more free memory out of fragmented memory −

External fragmentation may be decreased via way of means of compaction or shuffle reminiscence contents to location all loose reminiscence collectively in a single huge block. To make compaction feasible, relocation ought to be dynamic.

The inner fragmentation may be decreased via way of means of correctly assigning the smallest partition however huge sufficient for the process.

Paging

A laptop can deal with greater reminiscence than the quantity bodily hooked up at the system. This greater reminiscence is virtually known as digital reminiscence and it’s far a segment of a difficult it truly is installation to emulate the laptop’s RAM. Paging approach performs an essential function in enforcing digital reminiscence.

Paging is a reminiscence control approach wherein system deal with area is damaged into blocks of the equal length known as pages (length is strength of 2, among 512 bytes and 8192 bytes). The length of the system is measured withinside the quantity of pages.

Similarly, most important reminiscence is split into small fixed-sized blocks of (physical) reminiscence referred to as frames and the scale of a body is stored similar to that of a web page to have most reliable usage of the primary reminiscence and to keep away from outside fragmentation.

Address Translation

Page address is called logical address and represented by page number and the offset.

Logical Address = Page number + page offset

Frame address is called physical address and represented by a frame number and the offset.

Physical Address = Frame number + page offset

A data structure called page map table is used to keep track of the relation between a page of a process to a frame in physical memory.

When the gadget allocates a body to any web page, it interprets this logical deal with right into a bodily deal with and create access into the web page desk for use at some stage in execution of this system.

When a procedure is to be executed, its corresponding pages are loaded into any to be had reminiscence frames. Suppose you’ve got got a software of 8Kb however your reminiscence can accommodate most effective 5Kb at a given factor in time, then the paging idea will come into picture. When a pc runs out of RAM, the working gadget (OS) will flow idle or undesirable pages of reminiscence to secondary reminiscence to loose up RAM for different strategies and brings them returned whilst wished with the aid of using this system.

This procedure maintains all through the complete execution of this system wherein the OS maintains disposing of idle pages from the primary reminiscence and write them onto the secondary reminiscence and produce them returned whilst required with the aid of using this system.

Advantages and Disadvantages of Paging

Here is a list of advantages and disadvantages of paging −

· Paging reduces external fragmentation, but still suffer from internal fragmentation.

· Paging is simple to implement and assumed as an efficient memory management technique.

· Due to equal size of the pages and frames, swapping becomes very easy.

· Page table requires extra memory space, so may not be good for a system having small RAM.

Segmentation

Segmentation is a reminiscence control method wherein every process is split into numerous segments of various sizes, one for every module that includes portions that carry out associated functions. Each phase is simply a extraordinary logical cope with area of the program.

When a procedure is to be executed, its corresponding segmentation are loaded into non-contiguous reminiscence alevin though each phase is loaded right into a contiguous block of to be had reminiscence.

Segmentation reminiscence control works very just like paging however right here segments are of variable-duration in which as in paging pages are of constant length.

A application section carries the application’s primary function, application functions, statistics structures, and so on. The working gadget keeps a section map desk for each manner and a listing of loose reminiscence blocks along side section numbers, their length and corresponding reminiscence places in primary reminiscence. For every section, the desk shops the beginning deal with of the section and the duration of the section. A connection with a reminiscence place consists of a fee that identifies a section and an offset.

Advantages of Segmentation

  1. No internal fragmentation
  2. Average Segment Size is larger than the actual page size.
  3. Less overhead
  4. It is easier to relocate segments than entire address space.
  5. The segment table is of lesser size as compared to the page table in paging.

Disadvantages

  1. It can have external fragmentation.
  2. it is difficult to allocate contiguous memory to variable sized partition.
  3. Costly memory management algorithms.

--

--

Responses (1)