[Milestone XT720 Android Development] peshovec:
Ok will try to explain a little more...

2nd-init is a great tool.

When the kernel boots at some point it execute /init

what init has to do depends on configuration files init.rc and init.maphone_umts.rc (or init.maphone_cmda.rc).

The problem is that :

1. Some of the configuration parameters (example ro.* ones) can be set just once.

So if they are set from init based on these configurations, they cannot be altered with setprop command line

2. Some services are just described in these conf files, and are used lately. I was not able to found other way to describe or run such services

Badly, this configuration files are not accessible to directly edit them (i suspect that they are in initrd.img in the whole boot.img, so basically we cannot edit them).

Solution is using 2nd-init. A sript just replaces these configuration files (which are comming from the initrd.img from the boot.img (which i suspect contain the kernel, the initrd.img and some boot options) ) using simple detar command. And then 2nd-init using some hijack, reinitialize the init process. That way it is possible to change this one time set parameters, and to describe additional services or change configuration of existing ..

Then, in one of them ( i think init.rc), external script is called (maybe /system/oc may be /system/xbin/busybox run-parts /system/etc/init.c ...), which finish our customizations.

I'd like to put A BIG warning here about BUSYBOX. the included one (version 1.15.1 ) is working properly. when i changed it, bad thing happen:) (i suppose not every busybox understand correctly run-parts applet). So keep the original busybox in place, and use newer in other place if needed.

About values. I just recommend the setprop values, to match the /sys/module/lowmemory onese.. for example:

[ro.FOREGROUND_APP_MEM]: [3072]

is first from

cat /sys/module/lowmemorykiller/parameters/minfree
3072

3072

etc....

and

[ro.HIDDEN_APP_MEM]: [10752]

has to be same as

/$ cat /sys/module/lowmemorykiller/parameters/minfree
3072,4608,9216,10752

10752

So android framework and kernel level memory managament will be aligned.

When to use 128 ram presets, or 256 ram presets (they are both described in init.rc and init.maphone_umts.rc) or some custom values is up to us:)

# Adjust the out of memory thresholds to account for the larget
# space on sholes. These numbers are in pages (4k). Must be kept
# in sync with init.rc. This must be done before the regular init.rc
# since these properies can't change once set.

# This is set for 128M RAM
# setprop ro.FOREGROUND_APP_MEM 2048
# setprop ro.VISIBLE_APP_MEM 3072
# setprop ro.SECONDARY_SERVER_MEM 6144
# setprop ro.BACKUP_APP_MEM 6144
# setprop ro.HOME_APP_MEM 6144
# setprop ro.HIDDEN_APP_MEM 7168
# setprop ro.CONTENT_PROVIDER_MEM 8192
# setprop ro.EMPTY_APP_MEM 8192

# ST_SKT change this with 256M RAM
setprop ro.FOREGROUND_APP_MEM 3072
setprop ro.VISIBLE_APP_MEM 4608
setprop ro.SECONDARY_SERVER_MEM 9216
setprop ro.BACKUP_APP_MEM 9216
setprop ro.HOME_APP_MEM 9216
setprop ro.HIDDEN_APP_MEM 10752
setprop ro.CONTENT_PROVIDER_MEM 12288
setprop ro.EMPTY_APP_MEM 12288

class_start media_early_init

on boot

# Overwrite what init.rc selected for the memory killer params to match above.
# 128M RAM
# write /sys/module/lowmemorykiller/parameters/minfree 2048,3072,6144,7168,8192,8192
# 256M RAM
write /sys/module/lowmemorykiller/parameters/minfree 3072,4608,9216,10752,12288,12288

or using some custom specified values, actually dosen't matter, but if

that is true:

setprop ro.FOREGROUND_APP_ADJ 0
setprop ro.VISIBLE_APP_ADJ 1
setprop ro.SECONDARY_SERVER_ADJ 2
setprop ro.BACKUP_APP_ADJ 2
setprop ro.HOME_APP_ADJ 4
setprop ro.HIDDEN_APP_MIN_ADJ 7
setprop ro.CONTENT_PROVIDER_ADJ 14
setprop ro.EMPTY_APP_ADJ 15

write /sys/module/lowmemorykiller/parameters/adj 0,1,2,7,14,15

So basicaly with the setprop we tell the android framework which type of app, to have which priority.

Actually some android framework types, share the priority,because we have just 6 slots.

And we have to define the same priorities at the kernel level

and

setprop ro.FOREGROUND_APP_MEM 1536
setprop ro.VISIBLE_APP_MEM 2048
setprop ro.SECONDARY_SERVER_MEM 4096
setprop ro.BACKUP_APP_MEM 4096
setprop ro.HOME_APP_MEM 4096
setprop ro.HIDDEN_APP_MEM 5120
setprop ro.CONTENT_PROVIDER_MEM 5632
setprop ro.EMPTY_APP_MEM 6144

write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,5120,5632,6144

which is best understandable like this:

write /sys/module/lowmemorykiller/parameters/minfree ro.FOREGROUND_APP_MEM, ro.VISIBLE_APP_MEM, ro.SECONDARY_SERVER_MEM, ro.HIDDEN_APP_MEM, ro.CONTENT_PROVIDER_MEM, ro.EMPTY_APP_MEM

of course as you see the so called slots in adj and minfree are just 6, that's way some type in the android framework share the same priority (and mem level).

So here are my`s (i just use the 256 ram presets, because i use my phone as the average joe: corporate syncing, gmail syncing, imap syncing, 3g all the time, sync always on, eg pretty close to the usage pattern, for a corporate user (and i hope the phone is optimized for such usage:) )

in init.rc

# Define the oom_adj values for the classes of processes that can be
# killed by the kernel. These are used in ActivityManagerService.
setprop ro.FOREGROUND_APP_ADJ 0
setprop ro.VISIBLE_APP_ADJ 1
setprop ro.SECONDARY_SERVER_ADJ 2
setprop ro.BACKUP_APP_ADJ 2
setprop ro.HOME_APP_ADJ 1
setprop ro.HIDDEN_APP_MIN_ADJ 7
setprop ro.CONTENT_PROVIDER_ADJ 14
setprop ro.EMPTY_APP_ADJ 15

# Define the memory thresholds at which the above process classes will
# be killed. These numbers are in pages (4k).
# setprop ro.FOREGROUND_APP_MEM 1536
# setprop ro.VISIBLE_APP_MEM 2048
# setprop ro.SECONDARY_SERVER_MEM 4096
# setprop ro.BACKUP_APP_MEM 4096
# setprop ro.HOME_APP_MEM 4096
# setprop ro.HIDDEN_APP_MEM 5120
# setprop ro.CONTENT_PROVIDER_MEM 5632
# setprop ro.EMPTY_APP_MEM 6144
# above for 128, bellow for 256

setprop ro.FOREGROUND_APP_MEM 3072
setprop ro.VISIBLE_APP_MEM 4608
setprop ro.SECONDARY_SERVER_MEM 9216
setprop ro.BACKUP_APP_MEM 9216
setprop ro.HOME_APP_MEM 9216
setprop ro.HIDDEN_APP_MEM 10752
setprop ro.CONTENT_PROVIDER_MEM 12288
setprop ro.EMPTY_APP_MEM 12288
# Write value must be consistent with the above properties.
# Note that the driver only supports 6 slots, so we have HOME_APP at the
# same memory level as services.
write /sys/module/lowmemorykiller/parameters/adj 0,1,2,7,14,15

write /proc/sys/vm/overcommit_memory 1
write /proc/sys/vm/min_free_order_shift 4
# write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,5120,5632,6144
#above for 128 mem, below for 256
write /sys/module/lowmemorykiller/parameters/minfree 3072,4608,9216,10752,12288,12288

in init.maphone_umts.rc

# Adjust the out of memory thresholds to account for the larget
# space on sholes. These numbers are in pages (4k). Must be kept
# in sync with init.rc. This must be done before the regular init.rc
# since these properies can't change once set.

# This is set for 128M RAM
# setprop ro.FOREGROUND_APP_MEM 1536
# setprop ro.VISIBLE_APP_MEM 2048
# setprop ro.SECONDARY_SERVER_MEM 4096
# setprop ro.BACKUP_APP_MEM 4096
# setprop ro.HOME_APP_MEM 4096
# setprop ro.HIDDEN_APP_MEM 5120
# setprop ro.CONTENT_PROVIDER_MEM 8192
# setprop ro.EMPTY_APP_MEM 8192

# ST_SKT change this with 256M RAM
setprop ro.FOREGROUND_APP_MEM 3072
setprop ro.VISIBLE_APP_MEM 4608
setprop ro.SECONDARY_SERVER_MEM 9216
setprop ro.BACKUP_APP_MEM 9216
setprop ro.HOME_APP_MEM 9216
setprop ro.HIDDEN_APP_MEM 10752
setprop ro.CONTENT_PROVIDER_MEM 12288
setprop ro.EMPTY_APP_MEM 12288

class_start media_early_init

on boot

# Overwrite what init.rc selected for the memory killer params to match above.
# 128M RAM
# write /sys/module/lowmemorykiller/parameters/minfree 1536,2048,4096,5120,8192,8192
# 256M RAM
write /sys/module/lowmemorykiller/parameters/minfree 3072,4608,9216,10752,12288,12288

Actually even with "just 20 MB free ram" i was happy with phone. But, i think the above is the right way.

The values in minfree are in 4k pages,

so 5120 means ~ 20Mb

and 10752 means ~ 40Mb

look similar hough:) actualy the value in the 4-th slots (starting count from 1) will be the amount of ram we will see free. They are plenty of sources about that. Actually finding the right balance about enough memory and cached memory, without taking in account the usage pattern is not practical.

But in my point of view the following is true:

Setting parameters for preset 128, will make out phone feel good (e.g. 128 ram bonus, which can be used)

Leaving parameters for preset 256 will make most usage of phone memory

Sorry i cannot explain that one better, but it depend of how everyone use the phone.

Honestly i think the so speculated heap size memory has to be set with taking in to account the 3 and 4 slot of memory level too. but again it depends.