Should Apple enable virtual memory

Discussion in 'iPad' started by mikethebigo, Apr 22, 2010.

  1. mikethebigo macrumors 68000

    Joined:
    May 25, 2009
    #1
    I'll be honest, I don't know enough to have a good technical opinion of this either way. All I know is that 256 MB of ram starts to seem a little insufficient once you realize things like safari can't cache to the flash storage and the iPad has a significantly more ram-intensive frame buffer than the 3GS.

    When I'm only running safari, I can switch between multiple tabs without reloading, I can even quit safari, come right back, and not have to reload. But, if i quit safari and run another program that needs the ram, the next time I open safari almost all of the pages have to reload since their cache has been purged.

    Opinions?
     
  2. nStyle macrumors 65816

    Joined:
    Dec 6, 2009
    #2
    I don't fully understand virtual ram, but this doesn't sound like much of an opinionated question.
     
  3. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #3
    Apps should manage their own data caching intelligently and manually instead of letting the memory subsystem guess in a much less power efficient manner.
     
  4. 4DThinker macrumors 68020

    Joined:
    Mar 15, 2008
    #4
    Should Apple enable virtual memory?

    Yes. Of course they'll need to redesign the iPad so you can either add more RAM internally or stick on some external USB storage for that purpose.

    By simply stretching the iPhone UI to make an iPad it appears Apple didn't consider the consequences of increased web use (compared to a Touch or iPhone) and larger app size/functionality to take advantage of the increased screen area. A real shame IMO.
     
  5. 2002cbr600f4i macrumors 6502

    Joined:
    Jun 21, 2008
    #5
    Um, I don't think you understand what he's saying... He wants apple to use the on-board flash memory as a Virtual memory space. To do so wouldn't require either of the things you said, just a change to the underlying OS to support virtual memory (granted that's not just a simple change, although full desktop OSX does it, so it shouldn't be horribly difficult for them to backport that back into the iPhone OS.)

    No, the real issue is 1) speed (you'd totally notice it loading off the flash) 2) wear on the Flash memory cells.

    The fact is, 256MB SHOULD be plenty of memory... It wasn't all that long ago that we all only had 256MB of RAM in our desktop machines, and we were running window based OS's just fine. It's more a case of the applications being memory pigs and not cleaning up after themselves when they shut down.
     
  6. nsorrelle macrumors member

    Joined:
    Apr 12, 2010
    #6
    It also wasn't that long ago that 128mb, or even 64mb of ram was sufficient. That's a moot point that ignores advances/changes in technology. Have you ever tried surfing the internet on a relatively old computer? Many websites are much more processor and memory intensive than they were 5 years ago.

    Some applications may be memory pigs out of laziness or ignorance, but that's not the defining point here. Some apps need a lot of memory to deliver the experience to users that they're intending to, and it seems out of all the iPad's hardware, memory is the limiting factor. This may become a more prevalent issue once multitasking is introduced, but we really don't know at this point. Some people are rightfully pessimistic, considering memory issues many of us have seen with out iPads so far, so the burden of proof is on Apple.

    Supplementing the RAM with the other memory is a fantastic idea, especially since the main disk is flash based. Of course, it should be a last resort, but what would you honestly prefer? Programs randomly crashing or the possibility of slowdown? Desktops that use a traditional hard disk for virtual memory slow down when they use it, but flash memory is much faster, so I wouldn't expect to see the same level of slowdown. It'd be interesting to see how it could perform.

    EDIT:
    I also wanted to add that wearing down flash memory cells is not really a major issue here. By the time those fail, you probably will have a new model in your paws.
     
  7. mikethebigo thread starter macrumors 68000

    Joined:
    May 25, 2009
    #7
    How much slower do you think it would be to load from flash? Honest question, I really don't know. Also, I read that flash cells would last much longer than other things on the unit even if you were constantly paging them, is that true?

    One thing I've read about is that the desktop comparison is invalid for this exact reason. windows and OSX have virtual memory, so 128 or 256 MB was not a big deal. Remember what happened to Windows when your hard drive ran out of space? It basically froze and stopped working
     
  8. blackNBUK macrumors 6502a

    Joined:
    Feb 19, 2010
    Location:
    UK
    #8
    Flash memory isn't faster in all circumstances; for example writing to a flash disk can be significantly slower than writing to a HDD. The performance will also depend on what type of flash memory is used(SLC vs MLC) and how it has been optimised. I would also be interested to see how well virtual memory works using the iPad's flash but I don't think it is an automatic slam-dunk.

    In an ideal world Apple's existing mechanism of relying on the Apps to manage their memory use should work. For example there are already callbacks that Apps should use as the signal to reduce their memory usage. However it does depend on App developers following the guidelines properly.
     
  9. nsorrelle macrumors member

    Joined:
    Apr 12, 2010
    #9
    Considering that flash memory is a hell of a lot faster, I think it's something that should be on the table as a potential asset. Apple should definitely run some tests, if they haven't already.

    Flash cells that are constantly being paged will still last beyond the iPad's lifetime for an average user, given that it is, indeed, quality flash memory. Even so, this is assuming that the iPad would constantly be needing to use it, instead of using it merely as a backup.

    TLDR: Wearing out flash memory is the smallest issue in this discussion.
     
  10. spammerhamster macrumors 6502

    Joined:
    Feb 5, 2010
    #10
    There are dozens of situations on the iPad where virtual ram would come in handy, browsing a page with lots a images for instance. When the iPad is out of memory, images won't load anymore. Or worse, the browser would crash.

    The virtual ram does not need to be accessed or changed constantly like windows would do. It could just be used as in overflow, when really needed. Ssd reviewers had calculated that a constant usage of flash memory would not decrease the lifespan significantly more.
     
  11. jtara macrumors 65816

    Joined:
    Mar 23, 2009
    #11
    I think it's mostly a matter of waiting for 4.0 and Apple re-writing their own apps to take advantage of some 4.0 features. I gather there are some aspects of virtual memory in 4.0, but not exactly the way we traditionally view virtual memory. It's more of a cooperation between the OS and the app, rather than the OS just providing the app with boundless apparent RAM. So, apps will need to be re-written to use the facilities that are there intelligently.

    Unfortunately, iPad users will have to wait until fall for this, and then longer for many apps to be re-written.
     
  12. Runt888 macrumors 6502a

    Joined:
    Nov 17, 2008
    #12
    Sorry to be technical, but the iPhone OS does have virtual memory. What is doesn't have is a backing store, so non-readonly pages are never written out to disk (flash memory in this case). Instead, the OS asks the application to voluntarily free up some memory, and can terminate the application if enough memory isn't freed.

    Some good info:

    http://devworld.apple.com/iphone/li...tual/ManagingMemory/Articles/AboutMemory.html
     
  13. blackNBUK macrumors 6502a

    Joined:
    Feb 19, 2010
    Location:
    UK
    #13
    Good point, although I wonder now many pages of the average App are read-only. The article mentions code pages but I'd imagine that a lot of memory is taken up by images and such like. Any iPhone devs want to comment?
     
  14. Dammit Cubs macrumors 68000

    Dammit Cubs

    Joined:
    Jul 31, 2007
    #14
    using the flash nand as a caching system is probably not a good idea. the flash reliability is based on cycles. Normally, you will see about 100,000 read write cycles until you start seeing some wear on the oxide.

    If you are constantly writing to the flash, 100,000 times the system writing to it will be reached much faster and it will change the user model. Not to mention, managing flash memory is won't necessary make it faster. It would solve the memory issue, but the real solution should of always been 512mb of ram.

    This is dumb for apple to just put 256mb; I mean ipad apps aren't backwards compatible with iphone, but iphone apps are compatible with ipad. Developers would only gain from having more ram on the Ipad.
     
  15. jtara macrumors 65816

    Joined:
    Mar 23, 2009
    #15
    Frankly, I'd never read that document, as the apps I've written don't use a lot of memory and so it hasn't been a concern. Now that I have, I can see that the problem is largely one of poorly-written applications. Everything needed is already there in the CURRENT iPhone OS. No need to wait for 4.0.

    Apple's handling of read-only code pages is a departure from the convention in *nix systems, which typically do NOT support re-loading of code pages from the executable file. Instead, iPhone OS is more similar to how Microsoft Windows does things. In traditional *nix systems, there is no distinction between code and data pages in handing virtual memory - BOTH are written-out to backing store when pages are discarded, and code is never re-loaded from the original file. (One positive side-effect of this is that *nix systems are easy to hot-update, as there isn't the concern about changing an executable file while the application is running as there is under Windows.)

    So, we can really cast-away much concern about executable size. Pages of code will be paged-in as needed during execution. This will slow things down, but there's no reason for apps to "run out of memory" for code execution.

    But without backing store for data pages, applications have to be careful about how much working storage they use, and how they use it. I suspect that a lot of apps are being pretty dumb about how they use memory.

    Somebody asked above about resources - bitmaps, etc. I suspect that one of the problems right now is that application authors are not using the virtual memory system effectively. One technique that can be used is to map resources files into memory using mmap. The file can be read-only OR read-write. So, there's full read-write virtual memory WITH backing store! It just isn't *automatic* backing store.

    I'd bet that 99% of iPhone apps aren't doing this, but instead are allocating some memory and reading the resource into that memory. You have to be careful about just what format the file data is in - it does you no good if some kind of format conversion is needed on the data in the file. (Even if so, you still could read from or map a file that has data in one format, and write the modified data to another memory-mapped file that contains the transformed data...)

    http://www.alexcurylo.com/blog/2009/05/14/tip-iphone-virtual-memory/

    From the link above:

    Steve Jobs wants developers to RTFM. I suspect (hope) that they are going to be brutal with developers of background apps to make sure they are making use of virtual memory effectively and not over-using memory resources. I wouldn't be surprised to see them start cracking-down on sloppy non-background apps, as well.
     
  16. 2002cbr600f4i macrumors 6502

    Joined:
    Jun 21, 2008
    #16
    Ok, couple of things...
    1) we're using up the memory faster because on the iPad we're typically getting the "full web" pages, not a "mobile" version...

    2) 256MB is a LOT of memory... Yes, if the site has a lot of graphics that can be sucked up (especially big photos) , but a site itself, navigation and background and such should NEVER take anywhere near that much space! That's a LOT of HTML, Javascript etc if it's sucking up 256MB for a page...

    Frankly, pages have gotten rediculously overblown with all the DHTML, Flash, animations and other stuff over the last 10 years.

    Anyhow, yeah, I wouldn't mind seeing apple do some sort of limited virtual memory. Maybe that's something in 4.0? I can't see how they're going to support some of the background tasking APIs without it given that some apps need all the RAM they can get.
     
  17. nutmac macrumors 68040

    Joined:
    Mar 30, 2004
    #17
    Let's not forget that Safari and OS only (without any pages opened) consumes memory. After few pages and tabs, you can easily run out of memory.
     
  18. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #18
    Assuming the developer is doing agent detection properly. Most sites I visit on my iPhone are the "full" webpage and I have the same issue with pages reloading there too.

    256MB is not a lot of memory in this day in age. You said it yourself. Pages are much more involved than they were before. That is why 256MB is not a lot and not enough. And we are not talking for a single site. For the most part the max number of pages I can have up without having them refresh is 3. Of course, add in the usage of the browser itself... and the OS.. and we have hit 256MB easy.

    Apple would have done well to put 512MB in this device, at least.

    I don't get why you are saying pages are "overblown" while your opened the post by saying that the iPad is getting the "full web."

    Read the thread, virtual memory already exists in iPhone OS.
     
  19. mikethebigo thread starter macrumors 68000

    Joined:
    May 25, 2009
    #19
    This thread is fascinating! Don't worry about being technical, the better I understand it the happier I'll be. It actually makes sense that the OS does support some virtual memory because the iStat app does register page-outs. I wonder why they only made it for read-only data? Was it to reduce the number of read/writes?

    I have to admit, I don't quite understand the difference between virtual memory and a backing store. I guess a backing store involves non-read-only data?

    Obviously the best solution is simply more memory. EVERYONE anticipated at least 512 in the iPad and Apple skimped for some reason. I will definitely say that pages reload more often in Safari on the iPad versus the iPhone, which I do think has to do with the increased memory demand of the higher res screen.
     
  20. hazmatzak macrumors regular

    Joined:
    Apr 29, 2008
    #20
    What might be more useful in a constrained way is some sort of global semi-persistent cache that is keyed by application (so that apps can't see what other apps are doing, for security reasons), that uses some portion of unused flash memory. Applications would say to the OS, "Try and save this for me," and later depending on whether other apps more recently overwrote the memory, or you did a sync and more stuff got installed, it might no longer be there.

    This way, you aren't promoting "sloppy" programming by assuming you've got a ton of RAM; you're not constantly paging stuff in and out; and you potentially have a much larger cache than a regular virtual memory system (if A4 is 32-bit -- I don't know [or care, really]).

    You would use it any time you did a fetch and/or calculate that might be expensive or impossible to redo. There may be tricky bits with how to map that memory to avoid double-buffering, and whether it would be fast enough. But it might work.

    Even if they did not apparently do anything to address it, doesn't mean they didn't consider it. Maybe everything they thought of had other downsides that were not acceptable.

    When apps quit on a modern OS, they generally shouldn't have to bother much with cleanup. On Mac OS X, apps can support Sudden Termination, which is when they say, "It's safe to just make my process vanish." Quitting becomes an activity only because you need to save documents or state. Now there are potential complications with shared resources and such, but even those can be managed automatically by the OS to a degree: "The app that is holding onto these resources has been terminated, so these resources can be freed too."
     
  21. Runt888 macrumors 6502a

    Joined:
    Nov 17, 2008
    #21
    I'd be interested in trying this approach for some of our data. However, I would imagine that for images, 99% of developers use UIImage, which has the ability to purge it's image data in low memory situations, and reload it from the original file when it's needed again.
     
  22. otis123 macrumors 6502a

    Joined:
    May 4, 2006
    #22
    I really don't get why they just didn't throw 512mb in this thing, they could do virtual memory, but I do see apple doing it.
     
  23. Penooker macrumors member

    Joined:
    Apr 22, 2010
    #23
    The cycles thing really isn't an issue. Many laptops have SSD's, and use them for swap. I had one of the first generally available laptops with a SSD and it's perfectly fine. It does mean that Apple would have to be careful in choosing their flash chips, eg maybe SLC rather than MLC. There are also tried and true software designs that can reduce overwriting, such as wear-leveling / TRIM and log based file system.

    I do agree with you that more RAM is better. I'm actually quite surprised that we're not talking more on the order of GB's of RAM. I got annoyed that everytime I went back in safari, or switched tabs, it would have to reload the page. I found myself not wanting to click links because I was afraid of the load time when I hit back.

    If iPad can't even hold 2 copies of engadget.com in RAM, then it's poorly designed. RAM use so little power, and cost so little. I also think it provides great utility. This, and the price, are the two biggest reasons why I would want to wait for the next generation iPad (or other companies' equivalent).
     
  24. Runt888 macrumors 6502a

    Joined:
    Nov 17, 2008
    #24
    Correct - virtual memory is the ability to address more memory than is physically available. A backing store is one solution to solve the problem of what happens when an app tries to use more memory than is physically available. The data is written out to the backing store, and read back in when it's needed.

    iPhone OS uses a different approach than a backing store - it just doesn't allow the app to allocate more memory than is physically available. So what's the point of having virtual memory? If a page is marked as read-only, then the OS can remove it from main memory, and read it in later if its needed.
     
  25. blackNBUK macrumors 6502a

    Joined:
    Feb 19, 2010
    Location:
    UK
    #25
    Great conversation guys! As a developer, but not an iPhone developer I'm finding it really interesting.

    On the subject of why Apple didn't just put more memory in I think answer lies in the way that they integrated the 256MBs of memory into the same chip as the A4 processor. This would make adding memory much more difficult and expensive than if they'd used off-the-shelf memory chips. I suppose the next question is why did they integrate the memory so tightly? My guess is that they wanted to reduce the number of separate components. This would reduce costs and allow the A4 to be easily used in the next iPhone. Integrating the memory may also improve the bandwidth between the processor and the memory.

    I hate to bring up the F-word but I think that talking about memory usage on the iPhone does bring up some possible technical problems with platforms like Flash on the iPhone. If they don't correctly implement the various mechanisms (eg. UIImages or memory low callbacks) to release memory then Flash Apps could end up being really big memory hogs.
     

Share This Page