No video

The mechanics of VIRTUAL MEMORY //Source Dive// 005

  Рет қаралды 25,733

Low Byte Productions

Low Byte Productions

Күн бұрын

In this installment of //Source Dive//, we're back in xv6, learning how address translation works with the virtual memory subsystem.
=[ 🔗 Links 🔗 ]=
more in depth talk: • *(char*)0 = 0; - What ...
🐋 RISC-V Docker Image: github.com/fra...
🎥 Series Playlist:
🗣 Discord: / discord
⭐️ Patreon: / lowleveljavascript
💻 Github Repo: github.com/mit...

Пікірлер: 83
@aalsteinnhjorleifsson2941
@aalsteinnhjorleifsson2941 10 ай бұрын
I think you have a mistake when talking about the walk function when you say the first entry of the newly allocated table is marked valid. pte is still pointing to an entry in the previous level page table which is marked valid and pointed to the newly allocated page with the line: *pte = PA2PTE(pagetable) | PTE_V;
@rfgrooteman
@rfgrooteman 10 ай бұрын
Yes, I thought the same thing.
@LowByteProductions
@LowByteProductions 10 ай бұрын
Yes you're right!
@lewa_j
@lewa_j 4 ай бұрын
This series is awesome. I really hope for continuation
@TheodorMoroianu
@TheodorMoroianu 3 ай бұрын
Best *nix series on youtube by far!! I really hope there will be a continuation!
@paritoshmishra0891
@paritoshmishra0891 2 ай бұрын
Somehow the youtube algorithm landed me on this goldmine. great job!
@c2vi_dev
@c2vi_dev Ай бұрын
plz continue this series!!! It was an excellent learning resource to get into kernel inner workings so far and I think for me most of the things clicket.
@salilphadnis4147
@salilphadnis4147 Ай бұрын
Incredibly useful series of videos. Can't thank you enough. Hopefully you will get a chance to continue this series. Waiting eagerly.
@markuscwatson
@markuscwatson 21 күн бұрын
I am currently studying xv6 (there is a book which is REALLY great). This series is a great compliment. Please continue it!!!!!!!!!
@arturmyst5692
@arturmyst5692 8 күн бұрын
i keep my fingers crossed, that you continue the series, i am astonished by the way, that you do the usually boring code readings, i am not a newbie but to study the code is very intimidating, if there is no guide who knows which parts of code are important and of a secordary importance. great job
@miroslavstevic2036
@miroslavstevic2036 10 ай бұрын
Excellent. Simple code base, well explained. Don't keep us waiting for too long ...
@Sovereign589
@Sovereign589 21 күн бұрын
I loved the series so far and hope we will get another episode in the future :)! Thank you for your work
@MatthieuHonel
@MatthieuHonel 10 ай бұрын
Such a nice series, Francis. Really well explained, at least from the point of view of someone who has little to no experience in kernel stuffs. Can't wait for the next episode!
@user-gh5jo8un2e
@user-gh5jo8un2e 10 ай бұрын
I have been waiting impatiently for another episode of "Source Dive" since the very end of the previous one ;-)
@heepajunk
@heepajunk 10 ай бұрын
Extremely valuable walkthrough series.
@louiehoosk
@louiehoosk 5 ай бұрын
I'm gutted to have reached the end of the playlist so far, but I bet these videos are tough to make for you, considering the amount of information you're condensing into sensibly long videos. Thank you so much for that, I learned incredibly much!
@Jester01
@Jester01 10 ай бұрын
22:48 Having paging enabled for the kernel as well allows for the protections that you show later, such as read-only kernel code and stack guard pages. Incidentally, they should have mapped the .rodata read-only at 57:20. Interesting video, thank you!
@gillesvismara5228
@gillesvismara5228 7 ай бұрын
Cant wait for the next episode
@fhools
@fhools 10 ай бұрын
this is awesome. i love these videos that dig into well written open source code.
@RomanShchekin
@RomanShchekin 3 ай бұрын
This is simply amazing! Best OS explaining video I've seen so far. Thank you so much and please keep it up!
@umurgedik3440
@umurgedik3440 7 ай бұрын
Amazing content. When you explained like this it is very understandable. I hope you continue on xv6 source dive.
@rfgrooteman
@rfgrooteman 10 ай бұрын
Great series. Thank you very much. Enjoying every second of it.
@stefans2143
@stefans2143 10 ай бұрын
This is great education and great entertainment all in one! Thank you!
@taotuo
@taotuo 4 ай бұрын
please keep updating!!!!
@james88372
@james88372 10 ай бұрын
Loving this series. Keep up the awesome work!
@user-wq1wm9gr1h
@user-wq1wm9gr1h 9 ай бұрын
Great video, as always. Perfectly clear explanation just as it should be. p.s. its nice to watch how your hair grows with each video
@epickittylover489
@epickittylover489 10 ай бұрын
Loving this series! :)
@sparshpriyadarshi
@sparshpriyadarshi 4 ай бұрын
Appreciate this series, was very useful. Thank you.
@lewiswardita9902
@lewiswardita9902 6 ай бұрын
Great series! When's the next part?
@user-be8ud2qd2d
@user-be8ud2qd2d 10 ай бұрын
Thanks for the high quality content!
@daphne.fowler
@daphne.fowler 10 ай бұрын
Totally fascinating. Please continue.
@Ladik_kitik_amelia
@Ladik_kitik_amelia 9 ай бұрын
I completely like these series, so sad that I could not made such series myself before. Now you are a "pioneer" ?) Really lovely stuff
@etc_kula
@etc_kula 10 ай бұрын
Point of clarification: on the page table diagram, should all of the “PTE 512” be “PTE 511”? Since there are 512 entries but we’re going 0, 1, 2 … 510, 511.
@LowByteProductions
@LowByteProductions 10 ай бұрын
You're correct!
@wiseskeshom4673
@wiseskeshom4673 10 ай бұрын
Thank you so much for another great video in this series.
@dimajaykobson7506
@dimajaykobson7506 7 ай бұрын
Thank you!
@simonheeg6910
@simonheeg6910 10 ай бұрын
Really love your series and I am looking forward for each new episode. I really like that you always follow functions to the end. However, I had the impression that this episode was a little bit quicker and you „rushed“ some parts, for example the KSTACK macro.
@LowByteProductions
@LowByteProductions 10 ай бұрын
Thank you. Yes it's quite a big topic and hard to fit into a hour!
@aalawneh91
@aalawneh91 7 күн бұрын
This is awesome, can you finish the series
@DouwedeJong
@DouwedeJong 9 ай бұрын
Thanks for making this video. I learned a lot.
@LowByteProductions
@LowByteProductions 9 ай бұрын
Graag gedaan en goed om te horen!
@konstantinkovalchuk5424
@konstantinkovalchuk5424 9 ай бұрын
Great series, pls release more pieces
@tanchienhao
@tanchienhao 10 ай бұрын
Keep this series coming!! Very good videos
@VaibhavBhandarigplus
@VaibhavBhandarigplus 3 ай бұрын
when are you doing #6? great content
@TimDrogin
@TimDrogin 3 ай бұрын
I might be wrong, but 55 bits for addressing is 2^55 or 4 petabytes of addresses? 256 petabytes of potential ram is indeed a really big number!
@Jules-ki9nx
@Jules-ki9nx 6 ай бұрын
When are you making more videos?! I love this series ?
@patrickantonio6306
@patrickantonio6306 10 ай бұрын
such a great series
@AverageJoeHacks
@AverageJoeHacks 10 ай бұрын
I understand virtual memory right now.
@markuswerner1166
@markuswerner1166 10 ай бұрын
Thanks again :-) Keep going.
@Fleshy
@Fleshy 10 ай бұрын
In your graphic, wouldn't the last page table entries be 511 since you start at 0?
@LowByteProductions
@LowByteProductions 10 ай бұрын
You're right!
@MrJegerjeg
@MrJegerjeg 9 ай бұрын
I felt so adventurous that I tried to cross-compile the kernel on M1 Mac with nix and I failed miserably :D
@kaitingchang7765
@kaitingchang7765 7 ай бұрын
Can you explain a little bit about how you set up gdbserver attach to vscode? Or there is video I missed
@amadouthiernobah6071
@amadouthiernobah6071 7 ай бұрын
Hey I am trying to debug with gdb, any hint of how to configure the launch.Json ? thanks
@markuswerner1166
@markuswerner1166 10 ай бұрын
I did not understand vm right now. I will need the next days to play a bit around.
@rnishu_7218
@rnishu_7218 4 ай бұрын
Please do one on OpenSSL!
@JoseJimeniz
@JoseJimeniz 10 ай бұрын
Virtual memory was much easier to understand when your Windows PC had 4 MB of RAM, while an application can successfully allocate and use 2 GB MB of memory. Memory is your 2 GB virtual address space. RAM is one thing that can by used to hold your memory.
@markuswerner1166
@markuswerner1166 10 ай бұрын
@Low Byte Productions, Never did debugging with VS Code. Actually never used gdb before. What gdb extension are you using ? I use the risc-v toolchain directly on my macOS. And make qemo-gdb is working.
@LowByteProductions
@LowByteProductions 10 ай бұрын
I'm using "GDB Beyond" & "Native Debug"
@Bl00drav3nz
@Bl00drav3nz 10 ай бұрын
When we are done setting the satp to turn on address translation and return to our main() (or more likely, just inc the PC), does this only work, because we have mapped the same physical address to the virtual address for the kernel? The PC will still point to the old address, if I understand it correctly.
@LowByteProductions
@LowByteProductions 10 ай бұрын
Exactly - it works because we built a 1-to-1 mapping for the physical address space.
@user-vn5yw8wk7p
@user-vn5yw8wk7p Ай бұрын
Is there any documentation for this source code
@TheOneMaddin
@TheOneMaddin 10 ай бұрын
Is there a reason these page table entries are not implemented as a struct using bitfield? I have the feeling this would make a lot of this much easier to grasp compared to dealing with all these magic bitshifts and mask operations. Is there the worry that the compiler will do some shenanigans in the background to the struct's memory layout? I thought this can be turned off?!
@LowByteProductions
@LowByteProductions 10 ай бұрын
I can't say for sure, but I would guess that bitfields having implementation defined behaviour would be the main reason. Even if you can control the semantics with compiler flags, that is essentially out-of-band with respect to the code. Using shifts and masks means that the implementation will work regardless of compiler. As a side note: I don't personally think shifts/masks as magic. When I first encountered them, it was definitely confusing, but it actually become intuitive and natural at a certain point. I think that's the case with a lot of things.
@krzysztof-ws9og
@krzysztof-ws9og 9 ай бұрын
Nice series I think that you are explaining stuff that are not directly related to kernel stuff a bit too much, so I end up skipping large parts of the video, like explaining the algorithm of printf going through each iteration of the loop, or explaining how linked list to handle free memory works I just feel like that is just a normal C programming not very kernel specific However remember that im just a random person that might disagree with you on something, so keep up the great work 😉
@davidhand9721
@davidhand9721 7 ай бұрын
Am I understanding correctly that these page tables are in main memory? Even if it lives de facto in the cache, that seems like an enormous overhead for literally every instruction. This can't be right, it can't be tying up the busses like that.
@LowByteProductions
@LowByteProductions 7 ай бұрын
It's absolutely true. But what you're saying also true - it is an enormous overhead. This is why a structure called the TLB exists: the translation lookaside buffer. It's a cache that operates as a kind of hash table. Hardware accessing memory will first check the TLB, and otherwise walk the page table (writing the translated address to the TLB afterwards).
@davidhand9721
@davidhand9721 7 ай бұрын
@@LowByteProductions I'm sort of disgusted, but also kind of impressed that it seems to still be pretty fast. What is the actual cycle count for a TLB hit in the cache, then?
@Natalia-zt1dq
@Natalia-zt1dq 10 ай бұрын
I don't understand something. If there is 3 levels page table and each level hold 512 entries and each entry takes 8 bytes (64 bits) and function "walk" initialize them all, that means only pagetable needs 512*512*512*8 [B] == 1GB of the memory. Something's not right here (probably i didn't understand drawio diagram correctly).
@fastandfemme
@fastandfemme 10 ай бұрын
That seems mostly correct, although it only considers the third level of page tables. In total, the page tables use (1 + 512 + 512*512)*(4KiB), which is about 1GiB + 2MiB. Remember that this only covers the memory used for virtual address translation. The final layer of page tables has 512*512*512 entries, which all point to 4KiB pages that hold the memory the process sees (512 GiB total).
@trevinbeattie4888
@trevinbeattie4888 10 ай бұрын
It would need that much page table memory _if all_ of the virtual memory space were to be initialized, but that’s never the case. Programs start out with a pre-determined amount of memory needed to load the code and pre-initialized data, and at run time request additional memory on an as-needed basis, so the kernel only needs to initialize the page table for that smaller range of memory and then add pages as needed. Entries in the 1st-level table don’t need to point to a 2nd-level table if there is no memory allocated in the range the entry would point to, and likewise for the 2nd-level entries.
@miroslavstevic2036
@miroslavstevic2036 10 ай бұрын
You don't need to use full table for everything. For example, you can use only 3 tables to map 2 meg process. You'll need ~1 gig table only to map something huge that use 512 gig of memory, which is only ~0.2%
@enirya
@enirya 10 ай бұрын
So in xv6 the kernel's read-only data is mapped as writeable? >_> That's kinda funny
@LowByteProductions
@LowByteProductions 10 ай бұрын
It is indeed! I guess it's for simplicitys sake more than anything else.
@stefans2143
@stefans2143 10 ай бұрын
I watched this three times now. What I dont get is: Why do we need that 3-level structure of tables? I mean, why cant we have a linear table with 512*512*512 entries each entry containing a mapping of virtual page to physical page?
@LowByteProductions
@LowByteProductions 10 ай бұрын
The thing about page tables is that they're sparse, i.e. you actually don't define most of the table. You only need to setup entries for the memory you map for each process. What you're suggesting would be simpler in a way, but also extremely costly. 512*512*512 entries, with 8 bytes per entry is 1GiB - and that's per process! Not to mention the kernels page table.
@hzrgf
@hzrgf 9 ай бұрын
Your explanations are brilliant! I found a playlist of videos that cover the general concept of virtual memory and, for example, the TLB. As someone who has not studied this before, they really helped me gain a solid understanding of the topic: kzbin.info/aero/PLiwt1iVUib9s2Uo5BeYmwkDFUh70fJPxX
@segus_faultise
@segus_faultise 9 ай бұрын
Chad
@Lelende
@Lelende 9 ай бұрын
Great content, but difficult to digest. Maybe don't go so in_depth And just get the principle across. People who really want applicable knowledge will do further research anyway
@LowByteProductions
@LowByteProductions 9 ай бұрын
That's the thing, though: I'm making content for people who want to go further. This whole channel is about going in depth because so few others actually do.
@Lelende
@Lelende 9 ай бұрын
@@LowByteProductions I see. I understand. Maybe it maybe be better to have a fairly concise description of everything you plan/explanation to do in the beginning and also go in-depth later to gethr best of both worlds?
Getting up in another processes memory
46:54
Low Byte Productions
Рет қаралды 14 М.
How does KERNEL memory allocation work? //Source Dive// 004
44:42
Low Byte Productions
Рет қаралды 48 М.
КТО ЛЮБИТ ГРИБЫ?? #shorts
00:24
Паша Осадчий
Рет қаралды 3,7 МЛН
Пройди игру и получи 5 чупа-чупсов (2024)
00:49
Екатерина Ковалева
Рет қаралды 4,2 МЛН
Before VS during the CONCERT 🔥 "Aliby" | Andra Gogan
00:13
Andra Gogan
Рет қаралды 10 МЛН
The Magic of RISC-V Vector Processing
16:56
LaurieWired
Рет қаралды 287 М.
What's Virtual Memory? - Computerphile
22:40
Computerphile
Рет қаралды 177 М.
What is a spinlock? //Source Dive// 002
54:26
Low Byte Productions
Рет қаралды 46 М.
How does an OS boot? //Source Dive// 001
50:22
Low Byte Productions
Рет қаралды 409 М.
But, what is Virtual Memory?
20:11
Tech With Nikola
Рет қаралды 262 М.
Signals. I spent 2 years to understand this part.
21:24
kimylamp
Рет қаралды 219 М.
Creator of git, Linus Torvalds Presents the Fundamentals of git
1:10:15
Developers Alliance
Рет қаралды 82 М.
Enter The Arena: Simplifying Memory Management (2023)
1:47:50
Ryan Fleury
Рет қаралды 35 М.
How a Clever 1960s Memory Trick Changed Computing
20:05
LaurieWired
Рет қаралды 335 М.
КТО ЛЮБИТ ГРИБЫ?? #shorts
00:24
Паша Осадчий
Рет қаралды 3,7 МЛН