On 03.04.2011 23:05, Dio Brando wrote: > # time strace -S time -tt > /usr/src/grub2-1.98+20100804/debian/grub-common/usr/sbin/grub-probe > --device /dev/sda1 --target=fs_uuid -v > /tmp/probe_strace 2>&1 > > real 5m2.368s > user 0m0.080s > sys 0m0.092s > > log attached at this email. Looks like the time comes from calling BLKFLSBUF. Attached patch makes BLKFLSBUF only on write.
-- Regards Vladimir 'φ-coder/phcoder' Serbinenko
=== modified file 'grub-core/kern/emu/hostdisk.c' --- grub-core/kern/emu/hostdisk.c 2011-04-03 13:45:20 +0000 +++ grub-core/kern/emu/hostdisk.c 2011-04-03 21:21:00 +0000 @@ -629,11 +629,14 @@ #ifdef O_LARGEFILE flags |= O_LARGEFILE; #endif + #ifdef O_SYNC - flags |= O_SYNC; + if ((flags & O_ACCMODE) == O_WRONLY || (flags & O_ACCMODE) == O_RDWR) + flags |= O_SYNC; #endif #ifdef O_FSYNC - flags |= O_FSYNC; + if ((flags & O_ACCMODE) == O_WRONLY || (flags & O_ACCMODE) == O_RDWR) + flags |= O_FSYNC; #endif #ifdef O_BINARY flags |= O_BINARY; @@ -664,7 +667,17 @@ { free (data->dev); if (data->fd != -1) - close (data->fd); + { +#ifdef __linux__ + if (data->access_mode == O_RDWR || data->access_mode == O_WRONLY) + { + fsync (data->fd); + ioctl (data->fd, BLKFLSBUF, 0); + } +#endif + + close (data->fd); + } /* Open the partition. */ grub_dprintf ("hostdisk", "opening the device `%s' in open_device()\n", dev); @@ -675,10 +688,6 @@ return -1; } - /* Flush the buffer cache to the physical disk. - XXX: This also empties the buffer cache. */ - ioctl (fd, BLKFLSBUF, 0); - data->dev = xstrdup (dev); data->access_mode = (flags & O_ACCMODE); data->fd = fd; @@ -716,7 +725,16 @@ { free (data->dev); if (data->fd != -1) - close (data->fd); + { +#ifdef __linux__ + if (data->access_mode == O_RDWR || data->access_mode == O_WRONLY) + { + fsync (data->fd); + ioctl (data->fd, BLKFLSBUF, 0); + } +#endif + close (data->fd); + } fd = open (map[disk->id].device, flags); if (fd >= 0) @@ -932,7 +950,16 @@ free (data->dev); if (data->fd != -1) - close (data->fd); + { +#ifdef __linux__ + if (data->access_mode == O_RDWR || data->access_mode == O_WRONLY) + { + fsync (data->fd); + ioctl (data->fd, BLKFLSBUF, 0); + } +#endif + close (data->fd); + } free (data); }
signature.asc
Description: OpenPGP digital signature