ibuclaw
March 23rd, 2009, 12:20 PM
Overview
Firstly, I'd like to give all credit to sdennie for the idea he shared. This is my implementation of it, that I managed to post up before him. ;)
This guide is intended for anyone on Laptops who are taking measures to decrease disk activity, as shown on this howto here. (http://ubuntuforums.org/showthread.php?t=839998) Or anyone who is annoyed at firefox (along with SQLite) constantly fsyncing to disk, which could potentially also slow down the speed of the browser too if you are having to wait for the fsync to complete before continuing.
Implementation
It's has been a well known fact since the time of Firefox-3.0beta, Firefox constantly fsync's to disk after each time you load/reload a webpage. References as stated below:
Launchpad Bug Report: https://bugs.launchpad.net/ubuntu/+source/firefox-3.0/+bug/221009
Mozilla Bug Report: https://bugzilla.mozilla.org/show_bug.cgi?id=421482
A Mozilla Developer's Blog: http://shaver.off.net/diary/2008/05/25/fsyncers-and-curveballs/
As can be seen if you run this in a terminal:
strace -p `pidof firefox` -e trace=fsync,fdatasync
The fix, we create a new library with a our own definition of fsync() (http://www.opengroup.org/onlinepubs/009695399/functions/fsync.html) inside.
Or, for the technically adept explanation. We turn fsync() into a NOP function. (http://en.wikipedia.org/wiki/Nop)
Steps
1) Create a new file. Let's name it fsync.c for simplicity
gedit fsync.c
And create our function inside it.
int fsync (int fd)
{
return 0;
}
Save and Quit.
2) Compile our library.
gcc -fPIC -g -c -Wall fsync.c
And link it
gcc -shared -Wl,-soname,fsync.so -o fsync.so fsync.o -lc
3) Install the library into a logically named directory. (ie: /usr/local/lib or ~/.mozilla)
sudo install fsync.so /usr/local/lib
4) Assign the library to the LD_PRELOAD shell variable.
export LD_PRELOAD=/usr/local/lib/fsync.so
5) Run firefox
firefox &
Now run the strace command on it again, and fsync() will be nowhere to be seen.
Putting it into Practice
One way to set this the default on all Firefox Desktop icons in Ubuntu, we are going to create a script to be put in the /usr/local/bin directory.
gedit firefox
And put the following inside:
#!/bin/sh
export LD_PRELOAD=/usr/local/lib/fsync.so && /usr/bin/firefox "$@"
Save and Quit, now install it.
sudo install firefox /usr/local/bin
And you are all done.
Extending this HOWTO
You can, if you choose, re-implement fdatasync() too, to prevent firefox calling that function, but I would recommend not to due to the differences in the functions, as stated here. (http://linux.die.net/man/2/fsync) In short, fdatasync is a more mission-critical sync, whereas fsync just attempts to sync everything regardless of it's state in cache.
However, feel free to extended this HOWTO at your own discretion, fdatasync is defined in the same way fsync is, just incase anyone tries.
Questions/Comments/Suggestions on clean-up are welcome.
Regards
Iain
Firstly, I'd like to give all credit to sdennie for the idea he shared. This is my implementation of it, that I managed to post up before him. ;)
This guide is intended for anyone on Laptops who are taking measures to decrease disk activity, as shown on this howto here. (http://ubuntuforums.org/showthread.php?t=839998) Or anyone who is annoyed at firefox (along with SQLite) constantly fsyncing to disk, which could potentially also slow down the speed of the browser too if you are having to wait for the fsync to complete before continuing.
Implementation
It's has been a well known fact since the time of Firefox-3.0beta, Firefox constantly fsync's to disk after each time you load/reload a webpage. References as stated below:
Launchpad Bug Report: https://bugs.launchpad.net/ubuntu/+source/firefox-3.0/+bug/221009
Mozilla Bug Report: https://bugzilla.mozilla.org/show_bug.cgi?id=421482
A Mozilla Developer's Blog: http://shaver.off.net/diary/2008/05/25/fsyncers-and-curveballs/
As can be seen if you run this in a terminal:
strace -p `pidof firefox` -e trace=fsync,fdatasync
The fix, we create a new library with a our own definition of fsync() (http://www.opengroup.org/onlinepubs/009695399/functions/fsync.html) inside.
Or, for the technically adept explanation. We turn fsync() into a NOP function. (http://en.wikipedia.org/wiki/Nop)
Steps
1) Create a new file. Let's name it fsync.c for simplicity
gedit fsync.c
And create our function inside it.
int fsync (int fd)
{
return 0;
}
Save and Quit.
2) Compile our library.
gcc -fPIC -g -c -Wall fsync.c
And link it
gcc -shared -Wl,-soname,fsync.so -o fsync.so fsync.o -lc
3) Install the library into a logically named directory. (ie: /usr/local/lib or ~/.mozilla)
sudo install fsync.so /usr/local/lib
4) Assign the library to the LD_PRELOAD shell variable.
export LD_PRELOAD=/usr/local/lib/fsync.so
5) Run firefox
firefox &
Now run the strace command on it again, and fsync() will be nowhere to be seen.
Putting it into Practice
One way to set this the default on all Firefox Desktop icons in Ubuntu, we are going to create a script to be put in the /usr/local/bin directory.
gedit firefox
And put the following inside:
#!/bin/sh
export LD_PRELOAD=/usr/local/lib/fsync.so && /usr/bin/firefox "$@"
Save and Quit, now install it.
sudo install firefox /usr/local/bin
And you are all done.
Extending this HOWTO
You can, if you choose, re-implement fdatasync() too, to prevent firefox calling that function, but I would recommend not to due to the differences in the functions, as stated here. (http://linux.die.net/man/2/fsync) In short, fdatasync is a more mission-critical sync, whereas fsync just attempts to sync everything regardless of it's state in cache.
However, feel free to extended this HOWTO at your own discretion, fdatasync is defined in the same way fsync is, just incase anyone tries.
Questions/Comments/Suggestions on clean-up are welcome.
Regards
Iain