21.07.2015 Views

Linux Journal | December 2012 | Issue 224 - ACM Digital Library

Linux Journal | December 2012 | Issue 224 - ACM Digital Library

Linux Journal | December 2012 | Issue 224 - ACM Digital Library

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

COLUMNSTHE OPEN-SOURCE CLASSROOMRAM instead of 256, so it allowsfor much more flexibility with thememory split.To Swap or Not to SwapSD cards are getting better everyyear when it comes to wear levelingand write cycles. The concern isalways that excessive use of theSD card will wear it out, and it willbecome read-only. Because the RPialso suffers from limited and nonexpandableRAM, the issue of swapspace is highly debated.Raspbian comes installed bydefault with a swap file active—not a swap partition, but a swapfile. Whether this swap file willwear out your SD card is still upfor debate. I tend to be paranoidabout such things, so I searched foran alternative. Because I have the512MB units, I have a little moreRAM to work with, so I decidedto use zRam to compress someof the system RAM and use it asswap space. How does that work?Basically, zRam allows the systemto use RAM as swap space, but in acompressed mode that allows it toappear as more RAM+swap than thesystem actually contains.zRam already is compiled into theRaspbian kernel, so if you want totry my method, it just takes a littlescripting. I absolutely love the scriptI found at the eXtremeSHOK.comWeb site. That site is off-line atthe time of this writing, so I’veincluded the script below. Createa file called /etc/init.d/zram, whichcontains the following:#!/bin/bash### BEGIN INIT INFO#Provides: zram#Required-Start:#Required-Stop:#Default-Start: 2 3 4 5#Default-Stop: 0 1 6#Short-Description: Increased Performance In <strong>Linux</strong> With zRam#(Virtual Swap Compressed in RAM)#Description: Adapted for Raspbian (Rasberry pi) by eXtremeSHOK.com#using https://raw.github.com/gionn/etc/master/init.d/zram### END INIT INFOstart() {mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E➥--only-matching '[[:digit:]]+')modprobe zramsleep 1#only using 50% of system memory, comment the line#below to use 100% of system memorymem_total_kb=$((mem_total_kb/2))echo $((mem_total_kb * 1024)) > /sys/block/zram0/disksizeWWW.LINUXJOURNAL.COM / DECEMBER <strong>2012</strong> / 53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!