Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Development & Programming > Programming Talk
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Programming Talk
This forum is for all programming questions.
The questions do not have to be directly related to Ubuntu and any programming language is allowed.

 
Thread Tools Display Modes
Old September 16th, 2007   #1
cisk4me
First Cup of Ubuntu
 
cisk4me's Avatar
 
Join Date: Jan 2007
Location: Windermere
Beans: 10
Ubuntu 9.04 Jaunty Jackalope
Bash script is faster on Live CD

I have a script which runs a program multiple times, sorting the output files for further processing. These output files are deleted at the end of the job.
I have a speed-step processor and see that for much of the time it is only running at 600MHz instead of 1.5GHz because of the slowdown caused by all these disk accesses.
I've copied the script and program to a tar file on a USB drive, booted my computer with a Live CD and untarred the archive to /home/ubuntu. When I run the script, all the disk accesses are now to RAM and the processor speed is permanently at 1.5GHz. The job time is reduced from 250 minutes to 145 minutes.
When I run the script with my installed Ubuntu, how can I get the files written to RAM instead of disk, and thus enjoy the job times seen with the Live CD?

Last edited by cisk4me; September 16th, 2007 at 04:57 PM.. Reason: typo
cisk4me is offline   Reply With Quote
Old September 16th, 2007   #2
pxwpxw
Chocolate Ubuntu Mocha Blend
 
pxwpxw's Avatar
 
Join Date: Apr 2006
Beans: 1,771
Ubuntu 9.04 Jaunty Jackalope
Re: Bash script is faster on Live CD

cisk4me

I can use /dev/ram0.../dev/ram15 here, I hope this explains it:
Your ramdisk size may vary.

Code:
x@bigmac:~$ dmesg | grep RAM
[    0.000000] Top of RAM: 0x110000000, Total RAM: 0x90000000
[   21.567928] RAMDISK driver initialized: 16 RAM disks of 65536K size 1024 blocksize

x@bigmac:~$ ls -l /dev/ram*
brw-rw---- 1 root disk 1,  0 2007-09-16 22:09 /dev/ram0
...
brw-rw---- 1 root disk 1,  9 2007-09-16 20:29 /dev/ram15

x@bigmac:~$ sudo mke2fs /dev/ram0

x@bigmac:~$ sudo mount /dev/ram0 ramdir0

x@bigmac:~$ df
Filesystem           1K-blocks Used Available Use% Mounted on
/dev/ram0                63461      1289     58896   3% /home/x/ramdir0

x@bigmac:~$ mount
/dev/ram0 on /home/x/ramdir0 type ext2 (rw)
x@bigmac:~$
This is xubuntu in an Applemac G5, using 2.5GB ram. I dont know how that affects the ramdisk availability, and I dont know how to control the size or number of ramdisks.
pxwpxw is offline   Reply With Quote
Old September 17th, 2007   #3
cisk4me
First Cup of Ubuntu
 
cisk4me's Avatar
 
Join Date: Jan 2007
Location: Windermere
Beans: 10
Ubuntu 9.04 Jaunty Jackalope
Re: Bash script is faster on Live CD

Thanx for the info about ramdisks. I didn't know that.
I found good help at
http://www.vanemery.com/Linux/Ramdisk/ramdisk.html

and adapted it to my needs. I want a single ramdisk of 384MB which has to be changed from the default 64MB by modifying the parameters for grub. This is done by editing /boot/grub/menu.lst, adding the ramdisk size and rebooting.
Code:
$ sudo gedit /boot/grub/menu.lst
$ more /boot/grub/menu.lst
title           Ubuntu, kernel 2.6.20-16-generic
root            (hd0,6)
kernel          /boot/vmlinuz-2.6.20-16-generic root=UUID=17e83647-9ad5-487b-b659-81d04109ba66 ro quiet splash ramdisk=393216
initrd          /boot/initrd.img-2.6.20-16-generic
quiet
savedefault
After the reboot, as in your post:
Code:
$ sudo mke2fs /dev/ram0
mke2fs 1.40-WIP (14-Nov-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
98304 inodes, 393216 blocks
19660 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
48 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729, 204801, 221185

Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
$ sudo mount /dev/ram0 /home/ramdisk
$ sudo chown -R graham:users /home/ramdisk
User data and jobs can now be copied to /home/ramdisk where they run much more quickly if there are frequent disk accesses
cisk4me is offline   Reply With Quote
Old September 17th, 2007   #4
pxwpxw
Chocolate Ubuntu Mocha Blend
 
pxwpxw's Avatar
 
Join Date: Apr 2006
Beans: 1,771
Ubuntu 9.04 Jaunty Jackalope
Re: Bash script is faster on Live CD

Thanks for that, very useful.
pxwpxw is offline   Reply With Quote
Old September 17th, 2007   #5
avik
Dipped in Ubuntu
 
avik's Avatar
 
Join Date: Aug 2006
Location: Same place as Apple HQ
Beans: 529
Ubuntu 7.10 Gutsy Gibbon
Re: Bash script is faster on Live CD

Wow! That really is nifty. This is a great example of how the "everything is a file" mentality really pays off.
avik is offline   Reply With Quote
Old September 17th, 2007   #6
cisk4me
First Cup of Ubuntu
 
cisk4me's Avatar
 
Join Date: Jan 2007
Location: Windermere
Beans: 10
Ubuntu 9.04 Jaunty Jackalope
Re: Bash script is faster on Live CD

Not really so nifty. What would be better is say a command different from bash, say rambash, which would start the job in RAM and keep it there while there was sufficient memory, swapping it to disk automatically when the memory was exhausted. This is a bit like the old Apple "multitasking" where you had to manually allocate each jobs memory in advance.
Still, it is certainly better than not having the facility at all and I'm now using it every day
cisk4me is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:35 PM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry