On Fri, Oct 18, 2002 at 04:26:44PM +0300, Momchil Velikov wrote: > Jan> Yes, it should. But then message queue is most appropriate since it can > Jan> also pass the actual data along. That's what a file descriptor with > Jan> appropriately implemented poll is. > >> >> > >> >> It involves copying. Theoretically it is possible to have the read > >> >> system call avoid copying for whole overwriten pages (by exchanging > ^^^^^ > > >> >> page table entries (and flushing TLBs :-( )), but this may work well > >> >> on some systems, work not so well on others and not work AT ALL when > >> >> the source buffer is actually device memory. > >> > Jan> No, it won't work, because the read buffer would have to have same > Jan> alignment as the data in cache. > >> > >> I do not understand this ? What do you mean ? What won't work ? > > Jan> You said, that read could possibly avoid copying by replacing PTEs. But > Jan> it counldn't unless the data is appropriately aligned. That is if you > Jan> read a whole page, starting at page-aligned offset and the buffer is > Jan> page-aligned, then it will work, but in most other cases it won't. > Jan> (Exact condition is: if buffer % PAGE_SIZE == offset % PAGE_SIZE, it > Jan> could be done, otherwise not.) > > Every buffer larger than or equal to two page sizes contains at least > one page aligned on page size boundary, i.e. at least one page frame. > That page can be remapped. That's why I said "whole overwriten pages". No, it does not. Lets say PAGE_SIZE is 1 << 12 (as on i386). That means page-aligned addresses have last 3 hex digits equal to 0. Let's say you issue a command: pread(fd, buf=0x80601800, length=0x4000, offset=0); ^^^ Now, in page cache first byte in a file is a first byte on some page. So the first page of the buffer is partial, address 0x80601800 - 0x80601fff and is to be filled with bytes 0 .. 0x7ff from the first page in the page cache. The second page is a complete one, address 0x80602000 - 0x80602fff. However it's to be filled with bytes 0x800 - 0xfff from the first cache page plus bytes 0 - 0x7ff from the second one. So they must be copied, since they are on two different pages. And so on. See? > The first and the last partial pages have to be copied, of course. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz> -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/