Тёмный

Linux Technical Debt: A Visual Explanation (Directory Entries/struct dirent) - Jody Bruchon Tech 

Jody Bruchon
Подписаться 40 тыс.
Просмотров 753
50% 1

Опубликовано:

 

25 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 27   
@Error42_
@Error42_ 3 месяца назад
I have noticed on Linux dumping a listing of many files and folders to a text file seems much slower than it is to do on Windows. I was wondering why that would be the case, perhaps this explains it to some degree. This is even noticeable on an SSD.
@JodyBruchon
@JodyBruchon 3 месяца назад
@@Error42_ That depends heavily on how you're doing it. Some ways can result in massive forking or reopening. I'd do it with find -type f > list.txt But you can extremely slowly do it with find -type f | while read -r X; do echo "$X" >> list.txt; done This will cause every entry to open, seek, write, and close, and if echo isn't a shell builtin it'll also cause a fork-exec every time too.
@mathis8210
@mathis8210 3 месяца назад
Love the professionalism of just scribbling the stuff down chaotically on a paper. :)
@okaravan
@okaravan 3 месяца назад
Many years ago I searched for a good software for technical drawing, and after a long search came to conclustion, that it doesn't exist. Nothing surpasses a piece of physical paper with a pencil and an eraser. And the process of physical drawing activates technical imagination like nothing else do.
@bossu2005
@bossu2005 Месяц назад
looks like the struct layout may be due to legacy linux kernel code to save space
@s.b.8704
@s.b.8704 3 месяца назад
“Technical debt” is an understatement: more than not having a name length field, there is no reason in 2024 to have to deal with an API that exposes all these details as if we didn't have optimizing compilers capable to optimize away the abstractions needed to hide these implementation details (opaque types).
@JodyBruchon
@JodyBruchon 3 месяца назад
I don't understand what you're trying to say.
@s.b.8704
@s.b.8704 3 месяца назад
@@JodyBruchon if the structure was an opaque data type, accessible only via functions, one could change the implementation of the string (also opaque) from a zero-terminated string to a counted string (length-prefixed), also changing a length function from a loop to a simple field access (and an optimizing compiler could inline it), without impacting programs that use this interface (at least at the source level).
@JodyBruchon
@JodyBruchon 3 месяца назад
@@s.b.8704 But that would add tons of function call overhead to what currently is just a pointer reference.
@s.b.8704
@s.b.8704 3 месяца назад
​@@JodyBruchon it shouldn't, especially if the function is simple. At least with GCC and Clang, already at -O1 the function call disappears and the field access code is replaced inline. There is no difference between the code that the compiler produces for direct access to structure fields and access via a function. Try this in Compiler Explore (godbolt, if only YT would let me post a link…), choose C and x86-64 gcc or clang and put -O1 as argument to the compiler: [quick&dirty code: of course structure "S" is not really opaque here and even less the string "c", I just want to compare direct field access and via functions with less possible code.] #include #include typedef struct {float a; long int b; int len; char *c;} S; char *sc(S s){ return s.c; } int sl(S s){ return s.len; } int main(int argc, char *argv[]) { S s; s.c=argv[1]; s.len=strlen(argv[1]); printf("s.c: %s ", s.c); // 1 printf("s.c: %s ", sc(s)); // 2 printf("Length of string s.c = %lu ",strlen(s.c)); // 3 printf("Length of string s.c = %d ",sl(s)); // 4 return 0; } The assembly code produced for 1 and 2 is the same, no function call for 2. The code produced for 3 and 4 is different: in 3 it calls strlen but no function call for 4 (move the cursor over the assembly code and the corresponding C code will be highlighted). Note that if you want to execute the code, in source frame select "+Add new..." menu, add "Execution Only" and write a string for execution argument (argv[1]).
@tikabass
@tikabass 3 месяца назад
@@s.b.8704 If the structure is really opaque, the compiler will not be able to inline access as you describe. Linker optimization could inline the code, but the kernel is not just one big executable.
@vfjpl1
@vfjpl1 3 месяца назад
@Visentinel
@Visentinel 3 месяца назад
Why not write this up and send this up via the linux kernel mailing list ?
@JodyBruchon
@JodyBruchon 3 месяца назад
@@Visentinel Because they're not going to care.
@Visentinel
@Visentinel 3 месяца назад
@@JodyBruchon not with that attitude they won’t, you need to actually write it up and send it first to find out if they would.
@JodyBruchon
@JodyBruchon 3 месяца назад
Changing this structure requires a lot more work than you can imagine. A new syscall would have to be made, glibc would have to be modified to use it, and user software would have to be modified to use d_namlen when available instead of strlen, plus this ignores all compatibility issues. The ship sailed on this in 1995 when Torvalds shot down d_namlen completely. The changes needed to fix it are so invasive that it's almost certainly not worth it.
@gregandark8571
@gregandark8571 12 дней назад
@@JodyBruchon Make the letter anyway.
Далее
13 DOS commands you NEVER knew you NEEDED!
21:57
Просмотров 26 тыс.
Гаджет из даркнета 📦
00:45
Просмотров 140 тыс.
Китайка и Красивые Глаза😂😆
00:20
ITZY 예지한테 AI 메이크업하기💖 #shorts
00:23
How A Steam Bug Deleted Someone’s Entire PC
11:49
Understanding Linux
1:59:36
Просмотров 41 тыс.
Why Are Open Source Alternatives So Bad?
13:06
Просмотров 657 тыс.
The Rise of Unix. The Seeds of its Fall.
16:51
Просмотров 496 тыс.
Arch Linux Experience - Hyprland
39:02
Просмотров 238 тыс.
FydeOS: ChromiumOS with Android, Linux & no Google!
23:26
NEVER install these programs on your PC... EVER!!!
19:26
Гаджет из даркнета 📦
00:45
Просмотров 140 тыс.