Hinted mmap(2) without MAP_FIXED can fail prematurely
I'm not sure if this is a bug or not, but on NetBSD/amd64 9.2, hinted mmap(2) without MAP_FIXED can fail prematurely with ENOMEM if all the regions below the given hint address are occupied. The man page for mmap(2) suggests that the hint is just a hint. Shouldn't mmap(2) also search for available regions above the hint then? Test code: https://gist.github.com/depressed-pho/a629247b48b3e6178e35a14c62e9d44f#file-mmap-with-hint-c Test result: https://gist.github.com/depressed-pho/a629247b48b3e6178e35a14c62e9d44f#file-gistfile1-txt
Re: Hinted mmap(2) without MAP_FIXED can fail prematurely
I expected mmap(2) to search for an available region from the entire address space starting from the hint, not only half of it. On 2/17/22 5:32 PM, Johnny Billquist wrote: If it would ignore the hint, what's the point of the hint then? Johnny On 2022-02-17 08:23, PHO wrote: I'm not sure if this is a bug or not, but on NetBSD/amd64 9.2, hinted mmap(2) without MAP_FIXED can fail prematurely with ENOMEM if all the regions below the given hint address are occupied. The man page for mmap(2) suggests that the hint is just a hint. Shouldn't mmap(2) also search for available regions above the hint then? Test code: https://gist.github.com/depressed-pho/a629247b48b3e6178e35a14c62e9d44f#file-mmap-with-hint-c Test result: https://gist.github.com/depressed-pho/a629247b48b3e6178e35a14c62e9d44f#file-gistfile1-txt
Re: Hinted mmap(2) without MAP_FIXED can fail prematurely
If it would ignore the hint, what's the point of the hint then? Johnny On 2022-02-17 08:23, PHO wrote: I'm not sure if this is a bug or not, but on NetBSD/amd64 9.2, hinted mmap(2) without MAP_FIXED can fail prematurely with ENOMEM if all the regions below the given hint address are occupied. The man page for mmap(2) suggests that the hint is just a hint. Shouldn't mmap(2) also search for available regions above the hint then? Test code: https://gist.github.com/depressed-pho/a629247b48b3e6178e35a14c62e9d44f#file-mmap-with-hint-c Test result: https://gist.github.com/depressed-pho/a629247b48b3e6178e35a14c62e9d44f#file-gistfile1-txt -- Johnny Billquist || "I'm on a bus || on a psychedelic trip email: b...@softjar.se || Reading murder books pdp is alive! || tryin' to stay hip" - B. Idol
Re: Hinted mmap(2) without MAP_FIXED can fail prematurely
b...@softjar.se (Johnny Billquist) writes: >If it would ignore the hint, what's the point of the hint then? With MAP_FIXED it must use the hint, without it's just a best effort attempt.
Re: Hinted mmap(2) without MAP_FIXED can fail prematurely
p...@cielonegro.org (PHO) writes: >I expected mmap(2) to search for an available region from the entire >address space starting from the hint, not only half of it. It's not even half.
Re: Hinted mmap(2) without MAP_FIXED can fail prematurely
On 2022-02-18 01:05, Michael van Elst wrote: b...@softjar.se (Johnny Billquist) writes: If it would ignore the hint, what's the point of the hint then? With MAP_FIXED it must use the hint, without it's just a best effort attempt. Which then basically means that without MAP_FIXED, the hint don't really mean anything? It will take whatever address it can come up with, no matter what you put into the hint. Which is what a hint of 0 should do. So I don't get that. With MAP_FIXED, the hint needs to be exactly on a page boundary, which makes sense. Without MAP_FIXED, and with a hint, I would expect that things like rounding the address to the proper alignment, and so on, would be allowed, but not that it would just take any address. If I'm ok with it taking any random address, then I shouldn't provide a hint. Anyway, that's just my reflections/thoughts on it. Johnny -- Johnny Billquist || "I'm on a bus || on a psychedelic trip email: b...@softjar.se || Reading murder books pdp is alive! || tryin' to stay hip" - B. Idol
Re: Hinted mmap(2) without MAP_FIXED can fail prematurely
>>> If it would ignore the hint, what's the point of the hint then? >> With MAP_FIXED it must use the hint, without it's just a best effort >> attempt. > Which then basically means that without MAP_FIXED, the hint don't > really mean anything? Sure it does. It means it will use the hint if that space is available. Otherwise it will find somewhere else. An example of a case where this is appropriate might be an IRIX-style (I think it was IRIX I saw this on) pre-relocated shared library: if the place it is pre-relocated to is available, it can be mapped there and some work saved; otherwise, oh well, map it somewhere else and we'll have to re-relocate. Another example might be some data structure where it can save some work (or space) to have two blocks contiguous, but if they're not, it can deal, just slightly more expensively. > It will take whatever address it can come up with, no matter what you > put into the hint. Yes, but if the hint _is_ available, it can save some work to use it. That's why calling it a hint is appropriate: "I'd _like_ this address, but I can deal with not getting it". > If I'm ok with it taking any random address, then I shouldn't provide > a hint. _Being OK with_ any address doesn't mean there isn't some specific address you'd _prefer_. It's like me connecting to an IRC server: I'd _prefer_ Mouse as my nick, but if it's not available I can deal. /~\ The ASCII Mouse \ / Ribbon Campaign X Against HTMLmo...@rodents-montreal.org / \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
Re: Hinted mmap(2) without MAP_FIXED can fail prematurely
b...@softjar.se (Johnny Billquist) writes: >Which then basically means that without MAP_FIXED, the hint don't really >mean anything? It will take whatever address it can come up with, no >matter what you put into the hint. It still might reuse the address (or just a close address) for efficiency. >With MAP_FIXED, the hint needs to be exactly on a page boundary, which >makes sense. Without MAP_FIXED, and with a hint, I would expect that >things like rounding the address to the proper alignment, and so on, >would be allowed, but not that it would just take any address. If I'm ok >with it taking any random address, then I shouldn't provide a hint. Unfortunately it doesn't matter. Linux will try the hint (aligned to a page) and fall back to an arbitrary address. Software relies on this.