Hi, I'm working on a program that's intended to be used as a "filter", as in "something | myprogram > file". I'm trying it with cat and I'm seeing my read()s return small blocks, 64 kB in size. I suppose this is because cat writes in 64 kB blocks. So:
a) Is there a way to programatically, per-process, set the pipe buffer size? The program in question is a compressor and it's particularly inefficient when given small blocks and I'm wondering if the system can buffer enough data for it. b) Is there any objection to the following patch to cat: Index: cat.c =================================================================== --- cat.c (revision 184033) +++ cat.c (working copy) @@ -247,7 +247,16 @@ if (buf == NULL) { if (fstat(wfd, &sbuf)) err(1, "%s", filename); - bsize = MAX(sbuf.st_blksize, 1024); + if (S_ISREG(sbuf.st_mode)) { + /* If there's plenty of RAM, use a 1 MB + * copy buffer, else use a 128 kB buffer */ + if (sysconf(_SC_PHYS_PAGES) > 32768) + bsize = 1*1024*1024; + else + bsize = 128*1024; + } else + bsize = MAX(sbuf.st_blksize, + (blksize_t)sysconf(_SC_PAGESIZE)); if ((buf = malloc(bsize)) == NULL) err(1, "buffer"); } ?
signature.asc
Description: OpenPGP digital signature