Keywords: memory, virtualization, paging, segmentation, disc, thrashing, swapping, page table.
Operating Systems: Three Easy Pieces
We’re starting this week off with my favorite Operating Systems book titled Operating Systems: Three Easy Pieces
. I’ve personally read it because I was preparing for my technical interview at Garena (if you read my curated list for week 2 you might remember I mentioned this). (p.s. I failed the interview). I love this book so much at it is lengthy yet very concise. It is also structured very well into three main parts (hence the title): Virtualization (Memory)
, Concurrency
, and Persistence
. Last week’s material was closely related with persistence
as I’ve discussed about file systems, dfs, nfs. Please read more about in Top 10 List of Week 03. I chose this book as it is a must read and gives a detailed yet high overview on what to learn and expect from an Operating System course.
Segmented, Paged and Virtual Memory
This topic is about comparing memory virtualization methods. It compares segmented and paged memory. This video is highly visualized, thus helps me understand what actually happens in memory virtualization. In general, paged memory is better than segmented memory as it avoid fragmentation. Paged memory has a fixed size where it divides memory into fixed size units. It is also flexible, enabling sparse use of virtual address spaces. Do check out the Computer Science
youtube channel as it has beginner friendly explanations for you folks who want to learn more about OS/CS.
Virtual Memory in Operating System
It is inevitable that I include a GeeksForGeeks article. It explains basically the same as the previous youtube video, but in more detailed and in an article structure. It also explains in more detail about Swapping
and Thrashing
, two key concepts you should know about when learning about Virtualizing Memory
. Swapping happens to pages when the memory is full. It swaps the page not used in the memory into a secondary memory, disc, and then it will be swapped back in when needed. Thrashing happens when this event occurs very frequently. The system spends most of it’s time mostly on swapping pages rather than executing the actual instruction.
Page Table
Another great website to learn CS fundamentals from is on JavaTPoint
. This is a bit of a POK
or IDS
refresher with concepts from Database
course. I’ve explained before about memory virtualization, but how does it actually virtualize
memory? Well it turns out that it uses a table called Page Table
which maps the virtualized memory address
to the actual address in physical memory. It is a simple yet important concept to strengthen your database and ids fundamentals. The article also has pictures and illustrations to strengthen and clear your doubts.
Pointers vs References in C++
I thought I’ve understand pointers and references, but I guess not. Even though this is for c++
, this should be identical to the C
language. To sum up, pointers holds the memory address of a variable and is dereferenced with *
. References is similar, storing the address of a variable, but the compiler automatically apply the * and it is used in function parameters. Talk is cheap, so I suggest you to solve some problems in Leetcode about LinkedList
or BinaryTrees
as it uses pointers and you’ll get a deeper understanding of the topic.
What’s the difference between an object and a struct in OOP?
I’ve been using c++ for a while for my language of choice for solving algorithm problems, yet I still haven’t had the fundamental understanding of what’s the difference between a struct
and an object
. After reading, I found out that struct is just an organized data, whereas an object has full on OOP capabilities including inheritance and methods. Structs don’t have that. So the use case I can think of when using a struct over objects are when you need a data structure where it’s most likely not going to be modified. Article is a stackoverflow
thread and has all the comments and upvotes to clear all your doubts.
Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
From sir’s slide, you might’ve seen a command called malloc
. I’ve heard of this command a lot, yet I have no idea what it does. What i know is it has something to do with memory (hence it is the abbreviation of memory allocation). This article is from geeks4geeks, quite possibly the best site for CS students. Have you ever used a dynamic list? It’s called dynamic because of it’s resizing capabilities, but a primitive array
is not capable of doing that. Actually, arrays can resize, but with the help of commands such as malloc(), calloc(), free(), and realloc()
. This summary would be too long if I explained all of these commands, but esentially malloc
is used to dynamically allocate a block of memory with a specified size and returns a pointer to said memory location. Read more about pointers this week’s number 5.
TLB
, Translation Lookaside Buffer which speeds up memory paging and uses the same principles as a cache. Here’s how it works:
Logical and Physical Address in Operating System
Sorry, another g4g article, it’s about Logical and Physical addressing, one of the key topics in this week’s materials. This article is concise and, has illustrations
to tickle your fancy. To sum up, Logical Address
is generated by CPU and is known as the Virtual Address
or virtual memory. This is used to reference the actual physical memory using Page Tables
that I’ve explained before in number 4 on this week’s list. Physical Address
on the other hand is the actual physical memory and it’s size is the limitation when running tasks. Do take a read on what happens when a memory is full in this week’s number 3. Where I briefly explained about Swapping
and Thrashing
in memory paging.
d.umn.edu
(I don’t know what this organization is) but it is the perfect combination illustration and documentation type of material where you actually get a deep and highly detailed explanation PLUS it has questions and answers to verify your understanding. This article has multiple navigations but my favorite sub page is the Logical Addresses
part this article explains the process of how to calculate the number of bits in a page number and offsets fields of a logical address. This really uses the IDS/POK
knowledge and acts as a refresher. I highly recommend this article for a high overview, yet the most detailed article on this list.