NT下,per process 的 handle count limit应该 只有32位和64位之分,文章里写道了
a handle entry is 8-bytes on 32-bit Windows and 12-bytes on 64-bit Windows.
The Executive allocates handle tables on demand in page-sized blocks that it divides into handle table entries. That means a page, which is 4096 bytes on both x86 and x64, can store 512 entries on 32-bit Windows and 256 entries on 64-bit Windows. The Executive
determines the maximum number of pages to allocate for handle entries by dividing the hard-coded maximum,16,777,216, by the number of handle entries in a page, which results on 32-bit Windows to 32,768 and on 64-bit Windows to 65,536. Because the Executive
uses the first entry of each page for its own tracking information, the number of handles available to a process is actually 16,777,216 minus those numbers, which explains the results obtained by Testlimit: 16,777,216-65,536 is
16,711,680 and 16,777,216-65,536-32,768 is 16,744,448.
但是,你要知道,这只是Handle的hardcoded Max count,实际你可能更本触及不到这个Limit,因为一般不会去创建(也由于内存限制,创建不出)这么多Kernel Object,也不会像TestLimit程序那样疯狂地DuplicateHandle去指向同一个Kernel Object。。。。。
------------------------------------------------------------------------------------------------------------
说到这里,貌似还需要补充另一半概念。
因为你问的“最大文件打开数”,我一开始把你指引到handle limit,是让你知道在一条河边钓鱼,最大可以有多少鱼竿(比作handle)同时钓,而没有说河里最多可以容纳多少条鱼(比作File Object)。。。
那么,河里可以有多少条鱼(File Object),你又得参见Mark Russinovich 的另一篇博文,得知道你能有多大的Non-Paged Pool
Nonpaged pool is therefore always kept present in physical memory and nonpaged pool virtual memory is assigned physical memory. Common system data structures stored in nonpaged pool include the kernel and objects that represent processes
and threads, synchronization objects like mutexes, semaphores and events, references to files, which are represented as file objects, and I/O request packets (IRPs), which represent I/O operations.