[SCRIPT][1/22/2011] A Simple Cache2Cache for CM 6.x and 7.x ROMs

Search This thread

zach.xtr

Senior Member
Apr 9, 2010
943
82
Tallahassee, FL
Due to a number of requests I have built a flashable .zip that will install a simple cache2cache script for CyanogenMod 6.x and 7.x ROMs.

NAND backup BEFORE you try this!

From user feedback it seems that if you are ALREADY running Apps2sd this causes issues with apps that where installed to the SD card and you will have to remove and re download them. There have been no reports of issues if you flash PRIOR to enabling Apps2sd ...


Per dingermtb: check out post http://xdaforums.com/showpost.php?p=11487856&postcount=58 for an easy fix for Apps2sd.

By using this script the dalvik-cache has been relocated from the internal /data/dalvik-cache/ directory to the internal /cache/dalvik-cache directory. The Eris comes with an internal /cache/ file block of 130mb that is not used much (CyanogenMod does store the cache of system apps in the /cache file block but NOT any apps that are downloaded from the market)! So by moving the dalvik-cache to this free area you now have more space on internal /data/ for apps and over 75mb in internal /cache/ for dalvik-cache. This means that you can probably install close to 75-100 apps WITHOUT having to worry about apps2sd!

This IS NOT a Custom MTD script as I wanted to keep it simple. This solution is not as "ideal" as a Custom MTD scripts work but it is a bit easier, safer, and simpler... Plus it works ;)

How do I know it worked?
So why does my Settings>SD card & phone storage>Internal phone storage only show 150mb or less? This is because this number ONLY reflects the /data/ file block on your phone and does not "see" the /cache/ block that is now being used for dalvik-cache storage.

From adb or Terminal Emulator (you can get it free from the market if your ROM does not already have it) run the follow command:

Code:
df -h

You will see that your /cache partition now is more used and that your /data partition is less used.

Also you can browse to the /cache/dalvik-cache/ folder using your favorite file explorer and see that you now have files starting with "data@..." and not just "system@..."

What does it do?
Since CyanogenMod already uses an init.d framework that runs during boot on his ROMs it was easy to add a new shell script that would automatically run with the other boot scripts in the /system/etc/init.d/ folder.

This simply adds the following 07cache2cache file to /system/etc/init.d/

Code:
# !/system/bin/sh
#
# Author: zach.xtr Jan 2011
# Moves the /data/dalvik-cache files to largely unused /cache/dalvik-cache location and symlinks
# This code is intended for the ERIS, use on other phones may not work due to predefined file block sizes...

log -p i -t cache2cache "Running cache2cache to move data/dalvik-cache to cache/dalvik-cache..."; 

# Mount filesystem
/system/xbin/busybox mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system

# Make sure final /cache/ location is setup correctly
if [ ! -d /cache/dalvik-cache ];
then
	log -p i -t cache2cache "/cache/dalvik-cache directory not found, creating and adding permissions..."; 
	/system/xbin/busybox mkdir /cache/dalvik-cache;
	/system/xbin/busybox chown 1000:1000 /cache/dalvik-cache;
	/system/xbin/busybox chmod 777 /cache/dalvik-cache
fi;

if [ -d /data/dalvik-cache ] && [ ! -h /data/dalvik-cache ];
then
	log -p i -t cache2cache "Moving files from /data/dalvik-cache to /cache/dalvik-cache"; 
	/system/xbin/busybox cp -fp /data/dalvik-cache/* /cache/dalvik-cache;
	/system/xbin/busybox rm -r /data/dalvik-cache;
	log -p i -t cache2cache "Creating Symbolic Link of /cache/dalvik-cache as /data/dalvik-cache";
	/system/xbin/busybox ln -s /cache/dalvik-cache /data/dalvik-cache;
	/system/xbin/busybox chown 1000:1000 /data/dalvik-cache
	/system/xbin/busybox chmod 0771 /data/dalvik-cache
fi;

# Clean up 
/system/xbin/busybox mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system

How do I remove it?
Since it only adds 1 file all you need to do is delete the /system/etc/init.d/07cache2cache file and reboot your phone. One could use adb or RootExplorer (or similar) file manager.

NOTE: if you have been using this for a while and have installed enough apps and THEN remove it I am not sure what will happen when you reboot... Basically you may not have enough space in the /data file block alone.
 

Attachments

  • xtrCMCache2cache.zip
    259.1 KB · Views: 5,933
Last edited:

doogald

Senior Member
May 27, 2010
1,387
337
Oh my gosh, bless you! This is great.

Downloading and installing onto CELB 4.3 right now...

[edit - Reported phone storage remaining went from 28 MB to 70 MB free. It did restart my phone on the first restart; I'm not sure if that's normal, but things seem to be working fine.]
 
Last edited:

galbro

New member
Feb 6, 2010
2
0
Nicely done. Nonsensikal 16.1 went from 17 or 18 megs free to 67 megs. Working fine so far..
 

Hungry Man

Senior Member
Jun 11, 2010
2,103
35
Pretty cool. I'm never low on space so I won't need this, but thanks for creating it.

Is it possible for this to cause apps to slow down, since when they try to access the cache it'll be on the (slower) SD card?
 

galbro

New member
Feb 6, 2010
2
0
However, app2sd is now a little confused, and the apps it thinks are on the sd card cannot be found when I try to move them back to the phone. However, they are operable.
 

zach.xtr

Senior Member
Apr 9, 2010
943
82
Tallahassee, FL
Pretty cool. I'm never low on space so I won't need this, but thanks for creating it.

Is it possible for this to cause apps to slow down, since when they try to access the cache it'll be on the (slower) SD card?

No :)

This does not use the SD card in any way; it only redistributes from the INTERNAL /data file block to the INTERNAL /cache file block...

If anything you may gaine a minor permormance improvement as you will have more "working" space...
 
  • Like
Reactions: TheDrizz

Swifty31703

Senior Member
Aug 13, 2010
169
12
Indiana
I installed onto my phone running Vanilla FroShedyo. It is running like a champ so far and all the apps seems to work as usual. I went from 59.07MB free to 83.14MB! I know I am a minimalist when it comes to apps on my phone but man does it fly now. Thank you for this script and keep up the good work!
 
Last edited:

Bayhill Jacket

Senior Member
Jul 21, 2010
213
42
MCO
58mb to 77mb FroShedYo Vanilla

Linpack pre-script 4.8-5.1
Linpack post-script 4.8

Quadrant pre 380-420
Quadrant post 376

Thanks for the extra space and sharing
 

magnethart

Senior Member
Jul 16, 2010
76
17
Tampa, FL
Flashed on CELB and lost access to all of my apps on the sdcard. I'm using the built in Froyo apps2sd. Also broke my widgets on the home screens.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 15
    Due to a number of requests I have built a flashable .zip that will install a simple cache2cache script for CyanogenMod 6.x and 7.x ROMs.

    NAND backup BEFORE you try this!

    From user feedback it seems that if you are ALREADY running Apps2sd this causes issues with apps that where installed to the SD card and you will have to remove and re download them. There have been no reports of issues if you flash PRIOR to enabling Apps2sd ...


    Per dingermtb: check out post http://xdaforums.com/showpost.php?p=11487856&postcount=58 for an easy fix for Apps2sd.

    By using this script the dalvik-cache has been relocated from the internal /data/dalvik-cache/ directory to the internal /cache/dalvik-cache directory. The Eris comes with an internal /cache/ file block of 130mb that is not used much (CyanogenMod does store the cache of system apps in the /cache file block but NOT any apps that are downloaded from the market)! So by moving the dalvik-cache to this free area you now have more space on internal /data/ for apps and over 75mb in internal /cache/ for dalvik-cache. This means that you can probably install close to 75-100 apps WITHOUT having to worry about apps2sd!

    This IS NOT a Custom MTD script as I wanted to keep it simple. This solution is not as "ideal" as a Custom MTD scripts work but it is a bit easier, safer, and simpler... Plus it works ;)

    How do I know it worked?
    So why does my Settings>SD card & phone storage>Internal phone storage only show 150mb or less? This is because this number ONLY reflects the /data/ file block on your phone and does not "see" the /cache/ block that is now being used for dalvik-cache storage.

    From adb or Terminal Emulator (you can get it free from the market if your ROM does not already have it) run the follow command:

    Code:
    df -h

    You will see that your /cache partition now is more used and that your /data partition is less used.

    Also you can browse to the /cache/dalvik-cache/ folder using your favorite file explorer and see that you now have files starting with "data@..." and not just "system@..."

    What does it do?
    Since CyanogenMod already uses an init.d framework that runs during boot on his ROMs it was easy to add a new shell script that would automatically run with the other boot scripts in the /system/etc/init.d/ folder.

    This simply adds the following 07cache2cache file to /system/etc/init.d/

    Code:
    # !/system/bin/sh
    #
    # Author: zach.xtr Jan 2011
    # Moves the /data/dalvik-cache files to largely unused /cache/dalvik-cache location and symlinks
    # This code is intended for the ERIS, use on other phones may not work due to predefined file block sizes...
    
    log -p i -t cache2cache "Running cache2cache to move data/dalvik-cache to cache/dalvik-cache..."; 
    
    # Mount filesystem
    /system/xbin/busybox mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
    
    # Make sure final /cache/ location is setup correctly
    if [ ! -d /cache/dalvik-cache ];
    then
    	log -p i -t cache2cache "/cache/dalvik-cache directory not found, creating and adding permissions..."; 
    	/system/xbin/busybox mkdir /cache/dalvik-cache;
    	/system/xbin/busybox chown 1000:1000 /cache/dalvik-cache;
    	/system/xbin/busybox chmod 777 /cache/dalvik-cache
    fi;
    
    if [ -d /data/dalvik-cache ] && [ ! -h /data/dalvik-cache ];
    then
    	log -p i -t cache2cache "Moving files from /data/dalvik-cache to /cache/dalvik-cache"; 
    	/system/xbin/busybox cp -fp /data/dalvik-cache/* /cache/dalvik-cache;
    	/system/xbin/busybox rm -r /data/dalvik-cache;
    	log -p i -t cache2cache "Creating Symbolic Link of /cache/dalvik-cache as /data/dalvik-cache";
    	/system/xbin/busybox ln -s /cache/dalvik-cache /data/dalvik-cache;
    	/system/xbin/busybox chown 1000:1000 /data/dalvik-cache
    	/system/xbin/busybox chmod 0771 /data/dalvik-cache
    fi;
    
    # Clean up 
    /system/xbin/busybox mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system

    How do I remove it?
    Since it only adds 1 file all you need to do is delete the /system/etc/init.d/07cache2cache file and reboot your phone. One could use adb or RootExplorer (or similar) file manager.

    NOTE: if you have been using this for a while and have installed enough apps and THEN remove it I am not sure what will happen when you reboot... Basically you may not have enough space in the /data file block alone.
    2
    do I need to reflash every time I upgrade a ROM?

    I had been having success on GSB 1.6, but when I went to 1.7 without reflashing this script, half my apps were gone and I had 76KB availble for apps. :(((

    Attempting now to wipe, reflash (the rom AND this script this time), and see if I can salvage anything...

    Sure do. Flashing the ROM erases the script, so you need to reflash it when you reflash the ROM.

    Assuming you are GSB, every time you upgrade, even for a no-wipe update, if you want cache2cache to still be there, you must:

    - [optional, but strongly recommend] Nandroid backup
    - Wipe Dalvik
    - Flash GSB
    - Flash gapps
    - Flash xtrcache2cache
    - Restart
    1
    Pretty cool. I'm never low on space so I won't need this, but thanks for creating it.

    Is it possible for this to cause apps to slow down, since when they try to access the cache it'll be on the (slower) SD card?

    No :)

    This does not use the SD card in any way; it only redistributes from the INTERNAL /data file block to the INTERNAL /cache file block...

    If anything you may gaine a minor permormance improvement as you will have more "working" space...
    1
    This, along with CELEB 4.3, is the fastest and best my Eris has ever run. I'm blown away! Those extra megs of memory were what my phone needed to pick up the pace.
    1
    for app recovery purposes, I re-flashed the ROM, gapps, and then this script, and up until today, I assumed the script was working due all my apps being back and not getting "low memory" warnings right off the bat.

    Today, though, after installing one extra app, I got the warning, so I used the Terminal Emulator to check, and apparently, my /data is using 88% (141M used) compared to /cache's 84% (109.3M used).

    Is this normal, or is the script only partially working for me right now?

    This sounds normal. Even cache2cache has limits ;) and it sounds like you are just using a lot of space.

    Sent from my Eris using XDA App