11

I understand that "everything is a file" is not entirely true, but as far as I know, every process gets a directory in /proc with lots of files. Read/write operations are often great bottlenecks in speed, and having to read/write from/to files all the time can significantly slow down processing.

Does having to keep a bunch of files in /proc slow things down? If not, how doesn't having to do a lot of IO operations not be a huge design flaw in Linux?

  • 37
    /proc is not a real filesystem, it's a view into the kernel's process tables. Any overhead in maintaining this view falls somewhere between "nonexistant" and "negligible". – cas May 01 '21 at 09:49
  • 5
    @cas: I would say it's almost entirely on the "nonexistent" end of the spectrum, because with very few exceptions, the kernel already has to keep track of all that information anyway, just to keep the system running correctly. – Kevin May 01 '21 at 22:22
  • 3
    Welcome to the Unix philosophy of "everything is a file", and many things that do not exist on storage are represented using the same interface. – chrylis -cautiouslyoptimistic- May 01 '21 at 22:36
  • There is some overhead in reading out the structures by way of converting it to files and keeping some state (especially for large virtual files like the maps or sockstat), but the actual creation of processes does update the normal process structures only and is not concerned with /proc (besides some basic sane concurrent operations which would be needed for other ways to access the lists as well). In fact other methods like reading through process tables are more problematic in that regard, – eckes May 03 '21 at 05:54
  • 1
    @kevin I agree. overhead is very much on the "non-existent" side of the spectrum. But it's > zero, so non-existent isn't quite right. – cas May 03 '21 at 13:13
  • @cas Not sure I understand your comment. procfs is a very real filesystem that's mounted into /proc. – Konrad Rudolph May 03 '21 at 22:27
  • 1
    @KonradRudolph do you honestly have difficulty understanding, or are you just being tiresomely pedantic about your own artificially narrow and contorted definition of the word "real" and how it relates to the word "filesystem"? If the former, then the comments and answers here will tell you everything you need to know. If the latter, then please go quibble somewhere else, in private where no one else has to be exposed to it. – cas May 04 '21 at 11:51
  • @cas Please assume good faith instead of going straight for insults. I just honestly don’t understand your comment (and, what’s more, I’m baffled by the upvotes), since it’s factually incorrect (not for some “contorted” definition of “real” but rather for its most common meaning) and doesn’t seem to help OP’s understanding, on the contrary (it actively adds to OP’s confusion). I fear that it’s really doing OP a disservice. – Konrad Rudolph May 04 '21 at 11:53
  • 1
  • it's factually correct. /proc is not a real filesystem. the comments and the answers here explain why that is the case. 2. i find it hard to believe that someone could be honestly ignorant about this topic and still have the chutzpah to incorrect people about it in public. "Good faith" seems very unlikely.
  • – cas May 04 '21 at 11:58
  • @cas In that case let me reiterate my initial comment: procfs is a real filesystem (its files do not correspond to physical disk locations but that is irrelevant for the Unix/Linux concept of a file). Claims to the contrary are simply wrong, and being rude to people pointing this out doesn’t make you right. And, obviously, (contrary to your last comment) none of the comments or answers “explain” why procfs isn’t a filesystem. (And contrary to your assumption I am intimately familiar with Linux filesystem internals. Hacking the Linux FS was a large part of my last job.) – Konrad Rudolph Aug 19 '22 at 12:00