zRam on Gingerbread - Galaxy S Plus I9001 Android Development

Ok so the reason why I made this topic is because Coertmans asked me about virtual ram in android (2.3.6), which is available in CM9, so I went surfing on the interwebs to find about this zRam, first thing I found was this:
Site: http://code.google.com/p/compcache/ (ramzswap_32a.ko/ramzswap_32b.ko)
Instructions: http://code.google.com/p/compcache/wiki/CompilingAndUsingNew
This is the link to the zRam modules for linux kernels, as I'm not sure if it's able to import it into GB I continued searching and found a GB ROM (CM7) which has zRam. I downloaded the rom and searched for the files that possible could be the zRam. All ram/swap related items I got are these:
in /system/etc/init.d/07script
Code:
ZRAM=`ls -d /sys/block/zram*`;
for z in $ZRAM
do
echo 256 > $z/queue/read_ahead_kb;
echo 0 > $z/queue/iostats
done
if [ -e /sys/kernel/mm/ksm/run ]; then
echo "Kernel Samepage Merging support ON for RAM managment speedup."
echo 1 > /sys/kernel/mm/ksm/run
fi
ZRAM=`ls -d /sys/block/zram*`;
for z in $ZRAM
do
echo 256 > $z/queue/read_ahead_kb;
echo 0 > $z/queue/iostats
done
in /sdcard/gscript/swapon.sh
Code:
echo "Enabling SWAP Now! Please Wait."
echo "OFFLINE"
free | grep Swap
swapon -a
echo "ONLINE"
free | grep Swap
sleep 2
echo "DONE, Have a Nice Day!"
in /sdcard/gscript/swapoff.sh
Code:
echo "Disabling SWAP Now! Please Wait."
echo "ONLINE"
free | grep Swap
swapoff -a
echo "OFFLINE"
free | grep Swap
sleep 2
echo "DONE, Dont forget to turn it back ON"
in /sdcard/gscript/system-to-ram-off.sh
Code:
#!/system/bin/sh
#System unmount from ram by Dorimanx!
umount -l /system/app/ 2> /dev/null
umount -l /system/framework 2> /dev/null
echo "DONE. system is removed from RAM, do your changes now."
In /sdcard/gscript/ram-clean.sh
Code:
#!/system/bin/bash
#Created by Dorimanx for cron ram managment
CPULOAD=$(cat /proc/loadavg | cut -d " " -f1)
sleep 1
while [[ ! $CPULOAD < 2.00 ]]
do
echo "Waiting For CPU to cool down"
sleep 30
CPULOAD=$(cat /proc/loadavg | cut -d " " -f1)
sleep 1
done
#Boosting CPU
CHECKMAXFREQ=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq`
CHECKMINFREQ=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq`
echo 998400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo 998400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
sync
ZRAMUSE=`cat /proc/swaps | grep -v /dev/block/mmcblk0p3 | grep -v /sd-ext/swap | grep -v /sdcard/mnt/swap | grep -v /sdcard/swap | grep -v Used | cut -s -f3`
if [[ $ZRAMUSE < 10000 ]]
then
echo "no need to clean zram"
else
if [ -e /dev/block/mmcblk0p3 ]
then
sysctl -w vm.drop_caches=3
swapoff /dev/block/zram0
sleep 2
swapon /dev/block/zram0
sleep 2
swapoff /dev/block/mmcblk0p3
sleep 2
swapon /dev/block/mmcblk0p3
elif [ -e /sdcard/swap ]
then
sysctl -w vm.drop_caches=3
swapoff /dev/block/zram0
sleep 2
swapon /dev/block/zram0
sleep 2
swapoff /sdcard/swap
sleep 2
swapon /sdcard/swap
elif [ -e /sd-ext/swap ]
then
sysctl -w vm.drop_caches=3
swapoff /dev/block/zram0
sleep 2
swapon /dev/block/zram0
sleep 2
swapoff /sd-ext/swap
sleep 2
swapon /sd-ext/swap
fi
fi
#In case no secondary SWAP detected and ZRAM use lower than 80MB then we can safely clean it.
ZRAMUSE=`cat /proc/swaps | grep -v /dev/block/mmcblk0p3 | grep -v /sd-ext/swap | grep -v /sdcard/mnt/swap | grep -v /sdcard/swap | grep -v Used | cut -s -f3`
if [[ $ZRAMUSE < 80000 ]]
then
swapoff /dev/block/zram0
sleep 2
swapon /dev/block/zram0
fi
sync
sysctl -w vm.drop_caches=3
date > /data/cron-clear-swap
echo "runing clear swap every 4:20AM" >> /data/cron-clear-swap
echo "ram and swap cleared"
#Restoring CPU
echo $CHECKMAXFREQ > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo $CHECKMINFREQ > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
developer comment on the files in gscripts
dorimanx said:
About SWAP!
ROM will activate 3 kind of swap
It's will turn ON (only if you have already created swap file on partition, or set partition for swap (the hard way) )
SD-EXT SWAP
SD-SWAP
EXT dedicated SWAP partition
***If you have SWAP already, or EXT or SD-SWAP/EXT-SWAP, no need to run the swap activation scripts.
***I have created 2 scripts for disabling SD swap before use of USB storage.
I have put them in your /sdcard/gscript
so you only need the app (gscript light or full)
then load this scripts, when you need usb storage run swapoff script. when done run swapon.
or you can install dual mount app. i can’t live without it so try it.
Click to expand...
Click to collapse
and
dorimanx said:
SD SWAP THE EASY WAY!
In Easy way Swap you don't need to reformat or even reboot your phone to create swap!
If you installed my ROM and you don't have swap but you want to stay on HIGH END ROM,
Then you can do this to enable SD swap
Download script sdswap200.sh or dataswap250.sh from my mirror.
Run in in GSCRIPT App or copy it to SDCARD root,
Click to expand...
Click to collapse
sdswap200.sh
Code:
#!/system/bin/sh
# Created by Dorimanx
echo "WORKING PLEASE WAIT A MINUTE"
echo "Remounting System to allow WRITE"
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
if [ -e /sdcard/swap ]; then
swapoff -a
rm -f /sdcard/swap
fi
if [ -d /mnt/sdcard ]; then
echo "Creating SWAP on SDCARD"
busybox dd if=/dev/zero of=/sdcard/swap bs=1k count=250000 > /dev/null
mkswap /sdcard/swap > /dev/null
echo "/sdcard/swap swap swap" >> /system/etc/fstab
echo 50 > /proc/sys/vm/swappiness
swapon -a
echo "DONE CREATING, ENJOY MORE RAM"
free
sleep 3
else
echo "Your SDCARD NOT MOUNTED, SWAP CANT BE CREATED"
fi
dataswap250.sh
Code:
#!/system/bin/sh
# Created by Dorimanx
echo "WORKING PLEASE WAIT A MINUTE"
echo "Remounting System to allow WRITE"
mount -o remount,rw /system
if [ -e /sd-ext/swap ]; then
swapoff -a
rm -f /sd-ext/swap
fi
if [ -d /sd-ext ]; then
echo "Creating SWAP on SD-EXT"
busybox dd if=/dev/zero of=/sd-ext/swap bs=1k count=250000 > /dev/null
mkswap /sd-ext/swap > /dev/null
echo "/sd-ext/swap swap swap" >> /system/etc/fstab
echo 50 > /proc/sys/vm/swappiness
swapon -a
echo "DONE CREATING, ENJOY MORE RAM"
free
sleep 3
else
echo "You do not have EXT partition!, Cant create SWAP"
fi
in /sdcard/gscripts/swaphard.sh
Code:
echo "Activating EXT SWAP Please Wait"
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
mkswap /dev/block/mmcblk0p3
echo "/dev/block/mmcblk0p3 swap swap" >> /system/etc/fstab
swapon -a
echo "DONE"
free
sleep 3
So what do you guys think about it? It seems to me that this is really possible on GB

This is what I tried so far:
Code:
adb shell
su
mount -o remount rw /system
busybox dd if=/dev/zero of=/sdcard/swap bs=1k count=250000 > /dev/null
busybox mkswap /sdcard/swap > /dev/null
echo "/sdcard/swap swap swap" >> /system/etc/vold.fstab
echo 50 > /proc/sys/vm/swappiness
swapon -a
Now I don't get an error, but also nothing seems to happen, I'm going to try to make the sdcard "swappable ready" the manual way now
edit: Hmm I can only pick my internal sdcard for partitioning the sdcard, someone knows how to do that for external?
And how can I see if the virtual ram is actually working?
btw here is the mirror with the files I used: http://www.bourseanalyse.fr/dorimanx/
btw, totally of topic, but I saw 2 cars on fire so I made a video

broodplank1337 said:
And how can I see if the virtual ram is actually working?
Click to expand...
Click to collapse
The easiest and the only way i know of to check how ram, swap, and memory is used is by going into Terminal Emulator and typing in "free" and click enter... (without the quotations)

shahbaz5588 said:
The easiest and the only way i know of to check how ram, swap, and memory is used is by going into Terminal Emulator and typing in "free" and click enter... (without the quotations)
Click to expand...
Click to collapse
Ok thanks, used: "free | grep Swap" seems it's not working yet.

Hello
do you know the app swapper2 ?
it do the same what you try to do here !
But in the german forum there are some people who bricked their device with this app so i just want to say that you really have to pay attention with swapping

PortoBraso said:
Hello
do you know the app swapper2 ?
it do the same what you try to do here !
But in the german forum there are some people who bricked their device with this app so i just want to say that you really have to pay attention with swapping
Click to expand...
Click to collapse
they bricked it because of partition of internal sdcard If all of us will partition internal sdcard we have more than 50% chances to brick our device. It seems that partioning internal SD affects the 1-8 boot partitions (dunno how to explain it better) I`ve just woke up lol

Also we need a kernel that supports swap
And we don't have such a kernel
Sent from my GT-I9001 using XDA

broodplank1337 said:
Ok thanks, used: "free | grep Swap" seems it's not working yet.
Click to expand...
Click to collapse
if u are getting all 0's in swap then it is not working... i thik you can try going thru htc dream (G1) gingerbread roms.... they used swap and zramk a lot... well it was essential for the rom to run on that device
If it looks like this (with zeros in the swap line), you do not have swap/compcache:
total used free shared buffers
Mem: 97932 96640 1292 0 272
Swap: 0 0 0
Total: 97932 96640 1292
If it looks like this (with anything other than zeros in the swap line), you do have swap/compache:
total used free shared buffers
Mem: 97932 96004 1928 0 332
Swap: 24472 0 24472
Total: 122404 96004 26400

I had a swap partition on my galaxy 3 and i just wanted to say that it isnt fun...it makes the phone laggy cause you can never have a sd-card which is as fast as a ram module
Sent from my GT-I9001 using XDA

Yes! SDcards even class 10, ain't that stable. Anyhow what's the big deal ?
we never fall short of ram on our device.
Had tried ram swapping on my I9003 and i managed to screw up everything,made it a paper weight (Hard bricked it).
Had to get the board replaced from samsung, on the good side i got the latest latona board with 16gb onboard memory
but i no longer have the i9003

I tried swap while I had Galaxy 3 (it only has 256MB RAM) and I didn't like it. Also many other people reported that it was only slowing down system (even with class 10 cards) SD Cards just aren't fast enough to be used as a RAM...plus, Android is based on a though that free RAM is wasted RAM, right? 512MB for our phone is enough for me, and I've never fallen short of RAM..swap is not needed..but that's just my opinion

I'm not going to continue on this anyway, making your sdcard a swap drives really ****s it up, when I tried to install an app my phone shut down..

Related

Merging data and sdcard partition

I hate to have my 8 gigs of internal storage splitted between data and sdcard, considering that I have a 16gigs external sd, this is a lot annoying. So, checking the partition tree I found out that it should be possibile to merge internal_sd and data partition.
Now, this operation is risky, so I would like to ask if someone (even on other devices) has tryed this and succeded, or any possibile side effects on system behavior.
thanks
any news for this mod?
Sent from my HTC One SV using xda app-developers app
Thirded
madpausa said:
I hate to have my 8 gigs of internal storage splitted between data and sdcard, considering that I have a 16gigs external sd, this is a lot annoying.
Click to expand...
Click to collapse
I'm interested in this too, I want to get my Google Play music off my internal fake "sdcard" mount and onto my actual SD card. Plus I'm tired of running out of space on my "internal storage" and having to move it to the (also internal) "phone storage"...
I've had a look around the forums and there seems to be a few posts on achieving this for other handsets (Samsung Galaxy Ace, HTC One X) but I don't know how applicable the advice on those threads would be for a HTC One SV.
+1
I encountered this problem last night when I got an error saying I needed more storage space.
Code:
#!/system/bin/sh
# =========================================================================== # NexTool Swap Enble For Sense # # $LastChangedDate: 2012-10-10 20:27:06$ # ===========================================================================
LOG_FILE=/data/swap.log if [ -e $LOG_FILE ]; then rm $LOG_FILE fi
echo "Starting swap set $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE
if [ ! -e /system/xbin/busybox ]; then echo "busybox not installed" | tee -a $LOG_FILE exit -1 fi
# enable swap prtition 130m /system/xbin/busybox mkswap /dev/block/mmcblk0p27 | tee -a $LOG_FILE
# enable swap file on /mnt/emmc CREATE_EMMC_SWAPFILE=1
# mount /mnt/emmc if needed if [ -e /mnt/emmc ]; then # check if already mounted cat /proc/mounts |grep mmcblk0p32 &> /dev/null
if [ $? -eq 1 ]; then # not mounted till now busybox mount -t vfat -o nosuid,nodev /dev/block/mmcblk0p32 /mnt/emmc if [ $? -eq 1 ]; then echo "failed to mount /dev/block/mmcblk0p32 to /mnt/emmc" | tee -a $LOG_FILE CREATE_EMMC_SWAPFILE=0 fi else # mounted - check if its an ext partition cat /proc/mounts |grep mmcblk0p32 | grep ext4 &> /dev/null if [ $? -eq 1 ]; then echo "/mnt/emmc is not an ext4 partition" | tee -a $LOG_FILE CREATE_EMMC_SWAPFILE=0 fi fi else echo "/mnt/emmc not found" | tee -a $LOG_FILE CREATE_EMMC_SWAPFILE=0 fi
if [ $CREATE_EMMC_SWAPFILE -eq 1 ]; then if [ -e /mnt/emmc ]; then if [ -e /mnt/emmc/swapfile ]; then rm /mnt/emmc/swapfile fi
# 60m dd if=/dev/zero of=/mnt/emmc/swapfile bs=1024 count=61440 | tee -a $LOG_FILE /system/xbin/busybox mkswap /mnt/emmc/swapfile | tee -a $LOG_FILE /system/xbin/busybox swapon /mnt/emmc/swapfile | tee -a $LOG_FILE fi fi
/system/xbin/busybox free | tee -a $LOG_FILE cat /proc/swaps | tee -a $LOG_FILE
echo "Ending swap set $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $LOG_FILE
this was used on my HTC One V for this issue. even though it was only 130mb extra, it still helped.
^^ I was really hoping when I clicked "click to show content" there was a link to a magical program I could install to solve this issue
Lol I'm working on modifying it for this phone. Once I get it working I'll post it
EDIT: all the information I've found on creating the bind of internal storage and app storage seems like it does more damage than good
russellvone said:
Lol I'm working on modifying it for this phone. Once I get it working I'll post it
EDIT: all the information I've found on creating the bind of internal storage and app storage seems like it does more damage than good
Click to expand...
Click to collapse
For what I could understand, the fake partition was made to be used as fat32 filesystem, so that windows could read it as a mass storage device... For me this behaviour is not really useful :/
If we were on a PC I would've erased data and fake sd partition, to make a new data partition... though I don't have the knowledge to do this safely on android.
When I'll know more, I'll do that
Will this http://forum.xda-developers.com/showthread.php?t=2432479 work with our phones?
I am curious where are the people or posts that have done this to their one x phones?

[SCRIPT][UPDATED 03.26.14] Fix Lag, Defrag/Free Memory with |=>TrimDropOff<=|

Updated 03.26.14 - Released v2.1 - bug fixes and code cleaned
Introduction:
I am by no means a developer. I am just an android enthusiast who has learned a bit of bash. The reason I made this script was that settings>>wifi>>advanced was not promptly turning wifi off when my device would sleep; sometimes it would not turn off at all. So I figured since I am making a script to resolve this issue I might as well add a couple of other functions as well. To this end I noticed some people saying THIS APP was helpful and I missed the Flush-O-Matic script from V6 SuperCharger so I added fstrim and drop_caches=3 to the script.
Click to expand...
Click to collapse
What will this do?
The script will allow you to sync wifi, fstrim, and/or drop_caches=3 with sleep and/or it will allow you to schedule fstrim and/or drop_caches=3 using crond. The scheduling option can work on either a hourly (you can choose to run desired programs every hour on the hour, every two hours on the hour, every 3 hours on the hour, etc) or daily basis (you can choose to run desired programs at a given time on the hour).
Both the sync and schedule options will load themselves in to memory each boot and each time your device goes to sleep and/or when scheduled the scripts will depending on your options: (1) sync your data so as to ensure no data is lost; (2) TRIM your /system, /data, and /cache partitions; (3) DROP CACHES = 3; and (4) turn off wifi.
In addition, there is also an on-the-fly script to manually trim partitions and drop caches when desired.
Click to expand...
Click to collapse
Benefits:
Reduce lag/improve i/o efficiency (see THIS and THIS).
Although android automatically invokes fstrim when certain conditions are met, these criteria could seldom if ever be met depending upon your usage style. The init.d script should ensure fstrim is invoked more frequently for most users.
Should use less ram than apps that perform similar functions (I say should because I have never used such apps, but I imagine they consume more that .2-.5 mb of ram).
Click to expand...
Click to collapse
Requirements:
root
init.d
busybox
fstrim (should be in all nexus 4.3+ roms)
Click to expand...
Click to collapse
Warning/Disclaimer:
Although these scripts function as intended on my device – Nexus 7 (2013), SlimKat (weekly), ElementalX...Use at your own risk. Neither I nor XDA are responsible for any possible deleterious effects.
Click to expand...
Click to collapse
Known Issues/Bugs:
If you use the sync option, scripts with a lower priority than Z99 will not execute.
The log files don't always display as intended...dunno why...any help/suggestions would be appreciated.
Let me know if you find any others .
Click to expand...
Click to collapse
Install, Usage/Verification, & Uninstall:
Install -
Note: If you use crond for other tasks, both the install and uninstall routine account for this potential contigency and should leave your other crond tasks uneffects.
make a nandroid backup
download the zip (<<NOT flashable) attached to this post
extract the zip’s contents
if you were/are using the first version of this script manually delete: /etc/init.d/07TrimDropOff, /data/TrimDropOff_Awake.log, and /data/TrimDropOff_Sleep.log
run TrimDropOffInstaller with superuser permission via terminal or script manager.
follow the scripts prompts
reboot
enjoy
Usage/Verification -
Assuming you have followed the install procedure, next, put your device to sleep and then wake it if you are using the sync option.
Now check the various logs in /data/TrimDropOff. The logs will show the time, the script’s PIDs, the path of the PIDs (just to double-check the PIDs are correct), the ram used by the PIDs, action(s) preformed (amount trimmed from each partition and/or if drop_cahes was run), or errors.
If you want verify manually via terminal do [pgrep -f TrimDrop] for the sync option or [pgrep crond] for the scheduling option to get the PIDs, do [cat /proc/PID/cmdline] for each PID to verify it truly belongs to Z99TrimDropOff or crond, and do [dumpsys meminfo | grep PID] for each PID to verify ram usage (this command will yield duplicates, which can be disregarded and may output undesired additional results, which can be filtered by looking through the results for the relevant PID).
To use the on-the-fly script to trim and/or drop as desired, in terminal do [su -c trimdrop].
Should you want to reconfigure your setup, uninstall before reinstalling to avoid potential issues.
Uninstall -
Note: If you use crond for other tasks, both the install and uninstall routine account for this potential contigency and should leave your other crond tasks uneffects.
Rerun TrimDropOffInstaller with superuser permission and use uninstall option at the beginning of the script.
Reboot and all will be back to as it was before.
Click to expand...
Click to collapse
To-Do List:
Make in to an AROMA package.
I don't know, you tell me .
Click to expand...
Click to collapse
Code:
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Big thanks to zeppelinrox, dk_zero-cool, & gu5t3r @ xda for their contributions to portions of this script (see the code of my other script SwapItOn @ xda for detailed citations).
# Read Karl Marx.
input_error(){
echo "That is not a valid input...try again...bye ."
exit 69
}
mount_rw(){
mount -o remount,rw / 2>/dev/null
mount -o remount,rw rootfs 2>/dev/null
busybox mount -o remount,rw / 2>/dev/null
busybox mount -o remount,rw rootfs 2>/dev/null
mount -o remount,rw /system 2>/dev/null
busybox mount -o remount,rw /system 2>/dev/null
busybox mount -o remount,rw $(busybox mount | awk '/system /{print $1,$3}') 2>/dev/null
}
mount_ro(){
mount -o remount,ro / 2>/dev/null
mount -o remount,ro rootfs 2>/dev/null
busybox mount -o remount,ro / 2>/dev/null
busybox mount -o remount,ro rootfs 2>/dev/null
mount -o remount,ro /system 2>/dev/null
busybox mount -o remount,ro /system 2>/dev/null
busybox mount -o remount,ro $(busybox mount | awk '/system /{print $1,$3}') 2>/dev/null
}
clear
if [ ! "`busybox`" ]; then
echo "Missing busybox...try again...bye ."
exit 69
fi
id=$(id); id=${id#*=}; id=${id%%[\( ]*}
if [ "$id" = "0" ] || [ "$id" = "root" ]; then
echo "" 1>/dev/null
else
echo "Not running as root...try again...bye ."
exit 69
fi
if [ ! -d /etc/init.d ]; then
echo "Missing /etc/init.d...try again...bye ."
exit 69
fi
if [ ! "`grep -r fstrim /system/bin`" ] && [ ! "`grep -r fstrim /system/xbin`" ]; then
echo "Missing fstrim...try again...bye ."
exit 69
fi
echo "Do you want to install or uninstall TrimDropOff?"
echo "Note: If you are rerunning this script to"
echo "reconfigure your setup, uninstall first."
echo -n "Input (i)nstall or (u)ninstall: "
read install_uninstall
echo
case $install_uninstall in
i|I)mount_rw
if [ ! -d "/sqlite_stmt_journals" ]; then
mkdir /sqlite_stmt_journals
fi
if [ ! -d "/data/TrimDropOff" ]; then
mkdir /data/TrimDropOff
chmod 755 /data/TrimDropOff
fi;;
u|U)mount_rw
rm /system/etc/init.d/Z99TrimDropOff_Sync 2>/dev/null
rm /system/etc/init.d/07TrimDropOff_Cron 2>/dev/null
rm /system/xbin/trimdrop 2>/dev/null
rm -rf /data/TrimDropOff 2>/dev/null
echo "Are you using cron.d for any other services?"
echo -n "Input es or o: "
read crond_use
echo
case $crond_use in
y|Y)sed '/TrimDropOff/d' -i /system/etc/cron.d/crontabs/root 2>/dev/null;;
n|N)rm -rf /system/etc/cron.d 2>/dev/null;;
*)input_error;;
esac
mount_ro
echo "All done. You can close your app now."
echo "Reboot your device to stop all processes."
exit 0;;
*)input_error;;
esac
wifi_only(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
svc wifi enable
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Offing."
svc wifi disable
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
fstrim_only(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Trimming."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
drop_only(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Dropping."
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
wifi_fstrim(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
svc wifi enable
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Trimming, Offing."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
svc wifi disable
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
wifi_drop(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
svc wifi enable
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Dropping, Offing."
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
svc wifi disable
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
fstrim_drop(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Trimming, Dropping."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
wifi_fstrim_drop(){
cat > /system/etc/init.d/Z99TrimDropOff_Sync << EOF
#!/system/bin/sh
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
while [ 1 ]; do
AWAKE=\`cat /sys/power/wait_for_fb_wake\`
if [ "\$AWAKE" = "awake" ]; then
exec 1>/data/TrimDropOff/Awake.log
svc wifi enable
echo "\$(date +"%r %Y.%m.%d"): Waiting for screen to sleep. Confirming script in memory..."
echo "PIDs:"
pgrep -f TrimDrop
pidls=\`pgrep -f TrimDrop\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep sh | grep -m 1 pid
done
fi
SLEEPING=\`cat /sys/power/wait_for_fb_sleep\`
if [ "\$SLEEPING" = "sleeping" ]; then
exec 1>/data/TrimDropOff/Sleep.log
echo "\$(date +"%r %Y.%m.%d"): Trimming, Dropping, Offing."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
svc wifi disable
fi
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Sync_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
echo "Do you want to sync fstrim, drop_caches=3, and/or"
echo "wifi with sleep?"
echo "WARNING: This will cause init.d scripts with a"
echo "priority lower than Z99 to NOT execute."
echo -n "Input es or o: "
read TDOsync
echo
case $TDOsync in
y|Y)echo "Which function(s) would you like to sync with sleep?"
echo "Input 1 for wifi only, 2 for fstrim only,"
echo "3 for drop_caches only, 4 for wifi and fstrim"
echo "5 for wifi and drop, 6 for fstrim and drop, or"
echo -n "7 for all: "
read sync_opt
echo
case $sync_opt in
1)wifi_only;;
2)fstrim_only;;
3)drop_only;;
4)wifi_fstrim;;
5)wifi_drop;;
6)fsrim_drop;;
7)wifi_fstrim_drop;;
*)input_error;;
esac
chmod 755 /system/etc/init.d/Z99TrimDropOff_Sync;;
n|N);;
*)input_error;;
esac
only_fstrim(){
cat > /data/TrimDropOff/TrimDropOff_Cron << EOF
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Read Karl Marx.
exec 1>/data/TrimDropOff/CronRan.log
echo "\$(date +"%r %Y.%m.%d"): Trimming."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
exit 0
EOF
}
only_drop(){
cat > /data/TrimDropOff/TrimDropOff_Cron << EOF
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Read Karl Marx.
exec 1>/data/TrimDropOff/CronRan.log
echo "\$(date +"%r %Y.%m.%d"): Dropping."
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
exit 0
EOF
}
both_funct(){
cat > /data/TrimDropOff/TrimDropOff_Cron << EOF
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Read Karl Marx.
exec 1>/data/TrimDropOff/CronRan.log
echo "\$(date +"%r %Y.%m.%d"): Trimming, Dropping."
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
exit 0
EOF
}
cron_starter(){
cat > /system/etc/init.d/07TrimDropOff_Cron << EOF
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Read Karl Marx.
tdo_time(){
while [ ! "\`ps | grep -m 1 [a]ndroid\`" ]; do sleep 10; done
crond
exec 1>/data/TrimDropOff/CronBoot.log
echo "\$(date +"%r %Y.%m.%d"): cron.d service started."
echo "PIDs:"
pgrep crond
pidls=\`pgrep crond\`
echo "Verify Correct PIDs:"
for i in \$pidls; do
cat /proc/\$i/cmdline
done
echo ""
echo "RAM Usage:"
for i in \$pidls; do
dumpsys meminfo | grep \$i | grep -m 1 crond
done
}
if [ "\`ps | grep -m 1 [a]ndroid\`" ]; then tdo_time
else exec > /data/TrimDropOff/Cron_BootErrors.log 2>&1
tdo_time &
fi
exit 0
EOF
}
echo "Do you want to run fstrim and/or drop_caches"
echo "on a schedule?"
echo -n "Input es or o: "
read sched_opt
echo
case $sched_opt in
y|Y)echo "Which function do you want to schedule?"
echo "Input (f)strim only, (d)rop_caches only,"
echo -n "or (b)oth: "
read funct_opt
echo
case $funct_opt in
f|F)only_fstrim;;
d|D)only_drop;;
b|B)both_funct;;
*)input_error;;
esac
chmod 755 /data/TrimDropOff/TrimDropOff_Cron
echo "Do you want to schedule the function(s)"
echo "on an hourly or daily basis?"
echo -n "Input (h)ourly or (d)aily: "
read sched_opt
echo
if [ ! -d "/system/etc/cron.d" ]; then
mkdir /system/etc/cron.d
chmod 755 /system/etc/cron.d
fi
if [ ! -d "/system/etc/cron.d/crontabs" ]; then
mkdir /system/etc/cron.d/crontabs
chmod 755 /system/etc/cron.d/crontabs
fi
cron_starter
chmod 755 /system/etc/init.d/07TrimDropOff_Cron
case $sched_opt in
h|H)echo "Input 1 to run every hour, 2 to run every two hours,"
echo -n "3 to run every three hours...etc: "
read hour_opt
echo
if [ ! "`echo $hour_opt | awk '!/[^0-9]/'`" ]; then
input_error
fi
if [ -f "/system/etc/cron.d/crontabs/root" ]; then
echo "0 */$hour_opt * * * nohup /data/TrimDropOff/TrimDropOff_Cron" >> /system/etc/cron.d/crontabs/root
else
echo "0 */$hour_opt * * * nohup /data/TrimDropOff/TrimDropOff_Cron" > /system/etc/cron.d/crontabs/root
fi
chmod 755 /system/etc/cron.d/crontabs/root;;
d|D)echo "Input 0 to run at midnight every day,"
echo "1 to run at 1:00 am...13 to run at 1:00 pm"
echo -n "...etc...up to 23: "
read daily_opt
echo
if [ ! "`echo $daily_opt | awk '!/[^0-9]/ && $1<=23'`" ]; then
input_error
fi
if [ -f "/system/etc/cron.d/crontabs/root" ]; then
echo "0 $daily_opt * * * nohup /data/TrimDropOff/TrimDropOff_Cron" >> /system/etc/cron.d/crontabs/root
else
echo "0 $daily_opt * * * nohup /data/TrimDropOff/TrimDropOff_Cron" > /system/etc/cron.d/crontabs/root
fi
chmod 755 /system/etc/cron.d/crontabs/root;;
*)input_error;;
esac;;
n|N);;
*)input_error;;
esac
cat > /system/xbin/trimdrop << EOF
#!/system/bin/sh
# This script was authored by Defiant07 @ xda. Feel free to use it as you see fit, but please give proper credits.
# Read Karl Marx.
clear
trimmer(){
echo "/system:"
busybox sync
fstrim -v /system
echo "/data:"
busybox sync
fstrim -v /data
echo "/cache:"
busybox sync
fstrim -v /cache
}
dropper(){
echo "drop caches:"
busybox sync
busybox sysctl -w vm.drop_caches=3
}
echo -n "Do you want to run (f)strim, (d)rop_caches=3, or (b)oth? "
read funct_opt
echo
case \$funct_opt in
f|F)trimmer;;
d|D)dropper;;
b|B)trimmer
dropper;;
*)echo "That is not a valid input...try again...bye ."
exit 69;;
esac
echo
echo "All done...enjoy! You can close your app now."
exit 0
EOF
chmod 755 /system/xbin/trimdrop
mount_ro
echo "In addition to making the files required by"
echo "your desired configuration, I have also made"
echo "an on-the-fly script to run fstrim and/or"
echo "drop_caches on-demand."
echo "To use it, in terminal do: su -c trimdrop"
echo
sleep 3
echo "Reboot your device to start your desired services."
echo
sleep 3
echo "If you want to know how to verify everything"
echo "is working, read the script's OP (FFS)!"
echo
sleep 5
echo "All done...enjoy! You can close your app now."
exit 0
Click to expand...
Click to collapse
Changelog:
v2.0
made in to installer script
added cron options
added bootloop precautions to the init.d scripts (should make it compatible with all devices that meet the requirments)
the on-the-fly script, trimdrop, now allows user to choose fstrim and/or drop_caches=3
added more syncs to further ensure no data is lost
a bunch of other stuff I probably forget
v2.1
bug fixes - fixed issue if using only sync option (missing directory); fixed display of irrelevant errors in uninstall routine
cleaned code a bit (reduced redundancy)
Click to expand...
Click to collapse
Download History:
Defiant07s_TrimDropOff.zip - [Click for QR Code] (1.6 KB, 162 views)
Defiant07s_TrimDropOff_v2.0_[NOT_FLASHABLE].zip - [Click for QR Code] (3.0 KB, 89 views)
Click to expand...
Click to collapse
Credits:
Big thanks to @zeppelinrox, @dk_zero-cool, & @gu5t3r for their contributions to portions of this script (see the code of my other script SwapItOn for detailed citations).
Much thanks to @mdamaged for spotting the issue with sync init.d script and his note regarding syncing data.
Click to expand...
Click to collapse
Don't forget to click THANKS and RATE 5 STARS if you found this useful :highfive:.
peep my other script SwapItOn
Update to v2.1 if you were only using the sync option.
If you were using both the sync and schedule options or only the schedule option there is no need to update; the bug I found would not effect you.​
reserved...on the off chance it will be needed
Thanks, sounds interesting. I'm assuming the zip can be flashed right after flashing a new rom?
MidnightDevil said:
Thanks, sounds interesting. I'm assuming the zip can be flashed right after flashing a new rom?
Click to expand...
Click to collapse
Not a flashable ZIP per line 2.
AnarchoXen said:
Not a flashable ZIP per line 2.
Click to expand...
Click to collapse
Oh, thanks
Is compatible with custom kernel? Franco in my case
vía n7II r-paco
Will performing trimming operations too frequently cause additional flash memory degradation?
MidnightDevil said:
Thanks, sounds interesting. I'm assuming the zip can be flashed right after flashing a new rom?
Click to expand...
Click to collapse
As you were informed the zip is NOT flashable. If there is sufficient interest (say a 100 downloads) I'll make it flashable/aroma.
jordirpz said:
Is compatible with custom kernel? Franco in my case
vía n7II r-paco
Click to expand...
Click to collapse
Yes, it should be compatible...the fstrim utility is part of the rom (it should be in all nexus 4.3+ roms).
creeve4 said:
Will performing trimming operations too frequently cause additional flash memory degradation?
Click to expand...
Click to collapse
No, to my limited knowledge it should not be harmful (in fact it should increase lifespan - google "fstrim lifespan"). Did a quick google search but could not find anything definitive/reliable regarding frequency...what I did see seemed to suggest 'no' though.
If you are concerned about the frequency, you could not install the init.d script and just use the on-the-fly script, trimdrop, to trim on-demand. Should there be interest and if I have the motivation and time, I have been thinking about making this in to an installer script and/or aroma zip with cron-based options so it could be scheduled hourly, daily, or weekly.
Scheduling options would be awesome!
creeve4 said:
Scheduling options would be awesome!
Click to expand...
Click to collapse
+1
creeve4 said:
Scheduling options would be awesome!
Click to expand...
Click to collapse
BUBA0071 said:
+1
Click to expand...
Click to collapse
Seems there is a decent amount of interest (almost 100 downloads already ...thanks peeps), as such I'll add options and make things more configurable.
Regarding scheduling, I was thinking of doing hourly, daily (with ability to choose time), and weekly (with ability to choose day and time) options. Would every other hour or some other setting be desirable?
Regarding installation, what would be the preferred method, an installer script (e.g. V6 SuperCharger) or AROMA? Flashable zips would be another option, but would have less options/be less configurable.
Gimme some feedback and I'll put something together in the next week or two depending on work and my motivation .
wasn't this a nexus 7 2012 issue and fixed in the new version 2013?
defiant07 said:
Seems there is a decent amount of interest (almost 100 downloads already ...thanks peeps), as such I'll add options and make things more configurable.
Regarding scheduling, I was thinking of doing hourly, daily (with ability to choose time), and weekly (with ability to choose day and time) options. Would every other hour or some other setting be desirable?
Regarding installation, what would be the preferred method, an installer script (e.g. V6 SuperCharger) or AROMA? Flashable zips would be another option, but would have less options/be less configurable.
Gimme some feedback and I'll put something together in the next week or two depending on work and my motivation .
Click to expand...
Click to collapse
My 2 cents:
I would choose a daily option for my device.
I prefer Aroma over a script, but if you cannot get the customization you want with Aroma, then by all means go with a script.
Thanks again for the script and willingness to make it even better!
Thanks for the scripts, I time my startup, and this improved startup time by about 3-4secs, among other noticible improvements, apparently the stock OS does not run fstrim enough, initial operations freed several gigs on the data partition, and hundreds of megs on the others...
creeve4 said:
My 2 cents:
I would choose a daily option for my device.
I prefer Aroma over a script, but if you cannot get the customization you want with Aroma, then by all means go with a script.
Thanks again for the script and willingness to make it even better!
Click to expand...
Click to collapse
+1
Im going to turn this into a cron job, that will take care of scheduling, unless anyone else gets there first ( please lol )
Will give it a go in its present form, whats its resource footprint just sitting there waiting for screen off ?
Can we trigger the action from the screen off event ? or some other interupt type way ?
Great script by the way, your bash is damn site better than mine, jealous lol
KiaraTheDragon said:
wasn't this a nexus 7 2012 issue and fixed in the new version 2013?
Click to expand...
Click to collapse
Yes, I think this is true to a degree...it was more of a problem on the 2012 and other nexus devices. See the links in the OP for the conditions that need to be met for fstrim to autorun...for some users (myself included) the conditions will seldom if ever be met. Also see @mdamaged post; I get similar results the first time fstrim is initiated by my script after each boot...subsequent runs normally only frees up memory on /data.
creeve4 said:
My 2 cents:
I would choose a daily option for my device.
I prefer Aroma over a script, but if you cannot get the customization you want with Aroma, then by all means go with a script.
Thanks again for the script and willingness to make it even better!
Click to expand...
Click to collapse
imfun said:
+1
Click to expand...
Click to collapse
Okay will get to making an AROMA package...it will be my first, but it looks easy enough :fingers-crossed:...gimme a week or two to put it together and fully test.
mdamaged said:
Thanks for the scripts, I time my startup, and this improved startup time by about 3-4secs, among other noticible improvements, apparently the stock OS does not run fstrim enough, initial operations freed several gigs on the data partition, and hundreds of megs on the others...
Click to expand...
Click to collapse
Thanks for the feedback. I get similar results.
jubei_mitsuyoshi said:
Im going to turn this into a cron job, that will take care of scheduling, unless anyone else gets there first ( please lol )
Will give it a go in its present form, whats its resource footprint just sitting there waiting for screen off ?
Can we trigger the action from the screen off event ? or some other interupt type way ?
Great script by the way, your bash is damn site better than mine, jealous lol
Click to expand...
Click to collapse
See the first post on this page and my response to @creeve4 and @imfun in this post. I will make an AROMA package with cron options for fstrim and drop_caches=3.
However, should you feel ambitious and beat me to it, props to you...I will give you full credit in the OP and link your post as the d/l source so you should get the 'thanks' too.
Regarding triggering with screen on/off or some other event: It can probably be done, but I it's beyond my knowledge (screen on/off was actually the first trigger event I looked in to using, but despite fairly extensive searching I could not find how to detect it).
Regarding resource footprint: Read the OP (usage section) it explains where to find the log which contains this info and how to do it via terminal (should you not trust me )...also see OP (benefits section): in all my testing I have never seen it use more that .8 mb, but most of the time it is less than .2 mb.
Okay will get to making an AROMA package...it will be my first, but it looks easy enough :fingers-crossed:...gimme a week or two to put it together and fully test.
Click to expand...
Click to collapse
Can't wait already, because after whole day or two, hard usage of my nexus 7 tablet, the tablet starts to get laggy. I can see this on web browsing, touch press delay time, and onyl rebooting seems to help... Hope after istaling this will solve the problems
ohhh no dont want any credit lol lol, i have turned it into a cron job quite simply by adding it to the cron initilising script
Code:
###########
# IMPORTS #
###########
. /system/etc/init.d.cfg
#############
# FUNCTIONS #
#############
symlink_system_bin() {
# crond has "/bin/sh" hardcoded
if busybox [ ! -h /bin ]
then
mount -o remount,rw rootfs /
busybox ln -s /system/bin /bin
mount -o remount,ro rootfs /
fi
}
export_timezone() {
# set timezone (if you're not between -0500 and -0800 you get PST)
# todo - support other timezones
timezone=`date +%z`
if busybox [ $timezone = "-0800" ]; then
TZ=PST8PDT
elif busybox [ $timezone = "-0700" ]; then
TZ=MST7MDT
elif busybox [ $timezone = "-0600" ]; then
TZ=CST6CDT
elif busybox [ $timezone = "-0500" ]; then
TZ=EST5EDT
else
TZ=PST8PDT
fi
export TZ
}
set_crontab() {
# use /data/cron, call the crontab file "root"
if busybox [ -e /data/cron/root ]
then
mkdir -p /data/cron
cat > /data/cron/root << EOF
0 20 * * * sync; echo 3 > /proc/sys/vm/drop_caches
0 20 * * * sync; fstrim -v /system
0 20 * * * sync; fstrim -v /data
0 20 * * * sync; fstrim -v /cache
01 * * * * busybox run-parts /system/etc/cron/cron.hourly
02 4 * * * busybox run-parts /system/etc/cron/cron.daily
22 4 * * 0 busybox run-parts /system/etc/cron/cron.weekly
EOF
fi
busybox crond -c /data/cron
}
########
# MAIN #
########
if $enable_cron -a is_busybox_applet_available crond
then
symlink_system_bin
export_timezone
set_crontab
fi
adding the lines
Code:
0 20 * * * sync; echo 3 > /proc/sys/vm/drop_caches
0 20 * * * sync; fstrim -v /system
0 20 * * * sync; fstrim -v /data
0 20 * * * sync; fstrim -v /cache
should drop the caches and fstrim every 8 hours, oviously set to anything you want.
i also stuck it in boot at the end
/system/etc/init.d/92jubei
Code:
#!/system/bin/sh
if $file_system_speedups
then
busybox mount -o remount,noatime,barrier=0,nobh /system
busybox mount -o remount,noatime /data
busybox mount -o remount,noatime,barrier=0,nobh /cache
else
busybox mount -o remount,noatime,nobh /system
busybox mount -o remount,noatime /data
busybox mount -o remount,noatime,nobh /cache
fi
echo "$(date +"%r %Y.%m.%d"): Trimming, Dropping."
busybox sync
echo "/system:"
fstrim -v /system
echo "/data:"
fstrim -v /data
echo "/cache:"
fstrim -v /cache
echo "drop caches:"
busybox sysctl -w vm.drop_caches=3
exit 0
For an aroma script you will prob have to stick the file in /system/etc/cron/cron.hourly, daily, weekly and just give peeps that choice, will be most simple way. Ps not a fan of aroma lol
Ok, I should have spotted this issue right away, but did not, so here goes. It seems the use of while loop in the script in the OP causes any scripts with a lower priority in init.d to never get ran, if the script in the OP is the only one in your init.d this does not matter, nor should it matter if you have at boot script with a higher priority (they get ran before the OPs script).
I run the ElementalX kernel which depends on a init.d to initialize some parameters for the kernel, with this script in init.d they never get initialized, in my case this resulted in some things not 'taking' such as the battery life extender, which on my device, is set to stop charging at 4100mv, however, since the while loop kept the ElementalX init.d from running, it kept charging to ~4300mv, this is how I noticed (actually none of my settings wrt ElementalX were being initialized, but this symptom was most pronounced).
A simple fix would be to move up the priority of the ElementalX init.d script, but this would have to be done after each flash, and frankly since I run Tasker anyway, I saw no need for this, what I did was remove the OPs script from init.d and simply made a very simple task in Tasker to run /system/xbin/trimdrop when display goes off, it could just as easily be a time event.
Anyways, hope that helps someone who may come across this with other kernels, or other at-boot scripts which depend on being ran before the OPs script.
Again, thanks to the OP for his work. Also, I added another sync just before the drop caches, since the state of dirtyness could change after the fstrims.

[Q] Root with encrypted device

Is it possible to have the following all at the same time?
- SE Linux permissive Kernel (I use linux on android, so this is a must to mount a loopback filesystem and chroot)
- Encrypted Device
- Encrypted SD Card
- Root Access
Every time I try to do it I lose one of them, its like a game of choose any three of the four.
If I flash the RDDT (nd2) Rom I can get everything except for the SD card encrypted.
If I install the MOAR rom I get everything except for ROOT (I lose root after encrypting the device). Once the device is encrypted I can't flash from TWRP because it can't decrypt either. I would just Towel Root with the MOAR Rom, but it says that the device is not supported.
I even played around with MOAR 2.0 and flashed a different kernel, (the governaa). I think I got all four, but my data/voice modem wouldn't work.
I have played around with the idea of just using an ND2 based rom and just mounting my sd card manually with LUKS, but it'd be awesome if someone has figured this out.
Other approaches that don't work.
If I try cyanogenmod I can get everything except for sd card encryption.
cryptsetup script
I was able to get cryptsetup working so now I can access my external sd card. Here's how it works:
I installed a cyanogenmod 11 rom on my phone, though any se linux permissive rom should do.
I just used "Luks Manager" from the play store in order to get access to a cryptsetup binary.
I wrote a few shell scripts:
crypt_down
Code:
#!/usr/bin/env sh
source ./crypt_env
MOUNTED=`mount | grep $UBLOCK_PATH|wc -l`
if [ $MOUNTED -eq 0 ]; then
exit
fi
umount $MNT_PATH
lm.cryptsetup luksClose $UBLOCK_PATH $MNT_PATH
crypt_up
Code:
#!/system/xbin/env bash
source ./crypt_env
# open block device - unencrypted
lm.cryptsetup luksOpen $BLOCK_PATH $UBLOCK_ID
if [ ! -d "$MNT_PATH" ]; then
echo Creating $MNT_PATH
mkdir $MNT_PATH
fi
HAS_PART=`blkid | grep $UBLOCK_PATH | wc -l`
if [ $HAS_PART -eq 0 ]; then
# format unencrypted as ext4
mke2fs -F -t ext4 $UBLOCK_PATH
else
echo 'Already partitioned, proceeding...'
fi
# mount
echo Mounting $UBLOCK_PATH AT $MNT_PATH
mount -t ext4 -o rw $UBLOCK_PATH $MNT_PATH
crypt_env
Code:
#!/usr/bin/env bash
CRYPTBIN=lm.cryptsetup
BLOCK_ID=mmcblk1p1
UBLOCK_ID=luks_external_sd
BLOCK_PATH=/dev/block/$BLOCK_ID
UBLOCK_PATH=/dev/mapper/$UBLOCK_ID
MNT_PATH=/external_sd
crypt_install
Code:
#!/system/xbin/bash
source ./crypt_env
# get size of block device in byted
BYTECOUNT=`blockdev --getsize64 $BLOCK_PATH`
KBCOUNT=$((BYTECOUNT / 10**3))
MBCOUNT=$((BYTECOUNT / 10**6))
GBCOUNT=$((BYTECOUNT / 10**9))
# bail if bin missing
if [ ! -f `which $CRYPTBIN` ]; then
echo $CRYPTBIN not found!
exit
fi
echo
echo WARNING: THIS COMMAND WILL WIPE ALL DATA ON BLOCK
echo DEVICE $BLOCK_PATH
echo This device has...
echo Bytes: $BYTECOUNT
echo KiloBytes: $KBCOUNT
echo MegaBytes: $MBCOUNT
echo GigaBytes: $GBCOUNT
echo
echo The size listed above SHOULD be the same size
echo as your external sd card. IF IT IS NOT YOU SHOULD
echo NOT CONTINUE, IT COULD BRICK YOUR DEVICE.
echo
echo 'Edit "crypt_env" to change targeted block device'
echo
read -r -p "Type 'YES' in all caps to continue... " response
if [[ $response != "YES" ]]; then
echo 'You did not say "YES"'
exit
fi
echo
echo "WARNING: Randomization can take a LONG time"
echo ' Estimated (/dev/urandom) fast speed: 1.989MB/s'
echo ' Estimated time:' $((MBCOUNT / 114)) min
echo
echo ' Estimated (/dev/random) slow speed: 0.545MB/s'
echo ' Estimated time:' $((MBCOUNT / 32)) min
echo
echo
echo 'Would you like to randomize the device? (y/n) '
read response
if [[ $response == "y" ]]; then
read -r -p 'Use slow randomization method? (y/n) ' response
if [[ $response == 'y' ]]; then
RANDOMIZER=/dev/random
DDBS=512KB
else
# experimentally determined that bs=1024KB is fastest
# for my device
# oddly enough bs=1M is SUPER slow
RANDOMIZER=/dev/urandom
DDBS=1024KB
fi
dd if=$RANDOMIZER of=$BLOCK_PATH bs=$DDBS
echo Randomization complete!
fi
echo Luks formatting $BLOCK_PATH
# format block device
$CRYPTBIN luksFormat $BLOCK_PATH
echo "\nCrypt Install complete. Run crypt_up to access device \n"
Run
bash ./crypt_install
bash ./crypt_up
Additional notes
Another thing to mention is that for the above scripts to work you must unmount your sd card FIRST.
Does anyone familiar with android know how I could shim this into the 'mount sd card' option in the settings > storage dialog?
It wouldn't be difficult to modify this to run as an init.rc, but better integration with the settings menu would be perfect.
I'm on my phone right now, but maybe a grep of a rom would point me in the right direction.
Any help much appreciated!
hattwj said:
Another thing to mention is that for the above scripts to work you must unmount your sd card FIRST.
Does anyone familiar with android know how I could shim this into the 'mount sd card' option in the settings > storage dialog?
It wouldn't be difficult to modify this to run as an init.rc, but better integration with the settings menu would be perfect.
I'm on my phone right now, but maybe a grep of a rom would point me in the right direction.
Any help much appreciated!
Click to expand...
Click to collapse
If you're using Cyanogen you should be able to use Udev but I'm not sure how it's implemented or really if it still is implemented in Cyanogenmod.
Check this out http://www.reactivated.net/writing_udev_rules.html#external-run
You'd want to use the add Action variable if possible. Either that or just add what you need to load at startup via init.rc which would probably be easier depending on what is going on when you run whatever it is you need to mount the encrypted sd card. I didn't read through your scripts.

[Tweak][Guide] Init.d Tweaks

Init.d Tweaks
(Needs ROM (Kernel) With init.d Access And Busybox, Open Empty File In Text Editor (Notepad ++ Or Similar), Insert Tweak You Want In Header,Save in /system/etc/init.d and name it Lomething Like 73tweaks)
1. Strict minfree handler tweak
Code:
echo "2048,3072,6144,15360,17920,20480" > /sys/module/lowmemorykiller/parameters/minfree
2. Internet speed tweaks
Code:
echo "0" > /proc/sys/net/ipv4/tcp_timestamps;
echo "1" > /proc/sys/net/ipv4/tcp_tw_reuse;
echo "1" > /proc/sys/net/ipv4/tcp_sack;
echo "1" > /proc/sys/net/ipv4/tcp_tw_recycle;
echo "1" > /proc/sys/net/ipv4/tcp_window_scaling;
echo "5" > /proc/sys/net/ipv4/tcp_keepalive_probes;
echo "30" > /proc/sys/net/ipv4/tcp_keepalive_intvl;
echo "30" > /proc/sys/net/ipv4/tcp_fin_timeout;
echo "404480" > /proc/sys/net/core/wmem_max;
echo "404480" > /proc/sys/net/core/rmem_max;
echo "256960" > /proc/sys/net/core/rmem_default;
echo "256960" > /proc/sys/net/core/wmem_default;
echo "4096,16384,404480" > /proc/sys/net/ipv4/tcp_wmem;
echo "4096,87380,404480" > /proc/sys/net/ipv4/tcp_rmem;
3. Vm management tweaks
Code:
echo "4096" > /proc/sys/vm/min_free_kbytes
echo "0" > /proc/sys/vm/oom_kill_allocating_task;
echo "0" > /proc/sys/vm/panic_on_oom;
echo "0" > /proc/sys/vm/laptop_mode;
echo "0" > /proc/sys/vm/swappiness
echo "50" > /proc/sys/vm/vfs_cache_pressure
echo "90" > /proc/sys/vm/dirty_ratio
echo "70" > /proc/sys/vm/dirty_background_ratio
4. Misc kernel tweaks
Code:
echo "8" > /proc/sys/vm/page-cluster;
echo "64000" > /proc/sys/kernel/msgmni;
echo "64000" > /proc/sys/kernel/msgmax;
echo "10" > /proc/sys/fs/lease-break-time;
echo "500,512000,64,2048" > /proc/sys/kernel/sem;
5. Battery tweaks
Code:
echo "500" > /proc/sys/vm/dirty_expire_centisecs
echo "1000" > /proc/sys/vm/dirty_writeback_centisecs
6. EXT4 tweaks (greatly increase I/O)
(needs /system, /cache, /data partitions formatted to EXT4)
a) removes journalism
Code:
tune2fs -o journal_data_writeback /block/path/to/system
tune2fs -O ^has_journal /block/path/to/system
tune2fs -o journal_data_writeback /block/path/to/cache
tune2fs -O ^has_journal /block/path/to/cache
tune2fs -o journal_data_writeback /block/path/to/data
tune2fs -O ^has_journal /block/path/to/data
b) perfect mount options
Code:
busybox mount -o remount,noatime,noauto_da_alloc,nodiratime,barrier=0,nobh /system
busybox mount -o remount,noatime,noauto_da_alloc,nosuid,nodev,nodiratime,barrier=0,nobh /data
busybox mount -o remount,noatime,noauto_da_alloc,nosuid,nodev,nodiratime,barrier=0,nobh /cache
7. Flags blocks as non-rotational and increases cache size
Code:
LOOP=`ls -d /sys/block/loop*`;
RAM=`ls -d /sys/block/ram*`;
MMC=`ls -d /sys/block/mmc*`;
for j in $LOOP $RAM
do
echo "0" > $j/queue/rotational;
echo "2048" > $j/queue/read_ahead_kb;
done
8. microSD card speed tweak
Code:
echo "2048" > /sys/devices/virtual/bdi/179:0/read_ahead_kb;
9. Defrags database files
Code:
for i in \
`find /data -iname "*.db"`
do \
sqlite3 $i 'VACUUM;';
done
9. Remove logger
Code:
rm /dev/log/main
10. Ondemand governor tweaks
Code:
SAMPLING_RATE=$(busybox expr `cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_transition_latency` \* 750 / 1000)
echo 95 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
echo $SAMPLING_RATE > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate
11. Auto change governor and I/O Scheduler
a) I/O Scheduler (Best: MTD devices - VR; EMMC devices - SIO) - needs kernel with these
Code:
echo "vr" > /sys/block/mmcblk0/queue/scheduler
or
Code:
echo "sio" > /sys/block/mmcblk0/queue/scheduler
b) Governor (Best: Minmax > SavagedZen > Smoothass > Smartass > Interactive) - needs kernel with these
Code:
echo "governor-name-here" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
12. Move dalvik-cache to cache partition (if it's big enough) to free up data partition space
Code:
CACHESIZE=$(df -k /cache | tail -n1 | tr -s ' ' | cut -d ' ' -f2)
if [ $CACHESIZE -gt 80000 ]
then
echo "Large cache detected, moving dalvik-cache to /cache"
if [ ! -d /cache/dalvik-cache ]
then
busybox rm -rf /cache/dalvik-cache /data/dalvik-cache
mkdir /cache/dalvik-cache /data/dalvik-cache
fi
busybox chown 1000:1000 /cache/dalvik-cache
busybox chmod 0771 /cache/dalvik-cache
# bind mount dalvik-cache so we can still boot without the sdcard
busybox mount -o bind /cache/dalvik-cache /data/dalvik-cache
busybox chown 1000:1000 /data/dalvik-cache
busybox chmod 0771 /data/dalvik-cache
else
echo "Small cache detected, dalvik-cache will remain on /data"
fi
13. Disable normalize sleeper
Code:
mount -t debugfs none /sys/kernel/debug
echo NO_NORMALIZED_SLEEPER > /sys/kernel/debug/sched_features
14. GPS.conf
(create or edit your /system/etc/gps.conf with a text editor)
a) European NTP server (replace for america or asia in your case)
Code:
NTP_SERVER=europe.pool.ntp.org
XTRA_SERVER_1=http://xtra1.gpsonextra.net/xtra.bin
XTRA_SERVER_2=http://xtra2.gpsonextra.net/xtra.bin
XTRA_SERVER_3=http://xtra3.gpsonextra.net/xtra.bin
b) SE supl for A-GPS (better than Nokia's or Google's)
Code:
SUPL_HOST=supl.sonyericsson.com
SUPL_PORT=7275
Warning: Using these tweaks may brick your device. Use it with caution.
:good::good::good:
How can I know that my ROM / kernel support Init.d or not??
AK205 said:
How can I know that my ROM / kernel support Init.d or not??
Click to expand...
Click to collapse
Install Universal Init.d from Play Store and follow in-app instructions. Init.d support will be enabled on your device. Your device must be rooted first.
Build.prop tweaks by @bravonova
bravonova said:
Install Universal Init.d from Play Store and follow in-app instructions. Init.d support will be enabled on your device. Your device must be rooted first.
Click to expand...
Click to collapse
I make and init.d script and i copy your custom values to my init.d script. However, on net speed tweaks, the tcp_rmem and tcp_wmem didn't change the value at all even i edited it. Any help?
Should it be in text file or script file?
So we create a different text document containing each code for each tweak?? Not all In one document in the init.d folder??
Nice write up, bro. Thanks. Will have to try.
Guys so why aren't these enhancing tweaks and buildprop tweaks already available in our phones? Why aren't our phones optimized?
Tweaks good for one person or situation are not necessarily optimal for every case in general .
Medyredy said:
Guys so why aren't these enhancing tweaks and buildprop tweaks already available in our phones? Why aren't our phones optimized?
Click to expand...
Click to collapse
Can you help please?
Hello, I'm a newbie here. I wish to overclock my stock kernal, So it can be done through tweak? or I have to compile new overclock kernal from stock kernal source? Their's already a overclocked kernal for my device but its for cm11 and i want to use it on 4.1.2 JB stock ROM. Is their any simple way out?
Your help will be appreciated. Thanks .
use cm11 for s7392 or try
cm12 new developed
or stock i did give it to you before
choice is yours.......
i no longer have this device
rony raj said:
use cm11 for s7392 or try
cm12 new developed
or stock i did give it to you before
choice is yours.......
i no longer have this device
Click to expand...
Click to collapse
Thanks for suggesting new Cm12 kernal.
As of cm11, X264 encoding is important for me, plus their were some other minor bugs in that build. Though i agree its the best build compiled rom for Trend.
I will myself start some project after June~July.
What happened to your device though? You are among the few members who are guiding peoples on threads related to this device and i really appreciate it.

reset mac address (tested on lineage os)

original: https://cafe.naver.com/dr1phone/70671
some of it has mac address like 82:82:FF:bla:bla
this may occur some problems using wifi
but this is not a rom's problem,
It is default value of your phone
(why they made it like this?)
you can fix it simply using this script(attached)
run as root using bash on twrp shell or terminal emulator
Code:
echo "* created by djdisodo! *"
echo "Mounting filesystems..."
echo "generating mac address"
export MAC=$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1\2\3\4\5\6/')
echo "remounting /persist"
umount /persist
mount -t ext4 /dev/block/bootdevice/by-name/persist /persist
echo "new mac address: " $MAC
echo "removing old mac address"
rm -f /persist/wlan_mac.bin
echo "writing new mac address"
echo $MAC | echo -n -e $(tr -d '[:space:]' | sed 's/../\\x&/g') >> /persist/wlan_mac.bin
for i in $(seq 0 17)
do
echo -n '\0' >> /persist/wlan_mac.bin
done
echo "changing permissions"
chmod 644 /persist/wlan_mac.bin
echo "unmounting partition"
umount /persist
echo "done!"
exit 0
I wanted to make it to flashable zip
but i couldn't
someone will do?

Categories

Resources