Windows
How to analyze memory leaks on Windows
We use valgrind to find memory leaks in MySQL on Linux. The tool is a convenient, and often enlightening way of finding out where the real and potential problems are location.
On Windows, you dont have valgrind, but Microsoft do provide a free native debugging tool, called the user-mode dump heap (UMDH) tool. This performs a similar function to valgrind to determine memory leaks.
Vladislav Vaintroub, who works on the Falcon team and is one of our resident Windows experts provides the following how-to for using UMDH:
-
Download and install debugging tools for Windows from here
MS Debugging Tools
Install 64 bit version if you’re on 64 bit Windows and 32 bit version
otherwise. -
Change the
PATHenvironment variable to include bin directory of Debugging tools.
On my system, I added
C:\Program Files\Debugging Tools for Windows 64-bitto thePATH. -
Instruct OS to collect allocation stack for mysqld with
gflags -i.
mysqld.exe +ust
On Vista and later, this should be done in “elevated” command prompt,
it requires admin privileges.Now collect the leak information. The mode of operation is that: take the
heap snapshot once, and after some load take it once again. Compare
snapshots and output leak info. -
Preparation : setup debug symbol path.
In the command prompt window, doset _NT_SYMBOL_PATH= srv*C:\websymbols*http://msdl.microsoft.com/download/symbols;G:\bzr\mysql-6.0\sql\DebugAdjust second path component for your needs, it should include directory
where mysqld.exe is. - Start mysqld and run it for some minutes
-
Take first heap snapshot
umdh -p:6768 -f:dump1Where -p:
actually, PID of my mysqld was 6768. - Let mysqld run for another some minutes
-
Take second heap snapshot
umdh -p:6768 -f:dump2 -
Compare snapshots
umdh -v dump1 dump2 > dump.compare.txt - Examine the result output file. It is human readable, but all numbers are
in hex, to scare everyone except geeks. -
gflags -i mysqld.exe -ustInstruct OS not to collect mysqld user mode stacks for allocations
anymore.
These are 10 steps and it sounds like much work, but in reality it takes 15
minutes first time you do it and 5 minutes next time.
Additional information is given in Microsoft KB article about UMDH
KB 268343.
Setting up the developer stack issues
There’s a great post on Coding Horror about Configuring the Stack.
Basically the gripe is with the complexity of installing the typical developer stack, in this case on Windows, using Visual Studio. My VS setup isn’t vastly different to the one Jeff mentions, and I have similar issues with the other stacks I use.
I’ve just set up the Ultra3 mobile workstation again for building MySQL and other stuff on, and it took about 30 packages (from Sun Freeware) just to get the basics like gcc, binutils, gdb, flex, bison and the rest set up. It took the best part of a day to get everything downloaded, installed, and configured. I haven’t even started on modules for Perl yet.
The Eclipse stack is no better. On Windows you’ll need the JDK of your choice, plus Eclipse. Then you’ll have to update Eclipse. Then add in the plugins and modules you want. Even though some of that is automated (and, annoyingly some of it is not although it could be), it generally takes me a few hours to get stuff installed.
Admittedly on my Linux boxes it’s easier - I use Gentoo and copy around a suitable make.conf with everything I need in it, so I need only run emerge, but that can still take a day or so to get everything compiled.
Although I’m sure we can all think of easier ways to create the base systems - I use Parallels for example and copy VM folders to create new environments for development - even the updating can take a considerable amount of time.
I suggest the new killer app is one that makes the whole process easier.
Using static disks in Parallels for performance
Using a static disk, or even just multiple disks, within Parallels can make a big difference to performance. This is particularly true with Windows virtual machines within OS X; I’ve managed to change the boot time from about 30 seconds to under 20 just by changing to a static disk for VM.
The default disk in Parallels is an expanding type - this saves disk space, because Parallels automatically adds to the size of the disk as you need it, but it also means that Parallels has to manage the allocated disk space, adding to the file used. Not only does the management imply a small overhead, there is a much larger chance of the file being fragmented.
A more annoying effect is that the constant use of the expanding disk with virtual memory under Windows, means that size of the disk may increase just because you opened a large application once.
You can get round this by creating a statically-sized disk, and then setting the virtual memory within your virtual host, to use this statically sized disk.
To do this:
- Shutdown your virtual machine - you cannot do this with a machine in the paused stated, because you are effectively adding new hardware to the machine.
- Click Edit to edit the configuration for the virtual machine.
- Click Add, and select a new hard disk
- Unclick the Expanding checkbox and set the size; probably 1-2GB is fine, but keep in mind you will lose this amount of disk space permanently, even if your VM doesn’t use it all.
- Save your configuration.
- Start up your VM and configure the new drive.
For Windows:
- Log in as a user with Administrator privileges.
- Right click on
My Computer and choose Manage. - Choose Local Disk Management.
- Create a new partition/volume.
- Once the new disk is ready to use, right click on
My Computer again, and choose Properties. - Click the Advanced tab.
- Click Settings under Performance.
- Click the Advanced tab.
- Click Change under Virtual Memory.
- Reconfigure the VM settings, creating the new settings for the new drive (I recommend a lower value of 50MB and an upper value 2-10MB below the maximum size of the disk. Windows will use the minimum and dynamically increase it’s usage up until the maximum.
- Remove the VM configuration for the original system/expanding disk.
You should be all set.
It’s probably a good idea to run the Parallels Compressor and reduce the size of your disk now that you are no longer using the disk for virtual memory.
For Linux, Solaris and other Unix variants you might want to run, the process is of course slightly different. For some environments, there are other benefits, but I’ll cover that in a separate post.