Why Linux Has This Syscall?!

Ғылым және технология

Source Code: github.com/tsoding/mmap
Here is another lecture style video similar to the previous one. I'm not sure if these kinda videos are watchable, but they liberate me from the chore of video editing which I can't stand anymore, I really apologize for that! The need of editing the video was probably one of the main reasons that demotivated me from uploading here too often. I'm gonna keep doing these types of videos and see how it goes.
The videos are recorded live at my Twitch channel: / tsoding

Пікірлер: 73

  • @greob
    @greob4 жыл бұрын

    Thanks for sharing these stream recordings! I can never join in time for the live streams so I'm very grateful for these uploads. Very interesting and you make things easy to understand. Much respect! :)

  • @leong4847
    @leong48473 жыл бұрын

    I love this type of video! Definitely don't mind the lack of editing, it's great to see the full process

  • @tornikebuchukuri4114
    @tornikebuchukuri4114 Жыл бұрын

    im doing some os stuff rn and was struggling with mmap, this stream really helped

  • @aBamieh
    @aBamieh4 жыл бұрын

    Yay a 2 hours topic discussion! Thanks for uploading, Cheers

  • @ishdx9374

    @ishdx9374

    3 жыл бұрын

    do you have 20 kilograms of

  • @menumenu287
    @menumenu2873 жыл бұрын

    great stuff, high quality, so much knowledge transfer... Thank you; hope you make more videos

  • @dandymcgee
    @dandymcgee4 жыл бұрын

    Thanks for sharing the VOD!

  • @joedavid8662
    @joedavid86623 жыл бұрын

    0:7:43 Allocating Memory 0:25:41 Reading/Writing Files 0:56:21 IPC ( 0:58:52 ) 01:23:56 precise control over memory protection

  • @lordmushroom723

    @lordmushroom723

    6 ай бұрын

    Thanks Joe

  • @AdmiralMaur
    @AdmiralMaur4 жыл бұрын

    ".. but here you have do everything yourself. Like an adult" oof- I fealt that

  • @NinjaScorpio
    @NinjaScorpio4 жыл бұрын

    This is a very smart BBoomer i learn a lot in his streams! I love his "Unity" streams! Keep being awesome KKomrade

  • @mariuszdziem8203
    @mariuszdziem82034 ай бұрын

    Amazing shait ;) Great lecture professor!

  • @ILoveSoImAlive
    @ILoveSoImAlive3 жыл бұрын

    memory map is kind of a table, where system memory areas are "maped" into memory address range of a process. process doesnt have direct access to all the ram. only to the parts of the ram, which are mapped into his memory. the memory adress range of a process is virtual so to speak. sitting inside the sanbox. so you can map any range of system memory into process memory. for example file buffer. so you can read the file inside your process. or you can map a memory range to 2 different processes and use this part of system memory as shared memory between 2 processes. or you can map range of system memory, which ist reserved for hardware buffer into process memory, then your process will be able to access this hardware directly. btw, how do you think it was possible to have 2MB of system memory on a 8bit pc? btw2, most of the system functions are writen based on basic input output system functions. its the first thing you learn, if you do something with assembler.

  • @spandanroy8380
    @spandanroy83802 жыл бұрын

    This is one the best videos I ever saw on KZread

  • @dubbeltumme
    @dubbeltumme4 жыл бұрын

    big thanks for this. Really appreciate those bitesize Makefile tips, had no idea about that wildcards thing. Also best tabbed layout in i3wm.

  • @invokesus
    @invokesus3 жыл бұрын

    wow amazing stuff! Learned a lot.

  • @ynchen
    @ynchen10 ай бұрын

    I absolutely enjoy this video!!

  • @johnnyphoney5669
    @johnnyphoney56694 жыл бұрын

    This video was very useful for me, thank you Mr.!

  • @prayer4675
    @prayer46752 ай бұрын

    Actually this syscall is not Linux only and originally it came from the BSD. So actually it will work at any today's BSD as well. At least I see it in the FreeBSD.

  • @jokerpb4778
    @jokerpb47783 жыл бұрын

    Amazing video thank you so much!

  • @gscacco
    @gscacco2 жыл бұрын

    Great work !

  • @ErikNorlander-go1zv
    @ErikNorlander-go1zv3 ай бұрын

    Great video!

  • @alexandermyasoedov4564
    @alexandermyasoedov45644 жыл бұрын

    Keep it up man! Awesome video!

  • @4aasdaw
    @4aasdaw4 жыл бұрын

    Edit: The current title "Why Linux Has This Syscall?!" shows how misleading English can be. In the current form, this title is a subordinate clause -- a sentence which needs a leading sentence to make sense: - "This is the reason *why Linux has this syscall*" With an addition of a 'do' this subodinate clause turns into an independent question: - "Why *does* Linux *have* this syscall?" In Russian, the present form of a verb is the same form that is used in questions (particularly if we disregard prefective aspects). However, English isn't such a language. It differentiates verb form, sentence ordering and a lot more, even between types of questions (i.e. where/why/what). In the case of the 'why' question: the third person singular simple present form of 'to have' is 'has': - "Linux has this syscall" But, in questions, the active verb is wrapped in a do form ('to do' in respective tense + infinitive verb): - "He goes to school" / "Why *does* he *go* to school?" - "I ate an apple" / "Why *did* I *eat* an apple?" - "Linux has this syscall" / "Why *does* Linux *have* this syscall?" When used to slavic linguistic patterns, where the verb form in statements and questions is not distinguished, it is a bit unusual to place unnecessary constructs like 'do'. Furthermore, this 'do' rule does not apply for all tenses; For example, most passive verb forms in questions do not use do: - "A crime has been investigated" / "Why has a crime been investigated" This is because (oversimplified a bit) the verb has already been wrapped in a supporting construct: the 'has been' passive form. English is full of these redundancies and obscure rules with which you can easily guess the speaker's native tounge, provided you know it. Most of the time, a word-by-word translation to their mother tongue will get you the meaning behind an otherwise unintelligble statement. On a more interesting note: languages, as they age and get more fine-tuned, tend to move information from a single word into more complex structures. For example, in Russian, you can easily omit the subject, and with just the verb form you can tell the perfectiveness (has the action been finished), the subject, the transitivity (existance of an object), etc. In English, there is a lot of legwork getting all this information through as it usually involves many overlapping constructions. A clear example is the use of prepositions in favour of grammatical noun cases like those that Latin has. At first, it is a bit counterintuitive why it'd be easier to split words like this. The real complexity comes not from the amount of words necessary to convey a full meaning, but the mechanisms of forming those words that the speaker uses. If you think about all the productivity noun declensions, verb tenses, position and even intonation have, and the necessary premeditation to put together a meaningful utterance, it becomes clear. I think the same applies for programming languages: reusing short 'idiomatic' code to achieve greatly varying results ends up creating unnecessary illegibility and confusion when reading the code. btw, this type of video is fine by me

  • @smuecke

    @smuecke

    4 жыл бұрын

    I wouldn't say that languages "get more fine-tuned" as they age; I'd argue they're always just as expressive and nuanced as their speakers, but the strategies to express these nuances just tend to shift and change over time.

  • @4aasdaw

    @4aasdaw

    4 жыл бұрын

    ​@@smuecke That's more or less what I meant; they lose in complexity and sometimes even bits of productivity in certain areas, but retain the ability to express the same meaning as before. They also adapt more to the speakers' needs (though you could argue it is the other way round), where some things simply are removed altogether. This would be features such as middle and mediopassive voice or subjunctive moods. Of course, you can still convey a near identical meaning without them, but the strategy you'd use to get there didn't develop from reductions to the archaic forms.

  • @jit_rs

    @jit_rs

    4 жыл бұрын

    why did you spend your time on this comment?

  • @sadcat520

    @sadcat520

    3 жыл бұрын

    Nobody asked

  • @rodsmade
    @rodsmade3 ай бұрын

    Hi, I'm writing my own implementation of malloc/realloc/free and this vod really helped getting into it. Thank you so much! Take care

  • @coffee-is-power
    @coffee-is-power Жыл бұрын

    tsoding is my favorite teacher!

  • @bradocksolo
    @bradocksolo2 жыл бұрын

    Really good video! Thanks

  • @errelin1326
    @errelin13265 ай бұрын

    Probably few universities even teach these. This is AWESOME 🎉❤

  • @marcosconceicao3223
    @marcosconceicao32234 жыл бұрын

    Man, what a good content! Thank you!!!

  • @vysakhanh7878
    @vysakhanh78787 ай бұрын

    thank you, learned a lot!

  • @SekharPariga
    @SekharPariga3 жыл бұрын

    does it possible to do the last example storing stripped hello world code using MALLOC?

  • @josedejesuslopezdiaz
    @josedejesuslopezdiaz2 жыл бұрын

    Your content is amazing! you have a new follower.

  • @jacobscrackers98
    @jacobscrackers984 жыл бұрын

    1:53:50 What is up with the top line of the hex editor? That address is way too big to fit in the 51-byte file. What gives?

  • @DantevanGemert

    @DantevanGemert

    3 жыл бұрын

    If you're still wondering after 4 months (probably not but who knows who else might be confused): it's the header, showing what the values correspond to (87654321 and 0123456789abcdef). They're not actual values.

  • @yuriykhodak6299
    @yuriykhodak6299 Жыл бұрын

    you are good, man

  • @qerdcv
    @qerdcv2 жыл бұрын

    Hello! And welcome to another Tsoding session. How about that?

  • @nigmar957
    @nigmar9573 жыл бұрын

    Спасибо за видео)

  • @bitshift264
    @bitshift2642 жыл бұрын

    Great stream! Thank you!

  • @michaelutech4786
    @michaelutech47863 ай бұрын

    "This is probably why you shouldn't use mmap directly" - No. Mmap actually works on most if not all Unix-like systems and Windows has something close enough. The reason why you should not use mmap for memory allocation is because it the process of allocating memory from the kernel is probably more expensive than the task you are doing with that memory. Malloc works by allocating a big chunk of memory and then providing what you ask for. So f.e. you ask for 80 bytes, malloc allocates 1M and has enough memory to answer the next 50-1000 requests efficiently. Free is not necessarily returning memory to the system, it just marks it as usable for future malloc calls. You want to use mmap in favor of using sbrk, because using sbrk will mess with the stdc-c library (or any runtime you might use). You want to use it in favor of using malloc if you have a long running task in need of memory that you either need to control (f.e. exec code) or in some other fringe use case where malloc doesn't work or is inefficient (which next to never happens, unless you're writing a jit compiler). The problem with sbrk is that it increases the linear address space of the process. That was the only way how a process could get more memory in ancient UNIX. It's similar to what happens if you dynamically increase the memory of a virtual machine. Mmap solved this, by allowing a process to obtain access to memory outside of the linear address space that is assigned to a process at creation time. Sbrk is basically a DOS way of allocating memory ("extended" or "expanded" memory?).

  • @oliverscott6421
    @oliverscott64213 жыл бұрын

    How does your manpage search work?

  • @frederickwinter1823
    @frederickwinter18234 жыл бұрын

    Is there a Linux syscall for allocating disk space?

  • @uglyoldbob

    @uglyoldbob

    4 жыл бұрын

    open?

  • @xaro6132
    @xaro61322 ай бұрын

    I was thinking when i saw the video, damn tscoding got rich and fat uwu. But i saw the video is 4 years old. Sorry for your loss

  • @DanDart
    @DanDart3 жыл бұрын

    11:18 best moment

  • @alexisfrjp
    @alexisfrjp4 жыл бұрын

    mmap is used to map physical memory to virtual memory. more in embedded system.

  • @Heater-v1.0.0

    @Heater-v1.0.0

    10 ай бұрын

    What? Most embedded systems I have worked on don't have virtual memory support in their processors and hence no mmap.

  • @tatterdemalion898
    @tatterdemalion8982 жыл бұрын

    from byte -> kb -> mb -> gb etc. you multiply with 1024 not 1000 :D

  • @AlguienMas555
    @AlguienMas555 Жыл бұрын

    Awesome

  • @michaelutech4786
    @michaelutech47863 ай бұрын

    "single purpose [..] go away" - That's a bit unfair. System calls are not application programming interfaces, they are the interface between the kernel and processes. The guiding principle for this kind of interface is to minimize the number of interactions between kernel and user space, because that interaction is expensive. Another guiding principle for this interface is to be stable, don't change, be as general as possible. You're supposed to use malloc, because that's designed to be an api and that's actually observing the single purpose principle (malloc(size) -> memory).

  • @alrshdn

    @alrshdn

    2 ай бұрын

    Good take. I definitely agree that for less system calls, you would need functions that do many things. But I would still argue that single purpose functions are more stable and require less change in the future, thus complying to the standard would be easier for the OSes. So I would agree with the first guiding principle, but it would definitely make the goal of second principle be harder to achieve. This is because it is harder to not have to change a huge function in the future.

  • @michaelutech4786

    @michaelutech4786

    2 ай бұрын

    @@alrshdn I see the point regarding ease of change, but again, this is not something that is very relevant in this environment, because kernel interfaces (syscalls) rarely if ever change. System calls look a lot like any other API, but they are in fact not. They are designed to be used by system libraries (as in libc). That does not mean that you can't use them, it only means that usability in their design is not tuned to the ease of use but instead focusses on performance and stability of kernel and user space (as opposed to library/developer or system/user). A system call change is a catastrophic event. Otherwise there would not be things like "cgroup2".

  • @user-it8yh8tu7d
    @user-it8yh8tu7d3 ай бұрын

    I think its cute when I forget that just as I am weak on graphics programming graphics programmers are weak on kernel programming.❤

  • @DanDart
    @DanDart3 жыл бұрын

    16:09 is that your professional opinion?

  • @jacobscrackers98
    @jacobscrackers984 жыл бұрын

    1:08:50 Why use assert here()? If N == 1 then the for loop will be skipped because i 1 assert doesn't fix anything here, in fact it breaks something.

  • @andrewlankford9634
    @andrewlankford96346 ай бұрын

    Software evolves to work with new hardware. Hardware evolves to make better software. Some hardware problems problems provoked software people to find workarounds for slow hardware.

  • @2003vito
    @2003vito4 жыл бұрын

    has*

  • @MsDuketown
    @MsDuketown2 жыл бұрын

    lol, yeah the world behind the compiler...

  • @teenspirit1
    @teenspirit18 ай бұрын

    wow fat tsoding existed??

  • @davidprock904
    @davidprock9044 жыл бұрын

    I'm working on my own OS on my own architecture, just realized what you said there is no difference about allocation of memory and a file. That is true with my system, also my system is IMPOSSIBLE to have a buffer overflow, and has a Physical switch, if its off, then no assembly / machine instructions can be changed or added... or removed, they can still run thow...but everything else can be modified... the perfect level of protection! Bring it on all you worms out there lol,, those couldn't run on my system anyway

  • @totlajos587
    @totlajos5872 жыл бұрын

    What make great programmer is it IQ or something else?

  • @yunusozd

    @yunusozd

    Жыл бұрын

    practice

  • @cobbcoding

    @cobbcoding

    10 ай бұрын

    The 3 P's of programming: practice, patience, and programming socks.

  • @PLAYGAME-wj9bw

    @PLAYGAME-wj9bw

    8 ай бұрын

    ​@@cobbcodinghahaha

  • @ac130kz
    @ac130kz4 жыл бұрын

    !ban UB lmao

  • @andrewdunbar828
    @andrewdunbar8285 ай бұрын

    Why questions are asked funny?

  • @sadcat520
    @sadcat5203 жыл бұрын

    This was a really good and informative videos but all the mouth sounds were so annoying...

  • @sharpfang
    @sharpfang5 ай бұрын

    I'm baffled at this question. I'm not going to spend 2h to satisfy my curiosity why the author is surprised by mmap, but honestly the standard ways to access file look more suitable for some sort of tape memory where all the lseek calls rewind or fast forward the tape and read acts as play button. Mmap is a much more natural way to access files on a random access medium, you get the pointer to the first byte of the file and you can read, modify, move whatever you want wherever you want in any order just like you were operating on a mmalloc'd chunk of memory. Then you commit the changes and the file is what you wanted it to be. You can even mmap /proc/kmap as root and have unrestricted access to the entire RAM. Mmap is so easy, so convenient, so straightforward and obvious I'm completely stumped why anyone would ask 'why'.

  • @darkshadow5891
    @darkshadow58918 ай бұрын

    is this live stream is real. i dont thing so its real elon expretion not match with the voice.

Келесі