PSA: After applying 4.1.2, fill and delete empty space on Nexus 7 to remove lag.

mmaestro

Well-known member
Oct 13, 2010
84
4
0
Visit site
So this has been covered elsewhere (and in exhaustive detail on this XDA thread), but for those of you who have been suffering lag on your Nexus 7s, 4.1.2 fixes the problem. It seems likely the issue was caused by missing TRIM commands to clear storage that had been used and then subsequently freed up on some 16GB Nexus 7s that use Samsung NAND (some of the 16GB N7s use Hynix NAND, and so don't suffer from this problem), and TRIM has been implemented in the software in 4.1.2 where the OS seems Samsung NAND.

However, just updating to 4.1.2 won't fix the lag problem if you're experiencing it. The system needs to see the space filled, and then emptied so it knows that it has to properly clear the space and prepare it for fresh writes. You can do this manually by filling the space with.. whatever. MP3s, video, garbage zip files, then deleting them manually. The XDA thread above has some command line options to do this, as well, but the easiest way I've found is to use Forever Gone to fill the storage and wipe it. The app's actually designed to do a secure delete by filling and wiping storage, but it works for this purpose, too. I just finished performing this on my N7, and while I got a reset when I had only 150MB free, I was able to restart and completely fill and wipe my storage. My tablet wasn't suffering lag after a hard reset a few weeks ago, but I did notice a jump from 83.31 IOPS to 127.46 IOPS after the wipe (in Androbench), which may make a difference. If you've been suffering from lag, this is worth doing after you've received the update.

TL;DR:
To remove lag after receiving 4.1.2 fill storage completely and then free that space back up.
 

mmaestro

Well-known member
Oct 13, 2010
84
4
0
Visit site
Or just go to Google Currents and disable Background Sync.
So sort of. The lag tends to happen when a lot of writes are occurring. Obviously if something's writing to the storage in the background like Currents, that can provoke the lag. The storage is operating slowly, and the system halts waiting for those writes to complete before it moves on to the next task. But fundamentally, the storage ought to be fast enough to handle background writes and whatever you're doing in the foreground simultaneously. Disabling currents mitigates the symptoms, but doesn't address the underlying problem. Freeing up the storage as I suggest here should fix the underlying problem.
 

MajesticFlame

Well-known member
Jul 14, 2012
60
6
0
Visit site
So sort of. The lag tends to happen when a lot of writes are occurring. Obviously if something's writing to the storage in the background like Currents, that can provoke the lag. The storage is operating slowly, and the system halts waiting for those writes to complete before it moves on to the next task. But fundamentally, the storage ought to be fast enough to handle background writes and whatever you're doing in the foreground simultaneously. Disabling currents mitigates the symptoms, but doesn't address the underlying problem. Freeing up the storage as I suggest here should fix the underlying problem.

Yep, I tried the Currents tip awhile ago and it didn't really help but this did.
 

Curtis A

Active member
Aug 6, 2012
42
2
0
Visit site
Are you saying that I should backup all my data because I will need to delete all storage? Video, pics, songs, books etc.. Or just fill free space to capacity? Thanks.

Sent from my Nexus 7 using Tapatalk 2
 

junglejunkie

Well-known member
Jun 17, 2010
629
37
0
Visit site
Are you saying that I should backup all my data because I will need to delete all storage? Video, pics, songs, books etc.. Or just fill free space to capacity? Thanks.

Sent from my Nexus 7 using Tapatalk 2

I am also wondering this. Should I use TB and back up/restore everything, or would a nandroid work?
 

mmaestro

Well-known member
Oct 13, 2010
84
4
0
Visit site
Are you saying that I should backup all my data because I will need to delete all storage? Video, pics, songs, books etc.. Or just fill free space to capacity? Thanks.
Just fill the free space, then delete the "junk" data you used to fill that space. Files you want to keep can be kept.

The problem occurs because of the way NAND storage operates. My recollection of how this works (may be slightly wrong, it's been a while since I read up on this) is that you can't overwrite sectors which have data in them directly, they need to be completely emptied before new data can be stored. Normally when you tell your device to delete something, the data isn't actually removed, the storage just marks those sectors as having been deleted. Then when your device is idle, "garbage collection" takes place, deleting the data that was previously in those sectors and marking them as available to be written to again. There's some wear leveling that takes place, and there's a layer of complexity because blocks of storage have to be emptied at a time, so the system has to wait for an entire block of sectors to be filled and then be deleted, it can't be done piecemeal sector by sector (this process, when automated, is called "TRIM"). The Samsung storage in question here turns out to have not had TRIM enabled, and so as storage was used and then the contents deleted by caching or user behavior, the storage would get slower and slower, because the sectors that theoretically could be written to still had old data on them, and so if the system tried to write to them it first had to clear the block and then write the data, and if the block had a few sectors used that needed to be retained, that needed to be moved to a fresh block, too, making write speeds awful. The 4.1.2 update enabled TRIM, but it's only aware of needing to perform garbage collection on blocks and sectors that have been filled and then deleted after the update has been applied. It can't go back in time and see where garbage collection should be applied on sectors that had data deleted prior to the update. So what you're doing when you fill the space is basically telling the system to perform garbage collection on everything to make sure that all your empty storage is running as fast as it should do for fresh writes.
Hope that's all clear. I'm a little sleep deprived right now, so apologies if my coherence isn't quite there.
 

MajesticFlame

Well-known member
Jul 14, 2012
60
6
0
Visit site
Are you saying that I should backup all my data because I will need to delete all storage? Video, pics, songs, books etc.. Or just fill free space to capacity? Thanks.

You just fill up the free space you have, you don't have to uninstall or remove what you have already. Using the app it locked up when I got to around 160 free and I restarted and then deleted the fill files from within the app and everything was speedy again. Just don't do it until after you have the new firmware installed.
 

junglejunkie

Well-known member
Jun 17, 2010
629
37
0
Visit site
This NEEDS to be on the first page. Seriously, my N7 was PAINFULLY slow and laggy, but after the update and running this 2x it is just as fast as it was on day 1.
Much Thanks!
 

Curtis A

Active member
Aug 6, 2012
42
2
0
Visit site
This NEEDS to be on the first page. Seriously, my N7 was PAINFULLY slow and laggy, but after the update and running this 2x it is just as fast as it was on day 1.
Much Thanks!

Agree, this makes me want to go buy another N7 for when this one breaks :)

Sent from my Nexus 7 using Tapatalk 2
 

natehoy

Well-known member
Sep 2, 2011
2,667
71
0
Visit site
Just fill the free space, then delete the "junk" data you used to fill that space. Files you want to keep can be kept.

The problem occurs because of the way NAND storage operates. ...

Even the Russian judge would give you a ten on that. Nice explanation.


Sent from my Nexus 7 using Android Central Forums
 

Coco.ar

New member
Aug 10, 2012
3
0
0
Visit site
Great post. Just testing 4.1.2 (updated today). The performance is better, but I see a lag when is writing (Ie.: downloading and installing apps. from GPlay). Forever Gone crash when the free space is under 100 mb.. I will try with other apps.
Thank's
 

anon(680971)

Well-known member
Feb 10, 2012
176
10
0
Visit site
Thank you very much for this. I have found a lot of apps crashing because of the lag and I got the update the other night. So I'll give Forever Gone a try. thanks.
 

mmaestro

Well-known member
Oct 13, 2010
84
4
0
Visit site
If it's crashing with low space, try either turning on airplane mode (the crash may be due to background writes to the same spots FG is trying to write to) or just get it to remove the temporary files and call it a day. You may still have a few sectors that need garbage collection done, but they'll be minimal, and the system will sort those given time. You'll probably have fixed lag almost completely, anyway.
 

slosh74

Active member
Jan 8, 2012
36
1
0
Visit site
I didn't have any lag though when I updated. I bought my tablet about last week though

Sent from my Galaxy Nexus using Android Central Forums
 

amheck

Active member
Jan 6, 2011
35
0
0
Visit site
Thanks for the link to this app. I actually did a hard reset a week ago cause of the lag issues. It cleared up, and now I'm on 4.1.2, but I'm going to run this anyway.
 

mmaestro

Well-known member
Oct 13, 2010
84
4
0
Visit site
Aside from ripping it apart, is there any easy way to determine which manufacturer your Flash was sourced from?
Not that I know of, although some command line/ADB wizards may prove me wrong. If you don't have any lag, I would assume everything's fine, and if you do, run Forever Gone. There's not really any down side to doing so, even if you have different storage.
 

Forum statistics

Threads
942,975
Messages
6,916,707
Members
3,158,757
Latest member
Hisoka_Ryuzaki