Trying again with a shorter, more focused question. Please note this is NOT the usual "why is file-nr reporting a lower number than I expect" question. I have the opposite problem.
A Linux 2.6 system is leaking file handles. I know this because I periodically cat /proc/sys/fs/file-nr. The first number tends upwards over a few hours, the second number is always 0. When the first number reaches the third, login becomes impossible, no new shells, etc. So I trust the output of file-nr and have reason to believe there's a significant file handle leak. (The system doesn't always do this and we haven't found rhyme or reason to what makes it start happening, but it's fairly common.)
Now the weird part. Running as root, I do ls -l on all the fd's, via /proc/each process id/fd. Note I'm doing this as root, so I should see all the file handles of all processes.
According to my limited understanding, the output of ls should reveal about the same number of handles as file-nr shows. I wouldn't expect it to be exact, because processes might come and go and they might open or close files as I'm walking /proc/#. But done enough times I'd expect, on average, rough agreement. So the first question is, is that a reasonable assumption and if not, why not?
I ask because file-nr shows the slowly increasing handle count, marching up towards 65536. But the aggregated output from /proc/ids../fd shows thousands fewer handles. At one point, for example, file-nr looked something like "9900 0 65536" but counting up the file handles per process in proc came to less than 2000, and done repeatedly, it stayed more or less constant. Whatever's leaking handles isn't showing up as a process.
A difference of over 7000? When processes are not wildly starting and stopping and should not be frantically opening and closing files? Note that the hard file handle limit per process is 1024, so it's not as if any one process is causing this. The system does show a few dozen defunct processes but I didn't think defunct processes could retain file handles. And I've hard other people check my work so it doesn't seem to be a stupid misuse of ls or anything.
This is a critical problem for me and if someone can explain why there's this much wild disagreement in the counts, it could put me on track to solving a critical and production-stopping problem.
Note I'm not using lsof - it's been removed from the system. But since I'm only interested in actual file handles, which can be different than "open files", walking /proc/#s should be good enough. Or so I thought.