Bug 199072 - libmd inefficient read() calls
Summary: libmd inefficient read() calls
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: John-Mark Gurney
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-31 17:58 UTC by kcwu
Modified: 2018-05-28 19:45 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kcwu 2015-03-31 17:58:52 UTC
src/lib/libmd/mdXhl.c
MDXFileChunk(const char *filename, char *buf, off_t ofs, off_t len)
{
        unsigned char buffer[BUFSIZ];

where BUFSIZE is 1024 from stdio.h

This will make lots of read(2) syscalls. All utilities depend on libmd, including md5(1) and sha256(1), are affected.

==============
For example, on my system, (file content is already cached in ram)
$ du -h file.bin
4.9G    file.bin
$ time md5 file.bin
MD5 (file.bin) = 422bb7e6759dee9dd1af940f9d9db5ab

real    0m31.848s
user    0m11.500s
sys     0m19.526s

Notice that 19.526s spend in sys.

You could also verify the read size is 1024 using truss(1)
$ truss md5 file.bin
...
read(3,"^3fEiRA\M^S\^]\M-Rf\M-7\M-E\M-g"...,1024) = 1024 (0x400)
...
==============
If modified buffer[] to larger, say 1MB, md5(1) becomes much faster.
$ time md5 file.bin
MD5 (file.bin) = 422bb7e6759dee9dd1af940f9d9db5ab

real    0m14.369s
user    0m11.220s
sys     0m1.933s
Comment 1 Christian Brueffer freebsd_committer freebsd_triage 2015-07-13 15:56:05 UTC
Assigning this to jmg, since he increased the buffer size in r285324.
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:45:49 UTC
batch change:

For bugs that match the following
-  Status Is In progress 
AND
- Untouched since 2018-01-01.
AND
- Affects Base System OR Documentation

DO:

Reset to open status.


Note:
I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.