Search This Blog

Showing posts with label Xperia. Show all posts
Showing posts with label Xperia. Show all posts

Configuring zRAM on the Sony Xperia Play with FreeXperia Zeus

If you have unlocked your Xperia Play and installed FreeXperia (+CyanogenMod  9.1) then you will quickly discover that enabling zRAM via the Performance settings has no effect whatsoever.





















I have reported this as a bug but the project team seem more interested in burying their head in the sand so you won't get any help at all from them. I even asked for help on the +FreeXperia +Google+ page but I gave up on asking for any help from anyone there a long time ago.

The provided Linux kernel definitely does have zRAM enabled.

# ll /dev/block/zram*
brw-------    1 root         root          253,   0 Sep 10 13:10 /dev/block/zram0

The problem lies within the UI to configure it. No scripts seem to be created or executed so either the option is a stub or it is simply broken.

Initially I decided to use SetXperia which, again, proves that the kernel part is fine, but SetXperia remains in RAM all the time, and even in the notification area. I just don't see the point in that.

It can't be that difficult to enable zRAM, right?

Using the Ubuntu zram-config package it was fairly easy to work out what was needed and hence create a script.

#!/system/bin/sh

SWAPPINESS="35"
TAG="zram-config"

log -p i -t $TAG "Setting vm.swappiness to $SWAPPINESS"
logwrapper sysctl -w vm.swappiness=$SWAPPINESS
log -p i -t $TAG "Done."

log -p i -t $TAG "Setting up zram"
echo 75497472 > /sys/block/zram0/disksize
logwrapper mkswap /dev/block/zram0
logwrapper swapon /dev/block/zram0
log -p i -t $TAG "Done."

log -p i -t $TAG "All done."

I dropped this script into /data/local/userinit.d/zram-config (remember to set +x on the script).

All the log and logwrapper stuff is obviously to send details to the log. It probably doesn't work as the script is run before Android is loaded. Indeed, I've never seen anything using logcat unless it's run manually. They are not needed for the script to work.

vm.swappiness is set to 60 by default. You shouldn't change that unless you know what you're doing. In my case sysctl -w vm.swappiness=35 does this. I could not find a config file for sysctl (such as /etc/sysctl.conf) as is the case for most Linux distributions.

The Ubuntu script sets up the amount of zRAM based on the amount of RAM and creates separate devices based on the number of cores, which makes sense because it's a generic script to be used on a vast array of machines including, recently, mobile platforms. There's no real need to do that unless you plan on dropping the script on a variety of different devices. You should decide for yourself how much zRAM you want to configure.

echo 75497472 > /sys/block/zram0/disksize sets my zRAM device to 75 MB.

mkswap /dev/block/zram0 sets up the device as a swap device, as you would with any normal swap.

swapon /dev/block/zram0 enables the swap.

This can, of course, be used with any device that has zRAM enabled in the kernel.

# uname -a
Linux localhost 2.6.32.9-FXP #1 PREEMPT Fri Apr 19 17:37:58 EEST 2013 armv7l GNU/Linux

I recommend installing ZRAM Status from the Play Store so that you can see that your zRAM is being used, along with some interesting, nerdy statistics.




Remember that you will need to reboot your device (or run the script manually) to enable zRAM the first time.

Dropbear SSH server on Android

It's safe to say that if you're reading this then you know why one would want an SSH server running on your Android device. Personally I have SSH running on all my Linux boxes because it makes life so much easier, and I'm sure I do not need to explain why. Having an SSH server start on boot is simply a lot more convenient!

There are a number of apps on the Android market but most of them are utterly useless with one exception: SSHDroid.

If you are likely to use SSH once in a while then it may be easier for you to just install SSHDroid on your device and start it when needed, and I have been happy with it for a while.

However:
  1. It's an ugly app that sits in your notification tray once it has been started and uses up RAM and CPU. I want a background app.
  2. SSHDroid refuses to run if it cannot access adverts unless you pay for it. I block all adverts because they get on my nerves.
  3. All it does is drop a copy of Dropbear anyway, so you may as well do that yourself.
  4. Dropbear will happily run in the background and uses tiny amounts of CPU when active, so you can imagine how little it does when idle.
  5. If you can compile Dropbear yourself you can choose the options that you want.
As I'm sure you are aware there is no package delivery system for this kind of application in Android, but Android runs on a modified Linux kernel - this makes things so much easier! The result being that the following process is ridiculously easy assuming that your OS has:
  • su or sudo (root)
  • init.d support (or another way to run scripts at startup)
The only problem, really, is that the filesystem and methods used in Android aren't exactly standard compared to other *nix systems, but its not massively different. The result being that there are a number of ways that you can get things to work, so I'll simply show you what I have done. If I was doing this to a number of devices or in a corporate environment then I would use a bit more planning.

My profile on StackExchange