Positive to negative ratio
Positive to negative ratio
Posted Jul 7, 2026 15:29 UTC (Tue) by farnz (subscriber, #17727)In reply to: Positive to negative ratio by Fowl
Parent article: Limiting negative dentries
The motivating use case for negative dentries is something like the C include path; you write #include <stdio.h> in your source code, and your compiler searches multiple directories for stdio.h. In the case of a default Fedora 44 gcc, there's three before you add any library search paths, in the following order:
- Your cwd for "" includes, but not <> includes.
- /usr/lib/gcc/x86_64-redhat-linux/16/include - 141 files on my system
- /usr/local/include - empty
- /usr/include - 270 files.
Most header files are going to be found in /usr/include - /usr/lib/gcc/x86_64-redhat-linux/16/include is only for headers whose content is machine-specific, and /usr/local/include is for cases where you installed a package outside the system package manager's control.. On top of that, you have additional directories added by -I and similar options (including those added by things like pkg-config).
This gets worse for C++, which changes to the following list:
- Your cwd for "" includes, but not <> includes.
- /usr/lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16 - 137 files.
- /usr/lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/x86_64-redhat-linux - 3 files
- /usr/lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/backward - 8 files
- /usr/lib/gcc/x86_64-redhat-linux/16/include
- /usr/local/include
- /usr/include
So, we need something that's going to quickly return "not present" for all the directories that are earlier in the search path than /usr/include when we search for (say) stdio.h or zlib.h, or the directory vulkan, but that's not going to consume a lot of resources. Negative dentries are supposed to be that thing - so the question is how many negative dentries are reasonable to record before it'd be cheaper to just do a full lookup.
In turn, that means that the "right" number of negative dentries for directories in the search path for the C compiler before /usr/include is a function of the number of files in /usr/include, and not any function of the number of files in those directories. If you have a lot of libraries installing headers in there, then the right number can be quite large.
And related to that is cache management policy; while positive dentries are limited to the number of directory entries by definition, which dentries we should remove once we have too many dentries is itself a question that needs considering - are you better off removing the negative dentry that tells you that zlib.h is not found in /usr/lib/gcc/x86_64-redhat-linux/16/include, or the positive dentry that tells you that omp.h is found there? The right answer depends on whether you're compiling code that uses GOMP heavily, or code that uses Zlib heavily.
