How does Linux resolve pathnames with the help of the dentry cache?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite
2












While dealing with the Virtual Filesystem of Linux I have come across a little problem of understanding how pathnames are resolved if they are already cached as dentries in the dentry cache.

I know that the different dentries are organized in a hash table to speed up future lookups of already resolved pathnames. The book I am reading at the moment is saying the following:




d_hash(dentry, name)

Creates a hash value; this function is a filesystem-specific hash function for the dentry hash table. The dentry parameter identifies the directory containing the component. The name parameter points to a structure containing both the pathname component to be looked up and the value produced by the hash function.

...

The hash table is implemented by means of a dentry_hashtable array. Each element is a pointer to a list of dentries that hash to the same hash table value. The array's size usually depends on the amount of RAM installed in the system; the default value is 256 entries per megabyte of RAM. The d_hash field of the dentry object contains pointers to the adjacent elements in the list associated with a single hash value. The hash function produces its value from both the dentry object of the directory and the filename.



Understanding the Linux Kernel




Let's assume that we have the following path "/home/test/file". Now the VFS creates dentries for "/", "home", "test" and "file".

Now I don't understand how the corresponding hash value for each dentry is calculated and how the VFS looks up a pathname through these cached dentries in the hash table.
In my understanding the VFS does the following:



  1. Calculate hash value of dentry for "/" and filename "home"

  2. Look up hash value for corresponding dentry of "home" in hash table

  3. Calculate hash value of dentry for "home" and filename "test"

  4. Look up hash value for corresponding dentry of "test" in hash table

  5. Calculate hash value of dentry for "test" and filename "file"

  6. Look up hash value for corresponding dentry of "file" in hash table

But on some websites on the Internet it sounds like the VFS only hashes the complete pathname at once and looks up the corresponding dentry with the resulting hash value.



So it would be great if someone could bring some light into the darkness.







share|improve this question


























    up vote
    4
    down vote

    favorite
    2












    While dealing with the Virtual Filesystem of Linux I have come across a little problem of understanding how pathnames are resolved if they are already cached as dentries in the dentry cache.

    I know that the different dentries are organized in a hash table to speed up future lookups of already resolved pathnames. The book I am reading at the moment is saying the following:




    d_hash(dentry, name)

    Creates a hash value; this function is a filesystem-specific hash function for the dentry hash table. The dentry parameter identifies the directory containing the component. The name parameter points to a structure containing both the pathname component to be looked up and the value produced by the hash function.

    ...

    The hash table is implemented by means of a dentry_hashtable array. Each element is a pointer to a list of dentries that hash to the same hash table value. The array's size usually depends on the amount of RAM installed in the system; the default value is 256 entries per megabyte of RAM. The d_hash field of the dentry object contains pointers to the adjacent elements in the list associated with a single hash value. The hash function produces its value from both the dentry object of the directory and the filename.



    Understanding the Linux Kernel




    Let's assume that we have the following path "/home/test/file". Now the VFS creates dentries for "/", "home", "test" and "file".

    Now I don't understand how the corresponding hash value for each dentry is calculated and how the VFS looks up a pathname through these cached dentries in the hash table.
    In my understanding the VFS does the following:



    1. Calculate hash value of dentry for "/" and filename "home"

    2. Look up hash value for corresponding dentry of "home" in hash table

    3. Calculate hash value of dentry for "home" and filename "test"

    4. Look up hash value for corresponding dentry of "test" in hash table

    5. Calculate hash value of dentry for "test" and filename "file"

    6. Look up hash value for corresponding dentry of "file" in hash table

    But on some websites on the Internet it sounds like the VFS only hashes the complete pathname at once and looks up the corresponding dentry with the resulting hash value.



    So it would be great if someone could bring some light into the darkness.







    share|improve this question
























      up vote
      4
      down vote

      favorite
      2









      up vote
      4
      down vote

      favorite
      2






      2





      While dealing with the Virtual Filesystem of Linux I have come across a little problem of understanding how pathnames are resolved if they are already cached as dentries in the dentry cache.

      I know that the different dentries are organized in a hash table to speed up future lookups of already resolved pathnames. The book I am reading at the moment is saying the following:




      d_hash(dentry, name)

      Creates a hash value; this function is a filesystem-specific hash function for the dentry hash table. The dentry parameter identifies the directory containing the component. The name parameter points to a structure containing both the pathname component to be looked up and the value produced by the hash function.

      ...

      The hash table is implemented by means of a dentry_hashtable array. Each element is a pointer to a list of dentries that hash to the same hash table value. The array's size usually depends on the amount of RAM installed in the system; the default value is 256 entries per megabyte of RAM. The d_hash field of the dentry object contains pointers to the adjacent elements in the list associated with a single hash value. The hash function produces its value from both the dentry object of the directory and the filename.



      Understanding the Linux Kernel




      Let's assume that we have the following path "/home/test/file". Now the VFS creates dentries for "/", "home", "test" and "file".

      Now I don't understand how the corresponding hash value for each dentry is calculated and how the VFS looks up a pathname through these cached dentries in the hash table.
      In my understanding the VFS does the following:



      1. Calculate hash value of dentry for "/" and filename "home"

      2. Look up hash value for corresponding dentry of "home" in hash table

      3. Calculate hash value of dentry for "home" and filename "test"

      4. Look up hash value for corresponding dentry of "test" in hash table

      5. Calculate hash value of dentry for "test" and filename "file"

      6. Look up hash value for corresponding dentry of "file" in hash table

      But on some websites on the Internet it sounds like the VFS only hashes the complete pathname at once and looks up the corresponding dentry with the resulting hash value.



      So it would be great if someone could bring some light into the darkness.







      share|improve this question














      While dealing with the Virtual Filesystem of Linux I have come across a little problem of understanding how pathnames are resolved if they are already cached as dentries in the dentry cache.

      I know that the different dentries are organized in a hash table to speed up future lookups of already resolved pathnames. The book I am reading at the moment is saying the following:




      d_hash(dentry, name)

      Creates a hash value; this function is a filesystem-specific hash function for the dentry hash table. The dentry parameter identifies the directory containing the component. The name parameter points to a structure containing both the pathname component to be looked up and the value produced by the hash function.

      ...

      The hash table is implemented by means of a dentry_hashtable array. Each element is a pointer to a list of dentries that hash to the same hash table value. The array's size usually depends on the amount of RAM installed in the system; the default value is 256 entries per megabyte of RAM. The d_hash field of the dentry object contains pointers to the adjacent elements in the list associated with a single hash value. The hash function produces its value from both the dentry object of the directory and the filename.



      Understanding the Linux Kernel




      Let's assume that we have the following path "/home/test/file". Now the VFS creates dentries for "/", "home", "test" and "file".

      Now I don't understand how the corresponding hash value for each dentry is calculated and how the VFS looks up a pathname through these cached dentries in the hash table.
      In my understanding the VFS does the following:



      1. Calculate hash value of dentry for "/" and filename "home"

      2. Look up hash value for corresponding dentry of "home" in hash table

      3. Calculate hash value of dentry for "home" and filename "test"

      4. Look up hash value for corresponding dentry of "test" in hash table

      5. Calculate hash value of dentry for "test" and filename "file"

      6. Look up hash value for corresponding dentry of "file" in hash table

      But on some websites on the Internet it sounds like the VFS only hashes the complete pathname at once and looks up the corresponding dentry with the resulting hash value.



      So it would be great if someone could bring some light into the darkness.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 3 at 3:27









      muru

      33.3k576141




      33.3k576141










      asked Apr 3 at 2:36









      idlmn89

      453




      453

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f435178%2fhow-does-linux-resolve-pathnames-with-the-help-of-the-dentry-cache%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f435178%2fhow-does-linux-resolve-pathnames-with-the-help-of-the-dentry-cache%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay