FORUMS
Remove All Ads from XDA
Honor View 10

[Fix] Android Media scanner sdcard CPU utilization, battery drain

313 posts
Thanks Meter: 240
 
Post Reply Email Thread


Often your Media scanner can misbehave and eat lot of CPU, Battery un-wantedly.

I had been digging out how to fix it, and here are my solutions. Perhaps try al of them, it would definitely relieve your cpu and battery usage by large. Solution works on any Android version:

Solution 1. Clear media storage data
Settings > applications > Media Storage > clear data, force stop and reboot.

Solution 2. Remove unwanted media files
Navigate to /sdcard/DCIM/.thumbnails and delete all files. Repeat for external sd card.
On AOSP roms, Android gallery creates too many of thumbnails that later becomes problematic for media scanner.

Solution 3. Analyze and delete excessive media files
Find out what files are causing media scanner to go mad.
Use any sdcard analyst (I use ES file manager > menu > Sd card analyst) to determine which directory has lots of files/subdirectories inside it. Any directory having >1000 files/folders is an alarmingly high number. Get rid of them (if you can).

Solution 4. Probe and delete bad/damaged media
If you're sure you've tried above solutions and still encountering battery drain, its time to dig deeper with developer tools.
Pre-requisite: You must be rooted, and have android developer tools (adb) setup.

With ADB tools installed, enter shell and acquire su permissions

Code:
adb shell
su
Then run top (linux task manager) to see which process is eating cpu. You can filter top results

Code:
top -grep media
this would give you a result like

Quote:

130|root@n7000:/ # top | grep media
1905 0 10% S 7 23080K 6168K bg media /system/bin/mediaserver
2808 0 40% S 3 3524K 740K media_rw /system/bin/sdcard
2825 0 9% S 19 255832K 43936K bg u0_a5 android.process.media

%age cpu shows media server is eating cpu and needs to be fixed. Run the following command to determine which file is it currently reading

Code:
lsof | grep media_rw
If the media service is stuck at a directory/file for a long time, you know it's a damaged media file, you should get rid of it.

Once you get rid of such files, Its guaranteed media server would finish scanning soon enough.

Solution 5: Format SD cards
If nothing works (or you're too lazy of trying solution 4): Take backup and format Internal, external sd card and copy only selective files/folders that you need. Problems would go away for sure.

Solution 6: Disable Media scanner
If your Droid is against you and it just won't tame, its time to disable the media scanner. You can do this from adb shell

Code:
pm disable com.android.providers.media/com.android.providers.media.MediaScannerReceiver
All Solutions with full detail: Fix Android Media server scanner SDcard CPU, Battery drain


Have fun, Droid is your friend
The Following 65 Users Say Thank You to taranfx For This Useful Post: [ View ] Gift taranfx Ad-Free
 
 
28th February 2014, 10:44 PM |#2  
Senior Member
Thanks Meter: 160
 
More
Quote:

Solution 1. Clear media storage data
Settings > applications > Media Storage > clear data, force stop and reboot

This is the one that fixed it for me. Thanks!
12th March 2014, 08:46 AM |#3  
Junior Member
Thanks Meter: 1
 
More
Guys -

my problem is that i'm using another app to dump pictures to the DCIM folder. Therefore Android doesn't pickup new items in the DCIM folder.

I need to run "dev tools > media provider > scan sd card" to fresh. Then i'm able to see everything in gallery etc...

Is there a way to force this media scan to happen every 1hr? ie in the build.prop or something? I do have root access..

thanks.
The Following User Says Thank You to ds4 For This Useful Post: [ View ] Gift ds4 Ad-Free
28th April 2014, 10:51 AM |#4  
Senior Member
Flag Sarajevo
Thanks Meter: 25
 
More
It seems I have a different problem with this Media.
While trying to pinpoint directory/file, after I run "lsof | grep media" I see a few messages with "opendir" or "readlink" and "permission denied" that refer to /proc.
I use CM 11 with Xprivacy module and I'm not sure whether some wrong permission caused it.

BTW: In the beginning (of the problem), there was BetterBatteryStats (to know that it's Media scanner that easts a lot of CPU)..
8th May 2014, 12:24 PM |#5  
Senior Member
Flag Sarajevo
Thanks Meter: 25
 
More
I reworked this a little, hoping it might help someone:

In order to find out what's draining a battery, it's convenient to use BetterBatteryStats or OS Monitor.
If it's Media scanner, there are the following solutions.

Solution 1A. Clear media storage data and allow Media scanner to rebuild a database
Settings > Apps > Media Storage > Clear data, force stop and reboot.

Solution 2A. Remove unwanted media files
Navigate to /sdcard/DCIM/.thumbnails and delete all files. Repeat for external sd card.
On AOSP roms, Android gallery creates too many of thumbnails that later becomes problematic for media scanner.
Solution 2B. Analyze and delete excessive media files
Find out what files are causing media scanner to go mad.
Use any sdcard analyst (ES file manager > menu > Sd card analyst) to determine which directory has lots of files/subdirectories inside it. Any directory having > 1000 files/folders is an alarmingly high number. Get rid of them (if you can).
Solution 2C. Probe and delete bad/damaged media
If you're sure you've tried above solutions and still encountering battery drain, its time to dig deeper with developer tools. Pre-requisite: You must be rooted.
In Terminal Emulator, acquire su permissions.
Then run top (linux task manager) to see which process is eating cpu. You can filter top results
Code: "top | grep media" OR “top -n 1 | grep media”
this would give you a result like
Quote:
130|root@n7000:/ # top | grep media
1905 0 10% S 7 23080K 6168K bg media /system/bin/mediaserver
2808 0 40% S 3 3524K 740K media_rw /system/bin/sdcard
2825 0 9% S 19 255832K 43936K bg u0_a5 android.process.media
%age cpu shows media server is eating cpu and needs to be fixed. Run the following command to determine which file is it currently reading
Code: "lsof | grep media_rw"
If the media service is stuck at a directory/file for a long time, you know it's a damaged media file, you should get rid of it.
Once you get rid of such files, media server should finish scanning soon enough.

Solution 3A: Set Media scanner not to awake a device
revoke Keep awake privilege (from Settings > Privacy > Privacy Guard)
Solution 3B. Prevent from scanning by placing a file in folder
Placing a .nomedia file will scan a directory and shot in MTP but exclude it from the media database. Placing .noscanandnomtp completely prevents the scan, which saves considerable processing power and battery life on systems with numerous media files, but prevents them from being seen over MTP.
Solution 3C: Disable Media scanner
If your Droid is against you and it just won't tame, its time to disable the media scanner. You can do this from from Settings-Apps or from adb shell
Code: pm disable com.android.providers.media/com.android.providers.media.MediaScannerReceiver

Solution 4: Format SD cards
If nothing works you can still take backup and format internal and external sd card and copy only selective files/folders that you need.
The Following User Says Thank You to TimAnd For This Useful Post: [ View ] Gift TimAnd Ad-Free
9th May 2014, 12:49 AM |#6  
Junior Member
Thanks Meter: 0
 
More
Battery drain problem solved
Hi, I had the battery drain problem with Android 4.1.2. tablet. Tried everything found on several forums, and the result was - nothing worked. Mediaserver kept draining my battery.
Intuitively, I tried two things:
1. Unmounted SD card where I keep all sorts of media files.
2. Deleted downloaded PICTURES from "download" folder.

Result = problem SOLVED.

Then remounted the SD card - battery life still normal!

Conclusion: bloody mediaserver keeps scanning the downloaded pictures and drains the battery.

Simplicity is always the answer!
9th June 2014, 11:23 AM |#7  
Senior Member
Thanks Meter: 164
 
Donate to Me
More
my 64gb samsung sdcard is exFat formatted. Do you suggest keep ex fat or other type partition? My phone is samsung i9505 with stock rom
1st August 2014, 04:17 PM |#8  
berezker's Avatar
Senior Member
Flag Jeddah
Thanks Meter: 127
 
More
I just formatted my phone and it worked
#5
12th August 2014, 07:55 AM |#9  
Member
Thanks Meter: 4
 
More
Thumbs down Doesn't work for me
Hello,

I have this problem for a very long time now on my Galaxy S2 I9100.

Since the last months, I upgraded CM11 from M7 to M9, made full wipes and formatted the whole system/sd card a few times.

My girlfriend with the same phone model with CM11 doesn't have any problem, my guess is, it must really have to do something with the SD card content/installed apps.

I have the feeling that media scanner starts to scan infinitely after I transfer some files via USB (mass storage mode). I already put .nomedia and .noscanandnomtp files in every folder than contains a lot of files.

Yes I have some apps that put a few hundred files in a few folders on the internal SD card.

Access via ADB and top/grep didn't work, as somehow mediascan seems to stop when plugged in via USB...? It didn't lead to the solution.

For now I will try to disable wake ability via privacy manager but this doesn't cure the cause only the symptoms (I hope!)

Last I could try to start deleting some of those apps that create those large amount of files and look if it helps.

But it seems this problem is still there
16th August 2014, 06:20 PM |#10  
Junior Member
Thanks Meter: 0
 
More
Hello,

I faced this issue on 2 of my devices, a galaxy note 3, and a oneplus one.

Devices were very hot, with a percentage of usage about 43% of the battery.

I tried several things, and i was able to reduce it straight away by deleting from my download folder the images attachment you can download from mails, file names like :

download-file.bin (something like that).

I m now monitoring my battery usage, and media fell from 43% to 20% already in a matter of minutes.

It may worth a try removing such files and if all goes well, you could save lot of battery
19th August 2014, 10:06 PM |#11  
Member
Thanks Meter: 19
 
More
I've got my Android folder filled with what seems to be about 16k subfolders + files... I think I found the reason why sdcard is being a pain...
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes