You are inside a passionate computer engineer's lab...
Proceed at your own risk...

Look for something inside my Lab...

Minimize Firefox RAM Memory usage

Introduction

Today, many of you are using the Firefox browser to surf on the Internet and develop web applications, etc... Once you begin using Firefox you may realize that it consumes too much RAM which goes up to 200MB in normal usage and can reach 700MB after several hours of continuous browsing. Yet, many of us still have a 1GB laptop or even a 512MB good old desktop computer. This means that if you use Firefox to browse on such computers, your multi-tasking ability is severely reduced.

This made me decide to put in action a program that reduces RAM usage of Firefox by forcing the OS to move the memory pages of Firefox to the swap space, thus leaving much more RAM available. And I quickly made it using the C++ language.

From the end, it cuts down Firefox RAM usage to about 15MB! Cool! No?
Well, it is really cool especially when you know that it have no impact on performance because of the paging operations the OS does. This is because Firefox is a network-based program, so the major latency factor is the network speed. And the loss of CPU power put in swapping the memory pages is very thin compared to the network latency. Of course you won't probably use my program to minimize the RAM usage of Oracle Database Server...

Features

Here are some of the features:
  • Actually, the program is able to reduce RAM usage for any program, and any number of programs, not only Firefox instances.
  • It does this in a safe way (no code injection or dirty hacks).
  • It's open source under the "Simple BSD Licence".
  • It is very tiny in disk size (less than 90KB) and in RAM usage (less than 300KB).
  • It consumes almost zero CPU usage with the default configuration options.
  • It has no GUI and no Console.
  • It can be configured using command line options or a simple configuration file. I recommend using configuration file for novice users.
  • It's behavior can be customized depending on usage situations. The default options should suit most needs.
  • It is portable and consists of only one executable binary.
  • Runs on Windows 2000 or later, including XP, Vista, 7, 2003 Server, 2008 Server.
  • It has a modular design which enables source code reuse.
Download

The program is called MinimizeRAMUsage. And here I present the binaries and source files for download:
Usage

Now, to use the program, place it anywhere you want, then execute it. You will notice that nothing happens, except that a text file named "MinimizeRAMUsage.config.txt" appears next to the program in the same folder.
This file is the configuration file. Don't worry, open it using Notepad for example. You will find something like this:
timeout=400
rescan=1
#process=firefox.exe


To enable memory usage minimization for firefox, only remove the # and save the file. The contents of the file would become:
timeout=400
rescan=1
process=firefox.exe


Now execute the program again, and here it goes! You will find it in the Windows "Task Manager" and you will notice that Firefox RAM usage dropped instantly.

To make it do that automatically all the time,proceed as follows:
1. Right-Click on the MinimizeRAMUsage.exe program and choose "Create shortcut".
2. Cut the shortcut file created and paste it in the start up folder. This folder is located in: Start Menu > Programs > Startup. If you use the French version of Windows, you will find it in: Menu Démarrer > Programmes > Démarrage.
3. You're done, every time the PC boots, it will start the program and you will never ever again see Firefox consuming all your RAM memory.

Advanced usage

Now if you are an advanced or curious user, let me explain the configuration options:
  • "timeout=n" where n in an integer greater than or equal to 1. This is the duration in milliseconds that separates two periodic minimization routines done by the program. The lower it is the more you swap pages and the more free RAM you have and the higher CPU you consume. The higher it is, the lower CPU you consume and the lower free RAM you have.
  • "rescan=b" where b is one of {0, 1}. When this is 1, the program rescans the running processes every time before minimization routine, to ensure all instances of the given targets are operated on, even those started after the startup of MinimizeRAMUsage.exe. If this is 0, then the program will only operate on the instances that existed when it was started, and it will terminate its execution when all those end their execution.
  • "process=name.exe" where name.exe is the name of the executable whose RAM usage is to be minimized. This can be given several times and it operates in an incremental way.
And example of configuration file might be:
timeout=400
rescan=1
process=firefox.exe
process=chrome.exe
process=iexplore.exe


There is another way to configure this program: the command line options. The syntax is the following:
MinimizeRAMUsage.exe [-r] [-t timeout] file1.exe [file2.exe, [file3.exe[...]]]
Where:
  • -r option disables periodic rescan, which is enabled by default.
  • -t option indicates timeout in milliseconds, which is 1 by default.
  • file1.exe, file2.exe, file3.exe, ... are the executable programs to operate on.
The command line arguments overwrite the configuration file options.

That's all! I wish this come handy to some of you, as it is to me!

How to use more than 4GB of RAM with 32-bits Windows OS?

Actually, I am still running the good old Windows XP 32-bits system on my 4GB RAM laptop. And as some of you may know, Windows 32-bits OS can use a maximum of 4GB of RAM due to the addressing space constraint.

In practice, my Windows XP only allows me to use a maximum of 3GB of RAM for my programs, while 1GB is restricted to the kernel. This, given that I enabled the PAE (Physical Address Extension) option for the kernel.

Anyway, I found a solution that enables me to use the whole 4GB for my applications, and that enables in general to use even more than 4GB of RAM with a 32-Bits Windows OS.

The trick is easy. Among the memories used by the system there is the RAM and the disk swap space (commonly C:\PageFile.sys) and other types also. I will let Windows use the 3GB of RAM as normal. Then I will make it use the last 1GB of RAM as a swap space, as if it was on disk. But to do this I will have to create a RAMDisk. A RAM disk is a virtual volatile disk that exist only in RAM. This enables me to regain the 1GB RAM space and use it for memory pagination operations. So nothing is lost.

To do so, I use a program called VSuite Ramdisk. This program enables me to create a new virtual disk drive in "My Computer" folder that enables me to access the 1GB RAM space that the OS cannot access natively.

You can download the program from here. The free edition does well. Once installed, you have to configure it to make the new RAM drive. Here is how:

1. Open the program.
2. Click on "Options" on the left tab bar.
3. Check the option "Enable OS Invisible Physical Memory".
4. Click on "Ramdisk" on the left tab bar.
5. Look at the option "Use OS Invisible Memory", next to it there is the total space of the RAM the 32-bits OS cannot use. Note down that number, I will called it OSIRS.
6. Choose the options for the new RAM drive. Personally I chose:
- Disk Size: 892MB
- Drive Letter: M:
- File System: FAT. You will need to use FAT32 if you have 6GB or more of RAM.
- Volume Label: RAMDISK
The rest of the options I kept for the default.
7. Click on "Add" button.
8. Click on "Exit" button.

Now you have a new drive in your computer called RAMDISK accessible as M:. Because of its volatile nature, this drive does not retain any files written into it once the computer is rebooted or shutdown.

Now, we will tell Windows to use our new drive as a container for its swap space. Here is the procedure:
1. Right click on "My Computer" and select "Properties".
2. Click on "Advanced" tab.
3. Click on "Settings" button inside "Performance" frame.
4. Click on "Advanced" tab.
5. Click on "Change" button inside "Virtual Memory" frame.
6. Select "M: RAMDISK" from the list.
7. Choose the option "Custom size" inside "Paging file size for selected drive" frame.
8. In "Initial size (MB)", type the number OSIRS minus 6. For example, in my case I type "886".
9. Type the same number in the text field "Maximum size (MB)".
10. Click the button "Set".
11. Click the button "OK".
12. Click the button "OK".
13. Click the button "OK".

Now, Windows will use the RAM disk every time it runs out of those 3GB RAM memory. Windows will not tell you that it uses the full 4GB (or maybe more in your case), but it will effectively do it.

Windows is still configured to use hard disk space to do paging operations, and because of this, some might argue that Windows might use the hard disk to swap pages of memory, instead of the RAM disk, which makes our trick meaningless, but here some ways to get around it:
1. You can remove the swap space from all other drives except the RAM disk. This will make dead sure Windows will use the RAM disk for memory page swapping. But this limits the virtual memory size to exactly 4GB, and in deed disables disk paging. This is not recommended.
2. Reduce the disk space used on other drives. This is my adopted solution. I limit Windows to only 1GB of hard disk space (on C:) in addition to the 886MB space of the RAM drive. This gives me about 5GB of virtual memory. By experience, I have never got in an out of memory situation since I bought my laptop (This means about 5 months of usage without a single out of memory situation). This proves that the 5GB are really sufficient for my jobs. The amount of hard disk space you need depends on your set of applications and how you use them. You can test for yourself to find a suitable configuration, you can always higher that size given that you have free space on the hard disk.

That's all. Thank you for your attention. I wish I have given something useful.

Installing ATI Proprietary Linux Driver (fglrx) on Debian Lenny 5.0 Stable 64 bits

I am one of those unlucky peoples who happen to own a laptop equipped with an ATI graphic card, while being strongly attached to the open source world...

Yes, again, and the fight just continues between open source world (Linux, BSD, ...) and the ATI for its graphic chipset driver.

I am not going to reenter all that history. In brief, I have successfully installed the fglrx driver version 10.10 (the ATI Proprietary graphic chipset driver) on my laptop running the Linux Debian 5.0 Lenny Stable 64 bits.

Let's put it in perspective: I did that in 16 November 2010. In that day, the 10.10 version of fglrx is experimental, but not yet available in the experimental version of Debian. It may seem weired to install an experimental driver on the stable version of the OS, but I can say I had no choice. My graphic card was only supported starting from that version of fglrx. Yet I still stick to the reliable stable version of the Debian OS.

I am presenting this experience to the world because I find it useful for some of you, a bit like me. And I think it can help some others to install fglrx on their machines, if they have to. I made some bash scripts that automate the installation to some extent. But I want to show what they do first.

Hereafter are the general steps needed to install the fglrx driver. These are only meant to be understood, not to perfectly follow, because I will give some scripts that automate these actions just later.

1. Download the ATI Proprietary Linux Driver package. This got me the ati-driver-installer-10-10-x86.x86_64.run file.
http://support.amd.com/us/gpudownload/linux/Pages/radeon_linux.aspx

2. Remove all traces of ATI drivers using the package manager.
apt-get purge fglrx-driver fglrx-driver-dev fglrx-atieventsd fglrx-modules fglrx-kernel-src fglrx-control fglrx-glx fglrx-amdcccle fglrx-kernel fglrx-glx-ia32 fglrx-source


3. Extract ati-driver-installer-10-10-x86.x86_64.run into a directory fglrx-10-10.
"./ati-driver-installer-10-10-x86.x86_64.run" --extract "./fglrx-10-10"

4. Correct the internal structure of the fglrx installer package:
These steps are the fruit of hours of debugging efforts I did to figure out how to make the fglrx installer generate correct debian packages for me.

4.1. Create some directories.
The structure of the extracted installer files is not complete for a 64 bits system. So I corrected that.

4.2. Copy some files.
Some files needed to be copied to different locations inside the installer directory, in order to be installed in the right places when the packages are built.

4.3. Alter some files.
Some configuration files and scripts needed some changes to install the needed files and to make the correct links to the shared libraries when installed on the system.

5. Create the debian packages (.deb) from the extracted patched files.
./ati-installer.sh 10.10 --buildpkg Debian/lenny

6. Install the generated packages.
dpkg -i fglrx-driver*.deb
dpkg -i fglrx*.deb


7. Remove the open source ATI drivers available with Xorg.
apt-get purge xserver-xorg-video-ati

8. Patch some Linux source files.
This is required to solve a compatibility issue with fglrx and linux kernel API.
The issue is a change in the name of a function in the linux kernel, which is not taken into account by the developers of fglrx. The change I do does not really hurt the linux kernel itself, as all I am doing is adding a new function that is the exact copy of another one.

9. Build and install the fglrx kernel driver.
This will build the fglrx kernel module which enables the 3D acceleration of the graphic card.

10. Ensure that the fglrx kernel driver is loaded as a kernel module.
This is a final check to ensure the fglrx module has been installed and loaded into the kernel:
modprobe -l | grep fglrx

11. Configure the Xorg server to use fglrx driver.
First we have to stop gdm (GNOME Desktop Manager):
invoke-rc.d gdm stop

Then we generate the Xorg configuration that uses fglrx for X:
aticonfig --initial=dual-head

Finally we start gdm:
invoke-rc.d gdm start

12. Pin fglrx driver in the package manager to disallow any further automatic upgrades.
I don't actually provide the script needed to do this, as I easily do it using Synaptic Package Manager.

Here are the files needed. Just download this archive, extract it and put it in the same directory as the ati-driver-installer-10-10-x86.x86_64.run file. It will contain:
make_packages
install_driver
install_kernel_module
config_x
fglrx-driver.preinst
fglrx-driver.postrm


The scripts should be run as root from a real TTY (Alt-Ctrl-F2) as they don't expect X to be running all their lifetime. The run order is the following:

./make_packages 10 10
./install_driver
./install_kernel_module
./config_x


I am here for your comments or questions, don't hesitate.
I wish I added something to the community. Enjoy!