The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] the sin of buffering [offshoot of excise process from a pipeline]
@ 2014-07-15  2:31 Doug McIlroy
  2014-07-15  2:40 ` Larry McVoy
  2014-07-15 18:55 ` scj
  0 siblings, 2 replies; 12+ messages in thread
From: Doug McIlroy @ 2014-07-15  2:31 UTC (permalink / raw)


> Err, why is buffering data in the process a sin? (Or was this just a
humourous aside?)

Process A spawns process B, which reads stdin with buffering. B gets
all it deserves from stdin and exits. What's left in the buffer,
intehded for A, is lost. Sinful.



^ permalink raw reply	[flat|nested] 12+ messages in thread
* [TUHS] the sin of buffering [offshoot of excise process from a pipeline]
@ 2014-07-15 23:43 Doug McIlroy
  2014-07-16  0:32 ` Larry McVoy
  0 siblings, 1 reply; 12+ messages in thread
From: Doug McIlroy @ 2014-07-15 23:43 UTC (permalink / raw)


Yes, an evil necessary to get things going. 
The very definition of original sin.

Doug

Larry McVoy wrote:

>>>> For stdio, of course, one would need fsplice(3), which must flush the
>>>> in-process buffers--penance for stdio's original sin of said buffering.

>>> Err, why is buffering data in the process a sin? (Or was this just a
>>> humourous aside?)
 
>> Process A spawns process B, which reads stdin with buffering. B gets
>> all it deserves from stdin and exits. What's left in the buffer,
>> intehded for A, is lost. Sinful.
 
> It really depends on what you want.  That buffering is a big win for
> some use cases.  Even on today's processors reading a byte at a time via
> read(2) is costly.  Like 5000x more costly on the laptop I'm typing on:



^ permalink raw reply	[flat|nested] 12+ messages in thread
* [TUHS] the sin of buffering [offshoot of excise process from a pipeline]
@ 2014-07-16 21:46 Noel Chiappa
  0 siblings, 0 replies; 12+ messages in thread
From: Noel Chiappa @ 2014-07-16 21:46 UTC (permalink / raw)


    > From: Doug McIlroy <doug at cs.dartmouth.edu>

    > Process A spawns process B, which reads stdin with buffering. B gets
    > all it deserves from stdin and exits. What's left in the buffer,
    > intehded for A, is lost. 

Ah. Got it.

The problem is not with buffering as a generic approach, the problem is that
you're trying to use a buffering package intended for simple,
straight-forward situations in one which doesn't fall into that category! :-)

Clearly, either B has to i) be able to put back data which was not for it
('ungets' as a system call), or ii) not read the data that's not for it - but
that may be incompatible with the concept of buffering the input (depending
on the syntax, and thus the ability to predict the approaching of the data B
wants, the only way to avoid the need for ungetc() might be to read a byte at
a time).

If B and its upstream (U) are written together, that could be another way to
deal with it: if U knows where B's syntatical boundaries are, it can give it
advance warning, and B could then use a non-trivial buffering package to do
the right thing. E.g. if U emits 'records' with a header giving the record
length X, B could tell its buffering package 'don't read ahead more than X
bytes until I tell you to go ahead with the next record'.

Of course, that's not a general solution; it only works with prepared U's.
Really, the only general, efficient way to deal with that situation that I can
see is to add 'ungets' to the operating system...

	Noel



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-07-16 21:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-15  2:31 [TUHS] the sin of buffering [offshoot of excise process from a pipeline] Doug McIlroy
2014-07-15  2:40 ` Larry McVoy
2014-07-15 18:55 ` scj
2014-07-15 23:43 Doug McIlroy
2014-07-16  0:32 ` Larry McVoy
2014-07-16  3:53   ` John Cowan
2014-07-16  4:05     ` Larry McVoy
2014-07-16  6:03       ` John Cowan
2014-07-16 14:30         ` Larry McVoy
2014-07-16 14:56           ` Dan Cross
2014-07-16 15:41             ` Larry McVoy
2014-07-16 21:46 Noel Chiappa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).