1. 38
  1. 23

    The lobste.rs title is truncated from the actual title of

    Relative paths are faster than absolute paths on Linux (and other jokes I tell myself)

    Which has a different meaning than

    Relative paths are faster than absolute paths on Linux

    But also, both titles are unrelated to the contents of the blog post, which is about the semantics of openat flavor of syscalls and not in any way about performance.

    1. 4

      I had hoped that the last few paragraphs would explain the title, because performance was the reason I’ve been looking into this.

      1. 4

        It also has very little to do with rust. The examples could be written in any language with the same result

      2. 5

        I usually type cd . instead of cd "$(pwd)"

        1. 3

          That doesn’t work inside a deleted directory, since the . and .. directory entries have been removed.

          1. 3

            How would “cd $(pwd)” work inside a deleted directory?

            [jeeger@dumper /tmp] $ mkdir -p /tmp/test/test
            [jeeger@dumper /tmp] $ cd /tmp/test/test
            [jeeger@dumper /tmp/test/test] $ rm -rf /tmp/test
            [jeeger@dumper /tmp/test/test] $ mkdir -p /tmp/test/test
            [jeeger@dumper /tmp/test/test] $ cd .
            [jeeger@dumper /tmp/test/test] $ ls
            [jeeger@dumper /tmp/test/test] $
            1. 5

              That’s a good point. I ran some tests of my own:

              • start a shell, change to /tmp/test/test
              • in another terminal, remove and recreate that directory
              • in the shell in question, run /bin/pwd to verify the problem is detected
              • run cd . or cd $(pwd)
              • run /bin/pwd again to verify the problem is fixed

              It turns out cd . and cd $(pwd) work equally well in posh, mksh, dash, zsh and bash, in the default configuration. However, for historical reasons I have set -P in my .bashrc file, which (as an unintended side-effect) turns off the magic that allows cd . to work.

              1. 1

                Very interesting, it’s only after bash resolves /tmp/test/test/. to /tmp/test/test that they become equivalent.

              2. 1

                I’m not sure what you’re demonstrating but please be advised that ls does not error in deleted cwds anyway, it simply exits

          2. 4

            The output is really messy. What I did to narrow it down was to search for ENAMETOOLONG, which according to a Google search for “linux os error 36” is the human-readable version of os error 36.

            I’m personally fond of using errno from moreutils.

            1. 4

              the potential amount of extra syscalls and open file descriptors

              Well, you don’t have to openat just one level. Take the requested path string, find the rightmost separator that fits in the maximum size, chop there, syscall, repeat…

              1. 1

                Batching, essentially. But is the syscall really more expensive than searching through and subdividing the string?

              2. 2

                I did not know about these practical limitations of path lengths on Linux. I was curious to find more information about ENAMETOOLONG. I found this:

                [ENAMETOOLONG] is coming from the kernel. It’s also filesystem dependent hence why you can’t find SYMLINK_MAX defined anywhere

                From https://stackoverflow.com/questions/36757577/in-linux-can-the-value-of-a-symlink-be-longer-than-path-max