78

On ubuntu server here and I'm trying to unpack 300M image files from a compressed file format using Java.

My unpack rate is 0.5Mbytes/sec, abysmal (34 days to unpack 1.5TB at this rate).

I'm trying to figure out why, and the only oddity I notice is that updatedb.mlocate is always working when I'm doing the unpack process. I want to turn it off to see if it's getting in the way, but I don't understand much about what it is.

top

top - 05:16:52 up 1 day,  5:15,  3 users,  load average: 2.00, 2.01, 1.83
Tasks:  83 total,   1 running,  82 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.4%us,  0.8%sy,  0.0%ni,  8.4%id, 90.2%wa,  0.0%hi,  0.0%si,  0.2%st
Mem:   1737420k total,  1722680k used,    14740k free,  1241260k buffers
Swap:   917500k total,      160k used,   917340k free,   165448k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
22901 davidpar  20   0 1051m  56m 4992 S    3  3.3   0:47.84 java
 2221 root      20   0 32348  26m  268 D    1  1.6  27:57.86 updatedb.mlocat
   25 root      20   0     0    0    0 S    0  0.0  10:10.77 kswapd0
  678 root      20   0 15864  444  268 S    0  0.0   0:19.45 irqbalance
  849 davidpar  20   0 26560 1676  332 S    0  0.1  17:17.49 screen

iotop

Total DISK READ: 4.07 M/s | Total DISK WRITE: 789.62 K/s
  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND
 2221 idle root     1556.98 K/s    6.36 K/s  0.00 % 99.61 % updatedb.mlocate
22902 be/4 davidpar    2.54 M/s  671.93 K/s  0.00 % 96.96 % java -cp /home/davidparks21/fruggutils/lib/FruggMapreduceJobs.~educe.UnpackImages /mnt/local/imagebinaries-r-00010 /mnt/ebs1/
  547 be/3 root        0.00 B/s   87.47 K/s  0.00 %  0.30 % [jbd2/xvdf-8]
  177 be/3 root        0.00 B/s    3.98 K/s  0.00 %  0.15 % [jbd2/xvda1-8]
5
  • 1
    This problem has been affecting me for years and I can not understand why updatedb.mlocate run at high IO priority when the script says a idle mode... Jun 12, 2013 at 23:31
  • 7
    it's a bug. see bugs.launchpad.net/ubuntu/+source/mlocate/+bug/1190696
    – Thufir
    Jul 7, 2014 at 10:57
  • Why it still the default enabled? Over many years it happens to me every time I create a new system. :-/ Sep 20, 2017 at 13:49
  • 1
    For anyone wandering why is this thing needed and whether you break something by switching it off: unix.stackexchange.com/a/273283/126119
    – Ufos
    Nov 1, 2017 at 13:23
  • mlocate does not seem to be included in Ubuntu 20.04 by default. On the other hand, in Ubuntu 20.10 you could try plocate as an alternative.
    – jarno
    Mar 20, 2021 at 8:21

4 Answers 4

87

It can be killed with:

sudo killall updatedb.mlocate

Or:

sudo kill -9 <PID>

It runs every day by cron. Disable it with:

sudo chmod -x /etc/cron.daily/mlocate

And if you want to re-enable it:

sudo chmod +x /etc/cron.daily/mlocate
6
  • 11
    don't forget to delete /var/lib/mlocate/mlocate.db as well
    – reto
    Jul 3, 2013 at 8:50
  • 2
    Is it safe to disable it? Jun 17, 2014 at 8:49
  • 2
    ZOMG Yes. Do this.
    – meawoppl
    Jul 17, 2014 at 0:32
  • 13
    Edit the file /etc/updatedb.conf and set PRUNEPATHS with the directories you DO NOT want to search.
    – inetpro
    Jul 10, 2015 at 12:36
  • 1
    @inetpro Thanks. In my case, I was using backintime which creates a ton of hardlinks over time and things got much better once I added items to the PRUNEPATH.
    – woot
    Jun 8, 2016 at 12:26
20

I did not want to totally eliminate the process but I did want to make it happen less frequently so I worked out how to set it to run weekly instead of daily. This is based on the accepted answer above but probably best listed as its own answer as it's not disabling it.

That said... It's rather simple and appears to work just fine.

sudo chmod -x /etc/cron.daily/mlocate
sudo cp /etc/cron.daily/mlocate /etc/cron.weekly/mlocate
sudo chmod +x /etc/cron.weekly/mlocate

The first one disables the cron job. The second moves it to the weekly tasks. The third command sets the permissions so that it is enabled. Daily, hourly, weekly, and monthly are all options.

1
14

I never used locate, so I removed it. sudo dpkg -P mlocate See Also: https://wiki.archlinux.org/index.php/File_system_search

2
1

If you uninstall locate and mlocate with e.g.:

sudo apt remove locate mlocate

You can prevent them from being reinstalled with:

cat <<EOF | sudo tee /etc/apt/preferences.d/do-not-install-locate.pref
Explanation: Do not install locate or mlocate to avoid excessive Disk I/O
Package: locate mlocate
Pin: origin *
Pin-Priority: -1
EOF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.