Re: PROPOSAL: extend pipe() to support NULL argument.

From: Changli Gao
Date: Fri Jul 03 2009 - 04:27:48 EST


On Fri, Jul 3, 2009 at 4:16 PM, Amerigo Wang<xiyou.wangcong@xxxxxxxxx> wrote:
> On Fri, Jul 03, 2009 at 03:40:34PM +0800, Changli Gao wrote:
>>On Fri, Jul 3, 2009 at 3:15 PM, Amerigo Wang<xiyou.wangcong@xxxxxxxxx> wrote:
>>>
>>> If saving one fd really helps here, probably you want to
>>> save more, you will need a syscall like:
>>>
>>> Âint splice_without_new_fd(int infd, int outfd);
>>Do you know sendfile()? Its current implementation is buggy, and will
>>be blocked on outfd. Anyway, the above code is just a use case, there
>>are other cases sendfile can't cover.
>
> So what? So you should fix it intead of inventing a new pipe() and use
> splice(2)...
I said: It just a special case. Fixing sendfile() won't fix everything.

>
> Wait... if splice(2) doesn't block, what is your point for saving
> an fd in your code? You can do:
>
> int splice_two_fd(int fd1, int fd2)
> {
> Â Â Â Âint fds[2];
> Â Â Â Âpipe(fds);
> Â Â Â Âsplice(fd1, fds[0]);//not block
> Â Â Â Âsplice(fds[1], fd2);//not block
> Â Â Â Âclose(fds[0]); //can be closed soon
> Â Â Â Âclose(fds[1]); //ditto
> }
>
> Outside this function no new fd's are used.
>
In fact, sendfile(2) is implemented via splice(2) infrastructure. The
logic is the same, and much clever than yours. Dive into its code, you
will find the reason why it must be blocked on outfd.

>>
>>>
>>> But splice(2) is designed to be as it is. You need to increase
>>> your fd limit, instead of saving one by pipe().
>>>
>>I don't agree with you. We should save resource as much as we can, and
>>not work around it.
>
> You are saying splice(2) is wrong? Because it is splice(2) who
> needs 3 fd's finally.
>
It isn't splice(2)'s fault. In fact, I can also work around this issue
by named pipe.



--
Regardsï
Changli Gao(xiaosuo@xxxxxxxxx)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/