Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/246424

From BetaArchive Wiki
Knowledge Base


Increasing OPEN_MAX in INTERIX

Article ID: 246424

Article Last Modified on 10/30/2006



APPLIES TO

  • Microsoft Interix 2.2 Standard Edition
  • Microsoft Interix 2.2 Standard Edition
  • Microsoft Interix 2.2 Standard Edition
  • Microsoft Interix 2.2 Standard Edition



This article was previously published under Q246424

SUMMARY

As shipped, INTERIX 2.2 has a limit of 32 open file descriptors per process (not per user ID; the sysconf() man page is wrong and will be corrected in the next release). For many applications, a limit of 32 file descriptors is not enough.

There is an undocumented way to increase the number of open file descriptors per process. The maximum limit in INTERIX 2.2 is 400 file descriptors per process. While the number of open files may increase in a future INTERIX release, the registry mechanism described here is not supported.

The following describes the requirements and risks of changing the limit of open file descriptors:

  • Will require you to compile some existing INTERIX applications.
  • Will cause some problems with X11 programs. The X libraries do their own manipulation of file descriptors, and it is not possible to fix these.
  • May cause problems with your shells and with other INTERIX utilities. An increase in the open file descriptor limit may cause several INTERIX 2.2 utilities (for example, tcsh, vi, and ksh) to have problems, but only if these utilities try to keep open more than 32 files at once. Although this is possible, it is very unlikely to occur.


Make this change only if it is necessary for your applications. The current value is 32 file descriptors. You can retrieve this number from the system in several ways:

  • From the command line, you can use the getconf utility: getconf OPEN_MAX
  • You can use the value of OPEN_MAX in the file. This constant is set to the value 32 in .
  • You can use the sysconf(_SC_OPEN_MAX) call. This will return the current system value, even if it has been changed.




MORE INFORMATION

Setting the New Limit

Warning! This is a non-supported extension! There is no support for systems with an extended number of file descriptors, and this procedure is not recommended.

The maximum number of open file descriptors per process can be set by setting the value of the following Windows NT registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Softway Systems\Interix\MaxOpenFiles

The registry entry itself is a DWORD value; it can be set to any integer value between 32 and 400. (If the registry entry is not set, it defaults to 32.)

Important: Once you have set MaxOpenFiles in the registry, reboot the system. You may want to change the value of OPEN_MAX.

Programming with the New Limit

The new limit affects programs with the following interfaces:

  • Programs that use OPEN_MAX or FD_SETSIZE constants directly.
  • Programs that use select().
  • Programs that use the fd_set structure in , either directly or indirectly.


You must recompile any programs that make use of these interfaces. Programs that are not recompiled may have problems. For instance, allocating memory based on OPEN_MAX and then accessing this memory based on the return value of open( ) may attempt to exceed the allocated memory boundaries. Or, if bit masks are used (such as fd_set) and these sets are used with select( ) and the value of the first argument to select( ) (the argument nfds) exceeds FD_SETSIZE (which is set to OPEN_MAX by default) then the memory boundaries defined for these bit sets will be exceeded.

If OPEN_MAX Is Correct

If you have updated the value OPEN_MAX in to reflect the value of the registry variable, simply recompile.

If OPEN_MAX Is Outdated

If you have not updated the value OPEN_MAX in to reflect the value of the registry variable, you need to take the following steps:

  1. Programs interested in using a large number of file descriptors (that is, greater than 32) should be modified to ensure that any use of the macro OPEN_MAX be replaced with a call to sysconf(_SC_OPEN_MAX). This may result in static arrays becoming runtime dynamic.
  2. Programs that use select( ) should define a macro called FD_SETSIZE before the inclusion of the header file . The value of FD_SETSIZE should be as large as the maximum number of file descriptors the application will have open at the same time. By default, FD_SETSIZE is set to OPEN_MAX in . If the registry value is larger than OPEN_MAX, you will encounter problems with select( ) if the file descriptors selected are larger than OPEN_MAX. The best value for FD_SETSIZE in INTERIX 2.2 is 400 (the maximum).



Known Problems

  • Systems which increase the number of file descriptors are unsupported.
  • Some X11 clients will not work properly.
  • Existing binaries and libraries compiled on INTERIX 2.2 that make use of the OPEN_MAX constant or use the FD_SETSIZE constant or make assumptions like the maximum value returned by open( ) will be less than OPEN_MAX, may not work properly after increasing the MaxOpenFiles registry value.


Keywords: kbinfo KB246424