L-5.8: Need of Paging | Memory Management | Operating System

Gate Smashers
31 Mar 201814:20

Summary

TLDRThis video script delves into non-contiguous memory allocation, a method where memory is allocated to processes in a non-consecutive manner. It contrasts this with contiguous allocation, highlighting how non-contiguous allocation can combat external fragmentation by dividing processes into fixed-size partitions called pages, which are then placed in frames of the main memory. The script explains the dynamic nature of memory allocation, emphasizing the efficiency of paging in utilizing memory and eliminating fragmentation.

Takeaways

  • 🧩 Non-contiguous memory allocation allows processes to be divided and placed in different locations in RAM, unlike contiguous allocation which requires processes to be placed in consecutive memory locations.
  • 🔄 This method helps in reducing external fragmentation, a problem where memory is divided into many small blocks that cannot be used efficiently.
  • 💡 The script introduces the concept of 'paging' as a solution to external fragmentation, where memory is divided into fixed-size partitions called 'pages' and 'frames'.
  • 📏 The size of a page is made equal to the size of a frame to ensure that each page fits perfectly into a frame, optimizing memory usage.
  • 🚀 The process of dividing a process into pages is done in secondary memory before it is loaded into the main memory, which is a time-saving approach.
  • 🔄 Dynamic hole creation in RAM is a challenge because the availability and size of these holes change as processes are loaded and unloaded.
  • 📚 The script uses an 8KB RAM example with 1KB frames to illustrate how processes can be divided into pages and allocated to frames in a non-contiguous manner.
  • 🔄 When a process is completely removed, the frames it occupied become available as holes, which can then be used to accommodate new processes or parts of processes.
  • 📝 The script emphasizes that the non-contiguous allocation method can lead to a more efficient use of memory by fitting pages into available frames, thus reducing wasted space.
  • 🔑 The paging concept is crucial for modern operating systems as it allows for efficient memory management and helps to eliminate the issues associated with external fragmentation.

Q & A

  • What is non-contiguous memory allocation?

    -Non-contiguous memory allocation is a method where memory is allocated to different processes in a non-consecutive manner. It allows a process to be divided and placed in separate locations within the RAM.

  • How does non-contiguous memory allocation help with external fragmentation?

    -Non-contiguous memory allocation helps reduce external fragmentation by allowing processes to be divided and placed in different memory locations, thus utilizing the available memory more efficiently without leaving gaps between allocated memory blocks.

  • What is the main difference between contiguous and non-contiguous memory allocation?

    -In contiguous memory allocation, a process must fit entirely within a single, contiguous block of memory. In contrast, non-contiguous memory allocation allows a process to be divided and placed in separate, non-adjacent blocks of memory.

  • What is the concept of 'holes' in the context of memory allocation?

    -In the context of memory allocation, 'holes' refer to the unused or free memory spaces within the RAM. These holes can be of varying sizes and are dynamically created and changed as processes are loaded and unloaded from memory.

  • Why is dividing a process into partitions considered costly in non-contiguous memory allocation?

    -Dividing a process into partitions is considered costly because it requires analyzing the available memory holes at runtime, determining their sizes, and then dividing the process accordingly. This process is time-consuming and can lead to inefficiencies in memory management.

  • What is the term used for the partitions created during non-contiguous memory allocation?

    -The term used for the partitions created during non-contiguous memory allocation is 'pages'. These pages are the portions of a process that can be independently allocated to different memory frames.

  • What is a 'frame' in the context of memory management?

    -A 'frame' refers to a fixed-size partition of the main memory in a computer system. In the context of memory management, frames are the slots in RAM where pages from a process can be placed.

  • Why is it important that the size of a page is equal to the size of a frame?

    -It is important that the size of a page is equal to the size of a frame to ensure that each page fits perfectly into a frame without wasting any space, thus maximizing memory utilization and minimizing fragmentation.

  • How does the concept of paging help in managing memory more efficiently?

    -Paging helps in managing memory more efficiently by dividing processes into fixed-size pages that can be independently allocated to frames in the main memory. This method reduces external fragmentation and allows for more flexible memory allocation strategies.

  • What is the advantage of using non-contiguous memory allocation with paging?

    -The advantage of using non-contiguous memory allocation with paging is that it eliminates external fragmentation by allowing pages to be distributed across different frames in the main memory, regardless of their order or the size of the available holes.

Outlines

00:00

🧩 Introduction to Non-Contiguous Memory Allocation

This paragraph introduces the concept of non-contiguous memory allocation, explaining how memory can be allocated in different locations within the RAM. Unlike contiguous memory allocation, where a process must fit entirely in a single continuous block, non-contiguous memory allocation allows a process to be divided into smaller parts that can occupy separate locations. This method helps in utilizing available memory more efficiently by placing divided parts of a process into different holes or spaces in the memory. The example provided illustrates how a 6KB process can be divided into three 2KB partitions, each fitting into separate 2KB holes in the memory. This approach contrasts with contiguous allocation, which requires a single 6KB block for the process, highlighting the main benefit of non-contiguous allocation: the ability to use smaller, fragmented spaces effectively.

05:02

🔄 Challenges and Solutions in Non-Contiguous Memory Allocation

This paragraph discusses the dynamic nature of non-contiguous memory allocation and the challenges it presents, particularly the frequent creation and changing of memory holes during runtime. The holes vary in size and number, making the division of processes into partitions a complex and time-consuming task. The paragraph also emphasizes the inefficiency of dynamically dividing processes at runtime, proposing a more efficient method: pre-dividing processes into pages before they are loaded into the main memory. This method involves pre-partitioning both the processes and the main memory into pages and frames, respectively, with each page fitting precisely into a frame. The terms 'page' and 'frame' are introduced, defining the smallest units of a process and memory partitioning. By ensuring that the size of a page matches the size of a frame, the system can manage memory allocation more effectively, reducing the time and computational resources required during runtime.

10:04

📚 Practical Example of Paging and Its Advantages

The final paragraph provides a practical example to illustrate the concept of paging in non-contiguous memory allocation. It describes a scenario where an 8KB RAM is divided into eight 1KB frames, matching the page size of the incoming processes. The example demonstrates how processes of various sizes (2KB each) can be divided into pages and allocated to different frames in RAM. It shows that while non-contiguous memory allocation allows flexibility in placing these pages in any available frames, if contiguous memory were required, the process would fail due to fragmented space. The advantage of using non-contiguous allocation through paging is highlighted: it effectively eliminates external fragmentation by ensuring that each page can occupy any available frame, regardless of their location. This method ensures efficient memory utilization and simplifies the memory management process, supporting the need for and the benefit of implementing paging in memory allocation strategies.

Mindmap

Keywords

💡Non-contiguous memory allocation

Non-contiguous memory allocation refers to the process of assigning memory to different processes in a non-consecutive manner. This method contrasts with contiguous allocation, where memory must be allocated in a continuous block. In the video, this concept is crucial as it explains how memory can be fragmented into smaller blocks and allocated to processes in a scattered fashion, thus addressing the issue of external fragmentation.

💡External fragmentation

External fragmentation occurs when there are small gaps of free memory scattered throughout the memory, which are too small to be allocated to any process. The script explains that non-contiguous memory allocation helps to mitigate this issue by allowing processes to be divided and placed in different locations, thus utilizing the fragmented memory more effectively.

💡Process

A process in the context of the video refers to a program in execution, which requires memory allocation to function. The video discusses how processes are handled in non-contiguous memory allocation, where they can be broken down into smaller parts and placed in different memory locations, highlighting the flexibility of this allocation method.

💡RAM

RAM, or Random Access Memory, is the hardware in a computer system that stores data that is being used by the central processing unit (CPU). The video uses RAM as the context for discussing memory allocation strategies, emphasizing how non-contiguous allocation allows for more efficient use of this valuable resource.

💡Partition

In the script, partition refers to the division of a process into smaller, manageable pieces that can be individually allocated memory. This is a key concept in non-contiguous memory allocation, as it allows for the flexible placement of process parts in different memory locations, as illustrated by the example of dividing a 6KB process into three 2KB partitions.

💡Paging

Paging is a memory management technique where the main memory is divided into fixed-size partitions called frames, and each process is divided into equal-sized partitions called pages. The video explains how paging can be used to eliminate external fragmentation by ensuring that the size of pages matches the size of frames, allowing for efficient allocation of memory to processes.

💡Frame

A frame, as mentioned in the script, is a fixed-size partition of the main memory in a computer system. It is used in the context of paging, where processes are divided into pages that must fit into these frames. The video emphasizes the importance of frames being the same size as pages to ensure efficient memory allocation.

💡Dynamic allocation

Dynamic allocation refers to the process of assigning memory to processes at runtime, as opposed to static allocation which is done at compile time. The video discusses how non-contiguous memory allocation involves dynamic creation of holes (free memory spaces) that change as processes are loaded and unloaded, requiring real-time decisions on memory allocation.

💡Memory hole

A memory hole, as used in the script, is a block of free memory that becomes available when a process is removed from memory. The video explains how non-contiguous allocation deals with these holes by dividing processes into partitions that can fit into these varying sizes and locations of holes.

💡Contiguous memory allocation

Contiguous memory allocation is a method where memory is allocated in a continuous block of addresses. The video contrasts this with non-contiguous allocation, explaining that contiguous allocation cannot utilize small holes of memory, leading to potential waste of memory resources.

💡Memory management

Memory management is the process of organizing and allocating memory among multiple processes in a computer system. The video focuses on non-contiguous memory allocation as a strategy within memory management, aiming to optimize the use of available memory and minimize fragmentation.

Highlights

Introduction to non-contiguous memory allocation and its contrast with contiguous allocation.

Explanation of how processes can be expanded in non-contiguous allocation by being placed in different RAM locations.

Illustration of the concept using three 2KB memory holes and a 6KB process example.

Clarification that in non-contiguous allocation, a process can be divided and allocated across separate memory partitions.

Discussion on the limitations of contiguous memory allocation and the emergence of external fragmentation.

Proposed solution to external fragmentation through non-contiguous memory allocation.

Description of the dynamic creation of memory holes and the challenges it poses for process allocation.

The costly method of dividing processes based on the size and availability of memory holes.

The method of pre-dividing processes into pages before they arrive in the main memory.

Definition and importance of the term 'page' in the context of memory allocation.

Definition and importance of the term 'frame' in the context of main memory partitioning.

The critical point that the size of the page must always be equal to the size of the frame for efficient memory use.

Advantages of pre-allocating memory to pages in a non-contiguous manner to eliminate external fragmentation.

Example of how a 8KB RAM with 1KB frame size can be utilized for process allocation.

Demonstration of process allocation in RAM with the creation of holes and the subsequent allocation of a new process.

The concept of paging, dividing processes into pages of equal size to the frame before memory allocation.

The advantage of paging in fitting process pages properly into frames, thus improving memory efficiency.

Conclusion on the necessity of paging to remove external fragmentation and improve memory allocation.

Transcripts

play00:00

Hello guys the topic is non-contiguous memory allocation

play00:04

in non-contiguous memory allocation

play00:06

we are allocating the memory to the different different processes

play00:10

in a non-consecutive manner

play00:13

in non-contiguous memory allocation

play00:15

a process cannot span between the two different locations

play00:20

but here a process can be expand

play00:22

means after dividing one process can put in different different locations in RAM

play00:29

this is the concept

play00:30

now let's say in main memory there are these three holes

play00:35

of 2KB 2KB and 2KB

play00:38

if the process size is

play00:40

let's say a process came, P1 and the process size is 6KB

play00:47

now this 6KB process

play00:49

can not be put according to the contiguous memory allocation

play00:53

because, the rule in contiguous memory allocation is that

play00:57

that if one process will come then i will completely fit there

play01:01

we can not divide and put different locations

play01:05

but in non-contiguous memory allocation what we are doing..

play01:09

this process can be divided and it can be put on different different locations

play01:15

what i mean to say is

play01:16

to this 6KB process,

play01:22

by dividing in three partitions

play01:25

means we make three partitions of 2KB each

play01:30

and then

play01:33

first partition I put here

play01:35

second partition I put here

play01:37

and third one I put here,

play01:40

it can be done in non-contiguous memory allocation

play01:44

but it can not be done in contiguous memory allocation

play01:47

where a process can not be divided and placed in different different locations

play01:52

due to that what the problem was arising external fragmentation

play01:56

then how can we remove external fragmentation

play01:59

the method is non-contiguous memory allocation

play02:02

what are we doing there

play02:03

are dividing one process and putting different different locations in memory

play02:09

so we are trying to remove external fragmentation

play02:14

and definitely external fragmentation is getting removed

play02:19

but the point is when this process came

play02:22

when this process started to come in RAM

play02:25

means when it knocked in RAM at that time

play02:29

here i am checking how many holes are empty at what time

play02:33

and what is the size of those holes

play02:35

and i am dividing those process according to the size of holes

play02:39

A very important point is there

play02:41

I'm dividing the processes over here

play02:44

I'm doing the processes

play02:47

But this division is a very costly method

play02:50

While it is costly

play02:52

When this process has come to memory

play02:54

or is just about to come to the main memory

play02:59

What I'm doing at the same time

play03:02

according to the memory and according to these holes

play03:05

I am dividing the process

play03:07

What is the problem arising over here

play03:09

These holes are created dynamically

play03:12

Means these keep on changing on runtime

play03:15

It can also happen that you put this process here

play03:19

You have put one partition here and one partition here, and one partition here

play03:25

Further it can be possible

play03:27

It can be possible like

play03:29

If this partition is empty now

play03:32

If partition over here..

play03:34

sorry, If the process was there and this process has gone out

play03:40

What I meant to say is this space has become hole now

play03:44

and this has been occupied the process

play03:48

This also has been occupied by the process

play03:50

And this too is occupied by the process

play03:53

We have made P1 occupy this

play03:54

we have put P 1 in these three locations

play03:56

And I have put by dividing into 2KB 2KB 2KB

play03:59

Now this available empty space

play04:04

And the available size of this space is 1KB and 1KB

play04:12

1KB and 1KB

play04:14

these two holes of 1 KB are created

play04:17

now when these two holes of 1 KB are created 1 and 1KB

play04:22

now if one process comes

play04:23

let's say one more process came, P2

play04:26

and the size of process is 2KB

play04:30

can i put this 2KB here, no i can not put according the contiguous

play04:36

so according to the non contiguous i can put, but what will happen

play04:39

what will happen here, when this process is knocking here

play04:43

that i want to come in the RAM

play04:45

so at that time i am checking that how many holes are there, there are two holes

play04:51

and what is the size of these two holes 1KB 1KB

play04:54

then i will decide that the size of my process is 2KB

play04:58

I will decide this in 2 parts

play05:01

so size of first partition is 1 KB and second also 1 KB

play05:06

so I will put this 1KB here and this 1KB here

play05:11

but the problem is

play05:12

these holes are creating dynamically and these are changing every time

play05:17

Their size is changing and their number is changing

play05:20

Whenever the process will try to come in the RAM

play05:24

At that time by analyzing those holes, their numbers and their size

play05:29

you will be dividing the process

play05:31

And this is a very time consuming process

play05:34

In doing this thing your a lot of time might be wasted

play05:38

So here

play05:39

What method we are following in the non contiguous

play05:43

Method is same that we have a process

play05:48

Whenever the process will come we will divide it, but what are we changing here

play05:53

Whatever the process we have

play05:55

We will divide that process beforehand

play05:58

We will divide that process beforehand means before arrival of this in main memory

play06:04

Its division will complete, means its partition will complete

play06:08

so this process when i will divide in partitions

play06:12

So then what do I call this one partition page

play06:17

This is called the page

play06:19

And where am I doing this partition in the secondary memory

play06:23

When I read this process in the secondary memory

play06:26

at that time only I divided it in pages

play06:30

And what did other side

play06:33

The RAM we had the main memory we had

play06:37

We have divided main memory beforehand

play06:41

And in technical terms we call every partition and every slot of main memory..

play06:47

frame

play06:48

Yes that is called the frame

play06:51

So what method we are following here , we are following the same method

play06:54

But when the process will come in the RAM

play06:57

We are not doing divisions at that time

play06:59

We are already dividing processes in the secondary memory

play07:04

And what do we call each of these partition pages

play07:08

Means every process will be divided in the pages

play07:12

And what we will do in RAM also, in main memory also

play07:15

We will do partitions before itself

play07:17

And what do we call every partition and every slot ... frame

play07:22

So actually what are you doing here

play07:25

Important point is, the size of the page

play07:30

will always be equal to the size of the frame

play07:35

This is very very important point

play07:38

This point is will be used in all of the paging

play07:42

that the size of the page will be equal to the size of the frame

play07:47

reason being is obviously this page

play07:51

The process which we are dividing in the page

play07:53

Where will this partition go and sit

play07:56

This will go and sit in this frame.. ..this will go and sit there in that frame

play08:01

If it goes there then it should fit properly

play08:06

So to make it fit properly, so that I can use memory more efficiently

play08:12

What will I do, whatever the size will be of this page that will be the size

play08:15

of this frame also

play08:17

So that this frame can put one page easily

play08:23

Alternatively we can also say that this page should be fit in one frame

play08:29

So what we will have to do for that beforehand itself

play08:32

whatever the size of the pages is that should be the size of that frame also

play08:36

Or I can also say that whatever the size of the frame is according to that only

play08:40

We'll divide processes in the pages

play08:44

So I will already do this work

play08:47

So that when this process will come

play08:50

When the page of this process will come

play08:52

I will put this page here

play08:55

Next page comes i will put here

play08:58

If this slot is busy then I will put the third page here

play09:02

If this slot is busy then I will put 4th page here

play09:07

And let's say 5th page I'll put here

play09:10

So now means we can allocate the memory to these pages

play09:15

in a non contiguous memory

play09:18

It is not necessary that did these page should be continuous

play09:22

These can be distributed in the different different locations

play09:26

So what is the advantage I'm getting over here

play09:28

External fragmentation is totally removed from here

play09:31

Let's try to analyze it with the very simple example

play09:41

Let's say I'm having the RAM of 8KB

play09:49

I have RAM of 8KB

play09:51

and the page size or frame which i have fixed

play09:56

Frame size is 1KB

play09:59

so if the size of the RAM is 8 KB and the size of one frame is 1 KB

play10:03

Then how many number of frames will be there,

play10:05

there will be total 8 number of frames

play10:08

So we are drawing here 8 number of frames

play10:12

So zero one two three four five

play10:16

six and seven

play10:18

So 8 number of frames will be there

play10:20

Now say if the process comes

play10:23

let's say a process came P1

play10:25

And the size of P1 process is 2KB

play10:28

size of P1 process is 2KB

play10:30

Then I will also have to divide this process in pages

play10:35

And what is the size of the page,

play10:37

whatever is size of the frame is the size of the page

play10:40

So what will be the size of page also 1KB

play10:44

So page size is equal to frame size is equal to 1KB

play10:48

So now if the size of the process is 1 KB then I will make 2 partitions of 1 KB each

play10:53

Let's say one more process came let's say P2

play10:56

so i will write here P2 also

play10:59

Let's say if that is also of 2 KB, then I can make two partitions of P2 also

play11:03

so in the same manner P3 is also coming

play11:06

will make 2 partitions of P3 also, and if P4 comes,

play11:09

then will make 2 partitions fo P4 also

play11:10

if all those four processes are 2 KB each

play11:16

If already it is 2KB 2KB

play11:19

Now simply what we can do we can allocate the partition of P1 here

play11:25

Now if these slots are empty

play11:27

If initially these slots are empty,

play11:29

then it's not necessary that you have to follow non contiguous

play11:32

means you put these to different different locations, if these slots are empty

play11:36

Then you can put them directly also

play11:38

And yes if slots are not empty then you will put them separately only

play11:42

Normally non contiguous doesn't mean it is not contiguous

play11:47

yes If the slots are empty then you put P1 here

play11:51

Second slot of P1 put here

play11:53

similarly we have put the 1st page of P2 here and second page of P2 here

play11:59

first page of P3 process here and second page of P3 process here

play12:04

first page of P4 process here and second page of P4 process here

play12:09

we have given all these pages

play12:11

i have put these 2 pages here, these 2 pages here

play12:14

these 2 pages here, these 2 pages here

play12:16

So simply we have allocated the memory to the pages

play12:21

Now the point is

play12:23

if at a point

play12:26

let's say P2 has gone out from here

play12:30

P2's work is executed here

play12:32

Whatever the instructions were there in the P2 are executed

play12:35

Similarly P4 instructions are also executed here

play12:38

So P1 and P2 has gone out

play12:41

So in a way what we can say is, here these 2 holes are created

play12:44

and here these 2 holes are created

play12:46

Size of these two holes and the size of all these holes are 1KB 1KB 1KB 1KB

play12:51

means total I have 4 KB of space

play12:54

So if at this time a process comes P5

play12:58

and the size of P5 is 4KB

play13:02

So what will I do, first I will divide the process of 4KB in pages

play13:06

How many pages are created 4 pages

play13:09

So if it were a contiguous

play13:12

how much space do I have, 4KB

play13:14

And process is 4KB, so I cannot allocate

play13:18

because it is not continuous

play13:20

But in non contiguous we can easily distribute it

play13:24

How?, I will put 2 pages of P5 here

play13:28

and the remaining 2 pages of P5 will put here

play13:32

So means with the help of paging, this is called the concept of paging

play13:36

So what do we do in paging, we divide processes in pages beforehand

play13:41

And what will be the size of every page

play13:43

it will be equal to the frame size of main memory

play13:46

So what advantage i have

play13:48

The page of processes will properly fit in the frame

play13:52

Or the frame will properly carry a page

play13:57

And then simply we will allocate memory to the pages

play14:03

So easily we have removed the external fragmentation

play14:09

So this is the first advantage and This is why we need the paging

play14:14

So This is all about why we need the paging concept

play14:17

Thank You

Rate This

5.0 / 5 (0 votes)

関連タグ
Memory ManagementNon-Contiguous AllocationExternal FragmentationPaging ConceptOperating SystemsRAM AllocationProcess DivisionMemory EfficiencyDynamic HolesMemory Partitioning
英語で要約が必要ですか?