From owner-freebsd-hackers Mon Aug 12 13:54:50 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id NAA19733 for hackers-outgoing; Mon, 12 Aug 1996 13:54:50 -0700 (PDT) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id NAA19714 for ; Mon, 12 Aug 1996 13:54:47 -0700 (PDT) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id NAA26050; Mon, 12 Aug 1996 13:47:58 -0700 From: Terry Lambert Message-Id: <199608122047.NAA26050@phaeton.artisoft.com> Subject: Re: mmap #2 To: mrcpu@cdsnet.net (Jaye Mathisen) Date: Mon, 12 Aug 1996 13:47:58 -0700 (MST) Cc: joerg_wunsch@uriah.heep.sax.de, freebsd-hackers@FreeBSD.ORG, proff@suburbia.net In-Reply-To: from "Jaye Mathisen" at Aug 12, 96 10:42:14 am X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk > I think it was the other way around, it was truncating a mmap'd file. > > Specifically, I had problems when the active file shrunk after an rmgroup, > then I would get weird behaviour. John said he saw where that could > potentially be problematic, but I never saw any fixes run by that > addressed it by name. The question, of course, is what the heck does it mean when you mmap a file. If you interpret it as "provide page mappings into the address space of the process which made the mmap call equivalent to the size of the file at the time of the call", then you are asking for the page references to stay around, regardless of the fd-arbitrated file size. The problem is that if you truncate and automatically crop back the mapping following the truncation, shouldn't you also automatically increase the mapping in the extend case? The manual page is ambiguous as to what should happen to the address space on truncation. The implication of the interface is that the "len" parameter dictates that the size of the mapping object should be independent of the size of the file object. There is also an ambiguity with regard to "offset + len" being in excess of the file size. Finally, the documentation says "at most len bytes" instead of simply "len bytes", which implies that the mapped region is permitted to fall short of the actual mapping request when the file is smaller. Technically, the correct mechanism to eliminate all ambiguity would be to unmap , change the file size, and remap, for each time the file size is to be changed. This is true of Solaris, SunOS, and AIX, as well, where there are version dependencies on degree of VM and buffer cache unification, which can not be accounted for in any other way besides unmap, change, map. I would say that it is probably desirable to truncate the mapping region to the limit of the file length minus offset for the length requested, and adjust it up as the file is modified, until there are offset + len bytes mapped. This would require saving the value of the mapping request (perhaps 0 len should be the same as "dynamic" in this context, or (off_t)-1 (assuming 64 bit values are correctly sign-extended). I reiterate, however: this is not the current documented, nor expected behaviour, and further, you could only expect this behaviour on a machine where the VM and buffer cache were unified. For instance, the "failure" of some systems without a unified VM and buffer cache to do a read via fd of a page written via writing to a mapped page is to be expected when there is no protected mode write fault and a memory object is not being manipulated by a handle in such a way that the kernel can trap the manipulation in software (ie: copyin/copyout). Example: A 386 system will not honor the "Write Protect" bit of the MMU in protected mode, and will not generate a write fault to allow the buffer cache contents to be updated when the VM buffer is written through a valid user addressing. To resolve this, the page would have to be unmapped, generating a segmentation fault when written, and the fault handler would have to determine that it was an attempt to write page that is there, but which needs to generate a write fault call o the cache synchronization handler. It's possible to do this in a split cache environment, but it makes writing to mapped memory prohibitively expensive. In my opinion, it's INN at fault, not the OS's on which it runs; whoever wrote the mmap support didn't understand that they should use an mmap interface completely independent of using the fd insterface, since they could not depend on them being able to interoperate. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.