yashsingh1/xdaforums huggingface dataset:
[Galaxy S II Android Development] Lanchon:
so i extended the OP to include how to theoretically trim these devices. if someone ever does this, they should reserve unpartitioned trimmed space so that the phone never runs out of it again. here's the quote:

UPDATE: so now i know of a way to trim these untrimmable devices. it is extremely dangerous though (unless you have JTAG access to the eMMC). these eMMCs have a command to resize their boot partitions (boot0/boot1). these partitions are treated differently from all others by these modules. you can think of them as separate, safe, small, virtual disks; even if you write all over the main disk, you will never touch these partitions. also, wear leveling on the main disk will never move data around on these partitions. contrary to data on the main disk, once you write something here, it stays written forever (until you write something else). because they are treated differently, the eMMC needs to know their size. for versatility there is a non-standard command that will resize these partitions, and as a side effect it will repurpose the rest of the flash as the "main disk", creating all of its FTL structures from scratch. this full, low-level reformatting will fix a brickbug-damaged eMMC and will also trim an untrimmable device. the trick is to resize the boot partitions to some strange value, then resize them back to original size. all data everywhere will be lost, including the bootloaders, and this is why it is so dangerous. these phones will brick unless there are proper bootloaders and friends in place (though with JTAG access you could restore all this data). so the procedure would go like this: boot into recovery, make backups of all partitions you care about (bootloaders, EFS, etc), resize boot0/boot1, resize them back, and restore the needed partitions. but if anything goes wrong before you finish... you have a brick! because it is so dangerous, AFAIK this procedure has never been attempted to fix a brickbugged S2, much less to just trim one. but it has been carried on successfully on devices that boot from alternative sources when their eMMC is wiped, check it out here.
[Galaxy S II Android Development] Acid0057:
Wow thank you for your dedication to our s2 Lanchon. I've since moved onto a Nexus 6P but kept my S2 for travel and music while doing yard work. I don't have a jtag but my s2 was trimmable. Can't wait to try CM 12.1 and you're new kernels to see how they work.

Any thoughts if the s2 will get CM 13 marshmallow?
[Galaxy S II Android Development] Drx86:
http://xdaforums.com/galaxy-s2/development-derivatives/rom-cyanogenmod-13-t3223808

;)
[Galaxy S II Android Development] cescof:
how can i do to repartitioning boot0 and boot1?
[Galaxy S II Android Development] cescof:
up
[Galaxy S II Android Development] Drx86:
As Lanchon said, that is EXTREMELY dangerous and has NEVER been tested on the S2.

So think about what you are doing at least twice... :rolleyes:
[Galaxy S II Android Development] cescof:
maybe i'm mistaking

my trimming operation has a duration between 2 and 4 seconds.

is that normal? I had successfully the trim or not?
[Galaxy S II Android Development] Acid0057:
Nope that isn't normal. Most likely you have an emmc that wasn't allowed to trim. [MENTION=4141005]Lanchon[/MENTION] method to format boot 0 and 1 will do the trick BUT like was mentioned above is very dangerous. Do you know how to disassemble the S2? Do you know what a Jtag on the Emmc communications Port inside the S2 is? If the answer is no to both stop thinking about formatting boot 0 and 1 right now.

I'd do a lot more reading and again like was said above think twice or even 3 times before starting. And be fully prepared to have a paperweight brick of an S2 if it doesn't work.
[Galaxy S II Android Development] Drx86:
I think you're wrong: Lanchon himself wrote in OP that fstrim commands takes just a couple of seconds:

TRIMming takes a few seconds even on my almost empty 240 GB PC SSD. :fingers-crossed:

If Lanchon is right (and I think he is), than trim was successful. :good:
[Galaxy S II Android Development] Lanchon:
trim times depend on emmc firmware, partition size, empty space in partition, and how much trimming is actually needed at the time.

i think 2/4 seconds is normal for an already trimmed device, especially using small stock /data.

reports of non-trimmable emmcs mention "zero time", i think tenths of a second.
[Galaxy S II Android Development] Acid0057:
Thanks for the corrections! Much appreciated.
[Galaxy S II Android Development] cescof:
so i can't do anything for my S2, it is laggy and it will remain laggy forever... also with the lightest roms
[Galaxy S II Android Development] Lanchon:
if you have an untrimmable emmc, your only solution would be to develop a solution yourself. i gave you pointers for that.
[Galaxy S II Android Development] MikiGry:
It isnt true. I have never trimmed my SII. On AOSP roms it is really smooth and fast. Just use SD main from time to time to clear collected trash , and everyting will be ok.
[Galaxy S II Android Development] Dark1Angel:
[MENTION=4141005]Lanchon[/MENTION] will you make a twrp version of this kernel anytime soon?
[Galaxy S II Android Development] the.gangster:
[MENTION=6559665]Dark1Angel[/MENTION]

I doubt. He never wanted to do that so far.

But eat this: http://xdaforums.com/showthread.php?p=64722936

That would rock. :)

Edit:

Now, finally he did it himself! Thank you [MENTION=4141005]Lanchon[/MENTION] !
[Galaxy S II Android Development] ringen00:
deleted
[Galaxy S II Android Development] ajislav:
Fyi, in my case, trimming 4gb data takes over 1minute..
[Galaxy S II Android Development] Lanchon:
this is very unlike everything ive seen.
[Galaxy S II Android Development] Lanchon:
UPDATE: new CM 12.1 kernels are up... TRIM + FreezeFix + TWRP !

all-in-one kernels with TWRP are finally here, now including the official version of zeitferne's freezefix.

going forward, both TWRP and CM recovery versions of new CM 12.1 kernels will be produced.

enjoy TWRPing!
[Galaxy S II Android Development] makix13:
Man you save my life [emoji122] [emoji122] [emoji106] , do you sell T-shirt or similar with your kernel? [emoji6] [emoji2]

S2 Cyanogenmod 5.1.1 [official nightly] - Xposed [official framework] - Viper4Android
[Galaxy S II Android Development] bixi:
Which are the steps to install this kernel? Is better flash before a kernel wipe script?
[Galaxy S II Android Development] souler456:
Just me, pushing my luck...

Suggestion: Why not create your own Custom Kernel which is CM-based with enhanced feats, like, it has OC/UV, BLN, S2W and stuff. I'm sure everyone would love it, and will support beta kernel versions of it to test it out.

:D :) ;) :good:
[Galaxy S II Android Development] Acid0057:
See here: http://xdaforums.com/showthread.php?t=2222843
[Galaxy S II Android Development] Dark1Angel:
where can i see how long does it take the trimming operation?
[Galaxy S II Android Development] Acid0057:
Should show up in the Trimmer app or in the terminal next to the command
[Galaxy S II Android Development] the.gangster:
By counting seconds or looking at your watch...

Terminal (as well as trimmer app) will tell you how many bytes it trimmed (the free space of a partition). If you see that, stop counting...
[Galaxy S II Android Development] Acid0057:
You're right thanks for the correction. That's bytes not time. My bad.
[Galaxy S II Android Development] Lanchon:
lol only if you are a neanderthal! seriously he's just messing with you, you need an apple watch to do this right. and one of the cheap apps, just get several and try. we wont take bug reports unless you are up to standards.
[Galaxy S II Android Development] Lanchon:
unfotunately that was kinda shortlived... the twrp kernels are obsolote already :-p
[Galaxy S II Android Development] Lanchon:
UPDATE: new CM 12.1 kernels are up... TRIM + FreezeFix + IsoRec !

TWRP kernels were nice enough... for a day.

now they are obsolete! meet IsoRec, the isolated recovery solution that finally lets you choose your preferred recovery.

the new IsoRec-compatible TRIM kernels can be found here.

going forward, only the IsoRec-compatible flavor of CM 12.1 kernels will be produced.

enjoy TWRPing; or whatever you like best!
[Galaxy S II Android Development] svbarbosa:
My TWRP backup is not including Android Secure. It is displayed as "0 bytes" and not selected.

I have six apps moved to external sdcard. They are not backed up.

Am I missing something? Is there a way to make it work?
[Galaxy S II Android Development] Lanchon:
hi,

i know it is very recent but still, you are using an obsolete kernel :)

get the IsoRec kernel plus the separate TWRP recovery. (newer version of it just posted!)
[Galaxy S II Android Development] svbarbosa:
Thanks for the quick reply. Will try IsoRec and report back.
[Galaxy S II Android Development] Dark1Angel:
something is not clear for me. is there any difference in terms of performance between twrp kernel and isorec kernel with separate twrp?
[Galaxy S II Android Development] Lanchon:
yes, the isorec twrp is newer than the one bundled in the "old" kernel. there is no reason not to upgrade.
[Galaxy S II Android Development] Dark1Angel:
so isorec comes with a twrp too(separated but in the same zip) or do i have to flash it separately? if yes, which version and for what phone as there isn't a twrp version for I9100?
[Galaxy S II Android Development] Naudiz:
Suddenly, out of nowhere, comes the Kernel I've been waiting for for months :D

Well, not literally out of nowhere, of course. :D

Thank you so much [MENTION=4141005]Lanchon[/MENTION]!

Isorec works flawlessly!
[Galaxy S II Android Development] Drx86:
Today I have trimmed my 32 GB Samsung external SD Card. It took about two minutes, it was the longest trim operation I've ever seen. Trimminig internal SD card (7,5 GB) took only a couple of seconds.
[Galaxy S II Android Development] Lanchon:
lol, go and read the IsoRec thread OP.
[Galaxy S II Android Development] Dark1Angel:
yup, sorry, don't know how i missed it. thanks a lot
[Galaxy S II Android Development] svbarbosa:
Now I am running latest kernel and IsoRec revovery.

Unfortunately the "android secure 0 bytes" problem is still there.
[Galaxy S II Android Development] Lanchon:
the TWRP i published today? then you can take it up with [MENTION=414800]arnab[/MENTION] who is developing it. but...

stop using googles silly sdcard hack, repartition your phone instead. use my PIT 6gb data, 8gb sdcard, 1gb system, no preload.
[Galaxy S II Android Development] svbarbosa:
I did repartition using a 4GB PIT file I did myself three years ago.

I do not like the idea of a smaller internalsd. But if it comes to that I will do it.

[MENTION=414800]arnab[/MENTION], will it be possible to fix this?
[Galaxy S II Android Development] Naudiz:
Are you sure this is a bug then?

If you repitted your /data to 4GB and only 2,3GB are used, maybe your Android Secure really is empty... just saying. I personally haven't used android secure ever since I repitted my phone as well...
[Galaxy S II Android Development] svbarbosa:
I posted a fix request in [MENTION=414800]arnab[/MENTION] TWRP thread. Hope he will be able to figure it out.

The android secure is there for sure. See the screenshot below of the sdcard taken in my PC.
[Galaxy S II Android Development] Lanchon:
to follow up on this: TWRP worked fine and android secure was really empty.
[Galaxy S II Android Development] svbarbosa:
You mean applying the mods suggested by [MENTION=414800]arnab[/MENTION]? I was hoping to see a new build with the fix.

In my case android secure is not empty for sure. App .asec files are there.

It also came to my mind that not only the backup/restore fails, but the advanced wipe of android secure will also fail.
[Galaxy S II Android Development] arnab:
U need 1mb+ in android_secure files to get the size counter incremented. kb wont help.
[Galaxy S II Android Development] svbarbosa:
AS you can see I have 9 files in my android secure folder, all well over 1 Mb.
[Galaxy S II Android Development] arnab:
Try both the storage...i think its a counter for sd not emmc
[Galaxy S II Android Development] gadiyari:
Is there a kernel with fixed FPBug for CM 10.2?
[Galaxy S II Android Development] Lanchon:
no. there're not even CM 10.2 rom versions published by CM. 10.1.3, 11, or 12.1
[Galaxy S II Android Development] gadiyari:
I can see three snapshots of CM 10.2 at CyanogemMod Downloads http://download.cyanogenmod.org/?device=i9100&type=snapshot
[Galaxy S II Android Development] Lanchon:
look at the names, i think those were exoeriments. anyway, no. why do you want to run obsolete software?
[Galaxy S II Android Development] gadiyari:
I moved from the stock to CM11 because the data partition was too small for me. After this change the battery life of my bluetooth heart monitor decreased dramatically. I wonder if the bluetooth drivers of CM10.2 are closer to the stock and it would solve my problem. I will test CM10.1.
[Galaxy S II Android Development] Lanchon:
probably the same. ur monitor is probably bluetooth LE (low energy). i9100 is not hardware compatible with LE. you probably need a new phone. meanwhile better use 12.1.
[Galaxy S II Android Development] gadiyari:
Just the opposite :). My monitor does not support LE.
[Galaxy S II Android Development] svbarbosa:
First many thanks for looking at this matter.

Sorry but I did not understand. AFAIK I have no control on the "Move to sd ard" process. The apps get moved to externalsd, which is good because I have a 32Gb card.

I am willing to do whatever necessary to help you fix this problem, please explain what you meant in your last post.
[Galaxy S II Android Development] elTorres:
i9100 it´s hardware compatible with LE. I used it with Polar H7 and it works fine. I think it´s enabled from CM 10.2. You can see more info here
[Galaxy S II Android Development] Lanchon:
thank you! i didn't know this!
[Galaxy S II Android Development] gadiyari:
Yes. And i suspect that the addition of LE support in CM10.3 somehow broke the communication with the old devices.
[Galaxy S II Android Development] elTorres:
My phone can works fine with my car's Bluetooth (2.0), with Polar H7 (4.0) and with a Bluetooth speaker (3.0)...
[Galaxy S II Android Development] Lanchon:
UPDATE: i entered the TRIM patch into CM's gerrit!

cm-12.1: http://review.cyanogenmod.org/#/c/128930/1

cm-13.0: http://review.cyanogenmod.org/#/c/128931/1

hopefully it will get merged and i can close down this stupid thread once and for all!!! :)
[Galaxy S II Android Development] ajislav:
Hello [MENTION=4141005]Lanchon[/MENTION],

I am consistently getting trim times close to 2 mins on a 4GB /data partition

root@GT-I9100:/ # time fstrim -v /data
/data: 1092268032 bytes trimmed
1m41.59s real 0m0.00s user 0m0.24s system
root@GT-I9100:/ # time fstrim -v /data
/data: 1092268032 bytes trimmed
1m39.34s real 0m0.01s user 0m0.24s system
root@GT-I9100:/ # df
Filesystem Size Used Free Blksize
/dev 393.1M 36.0K 393.0M 4096
/sys/fs/cgroup 393.1M 0.0K 393.1M 4096
/mnt/asec 393.1M 0.0K 393.1M 4096
/mnt/obb 393.1M 0.0K 393.1M 4096
/system 755.9M 473.4M 282.5M 4096
/cache 98.4M 5.9M 92.5M 4096
/efs 19.7M 8.3M 11.4M 4096
/data 3.9G 2.7G 1.3G 4096
/preload 22.1M 4.0M 18.1M 4096
/mnt/media_rw/sdcard0 9.7G 6.8G 3.0G 4096
/mnt/secure/asec 29.5G 23.6G 5.9G 16384
/storage/sdcard0 9.7G 6.8G 3.0G 4096
/mnt/media_rw/sdcard1 29.5G 23.6G 5.9G 16384
/mnt/secure/asec 29.5G 23.6G 5.9G 16384
/mnt/media_rw/sdcard0/.android_secure 29.5G 23.6G 5.9G 16384
/storage/sdcard1 29.5G 23.6G 5.9G 16384

Is it normal that the "bytes trimmed" does not change even on subsequent trims?

Regards ajislav

p.s. big thanks for uploading the trim-enabling patch to gerrit
[Galaxy S II Android Development] arnab:
There are two .android_secure folders..One in emmc and one in micro sd...Try both ones. Put 1mb + files in both of them.
[Galaxy S II Android Development] Lanchon:
yes, it is 100% normal.

regarding trim times: the system has to send a TRIM or DISCARD command to the eMMC for each "hole" or non-allocated sector range in the partition. each command is executed by the eMMC's firmware. old firmwares are not very efficient at doing this. (in fact, the TRIM standard command set itself did not allow for efficient implementations and was later redefined.) so you can say that for each TRIM command there is a fixed time cost plus a variable time cost roughly proportional to the size of the trimmed area. your /data might be full of holes, and you firmware might be particularly slow, so that a lot of slow commands are issued.

i bet that if you back up /data, format it, and then trim it, the trim operation would only take a few seconds.
[Galaxy S II Android Development] Lanchon:
hi [MENTION=6159291]Lysergic Acid[/MENTION], i forgot to tag you here before.
[Galaxy S II Android Development] svbarbosa:
Ok. After adding a dummy file to emmc/.android_secure TWRP made the backup. But only for emmc contents.

It is still ignoring externalsd .android_secure, which is the one that holds the actual .asec files that are in use.

I am enclosing the recovery.log. Hope it will help.
[Galaxy S II Android Development] Lanchon:
is it internal or external sdcard? have u tried with stock CM? how do u format the internal in ext4?
[Galaxy S II Android Development] Aerotinge:
is external sdcard. I tested 3 different sdcards to make sure it is not a sdcard problem.

And tried with official CM recovery, it does format.

here's log.
[Galaxy S II Android Development] Lanchon:
thanks! interesting... the difference between the recoveries is just that mine does a partition erase (eMMC level) and official skips it. but its not my code, that is (more or less) standard official recovery for other devices (well, official does a secure erase instead). so its strange it fails. its too bad i dont have a device to test.

is this too much of a problem for you?
[Galaxy S II Android Development] Aerotinge:
Not really a problem....I can do formatting using PC.

Okay...No wonder CM wanted to drop Kitkat support for S2 in early 2014. such a strange, and maybe difficult-to-maintain device.
[Galaxy S II Android Development] Lanchon:
really? i didnt know that. the exynos platform sucks, make sure u dont buy another exynos device ever again.
[Galaxy S II Android Development] ajislav:
Hi Lanchon,

your project seems really interesting. I am actually quite tempted to do the folowing:

A) repartition to get bigger /data

B) format /sdcard to ext4 to get rid of the music bug (and enable TRIM)

C) apply your TRIM capable kernel

I am on VYL00M rev0x19, I.e. brickbug

Waiting to hear more positive feedback from other users...

BTW, what does Entropy512 think about this?
[Galaxy S II Android Development] empulse92:
be aware, if you use windows it may won't mount your sdcard anymore if it's formatted to ext4
[Galaxy S II Android Development] Lanchon:
as long as you have 1 or 2 Gb of free trimmed space, it doesnt matter that the fat32 partition is not trimmed. if u use 6gb /data for 4Gb apps + 2gb free space, and 8Gb sdcard in fat32, u'd be great.

in fact 2gb is probably gross overkill. the amount of data written to the emmc per day times the write amplification factor must be well below 1gb.

you can go to ext4, but it wont be mounted mass storage by windows nor mac os. that said, its a much better and trusty fs to use. i guess u can still mount it via MTP. CM allows that, right?

regarding entropy, i cant talk for other people. i talked to him many months ago and he didnt respond to my arguments for expecting safety, other than saying that u could be affected by other bugs.

go to my main brickbug aftermath thread and read it, especially the safety post, then choose.

it has recently come to my attention that the maintainer of CM for kindle fire (was it this one?) enabled trim with samsungs fix in the main branch. he said he saw too many wipes and erases without issues already and was confident no issues would arise. u could look for bricks there.

finally, ive seen many instances of the wear leveling bug causing corruption. this doesnt happen when the phone is new. so maybe its preferably triggered by having no trimmed free space. maybe keeping trimmed space will fend off corruption as bonus. time will tell.
[Galaxy S II Android Development] mparus:
I have the same problem - CM11 M9 and this-will-hard-brick-your-device--kernel-cm-11-20140807-UNOFFICIAL-Lanchon-11-M9-TRIM-i9100.zip

D/WifiService( 2216): setWifiEnabled: true pid=4339, uid=1000

E/WifiStateMachine( 2216): Failed to load driver

maybe this is a problem?

D/WifiService( 2216): setWifiEnabled: true pid=2216, uid=1000

I/SystemServer( 2216): Network Service Discovery Service

D/NsdService( 2216): Network service discovery enabled true

I/SystemServer( 2216): UpdateLock Service

D/WifiHW ( 2216): Unable to unload driver module "dhd": No such file or directory

E/WifiStateMachine( 2216): Failed to load driver

D/WifiController( 2216): DEFERRED_TOGGLE handled

E/WifiStateMachine( 2216): Failed to load driver

root@GT-I9100:/system/lib/modules # insmod /system/lib/modules/dhd.ko firmware_path=/system/etc/wifi/bcmdhd_mfg.bin nvram_path=/system/etc/wifi/nvram_mfg.txt

insmod: init_module '/system/lib/modules/dhd.ko' failed (Exec format error)

lsmod on cm11 m9 with trim kernel

shell@GT-I9100:/ $ lsmod

shell@GT-I9100:/ $

lsmod on cm11 m9 with default kernel

shell@GT-I9100:/ $ lsmod

dhd 429636 0 - Live 0x00000000

Si4709_driver 25154 0 - Live 0x00000000

shell@GT-I9100:/ $
[Galaxy S II Android Development] empulse92:
ext4 should be completely trimmable right?
[Galaxy S II Android Development] xhoster:
The Kernel should be compatible with the CM11 nightlies, right?

Or do I have to run M9?
[Galaxy S II Android Development] Lanchon:
thanks!!!

if u read the thread u may know i dont have an i9100 to test. part of the problem is i cant even pull the blobs an official CM. im using themuppets but evidently there seems to be a problem with that repo. whats even stranger is that it works fine for some people, maybe its some kind of interaction with the radio? it would really help if somebody could donate a cracked screen phone, or IMEI-less phone. but so far no candidates.

i can have brief access to a friend's i9100, his daily. maybe ill install CM11 on it and pull, but no testing since it has brickbug and friend is afflicted risk aversion :)

either that will happen or M10 will come out sooner and ill retry with that codebase. unfortunately i cant think of anything else to do for now.
[Galaxy S II Android Development] Lanchon:
yes. but read my previous answer, i think increasing trimmed space has very diminished returns after maybe 1 or 2 GB. it should however speed up write access to the internal sdcard, and diminish the resulting write amplification and lengthen the life of the flash.

vold is supposed to regularly trim all writeable mounted partitions, so i guess it will trim it. lagfix does not have an option for it, but you can invoke fstrim manually.
[Galaxy S II Android Development] Lanchon:
strictly, no. in practice, probably. also in theory u cant downgrade from nightly to M without wipe. to be totally kosher u would need to stay on the current nightly till M10 comes out (it should be based on something newer than your nightly i think, but not if u keep upgrading). then upgrade to it and flash my next M10 kernel.
[Galaxy S II Android Development] xhoster:
Tried it with the 23.08 nightly, booted fine, but wifi didn't work, so I didn't get to try out the lagfix. Went back to stock cm11 kernel, everything working again. I think I will wait for the M10 release before I give it another try ;) looking forward :D
[Galaxy S II Android Development] Lanchon:
no! flash my kernel, trim, then get back to stock! the trimmed free space will speed up ur phone until it runs out. how long depends on how much space u trim and how much data u write to the emmc afterwards.
[Galaxy S II Android Development] xhoster:
Done ;) trimmed fine, booted after trim and reverted back to cm stock kernel. Seems to be running fine, but I have to wait and see (Placebo has to wear off ;) )

Looking forward to M10!