yashsingh1/xdaforums huggingface dataset:
[G1 Android Development] Janis:
Clueless. Cyanogen's Compcache and userinit.sh?

Is there a way I can use Cyanogen's 3.9.10 default compcache and only enable linux swap with a userinit.sh? Or does a userinit.sh automatically comandeer compcache no matter what? Can I just delete everything compcache, or would that make my phone explode?

I personally only run the compcache to cache web pages, and if Cyanogen is making the tweaks to the ROM, I trust him on that. I'd like to let him do that, and continue to load the ROMs and just use one userinit.sh from ROM to ROM. I do seem to really need the linux swap, though, just because I've got so much running. (Swapper doesn't start up reliably, and boot up is the worst time not to have my linux swapping in place.)

Thanks.
[G1 Android Development] miketaylor00:
The userinit.sh doesn't have to run compcache. You can go into your user.conf file and set it = 0 and reboot. However, you would be better off to keep Compcache. It is faster than Linux-swap when configured correctly.
[G1 Android Development] miketaylor00:
Just to clarify a little bit, the userinit.sh (or swap.sh on xROM) tells the phone at startup to grab the values in your user.conf and set the appropriate settings. The first time you run it, the userinit.sh places default values. After that, it will always take values from the user.conf. So any change you want to make has to be done in the user.conf.
[G1 Android Development] huanyu:
You don't have to edit the script. All you need to do is edit the user.conf

Cyanogen's CC default setting:

set compcache_en=1
set cc_disksize=24
set cc_backingswap_en=0
set cc_swappiness=60

but i am not sure the default swappiness for CMs is 60 or not

Cyanogen didn't include the userinit.sh file. You have to push it manually. The latest CM enables the CC using the a2sd script.
[G1 Android Development] aron7awol:
Where is the user.conf file located on CM?
[G1 Android Development] prash:
There is no user.conf file included with the CM roms. He's using a different method to enable compcache (through a2sd script.)

What you can do is use THIS method and change his settings if you want to do that. Basically if you wanted to turn off compcache he has turned on by default, use the userinit.sh and user.conf file from here, disable everything.
[G1 Android Development] Janis:
Want Cyanogen's Compcache as is, plus Linux swap

I'm wondering what I can do to get Linux swap enabled while not touching Cyanogen's compcache. I don't want to disable it, nor do I want to enable it to custom settings. (it would also be nice to set my CPU speed, too. The virtual stuff I know nothing about and have always used defaults provided. Thanks for good numbers on that.)

Is there a way to run a userinit.sh and not touch any compcache that's already enabled by the ROM? Safely? Has anyone tried it?

Can I just use parts of this?

This is what I want, and am willing to work it out myself, but I don't know what the rest of the file does or the role that the userinit.sh plays.

#!/system/bin/sh

#

apps2sd=0

media2sd=0

linux_swap_en=1

linux_swap_partition=/dev/block/mmcblk0p3

swappiness=60

proc_cpu_en=1

scaling_min_freq=384000

scaling_max_freq=528000

sampling_rate=2000000

powersave_bias=200

up_threshold=16

CC_NEW_DECT=0;

swap_file_en=0;

linux_swap_file_size=32;

linux_swap_file=/sdcard/swap.file;

insmod="/system/xbin/bb/insmod"

rmmod="/system/xbin/bb/rmmod"

modprobe="/system/xbin/bb/modprobe"

I don't want to mess with Cyanogen's settings, except maybe CPU idle speed, and definitely to enable Linux swap. I like what Swapper and SetCPU do for me, but they don't start at boot, and it took me quite a long time to boot the last time because of it (like 20 minutes, my logcat is full of dalvik GC freed lines.)
[G1 Android Development] miketaylor00:
It's not the a2sd file. That file only has code for apps2sd. I just checked it. If anyone knows the file that the user.conf info is in, let me know. I know .10 had a user.conf in it.

Edit: it is in the a2sd file. I will figure it out in a few minutes.
[G1 Android Development] huanyu:
Editing the default values in userinit.sh won't make any differences. Because it still fetch the user.conf value.

if you use any userinit.sh, the compcache is not enabled. see the code (from CM's a2sd script) below

# call a userinit.sh script if it's present on the sdcard
# otherwise just enable compcache with no backing swap
if [ -e /system/sd/userinit.sh ];
then
echo "--- Executing userinit.sh"
busybox chmod +x /system/sd/userinit.sh
/system/bin/sh /system/sd/userinit.sh;
else
modprobe ramzswap;
/system/bin/rzscontrol /dev/block/ramzswap0 --init
swapon /dev/block/ramzswap0
fi

CM just use a default setting of compcache which enables 1/4 (24MB) of ram as ramzswap and no backing swap. The equivalent setting in user.conf are the follows

compcache_en=1
cc_disksize=24
cc_backingswap_en=0

the alternative method is to change the following line in userinit.sh

elif [ $compcache_en -eq 0 ]; then
CC_SWAPOFF;
fi;

to

elif [ $compcache_en -eq 0 ]; then
#CC_SWAPOFF;
fi;

so when you set compcache_en=0 it won't turn off compcache.

and change the following lines in a2sd

# call a userinit.sh script if it's present on the sdcard
# otherwise just enable compcache with no backing swap
if [ -e /system/sd/userinit.sh ];
then
echo "--- Executing userinit.sh"
busybox chmod +x /system/sd/userinit.sh
/system/bin/sh /system/sd/userinit.sh;
else
modprobe ramzswap;
/system/bin/rzscontrol /dev/block/ramzswap0 --init
swapon /dev/block/ramzswap0
fi

to

# call a userinit.sh script if it's present on the sdcard
# otherwise just enable compcache with no backing swap
if [ -e /system/sd/userinit.sh ];
then
modprobe ramzswap;
/system/bin/rzscontrol /dev/block/ramzswap0 --init
swapon /dev/block/ramzswap0
echo "--- Executing userinit.sh"
busybox chmod +x /system/sd/userinit.sh
/system/bin/sh /system/sd/userinit.sh;
else
modprobe ramzswap;
/system/bin/rzscontrol /dev/block/ramzswap0 --init
swapon /dev/block/ramzswap0
fi

so the compcache is enabled even if there is userinit.sh file
[G1 Android Development] miketaylor00:
So basically the file checks to see if there is a userinit.sh. If there is, it reads from the user.conf. If there isn't it takes the settings in the rzscontrol file, which isn't a plain text file.

So, you will need to run the userinit.sh to make it work with Cyan's latest build. If there is a bug that makes it not work, that will have to be fixed by Cyan and/or huanyu
[G1 Android Development] zimphishmonger:
I usually run it in terminal and then check it by running /system/sd/userinit.sh -s to verify it, and then reboot.
[G1 Android Development] miketaylor00:
That's what I do. I'm not on the Cyan build to test it but someone said that it wasn't working on his latest earlier in the thread. If anyone is unable to do it, post what happened. I'm sure huanyu can help get it working.

Edit: @zimphishmonger - do you have it running on 3.9.11.2? If so, I'd say that is proof that it works.
[G1 Android Development] huanyu:
Forgot to tell you guys, you can now run userinit -s to check the status. I made a symbolic link which links the /system/sd/userinit.sh to /system/bin/userinit. PS for version 0.1.4+
[G1 Android Development] smuvman:
a little assistance

i've read through all the pages and taken a little bit of info from everyones posts and set up my own modified user conf. i dont have any issues with it and using it with cyans latest 3.9.11.2 has my phone running superfast. my only question is that i see people with 100% good compress and mines is at 71% so im wondering if that makes any difference and if so can someone guide me as to setting it up? btw im running compcache with linux swap. i have attached my stats. please pm so i dont clutter the thread any help would be appreciated.
[G1 Android Development] huanyu:
if you enable CC with backingswap, you should have 100% good compress. This is because CC push those pages that can't be compressed to backingswap partition/file. Therefore the ramzswap only contains the pages that can be compressed.
[G1 Android Development] Janis:
Wow. I learned so much from this!

@ Huanyu: This is packed with info on how this whole thing works. I am so appreciative! I'll try to make the time to get this up and running, but I think for now/today/maybe-this-week I'm just going to find and use Cyanogen's settings in the user.conf (I'm still on 3.9.10 since stability won over global search for me) and use your excellent work as is.
[G1 Android Development] ei8htohms:
this won't work

Reportedly even if you have a completely blank userinit.sh file (well, one line like #nothing) compcache will not be turned on in the latest builds. You'd be better off deleting the userinit.sh and booting without it, then checking the compcache values (writing them down) and then enabling them identically in your userinit.sh after reinstalling it.
[G1 Android Development] sha.goyjo:
I don't know if anybody else has done it yet, but I've been playing around with backingswap files. I've got one running at 32 mb. One thing I've noticed is that the code "userinit.sh -s" says that compcache has gotten one read, and stats everything else zero. Writes, compression, everything. Now, I'm inclined to believe that is false (cause I stressed the hell out of the phone with multitasking and it didn't even hiccup) but I wan't to know if there is a good way to confirm this as a bug. Sorry my dev knowledge isn't more exact.
[G1 Android Development] miketaylor00:
Huanyu kind of already answered this. The only thing he wasn't sure of was the swapiness setting. So just don't set it at all and it will take the default setting. Completely remove the line from your user.conf. That is what Cyan does.

set compcache_en=1
set cc_disksize=24
set cc_backingswap_en=0

Or, if you really want to use Cyan's settings delete your userinit.sh and your user.conf. That will make his script run on it's own.
[G1 Android Development] miketaylor00:
Turn off Linux Swap and turn on backing swap. My original file that you are using will do this for you. Backing Swap works better with Compcache than Linux Swap because Compcache is managing both.
[G1 Android Development] miketaylor00:
You need to make the following change to get 32Mb of backing swap:

cc_memlimit=32

Right now you have it set to 18.
[G1 Android Development] miketaylor00:
Please post your configuration and someone will be able to help you.
[G1 Android Development] Argusi:
Changed to 32. I have to figure out which fields in the ./userinit.sh -i output will show me it's working the way I want, so I'll keep reading up. Thanks for your help!
[G1 Android Development] huanyu:
You need to modify the a2sd as well. The a2sd detects the existence of userinit.sh. If userinit.sh is presented, it will not enabled compache no matter what you change in userinit.sh. Check here http://xdaforums.com/showpost.php?p=4339391&postcount=350

Hum... which CM rom are you using? did you just run userinit -s after you exercise the phone or did you run userinit before status check. If you run userinit before the status check, it will reset everything.
[G1 Android Development] sha.goyjo:
I'm on cm 3.9.11.2 right now. I've also attached my user.conf. I haven't attached a log, but I can explain the problem very easily. Everything is fine, except that every field of ramzswap stats displays a value of zero.

Thats all I know. Advice?

(fyi as far as stats vs reset THEN stats, I've tried it both ways. Still no dice)
[G1 Android Development] uwonsum:
I didn't see an issue with your user.conf. More than likely a corrupt system.
[G1 Android Development] pershoot:
found a possible bug. when using compcache with backing swap, when using userinit.sh -i, setting swappiness in the compcache section appears to be ignored. when setting swappiness in the linux swap section (even tho it is supposed to be 0 when using backing swap), this gets recognised.

can anyone else confirm this behavior?
[G1 Android Development] uwonsum:
post your user.conf
[G1 Android Development] huanyu:
Thanks. I will fix this bug for next release.
[G1 Android Development] pershoot:
thx:)

........
[G1 Android Development] rub1k:
Any caveats/incompatibilities/gotchas with using the latest userinit.sh here (0.1.4.1?) with CM 4.0.1? Any settings to stay away from or "must have"?

I'd like to stay as close to what Cyan did by default (as per his changelog, I think he just turns on compcache with 32MB if there is no userinit.sh file present but obviously, I'd like to have this script present to take advantage of the nice info/status tables, etc.)

So, since I must set explicit options or else no compcache for me (it gets disabled since it finds the /system/sd/userinit.sh script), it seems like this would be what I want to set:

set compcache=1
set cc_backingswap_en=0
set linux_swap_en=0
set cc_disksize=32
set cc_memlimit=0

Just wanted to check first that I won't screw things up or hurt my precious G1 in the process. Hah!
[G1 Android Development] nemlet:
If I don't set apps2sd=1 will the built in cyanogen apps2sd still work? I have searched the forum and not found an answer on this.

Also if I don't set sys_vm will it just use the settings that cyanogen has set or will it just use bog standard android settings?
[G1 Android Development] IConrad01:
I'm getting a curious bug when using this script... I lost autorotate. I haven't played with the settings; and I've used Cyanogen v. 3.9.7 through 4.0.1. (Including 3.9.11.2) -- they all replicate the behavior.

Am I doing something wrong?
[G1 Android Development] miketaylor00:
That's not the userinit.sh. Look at the Q&A for Cyanogen and he will tell you a temporary fix.
[G1 Android Development] miketaylor00:
So if you are using Compcache v0.6, how could you switch between using linux_swap and swap file? Does it always use the linux swap partition if it finds it or can you force it to use swap file even if the partition exists?

Edit: Nevermind, I figured it out. Sorry.
[G1 Android Development] miketaylor00:
Ok, I need a little help. I'm using xROM. It uses a modified version of the userinit.sh. I wanted to setup Compcache with backing using a swap file, so I updated the xROM file with the changes in the latest userinit.sh. When I check the status I get this:

CompCache version 0.6+
Compcache enabled
CompCache: MemLimit 18432(system) 18432(user)
CompCache: BackingSwap /system/sd/swap.file(system) /system/sd/swap.file(user)
CompCache: cc_swappiness - 28(system) 28(user)

=== CompCache status output ===
BackingSwap: /system/sd/swap.file
DiskSize: 32356 kB
MemLimit: 18432 kB
NumReads: 1
NumWrites: 0
FailedReads: 0
FailedWrites: 0
InvalidIO: 0
PagesDiscard: 0
ZeroPages: 0
GoodCompress: 0 %
NoCompress: 0 %
PagesStored: 0
PagesUsed: 0
OrigDataSize: 0 kB
ComprDataSize: 0 kB
MemUsedTotal: 0 kB
BDevNumReads: 0
BDevNumWrites: 0

===VM status===
Set VM: page-cluster - 3(system) 3(user)
Set VM: laptop_mode - 0(system) 0(user)
Set VM: dirty_expire_centisecs - 3000(system) 3000(user)
Set VM: dirty_writeback_centisecs - 500(system) 500(user)
Set VM: dirty_background_ratio - 5(system) 5(user)
Set VM: dirty_ratio - 10(system) 10(user)

===CPU status===
Set CPU: scaling_min_freq - 192000(system) 192000(user)
Set CPU: scaling_max_freq - 528000(system) 528000(user)
Set CPU: sampling_rate - 2000000(system) 2000000(user)
Set CPU: powersave_bias - 0(system) 0(user)
Set CPU: up_threshold - 45(system) 45(user)

It looks like it is enabled but all the values are 0 except for 1 read. Does anyone know what that means?
[G1 Android Development] huanyu:
for some reason the CC with backing swap file does not work. It does intitalise the ramzswap (no error), however, swapon ramzswap command fails enable the ramzswap.

You will find no swap is enabled when checking swap status by cat /proc/swaps.

If i got time over the weekend, I will look into this problem.
[G1 Android Development] miketaylor00:
Ok. Thanks for letting me know. I won't spend any more time trying to get it working.
[G1 Android Development] ShatBag1105:
Ok Heres what i get.

☝ These errors were from Compcache w/ backing swap configuration.

Ive received these errors with your STOCK user.conf/userinit.sh files and from a modified user.conf file for compcache w/backing swap.

The main thing that worries me is >> "/proc/ramzswap: no such file or directory" What does this mean?

Ive installed CM 3.9.2 on a fresh wipe, and my sd card is partitioned FAT32/EXT3/Linuxswap(32mb) with gparted live cd. Thanks to ALAPAPA

WHAT THE DEUCE??
[G1 Android Development] huanyu:
As more configurable options available to userinit.sh, the userinit.sh became more difficult to manage and modify for some of the users. It is also little confuse for many users as they don't know much about shell script.
[G1 Android Development] uwonsum:
I think this is a great idea...I wish huanyu would have reserved for himself the 2nd and 3rd posts for this.
[G1 Android Development] huanyu:
can you try

sh /system/sd/userinit.sh

before you enter

sh /system/sd/userinit.sh -s
[G1 Android Development] huanyu:
this is a know issue with 3.9.3 http://xdaforums.com/showpost.php?p=4185546&postcount=2

I may give a go with this new rom tomorrow if i got time.
[G1 Android Development] ShatBag1105:
OOPS.

5 DAYS of messing with this and FINALLY I am up and running! My hands are shaking...

HUANYU THANK YOU! this user.conf file is what it took.

oh btw how do we get 3.9.3 to work? :D
[G1 Android Development] huanyu:
Good idea.

rom compatibility can only be done by users, as i don't have that much time to try out everything. But i could try to list them on the first post or third post
[G1 Android Development] huanyu:
I just had a look at the a2sd file in 3.9.3

change

# call a userinit.sh script if it's present on the sdcard
if [ -e /system/sd/userinit.sh ];
then
. /system/sd/userinit.sh;
fi;

to

# call a userinit.sh script if it's present on the sdcard
if [ -e /system/sd/userinit.sh ];
then
/system/bin/sh /system/sd/userinit.sh;
fi;

may fix the issue... but i am not sure until i test it out
[G1 Android Development] sacredsoul:
Ill test it... How do I pull the a2sd file using ADB?
[G1 Android Development] Binary100100:
I'll give it a go.

/system/bin/a2sd right?

edit: didn't work. just hanging at boot screen. :(
[G1 Android Development] sacredsoul:
adb pull /system/bin/a2sd doesnt work for me :confused:

EDIT: Ok pulled, edited, pushed, rebooted and hung on G1 screen. Thats without pushing the userinit.sh and user.conf files over. I tried pushing them and rebooted and still same. Gonna reflash now.
[G1 Android Development] Binary100100:
Good luck. Didn't work for me though. Just hung at the G1 screen for me too.
[G1 Android Development] sacredsoul:
Will wait for any other possible solutions. 3.9.3 up and running again :D
[G1 Android Development] uwonsum:
diff command on the a2sd on cm 3.9/3.9.2 vs 3.9.3 outputs:

11c11
< /system/bin/sh /data/firstboot.sh;
---
> . /data/firstboot.sh;
96c96
< /system/bin/sh /system/sd/userinit.sh;
---
> . /system/sd/userinit.sh;

You should know what this means and should be able to fix your issues with userinit.sh with this.

Good luck!
[G1 Android Development] Binary100100:
So we pull the a2sd file, change those, save, push back and reboot?
[G1 Android Development] huanyu:
Yap, thats right. It should work. I have test it with CM 3.9.3

If you plan to flash CM3.9.3, make sure you rename your userinit.sh file to something else before you flash CM 3.9.3.

If you have already flash the rom and hung at boot, boot into recovery mode and rename your userinit.sh first. In recovery terminal

mount /system/sd
mv /system/sd/userinit.sh /system/sd/userinit.sh.b
reboot

unzip the a2sd file and push it to /system/bin

then rename userinit.sh.b back to userinit.sh

using adb

adb remount
adb push a2sd /system/bin
adb shell mv /system/sd/userinit.sh.b /system/sd/userinit.sh

using terminal

su
mount -o remount,rw /dev/block/mtdblock3 /system
cp /sdcard/a2sd /system/bin
mv /system/sd/userinit.sh.b /system/sd/userinit.sh
[G1 Android Development] pychobj2001:
I would rather use the existing a2sd script in CM 3.9.3 build then replace it to get the compcache to work...i know it's not much work...but then i would have to do it every flash...no thanks...i'll wait either CM to fix the conflicts or for a permanent work around like changing the a2sd script.
[G1 Android Development] pychobj2001:
I'm sure tons of ppl including me would love to help rom compatibility, and thanks for starting it up as i saw this morning...v0.1! and dang it...i'm gunna flash the a2sd despite what i said....i want compcache back that bad...swapper is ok..but i can feel the difference already when i'm done w/ doing like 4 different things then hopping back to the homescreen....almost like a "please wait" sign there...can't take it! ha
[G1 Android Development] sacredsoul:
I can confirm the a2sd and V0.1 works in 3.9.3. I came from a clean install of 3.9.3. What I did was;

1. Edit user.conf according to my preference (compcache with back swap, make sure cc_backingswap_en=1 if you want backswap. Wasn't stated in the first post ;))

2. Pushed the a2sd provided here.

3. Pushed both userinit.sh and the edited user.conf.

4. Reboot

5. IT'S ALIVE! :D

What I am wondering is, do we have to run "adb shell sh /system/sd/userinit.sh -s" at every boot? And thanks for the quick fix huanyu. Excellent job. Hopefully, it won't be so complicated in 3.9.4.
[G1 Android Development] uwonsum:
Not unless you feel like it.
[G1 Android Development] lycoln:
**Auto SD partition**

***To help out anyone that wants partitions, but can't get their card partitioned correctly...***

**Requires:

phone (need)

computer (optional)

other's in the thread**

if you have a knowledge of adb (install w/ computer):

Process with the use of computer

if you don't want to use adb or a computer:

Process w/o computer (go to post #87 when you click the link)

**Was a lot of aggravation so appreciate the work**

***Big thanks to "51dusty" for the process w/ computer***
[G1 Android Development] miketaylor00:
Here is the error that I get:

swapon: /dev/block/ramzswap0: Invalid argument
[G1 Android Development] Binary100100:
So is the the typical result that I should be expecting? Or is it working for me for some odd reason?

# cat /proc/swaps

cat /proc/swaps

Filename Type Size Used Priority

/dev/block/ramzswap0 partition 40152 604 -1

#
[G1 Android Development] huanyu:
yes something like this. Are you using a swap file with compcache?

I am pretty sure the swap file created by userinit.sh is a valid swap file with block size of 1k. I have tested the linux swap with swap file, it works fine but not with compcache.

Anyone got compcache working with backingswap/swapfile? I am not sure this is ROM related issue or requires a specific swapfile format or this feature is just not yet fully functional in CC0.6.
[G1 Android Development] Binary100100:
Yes I'm running compcache with backingswap AND swapfile.

Here is my user.conf and my phone is running really smooth. I'm having great results and using the overclock widget to monitor my cpu which is pretty consistant at 128. Using Cyanogen 4.0.1 with a 40mb ext3 partition.

And here are my results (#sh userinit.sh -s, #free and #cat /proc/swaps)
[G1 Android Development] huanyu:
You are still using swap partition as CC backswap device. To use swapfile, you need to modify the "cc_backingswap=/dev/block/mmcblk0p3" to "cc_backingswap=/system/sd/swap.file" in user.conf. You did create the swap file but you not using it atm.
[G1 Android Development] Binary100100:
ah... i see. well... for what it's worth... i like these settings. :D
[G1 Android Development] sha.goyjo:
yes, but you'd acheive the EXACT same results you are currently getting by disabling the swap file.
[G1 Android Development] miketaylor00:
Did you get a chance to check this out anymore? I really want to get backing swap working with swap file to help out some people who don't have a linux-swap partition.