I built my own memory profiler (in Rust, on Linux)

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 มิ.ย. 2024
  • To try everything Brilliant has to offer-free-for a full 30 days, visit brilliant.org/fasterthanlime
    The first 200 of you will get 20% off Brilliant’s annual premium subscription.
    This video was sponsored by Brilliant.
    Follow me on Mastodon: hachyderm.io/@fasterthanlime
    Support me on Patreon or GitHub: fasterthanli.me/donate
    Source code for the memory visualizer: github.com/fasterthanlime/mevi
    "The Linux Memory Manager" book (Lorenzo Stoakes): linuxmemory.org/
    (Reference continue below)
    Contents
    00:00 Intro
    01:09 Memory fragmentation explained with cars
    02:26 Virtual memory 101
    06:10 Observing simple programs with mevi
    10:30 Sponsored segment (real)
    11:33 Why does this Rust program leak memory, visualized
    13:30 mevi is Rust on the front & back
    15:40 userfaultfd: the reason why mevi works (slowly)
    18:13 The hard bits
    21:06 Some bigger programs seen through mevi
    22:15 Y'all are so good to me
    More references
    The Quest for Netflix on Asahi Linux (David Buchanan): www.da.vidbuchanan.co.uk/blog...
    Making our own executable packer: fasterthanli.me/series/making...
    Swiss Tables Design Notes (Abseil): abseil.io/about/design/swisst...
    SwissTable CppCon talk (Matt Kulukundis): • CppCon 2017: Matt Kulu...
    Live migration: en.wikipedia.org/wiki/Live_mi...
    Chromium’s Zygote process: chromium.googlesource.com/chr...
    bytehound memory profiler: github.com/koute/bytehound
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 115

  • @fasterthanlime
    @fasterthanlime  ปีที่แล้ว +27

    To try everything Brilliant has to offer-free-for a full 30 days, visit brilliant.org/fasterthanlime
    The first 200 of you will get 20% off Brilliant’s annual premium subscription.

    • @mzg147
      @mzg147 ปีที่แล้ว +7

      Yes!! Go get that sponsors boyy

    • @PaulFisher
      @PaulFisher ปีที่แล้ว

      Stack that paper baby

  • @aleksandermirowsky7988
    @aleksandermirowsky7988 ปีที่แล้ว +254

    Honestly, every one of your videos always feel like a blessing. It's reminiscent of a sage descending from the mountains to share his sacred knowledge with the village folk.

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว +82

      I see myself more like a fool tumbling down the hill every so often to bestow the curse of knowledge upon others, but I think the idea is roughly the same!

    • @charetjc
      @charetjc ปีที่แล้ว +3

      @@fasterthanlime You have an amazing ability to digest all you learned into a concise, interesting, and easy-to-follow manner. This video is excellent.

  • @JheregJAB
    @JheregJAB ปีที่แล้ว +67

    every one of your videos up until now has been right on the perfect edge of "I understand, but we're stretching it". I've got to be honest, this one managed to get over my head. That's not bad, its a challenge. Gonna have to rewatch it a couple times and do some extra research on top of it, I think.

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว +14

      Thanks for the feedback! That video definitely warrants at least a couple follow-ups, I have unscripted ideas that I think could be neat. Gotta change it up a little, those videos are an enormous amount of work.

  • @abiiranathan
    @abiiranathan ปีที่แล้ว +36

    PHD-esque stuff. Mind-blowing 🤯

  • @dnullify100
    @dnullify100 ปีที่แล้ว +23

    Your content is the absolute nexus of production quality, content quality, and approachability. The thoughtful and smooth crescendo of complexity that keeps one engaged for the whole video/story.

  • @multispectrum
    @multispectrum ปีที่แล้ว +24

    This was absolutely fantastic. A follow up video or resources to explain things in more detail for people who don't have much low level experience would also be great.

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว +2

      I have a couple in mind, but can you give me a few areas in particular you'd like cleared up?

    • @multispectrum
      @multispectrum ปีที่แล้ว +6

      ​@@fasterthanlime Again, fantastic work, you're a really great teacher. Watching it again, I wrote down things that I have questions on. There are definitely resources on most of things available and I have a good place to start learning from now. The largest gap in available resources to me seems like eBPF.
      What defines the memory sections (ro, rw, re)? (Making our own executable packer is on my list to read yet.)
      TLB makes sense for virtual->physical, but what does walking the page table mean? (Also how does the TLB cache recent memory accesses? Is there a large performance hit to TLB misses? And can the TLB only work for a single process at a time? How does flushing work?)
      What exactly is a page fault? What is stack/heap, and how to they relate to syscalls (break, mmap, madvise, etc)? Does madvise just allow the kernel to remove pages from the resident memory, but they're still in the virtual memory?
      What is malloc, malloc_trim, calloc, realloc, free, and how do they relate to syscalls, heap, virtual address space, etc?
      With your mention of eBPF I lost all understanding of what eBPF is. I thought that it was only for packet manipulation and statistics collection on network traffic. A video on eBPF would be awesome.
      Everything after ~18:00 I was completely lost. That could probably take a decade of learning. (ptrace, userfaultfd, what is a fd?, what's a setuid binary, self-tracing processes, PID namespaces, seccompbpf?)

  • @sambazeley5366
    @sambazeley5366 หลายเดือนก่อน

    I watched this video all the way through assuming that this was another big programming channel. I was surprised to see how small your channel is. There is so much quality!

  • @SamSargent-kh7gl
    @SamSargent-kh7gl ปีที่แล้ว +6

    It's such a relief that people like you make content for us like this. This is exceptional, cheers.

  • @lejee_
    @lejee_ ปีที่แล้ว +5

    great video, as always :)
    btw. nice seeing you have a (real) sponsor now!

  • @FryuniGamer
    @FryuniGamer ปีที่แล้ว +3

    "My previous video about this was, in fact, correct. I was as shocked as you are"
    I wish I had that confidence, but even more I wish I was at the level of saying such a thing.

    • @walksanator
      @walksanator หลายเดือนก่อน

      Thats not co fidence though...

  • @artifishul
    @artifishul ปีที่แล้ว +13

    Love this content. Thanks for all the work you put in to explain this so well

  • @kehaarable
    @kehaarable ปีที่แล้ว +1

    Your videos are great.
    I was looking for some rust videos when I stumbled upon them. I've been programming for about 20 years so most videos are painfully slow.
    Your videos always touch on subjects that I've never had to deal with. I've not learnt a huge amount of rust, but my understanding of how systems actually work has grown a lot, and enticed me to think more about the tools I take for granted every day and to think about in earnest how I would build them.
    So thank you!

  • @louisfifteen
    @louisfifteen ปีที่แล้ว +1

    "This town aint big enough for both of us" by "The Sparks" The one playing the piano is what this guy reminds me off. They were brilliant and so is he.

  • @ahuggingsam
    @ahuggingsam ปีที่แล้ว +1

    as always I'm gonna have to go over some of this stuff multiple times, but I'm learning so much. Thanks for making these videos Amos, I doubt I could clearn about this stuff without someone like you making it engaging.

  • @meegleeto
    @meegleeto ปีที่แล้ว +2

    I can't believe the "this video is sponsored by" bit actually paid off

  • @zperk13
    @zperk13 ปีที่แล้ว +3

    Congrats on getting sponsored!

  • @nindalf
    @nindalf ปีที่แล้ว

    Fantastic video, thank you for making it.
    I'd love to see a video of using mevi to optimise existing programs.

  • @driedurchin
    @driedurchin ปีที่แล้ว +4

    This video exposes a lot of "false dogma" IMO. You traditionally hear the simple explanation of the cost of dynamic vectors, usually saying something like "if a push exhausts the capacity, you have to reallocate and copy everything over", which is *morally* true, and maybe was *actually* true 20 years ago. Nowadays, on modern OSes its interesting to see how it's not the case. Yet another reason to never preemptively optimize. Measure first!

  • @desuburinga
    @desuburinga ปีที่แล้ว

    Amazing video, like everyone else mentioned, absolutely mind blowing stuff! Keep up the great work and congrats on the sponsorship!

  • @Dygear
    @Dygear ปีที่แล้ว +1

    Crushed it again Amos! So many things to try this out on!

  • @nikandfor
    @nikandfor ปีที่แล้ว

    Super cool! I love the observability, and this is the next level!

  • @appelnonsurtaxe
    @appelnonsurtaxe ปีที่แล้ว

    That was both interesting and very enjoyable to watch! Thanks a lot for making these videos.

  • @kickeddroid
    @kickeddroid ปีที่แล้ว +4

    What's crazy is I looked this up earlier this morning, taking a break now and watching youtube I see this lmao

  • @flippert0
    @flippert0 5 หลายเดือนก่อน

    While way over my head for now, this feels amazing! One day, I might be able to understand what's going under the hood.

  • @jorgeosorio1613
    @jorgeosorio1613 10 หลายเดือนก่อน

    this video was great, I loved the introduction.

  • @employee9911
    @employee9911 ปีที่แล้ว

    Really enjoy content like this

  • @Onkoe
    @Onkoe ปีที่แล้ว

    I love these videos! I’d happily watch a one or two hour version.
    I have ADHD, so your articles are a lot harder for me, but these videos are perfect!!!

  • @OhadLutzky
    @OhadLutzky ปีที่แล้ว +1

    Excellent job, and congrats on the sponsor!

  • @simonfarre4907
    @simonfarre4907 ปีที่แล้ว +3

    You haven't looked at RR code base before? A lot of this stuff's in there, although, your project I think is a better source to learn this stuff from since it's probably smaller in scope (and it's in Rust, RR is written in C++). But you've got the sending of fd's over a socket, the injection of syscalls, etc and all that really cool Linux stuff.

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว

      I've never cracked rr open (but I've used it a couple times!) but I 100% trust you on that. mevi definitely makes for a smaller surface to study, and you can always drop into some of the crates it uses if you're interested in a specific abstraction!

  • @patryk6769
    @patryk6769 ปีที่แล้ว +1

    Thank you Brilliant for sponsoring this video ❤

  • @craigcraig6248
    @craigcraig6248 ปีที่แล้ว

    Wow, great video. Im glad i found this channel.

  • @gruelingpine1857
    @gruelingpine1857 7 หลายเดือนก่อน

    this is pretty cool! Your profile pic reminds me of the scrap metal artist from the Iron Giant

  • @fluffy_tail4365
    @fluffy_tail4365 ปีที่แล้ว

    Incredible video as usual

  • @MrMariy0
    @MrMariy0 ปีที่แล้ว

    very interesting, as always!

  • @bakabaaka2681
    @bakabaaka2681 ปีที่แล้ว

    Damn... Great video man.

  • @johanngambolputty5351
    @johanngambolputty5351 ปีที่แล้ว +1

    Not sure I understood any of that, but I was impressed ;)

  • @flyingsquirrel3271
    @flyingsquirrel3271 ปีที่แล้ว

    I'm so happy that you casually use the term "kibibytes" :D
    (I had this discussion a few times with unteachable people...)

  • @jackevansevo
    @jackevansevo ปีที่แล้ว

    Blown away by every single one of these videos

  • @asadullahfarooqi254
    @asadullahfarooqi254 ปีที่แล้ว

    yo brah it was amazing, can't wait to see the eBPF :)

  • @gpugpugpu
    @gpugpugpu 8 หลายเดือนก่อน

    Another fire fasterthanlime video let’s GOOOOOOOOO

  • @__mrmino__
    @__mrmino__ ปีที่แล้ว

    Technically sections in an ELF don't need padding. The section header contains the size field, the loader in the kernel can just load the non-zero stuff and leave the rest. Filling ELF section with zeroes ensures that the page is also filled with zeroes, instead of garbage. It has nothing to do with page alignment.
    The virtual *adresses* still need to be page aligned though, as most MMUs don't support setting memory attributes on anything other than a whole page.

  • @chylex
    @chylex ปีที่แล้ว

    I love the visualization of memory allocations

  • @clo4
    @clo4 ปีที่แล้ว +1

    Yooo get that bag! Good job Amos!!

  • @zperk13
    @zperk13 ปีที่แล้ว +2

    Thanks for captions!

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว +1

      Thanks! I used Whisper for these but even then it's a solid 2.5x-the-runtime of manual cleanup/sync work :)

  • @TobiasFrei
    @TobiasFrei ปีที่แล้ว +1

    Oh, these great contributions of yours. You *do* have an impact on the way I think about- and write Rust.
    Looking forward to some eBPF. Will you go the Aya way? 🤓🐝

    • @TobiasFrei
      @TobiasFrei ปีที่แล้ว

      Or no. It won't be the Aya way. Just as likely you're gonna roll it yourself 😋

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว +1

      I've naturally looked at Aya since I've used it before for networking, but I'm unsure whether it'll do the job for that project. Time will tell!

  • @oyewodayo
    @oyewodayo ปีที่แล้ว

    You're a good teacher. You explain things differently, even a 2 years old kid will understand anything you explain.

  • @Otakutaru
    @Otakutaru ปีที่แล้ว +3

    I didn't expect the linux kernel to be so fiddly. Is everything related to low level OS that challenging? For example, memory management on windows? Because I got scared

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว +8

      I think the short answer is yes. But the good news is that it's "knowable", and then you slowly change from feeling intimidated by it to feeling irritated by it at times 🙃

  • @JustAnotherLight
    @JustAnotherLight ปีที่แล้ว

    At the beginning of the video, I thought Brilliant's starting a Rust course!

  • @pkoch
    @pkoch ปีที่แล้ว +1

    If only my OS class was this good. ❤

  • @bowarc
    @bowarc ปีที่แล้ว

    Rly cool, keep up the content, it's really interesting l!

  • @musikosv
    @musikosv ปีที่แล้ว

    Very interesting, thanks for sharing!"

  • @ExCyberino
    @ExCyberino ปีที่แล้ว

    rm -rf = rename --recursive --flawlessly
    Basically solves the slash problem in all files

  • @user-ed5qx1ih3i
    @user-ed5qx1ih3i ปีที่แล้ว

    Your doctor is great!

  • @Vampirat3
    @Vampirat3 ปีที่แล้ว

    @fasterthanlime , you get mad respect.
    great video thank you.

  • @YTCrazytieguy
    @YTCrazytieguy ปีที่แล้ว

    Yay sponsorship!

  • @DarrienGlasser
    @DarrienGlasser ปีที่แล้ว +1

    Buses and trains don’t exist in that universe
    I didn’t know you visited America recently :o

  • @heyiamigor
    @heyiamigor ปีที่แล้ว

    Could you please share your code editor setup? I saw you using VSCode and vim extension, what other configs/extensions do you use? Thx!

  • @brazni
    @brazni ปีที่แล้ว

    17:29 Don't tell me what to do magic mind reading slides!

  • @Leik000
    @Leik000 ปีที่แล้ว +1

    Going from "sponsored by coffee" to "sponsored by Brilliant". TH-cam achievement unlocked.

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว +1

      All that caffeine finally paid off!

  • @bxnny0374
    @bxnny0374 ปีที่แล้ว

    Have nothing to say, just commenting to help this video out so more people can see it :) insanely high quality

  • @CramBL
    @CramBL ปีที่แล้ว

    Great video. What's the website you use for making those sketches at @3:11 for example?

  • @oyewodayo
    @oyewodayo ปีที่แล้ว

    Please do a series on Axum indepth.

  • @MateuszWykurzIsAwesome
    @MateuszWykurzIsAwesome ปีที่แล้ว

    Thanks!

  • @EricTorreborre
    @EricTorreborre ปีที่แล้ว +1

    Your videos are always mind-blowing, not only for their content but also for the quality of the presentation. Kudos!

  • @fulgorete
    @fulgorete ปีที่แล้ว

    This is not a trivial subject. Good work overall

  • @versacebroccoli7238
    @versacebroccoli7238 ปีที่แล้ว +2

    It's so crazy that the minimum memory a program can allocate (4k) used to be sold as high end ram sticks.
    I was reading a comment on some other tech video and a person said their computer could have up to 20 4k ram cards. But that would take all their expansion slots.

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว

      It was another time, for sure! From devblogs.microsoft.com/oldnewthing/20200728-00/?p=104012
      Huge pointers could refer to memory blocks larger than 64KB by adjusting the segment whenever the offset overflowed.¹ Pointer arithmetic with huge pointers was computationally expensive, so you didn’t use them much.²

  • @Verrisin
    @Verrisin ปีที่แล้ว

    so, do we see if Firefox is leaking memory in the "third way" ? That would be a cool thing to find out after the effort.

  • @Verrisin
    @Verrisin ปีที่แล้ว

    damn, ok, growing a Vec looks a LOT nicer than something like ArrayList in JVM, which I think DOES copy the array.
    - I might be wrong and it does some magic behind the scenes, but this looks beautiful ...

  • @kasvith
    @kasvith ปีที่แล้ว

    Can you do Zig vids as well

  • @kowalkem
    @kowalkem ปีที่แล้ว

    Missed opportunity here - should have been built on Gentoo or at least Arch 😉
    In all seriousness - massive thumbs up 👍

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว +1

      Oh I've served my time in both the Gentoo & ArchLinux jails, I'm free now, I can use Ubuntu and still have street cred 😎

  • @m4rt_
    @m4rt_ ปีที่แล้ว

    could you make a thing like RemedyBG... but for linux?

  • @sammay1540
    @sammay1540 ปีที่แล้ว

    Gold

  • @focusEngineered
    @focusEngineered ปีที่แล้ว

    AMAZING

  • @as-qh1qq
    @as-qh1qq ปีที่แล้ว

    This is way above my pay grade.

  • @thepetesmith
    @thepetesmith ปีที่แล้ว

    I’d like to see faster than lime’s car.

  • @mint_fresch4329
    @mint_fresch4329 7 หลายเดือนก่อน

    imagin u#r talking about linux kernel very basic/complex stuff and get an normal sponsor xD, bro u made it xD

  • @jeffg4686
    @jeffg4686 ปีที่แล้ว

    nice

  • @Verrisin
    @Verrisin ปีที่แล้ว

    I wonder if this needed so much unsafe code, it would have been easier to write in Zig ? Probably not, but I wonder. (and yes, it would probably not share code with browser)
    - Also, I have zero clue how one would even research all the documentation to make all this crazy stuff work ...
    - How to even figure out all the magic kernel stuff? And how to do it from something other than C ?
    EDIT: 22:22 - I see. So that's how! Naruhodo.

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว

      I've seen that same "we switched from unsafe Rust to Zig" article that you have, but in that case, no, Rust was plenty comfortable, thanks to a wealth of crates that exposed all the system interfaces I wanted :)

    • @Verrisin
      @Verrisin ปีที่แล้ว

      @@fasterthanlime hehe, yup. - Awesome to know! - It's good to know it can be abstracted away into a safe crate.

  • @Dragon-xd4ru
    @Dragon-xd4ru ปีที่แล้ว

    Keep making more videos pls 🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

  • @sudiproy4413
    @sudiproy4413 8 หลายเดือนก่อน

    😨 18:13

  • @gakman
    @gakman ปีที่แล้ว +1

    lol "Stop reading these slides and pay attention"

  • @rotteegher39
    @rotteegher39 ปีที่แล้ว

    Everytime you say "Mevy" I hear "Bevy" instead (rust game engine)

  • @justaguy1299
    @justaguy1299 ปีที่แล้ว +1

    This made me think about a video about the same topic I saw a while ago, there they made a tool that compacts the fragmented memory pages of a process. Might be an interesting watch th-cam.com/video/c1UBJbfR-H0/w-d-xo.html

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว

      Yes! I've been meaning to talk about MESH - anything Emery Berger is involved in is sure to be fascinating :)

  • @xmeo209
    @xmeo209 5 หลายเดือนก่อน

    I have no idea what this man says, but its very uhm.. interesting?

  • @muneebdev
    @muneebdev ปีที่แล้ว

    "a lesser man"

  • @kaioh33
    @kaioh33 ปีที่แล้ว +3

    Pagliaci joke😂😂😂

  • @motbus3
    @motbus3 หลายเดือนก่อน

    For a month? Hummm...

  • @victorfds
    @victorfds ปีที่แล้ว

    I don't understand 7 in each 10 words you say.

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว

      Is my pronunciation that bad?

    • @victorfds
      @victorfds ปีที่แล้ว

      @@fasterthanlime absolutely not. I have a little bit knowledge about low level programming. The topics looks so deep that I can't get it.

    • @fasterthanlime
      @fasterthanlime  ปีที่แล้ว +1

      I have quite a few videos about that but I've been slowly figuring out how to do more accessible videos with a tighter scope. I'll get it right someday!