Re: Online and Shared memory
Posted in 1993
ywleung@ouray.denver.colorado.edu (YIU WAH LEUNG) writes: >I went into a theoretical discussion with my workmate on how Informix handles >shared memory that is defined by using tbmonitor/Parameter/Shared memory. >He said that the size of the shared memory that defined in Informix >is the MAXIMUM amount of the shared memory Informix can get from UNIX (from >the pool of shared memory UNIX has defined in kernel). This is more or less correct -- it defines the amount of memory that Informix will request from the kernel. Watch out for the extra shared memory used by the XA parts of OnLine in version 5.0. >You cannot define more than what the System Administrator specified in the >UNIX kernel shared memory parameter. You can define that Informix should used as much shared memory as you like, but if the system is not configured to let you use that much memory, Informix (tbinit) won't start. >He also said that even though you setup the SIZE of the shared memory >Informix wanted in tbmonitor, Informix actually does not own any shared >memory. When an Informix process needs shared memory, it sends a request >(shmget) to the kernel and asks for it. Tbinit does the initial shmget() with flags to indicate that the shared memory segment(s) should be created, and then attaches to the shared memory with shmat(). Tbinit is effectively the owner of the shared memory. More precisely, user informix is the owner of the shared memory, which could survive a catastrophic crash of tbinit. All the other processes do shmget() without the create flags, and then call shmat() to attach to the existing block of shared memory. >If the amount of shared memory is available in kernel, the request is >granted. If the amount is not available or the total amount of the shared >memory is exceeding what you defined in the tbmonitor, Informix will >return 'get shmget fail'. Since each sqlturbo only attaches to the existing shared memory segment, the only reason why the shmget() should fail is because the block of shared memory doesn't exist. An alternative is that the product is installed incorrectly and sqlturbo has the wrong permissions. >My friend also said that UNIX has deficiency for handling semaphore and >shared memory. If a programmer in one shop chooses a 'key' for its region >of shared memory and another programmer in another shop choose the same >'key', both programs will overwrite each other's shared memory when they >run on the same machine. Yes, but only if the programs are careless enough not to check that the shared memory does not exist when they try to create the shared memory (more flags to shmget()). With OnLine, the server number affects the shared memory (and semaphore) keys that are used, so if by mischance there is a conflict, use a different server number. And the permissions on the shared memory and semaphores used by OnLine are such that a non-root, non-informix program will not be able to use Informix's shared memory or semaphores. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>