Skip to main content

virtual memory on the iPad, or, the impact of swap files on NAND flash memory

i've noticed that the use of virtual memory on the iPad is a rather controversial topic on several online forums. in this article, i shall talk about what it's all about, and how it affects system performance. suffice to say, this technique currently only works on jailbroken iPads - however, i'm rather certain the same underlying technique will be used by apple when iOS4 is released sometime in november. until confirmation though, we can only hang tight.

to appreciate the import of virtual memory on modern systems thus, it is crucial to have at least a basic understanding of how a computer works beneath and behind the smoke and mirrors.

a short history lesson therefore...

a feature of the modern computer that is not widely known outside of the tech community is how the computer handles 'multitasking'. computers, well, when it all began anyway, started with only a processor core and memory chips that run in a synchronized fashion. that, incidentally, is how you get processors' clock speed, with the major processor makers going into a little arms race of their own for a couple of years.


back to clock speeds, a processor clocked a 1GHz would theoretically run at 1,000,000,000 cycles per second. that's an insane number of cycles squeezed into an incredibly short amount of time. any operation that your computer does will require a certain number of cycles to run. for example, you might choose to play an mp3, the computer will use a few cycles of processing to retrieve the file from disk, and after the file is read into the computer's memory (or Random Access Memory), the processor goes on to decode the mp3 file and uses an audio synthesizer to output the signal to your earphones or speakers.

now, obviously this is a very complicated process at the lowest levels, and techniques such as pipelining [wikipedia.org] can increase the perceived snappiness of the computer. using free cycles while the computer is fetching data from a data store, or even as it's running idle (remember, lots of cycles in a small time!) gives the user the impression of multitasking.

when we talk about system performance, however, the most obvious variables are:
  1. processor speed (clock speed)
  2. amount and type of RAM
  3. access time of the storage media
you must be wondering, okay, so this fella's telling me about processor speed and cycles, and i can understand more RAM means its faster, but type of RAM* and access time of the storage media? well, it so happens that the processor and RAM performance are magnitudes faster than conventional spinning disk formats. flash memory, not unlike those on your USB sticks, offer much faster access times, and that is part of the reason why the iPad is so snappy even though it ships which _gasp!_ 256MBs of RAM for the whole range, from the 16GB WiFi to the 64GB WiFi+3G.

the fantastic thing about apple's walled garden model of apps is the full control that they have over the product experience. in my opinion, i find that it's really true when they say they design the hardware, and then integrate it with their (approved) software to enhance the user experience. there's no question that their mantra _just works_. on the other hand, nobody ever said that there's only 1 way to skin a cat. some might even say apple's policies are rather high-handed.

i'm not going to go into a diatribe about how i feel about apple's policies. however, i will say that their engineers have created far superior hardware than their software will have you believe. for example, how many of us have used the iPad's onboard Safari browser and cringed everytime it reloads a page after we've come back from another tab?

the way Safari on the iPad works is that it runs almost exclusively on RAM, all 256mb and not very much of it at all (especially after taking into account the system programs running in the background, only 140mb or so is left for use). for this reason alone, the browser will clear it's memory store of any backgrounded tabs to free up memory to display the active tab. this certainly makes the browsing experience jarring when one returns to their previous tab...

naysayers will immediately point to other browsers who write their memory to a flash cache, and say that those do not suffer the same performance penalty. however, there is a universal method that works for Safari, and not just that app in particular. the fix will work for the whole system and generally make things snappier.

in the beginning of the post i mentioned how virtual memory is a controversial hot topic on the online forums. as it turns out, virtual memory (or VM for short) is also the way to improve performance on the iPad. the above example of the browsers actually give us a clue on how VM might work. essentially, when activated, iOS will create a swap file on disk (in our iPad case, the flash memory), and write the current contents of RAM to this swap file. it will then free up the RAM for use by the currently active app. when the "older" information is requested, iOS will load the data from the swap file back into RAM, providing rather transparent handover from the user's standpoint. a caveat though - i have to say "rather transparent" because there will be a barely noticeable <1 second lag as the system loads data into RAM. however, with VM activated, the user experience will be enhanced so much that it doesn't seem to matter.

on the dark side, people on the forums seem to be hung up about the longevity of NAND flash memory when VM is activated on their iPads. there are a vocal few in the community who argues that NAND flash has a limited life-span (true) and that using this method will significantly shorten that life-span (controversial).

to elaborate, NAND memory _does_ have a limited life-span, in the range of 100,000 write cycles for the older models to 1,000,000 cycles for the newer models. as of writing, their is no definitive answer as to which chips are installed in the iPads. however, there are mitigating factors arguing that the VM method will not significantly shorten the iPad's life.

firstly, activating VM will create swap files on the flash disk. these files are written and overwritten once or twice or even 3 times a day with heavy usage. 100,000 / 3 per day = 3300+ days = more than 9 years of usage time. supposing the newer NAND chips with a rated 1,000,000 cycles were installed, we would have more than 90 years of usage on the device. i'm not even sure if i'll be alive in 90 years' time.. haha.

secondly, there is this technique among flash disk makers to mitigate the limited write cycles of their products. this is known as wear levelling [wikipedia.org]. in essence, writing is spread across the available "free space" on the flash disk to ensure that no single sector is being heavily used. whether this method has been implemented by apple or not is unclear, but given the range of flash based products that apple produces (think iPad, iPhone, iPod touch, iPod shuffle, iPod nano and so on..), it wouldn't be overly optimistic that they are rather sophisticated in their handling of flash memory.

hence, i do believe that activating virtual memory is a worthy and low-risk hack for your iPad. i shall be posting up step by step instructions for doing so shortly. as usual, if you liked this post, comment or give us a shout out!


*i shall not talk more about how the type of RAM affects system performance, for that's a study into the history of RAM, and delves into far too much detail for this article. however, do leave a comment if you're keen and i'll see if i can't point you in the right direction :-)

Comments

Popular posts from this blog

777 CBT hacks

so i was about to go through the computer based training package from boeing on my computer at home, when i came across an error asking me to locate the files on my computer. a simple "replace.." command editing the lessons.lst file via notepad made light work of that. basically, all that needed to be done was to change the lessons.lst file so that the CBT program knows which directory the files are stored. once fired up, i realised that the fonts look crappy as a geocities website. i figured it's gotta be a font problem since, you know.. crappy fonts right? so i muck around the directory and voila ! a folder called "fonts". i did the silly thing first - copying the entire "fonts" directory from my windows\fonts folder into my CBT folder, and when that didn't work, i figured the next best thing to do was to copy the contents of the "fonts" directory from CBT into the windows one. brilliant. my CBT now looks pretty as a pancake. with...

Sticky rubber/plastic coating on gadgets and how to remove them

I’ve drowned my old Sony Z4 Tablet (yeah, I’m still not entirely sure how I pulled that one off) and have been living without an Android tablet for about a year now. In the meantime, I’ve bought myself a 12.9 inch iPad Pro 1, which I’m using to type this post. Anyway, the point of this post isn’t about neither the Z4, nor the iPad Pro. Yes, this post is all about my 10 inch Nexus 10, the flagship hardware created by Samsung to Google’s exacting specifications. I’ve stopped using it since 2016 (I know, because when I fired the baby up, she held a full charge* and all the chrome tabs were circa ‘16), and 2 years of storage in humid South East Asia did the poor sod no favors. In some way, I think I’ve come to disuse this tablet because of how bad it feels in the hand. Some boffin thought it would be splendid if the Nexus 10 felt like a good 2B accompaniment - the veritable eraser - and coated the damned thing in a layer of rubberised something . In some way, I suppose they had thei...

jailbreaking your iPad - a primer

/* for the sake of simplicity, iPod touch, iPhone and the iPad shall be known as iDevices */ according to the US Copyright Office on 26 july 2010 [cnet.com], jailbreaking your iDevice does not contravene federal copyright law anymore. in practice, it basically states in legalese that it is now okay for American iDevice users to break out of apple's walled garden model of apps from the appstore only. suffice to say, people in the rest of the world don't have to deal with all these.. do note, however, that this still doesn't absolve the user from apple's software licence agreement - apple will void your warranty if you jailbreak your iDevice. but well.. at least it's not a statutory crime to do whatever you want with what you bought anymore. it is also important to note that should you require warranty service, the process of restoring your iDevice to factory settings is easy as pie...