DOS/4G

Tenberry Home

Consulting Services

Order DOS/4G

DOS/4G FAQ

Release Notes

DPMI Spec

* * *

DOS/4GW

DOS/4GW Pro

DOS/4G
for Watcom

DOS/16M

DOS/4G and DOS/4GW FAQ:
Virtual Memory Management


[Previous Section] * [Index of FAQ] * [Next Section]
  1. Is there a way that my program can check for the presence of a virtual memory manager?
  2. Are there any precautions I need to take when spawning a DOS/4G program from another DOS/4G program in a virtual memory environment?
  3. My program runs fine without VMM but crashes when VMM is running. What should I be looking for?
  4. My program is running out of memory, even though I have a huge virtual address space. What could be wrong?
  5. Is there an advantage to creating a permanent swap file?
  6. >How do I specify a directory name for the swap file?
  7. >How should I configure VMM for best performance?
  8. I've tried various things to speed up my program, but it still seems sluggish. Are there any other factors that affect VMM performance?
  9. Why do I need such a big swap file?
  10. Can you have virtual memory for one DOS/4G program, and not for the other DOS/4G programs that it spawns?

1. Is there a way that my program can check for the presence of a virtual memory manager?

Interrupt 31h/400h returns a value (BX, bit 2) that tells if virtual memory is available. Under a DPMI host such as Windows 3.1, this will be the host's virtual memory manager, not DOS/4G.

You can use Interrupt 31h/0A00h, with a pointer to the null-terminiated string 'RATIONAL DOS/4G' in DS:ESI, to test for the presence of a DOS/4G family DOS extender. The function will return with carry clear if a DOS/4G family extender is running.


2. Are there any precautions I need to take when spawning a DOS/4G program from another DOS/4G program in a virtual memory environment?

If you spawn one DOS/4G application from another, you should make sure that the DeleteSwapFile configuration option is on so that the two applications don't try to use the same swap file (this is the default behavior in DOS/4G versions 1.97 and later).

You should also set the PhysMax option low enough so that the parent application doesn't take all available physical memory; memory that's been reserved by the parent application is not available to the child application.


3. My program runs fine without VMM but crashes when VMM is running. What should I be looking for?

If your program hooks hardware interrupts, and works fine without VMM but crashes sporadically with it, check to be sure that you're locking all of the code and data for its hardware interrupt handlers down in memory. DOS/4G does not support page faults during hardware interrupts, because DOS services may not be available at that time.

Memory can be locked down with Interrupt 31h/600h (Lock Linear Region).


4. My program is running out of memory, even though I have a huge virtual address space. What could be wrong?

Because DOS/4G has to create page tables to describe your virtual address space, we recommend that you set your VIRTUALSIZE parameter just large enough to accommodate your program. If you set your VIRTUALSIZE to 4GB, the physical memory occupied by the page tables will be 4MB, and that memory will not be available to DOS/4G. The default setting of 16MB is large enough for most programs.


5. Is there an advantage to creating a permanent swap file?

Yes. Normally, DOS/4G will start out by creating a zero-length swap file. As your program uses more memory, the swap file will grow by the value specified as SwapInc.

Virtual memory performance will be better if you configure DOS/4G to use a permanent, full-size swap file. The cost in disk space is usually only worthwhile if your program is typically run over and over again.

If you want DOS/4G to reuse a permanent swap file, set DeleteSwapFile to OFF. To have the swap file padded to full size at startup, set SwapInc to Zero.


6. >How do I specify a directory name for the swap file?

If you set SwapFileName to a directory name, DOS/4G will create the swap file in that directory. The default SwapFileName setting is '.', which means 'the current directory'.


7. >How should I configure VMM for best performance?

The default setting changed since version 1.97, to provide better performance for a wider range of applications and machines. Using the default settings is usually the right choice.

However, you may still want to experiment with the settings. Here are some recommendations for configuring the DOS/4G virtual memory manager.

VirtualSize

Default is 16384. Set VirtualSize larger if your program uses more than 16MB of code and data, but don't set it to more than twice your program's memory requirement.

There is only a small penalty for setting this value larger than you will need. But your program won't run if you set it too low.

PhysMin

Default is 1024. Set it to the minimum hardware requirement for running your application. If you require a 4MB machine, set it to 4096; if your program is very small and can run in 512KB, set it to 512.

PhysMax

Default is all available memory, up to 64MB. This setting minimizes disk swapping, so that large applications will run as fast as possible. However, it may actually slow down small applications on machines with lots of memory, since more memory will be managed that is actually needed!

You may wish to restrict the amount of physical memory VMM uses for the following reasons:

  • Your application is small, and you know its maximum memory requirement. You can speed it up at startup by telling VMM not to manage everything.
  • You need to spawn another application that uses extended memory. You need to leave enough available for the other program.

SwapMin

Default is 0. You might want to change this setting if you want VMM to verify, at startup time, that there is a certain amount of disk space available for the swap file.

SwapInc

Default is 4096. If you set this to 0, VMM will create a swap file equal in size to your VirtualSize. Swapping pages in and out will be slightly faster because VMM can use a simpler algorithm.

On the other hand, startup will be slower because VMM has to create the swap file, and you'll need to have free disk space even when your entire program fits in memory.

SwapFileName

You might need to change this setting when you run your application from a network drive, and you don't have write access to the applications's home directory.

DeleteSwapFile

DOS/4G normally creates a new swap file each time, which slows down program startup slightly. If your application will typically be run over and over again, and you can spare the disk space, you can set DeleteSwapName to OFF so that DOS/4G reuses an existing swap file.

Don't set DeleteSwapFile to OFF if your application spawns another DOS/4G application which uses VMM.


8. I've tried various things to speed up my program, but it still seems sluggish. Are there any other factors that affect VMM performance?

Since our VMM does all file I/O directly through DOS, disk fragmentation can slow down performance. If you experience performance problems, you should try running a disk defragmenting tool.

Long delays can sometimes be caused by virtual memory swapping. When running a DOS/4G family application under Windows, the Windows DPMI virtual memory manager is used instead of the DOS/4G(W) memory manager. One result of this is that any DOS/4G(W) tuning parameters have no effect - it's the Windows tuning that you need to adjust.

If there is a lot of disk activity during your sluggish performance, and your program does not do a lot of writing to the disk, then your application is probably swapping too much. You can address this problem in a number of ways:

  • Install more memory.

  • Close other Windows applications.

  • Close other DOS windows.

  • Make your windows swap file a permanent one.

In these cases, a faster processor or video card won't help much. Neither will increasing the size of the swap space.


9. Why do I need such a big swap file?

Programs which have large amounts of static or common data (even data which is mostly ignored, like sparse matrices) will require large swap files. DPMI 0.9 providers like Windows only provide 'committed' virtual memory. Committed virtual memory requires backing store (physical memory or disk space). This property of DPMI 0.9 means that, while your data WILL be demand-loaded from the disk, you will still need to have enough backing store to hold it all.

Note that DOS/4G supports 'uncommitted' virtual memory as well (in the absence of a DPMI 0.9 host).


10. Can you have virtual memory for one DOS/4G program, and not for the other DOS/4G programs that it spawns?

Yes, if you turn off the DOS4GVM environment variable before you spawn. Use putenv() to turn off the variable if it was set in the DOS environment. You may want to restore the environment variable after the program returns.


[Previous Section] * [Index of FAQ] * [Next Section]
Last modified 2003.02.06. Your questions, comments, and feedback are welcome.