I recently experienced a slow MariaDB upgrade/migration from MySQL 5.5 to MariaDB 5.5, after the server has been stopped it took maybe one or two minutes before starting the new one.
A process doing a "chown mysql -R /var/lib/mysql" was runing for quite a long time.
This particular server has about 350000 files on its datadir, while its far from being the best practice its not easy to change that (its a shared hosting server).
Replacing the line on "mariadb-server-*.postinst" :
With something like (there is probably a better alternative) :
It seems to be marginally slower (less than 1/100th of a second on my tests) on small directories but faster on directories with many files on it (about 20-40% faster on a directory with only 25k files on a software raid1 with 2* 7200k HDDs).