Let's read the Linux socket source code

  Рет қаралды 3,151

Ants Are Everywhere

Ants Are Everywhere

Жыл бұрын

In this live stream, we look at the source code for Linux's implementation of the Berkeley socket API. We also look at "socks" (no "et"), which seem to contain the lower-level implementation details for "sockets".
In a now time-honored tradition, I confuse the right and left shift operators. And @Raxneff Nextnerf and others help me out with some of the thornier details in the code.
Along the way, we take a detour to learn a bit about how to optimize C structs for cache locality.
Useful links:
- Socket.h: github.com/torvalds/linux/blo...
- Socket.c: github.com/torvalds/linux/blo...
- Sock.h: github.com/torvalds/linux/blo...
- Sock.c: github.com/torvalds/linux/blo...
Related videos:
- Linux kernel: • Let's read the Linux k...
- TCP: • Let's read the Linux T...
Sorry about the harsh sound on this video, I accidentally plugged my microphone into the wrong channel 🤦‍♂️.
Thanks for watching :)
‪@raxneff‬ put together the following timeline:
00:00:15 What this live show is about
00:03:28 socket.c
00:05:06 includes in socket.c
00:07:30 opening files
00:13:44 socket address families in socket.h
00:15:35 protocol families in socket.h
00:16:25 flags for send/recv in socket.h
00:17:13 setsockoptions level in socket.h
00:11:54 basic functions in socket.h
00:18:33 sockaddr in socket.h
00:19:32 sockaddr_storage in socket.h
00:20:02 msghdr in socket.h
00:24:06 Linux socket API
00:26:35 for_each_cmsghdr in socket.h (PLEASE, do not touch)
00:29:04 msg_data_left in socket.h
00:32:04 control message types in socket.h
00:32:49 recvmsg in socket.h
00:35:36 sendmsg lookup man page
00:38:49 What I think sock.h is about
00:39:23 includes in sock.h
00:40:34 SOCK_DEBUG in sock.h
00:41:04 socket_lock_t sock.h
00:42:59 sock_common struct in sock.h
00:49:22 SO_REUSEADDR lookup
00:43:10 for what the unions are used
00:53:03 tcp timewait lookup
00:55:51 sock.h (cont.)
00:56:07 sock structure in sock.h
00:58:45 we are in lower level land
01:02:11 sound issues
01:04:04 How ordering of elements in structs can help performance
01:09:18 back in sock.h
01:10:13 optimisation in sock.h and Google QUIC
01:15:04 CPU caches
01:22:09 further stuff in sock.h
01:23:11 sk_page_frag ... in sock.h
01:23:50 sk_pacing_shift_update and right-shift for ms
01:31:13 socket.c
01:32:30 file_operations ... in socket.c
01:34:22 spinlock in socket.c
01:34:40 support routines and audit_sockaddr in socket.c
01:35:17 sockfs_dname in socket.c
01:36:38 sock_alloc_file in socket.c
01:38:48 sock_sendmsg in socket.c
01:39:17 Linux Security Modules
01:39:53 socket.c (cont.)
01:40:35 __sock_recv_timestamp and more in socket.c
01:43:01 sock.c
01:43:03 includes in sock.c
01:45:20 sk_clear_memalloc in sock.c
01:46:26 timeout, netstamp, ... -stuff in sock.c
01:47:53 sk_setsockopt in sock.c
01:52:21 static_branch_unlikely lookup
01:56:45 outro and what comes next

Пікірлер: 19
@nikitapapkov4385
@nikitapapkov4385 Жыл бұрын
Wow, this is so cool! I'm happy I found this channel by chance! I've wanted to study the source code of these projects for a long time, but never managed to find the time for it. Thank you!
@ants_are_everywhere
@ants_are_everywhere Жыл бұрын
Thank you so much :-D and welcome!
@amikomalania3406
@amikomalania3406 Жыл бұрын
Great videos! You got yourself a new subscriber. It'd be great to do more linux kernel related videos. Can't wait to see more of those.
@ants_are_everywhere
@ants_are_everywhere Жыл бұрын
Thank you and welcome! We'll definitely keep coming back to the kernel :)
@sillybuttons925
@sillybuttons925 Жыл бұрын
Love these
@ants_are_everywhere
@ants_are_everywhere Жыл бұрын
Thank you!
@XenoZeduX
@XenoZeduX Жыл бұрын
nice
@ants_are_everywhere
@ants_are_everywhere Жыл бұрын
Thanks!
@voidsifr
@voidsifr Жыл бұрын
This is pretty cool. Would you ever consider going through libssh2 or openssh?
@ants_are_everywhere
@ants_are_everywhere Жыл бұрын
Yeah sure! Probably OpenSSH since I think that's most widely used. That's a great idea, thank you.
@lefigo182
@lefigo182 Жыл бұрын
thanks youtube algorithms, thanks.
@ants_are_everywhere
@ants_are_everywhere Жыл бұрын
haha, welcome!
@DmitriyKopylenko
@DmitriyKopylenko Жыл бұрын
Please do Git source code
@ants_are_everywhere
@ants_are_everywhere Жыл бұрын
Will do!
@firstnamelastname8790
@firstnamelastname8790 Жыл бұрын
Great video. I'm curious, did you choose to leave google? If so, why?
@ants_are_everywhere
@ants_are_everywhere Жыл бұрын
Thanks! I did choose to leave Google. It's a great place to work, but I left because I've got some stuff I want to build.
@raxneff
@raxneff Жыл бұрын
I think you have to add a 00:00:00 intro timestamp on the beginning of the list, so that the video timeline gets split into sections. Maybe its necessary to add "Chapters:" above that. That's how it is in the tutorial: kzfaq.info/get/bejne/mJd2osJ-xNrOZqs.html Additionally, there is a “Allow automatic chapters" setting in KZfaq Studio under "video settings"
@ants_are_everywhere
@ants_are_everywhere Жыл бұрын
Thanks! It turns out I just had an extra space before the first entry, so KZfaq didn't realize it was a list of timestamps. It should work now.
Let's read the Stack (Haskell) source code
2:22:49
Ants Are Everywhere
Рет қаралды 748
Let's read the Linux TCP source code
1:29:22
Ants Are Everywhere
Рет қаралды 75 М.
Эффект Карбонаро и нестандартная коробка
01:00
История одного вокалиста
Рет қаралды 10 МЛН
小蚂蚁被感动了!火影忍者 #佐助 #家庭
00:54
火影忍者一家
Рет қаралды 28 МЛН
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 108 МЛН
The Superpower of Unix Sockets
1:20:00
Simon Racz
Рет қаралды 4,3 М.
Understanding the Structure of a Linux Kernel Device Driver
58:30
Sergio Prado
Рет қаралды 39 М.
GNU Hurd: Let's read the code!
1:12:09
Ants Are Everywhere
Рет қаралды 1 М.
OOP in Pure C
2:00:13
Tsoding Daily
Рет қаралды 70 М.
Basics of UNIX Sockets - Screencast by Mischa Spiegelmock
52:46
JetBridge - Elite Software Devs
Рет қаралды 19 М.
The Tragedy of systemd
47:18
linux.conf.au
Рет қаралды 1,1 МЛН
The Linux socket API explained
15:21
Chris Kanich
Рет қаралды 34 М.
How to Write a Socket Server with Thread Pools & Epoll!
1:13:18
hoff._world
Рет қаралды 2,1 М.
Solving distributed systems challenges in Rust
3:15:52
Jon Gjengset
Рет қаралды 222 М.
$1 vs $100,000 Slow Motion Camera!
0:44
Hafu Go
Рет қаралды 29 МЛН
Looks very comfortable. #leddisplay #ledscreen #ledwall #eagerled
0:19
LED Screen Factory-EagerLED
Рет қаралды 12 МЛН
Какой ноутбук взять для учёбы? #msi #rtx4090 #laptop #юмор #игровой #apple #shorts
0:18
iPhone 15 Pro в реальной жизни
24:07
HUDAKOV
Рет қаралды 494 М.