Re: Tagged pointers

2018-07-12 Thread Alexis Beingessner
On Thu, Jul 12, 2018 at 11:03 PM, Robert O'Callahan 
wrote:

> On Fri, Jul 13, 2018 at 11:40 AM, Steve Fink  wrote:
>
> > On 07/12/2018 04:27 PM, Cameron McCormack wrote:
> >
> >> On Fri, Jul 13, 2018, at 6:51 AM, Kris Maglione wrote:
> >>
> >>> I actually have a patch sitting around with helpers to make it super
> >>> easy to
> >>> use smart pointers as tagged pointers :) I never wound up putting it up
> >>> for
> >>> review, since my original use case went away, but it you can think of
> any
> >>> specific cases where it would be useful, I'd be happy to try and get it
> >>> landed.
> >>>
> >> Speaking of tagged pointers, I've used lower one or two bits for tagging
> >> a number of times, but I've never tried packing things into the high
> bits
> >> of a 64 bit pointer.  Is that inadvisable for any reason?  How many bits
> >> can I use, given the 64 bit platforms we need to support?
> >>
> >
> > JS::Value makes use of this. We preserve the bottom 47 bits, but that's
> > starting to be problematic as some systems want 48. So, stashing stuff
> into
> > the high 16 bits is pretty safe!
> >
>
> 57-bit address space support is coming for x86-64.
>
> Rob
>

Last I heard the 48-bit assumption had become so pervasive (and useful)
that
OS devs were planning to only expose this to processes that explicitly
opted into it.

In the case of linux, you would have to explicitly request high-address
pages to
start receiving them: https://lwn.net/Articles/717293/

I always assumed firefox simply wouldn't ever opt into high-addresses,
unless
fission mem-shrink doesn't work out and firefox suddenly needs 300TB of RAM
;p
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Tagged pointers

2018-07-12 Thread Mike Hommey
On Fri, Jul 13, 2018 at 03:03:47PM +1200, Robert O'Callahan wrote:
> On Fri, Jul 13, 2018 at 11:40 AM, Steve Fink  wrote:
> 
> > On 07/12/2018 04:27 PM, Cameron McCormack wrote:
> >
> >> On Fri, Jul 13, 2018, at 6:51 AM, Kris Maglione wrote:
> >>
> >>> I actually have a patch sitting around with helpers to make it super
> >>> easy to
> >>> use smart pointers as tagged pointers :) I never wound up putting it up
> >>> for
> >>> review, since my original use case went away, but it you can think of any
> >>> specific cases where it would be useful, I'd be happy to try and get it
> >>> landed.
> >>>
> >> Speaking of tagged pointers, I've used lower one or two bits for tagging
> >> a number of times, but I've never tried packing things into the high bits
> >> of a 64 bit pointer.  Is that inadvisable for any reason?  How many bits
> >> can I use, given the 64 bit platforms we need to support?
> >>
> >
> > JS::Value makes use of this. We preserve the bottom 47 bits, but that's
> > starting to be problematic as some systems want 48. So, stashing stuff into
> > the high 16 bits is pretty safe!
> >
> 
> 57-bit address space support is coming for x86-64.

The high 16 bits are also used for user-space address space on some tier-3
platforms, and we've had to make the memory allocator avoid those
addresses to make JS::Value work there.

Mike
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Tagged pointers

2018-07-12 Thread Robert O'Callahan
On Fri, Jul 13, 2018 at 11:40 AM, Steve Fink  wrote:

> On 07/12/2018 04:27 PM, Cameron McCormack wrote:
>
>> On Fri, Jul 13, 2018, at 6:51 AM, Kris Maglione wrote:
>>
>>> I actually have a patch sitting around with helpers to make it super
>>> easy to
>>> use smart pointers as tagged pointers :) I never wound up putting it up
>>> for
>>> review, since my original use case went away, but it you can think of any
>>> specific cases where it would be useful, I'd be happy to try and get it
>>> landed.
>>>
>> Speaking of tagged pointers, I've used lower one or two bits for tagging
>> a number of times, but I've never tried packing things into the high bits
>> of a 64 bit pointer.  Is that inadvisable for any reason?  How many bits
>> can I use, given the 64 bit platforms we need to support?
>>
>
> JS::Value makes use of this. We preserve the bottom 47 bits, but that's
> starting to be problematic as some systems want 48. So, stashing stuff into
> the high 16 bits is pretty safe!
>

57-bit address space support is coming for x86-64.

Rob
-- 
Su ot deraeppa sah dna Rehtaf eht htiw saw hcihw, efil lanrete eht uoy ot
mialcorp ew dna, ti ot yfitset dna ti nees evah ew; deraeppa efil eht. Efil
fo Drow eht gninrecnoc mialcorp ew siht - dehcuot evah sdnah ruo dna ta
dekool evah ew hcihw, seye ruo htiw nees evah ew hcihw, draeh evah ew
hcihw, gninnigeb eht morf saw hcihw taht.
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Tagged pointers

2018-07-12 Thread Mike Hommey
On Thu, Jul 12, 2018 at 04:40:39PM -0700, Steve Fink wrote:
> On 07/12/2018 04:27 PM, Cameron McCormack wrote:
> > On Fri, Jul 13, 2018, at 6:51 AM, Kris Maglione wrote:
> > > I actually have a patch sitting around with helpers to make it super easy 
> > > to
> > > use smart pointers as tagged pointers :) I never wound up putting it up 
> > > for
> > > review, since my original use case went away, but it you can think of any
> > > specific cases where it would be useful, I'd be happy to try and get it
> > > landed.
> > Speaking of tagged pointers, I've used lower one or two bits for tagging a 
> > number of times, but I've never tried packing things into the high bits of 
> > a 64 bit pointer.  Is that inadvisable for any reason?  How many bits can I 
> > use, given the 64 bit platforms we need to support?
> 
> JS::Value makes use of this. We preserve the bottom 47 bits, but that's
> starting to be problematic as some systems want 48. So, stashing stuff into
> the high 16 bits is pretty safe!
> 
> The number of low bits available depends on your pointer alignment. But you
> can generally get away with 2 bits on 32-bit, 3 bits on 64-bit -- unless
> it's a char*, in which case it's quite common to have byte-aligned pointers
> (eg when sharing part of another string.) You really do need to know the
> exact alignment, though, rather than guessing.
> 
> Bit ops are pretty cheap, and in these post-Spectre days, it's not an awful
> idea to xor with a type field in those high bits before (potentially
> speculatively) accessing pointers. I think you still get the benefits of
> speculation if it's the right type.

On the topic of tagged pointers, the approach taken in the LLVM code
base is interesting, as described in this talk by Chandler Carruth.
https://www.youtube.com/watch?v=vElZc6zSIXM
(the part relevant to tagged pointers starts at 22:36)

(relatedly, I have the beginning of something similar for rust)

Mike
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Tagged pointers

2018-07-12 Thread Steve Fink

On 07/12/2018 04:27 PM, Cameron McCormack wrote:

On Fri, Jul 13, 2018, at 6:51 AM, Kris Maglione wrote:

I actually have a patch sitting around with helpers to make it super easy to
use smart pointers as tagged pointers :) I never wound up putting it up for
review, since my original use case went away, but it you can think of any
specific cases where it would be useful, I'd be happy to try and get it
landed.

Speaking of tagged pointers, I've used lower one or two bits for tagging a 
number of times, but I've never tried packing things into the high bits of a 64 
bit pointer.  Is that inadvisable for any reason?  How many bits can I use, 
given the 64 bit platforms we need to support?


JS::Value makes use of this. We preserve the bottom 47 bits, but that's 
starting to be problematic as some systems want 48. So, stashing stuff 
into the high 16 bits is pretty safe!


The number of low bits available depends on your pointer alignment. But 
you can generally get away with 2 bits on 32-bit, 3 bits on 64-bit -- 
unless it's a char*, in which case it's quite common to have 
byte-aligned pointers (eg when sharing part of another string.) You 
really do need to know the exact alignment, though, rather than guessing.


Bit ops are pretty cheap, and in these post-Spectre days, it's not an 
awful idea to xor with a type field in those high bits before 
(potentially speculatively) accessing pointers. I think you still get 
the benefits of speculation if it's the right type.


___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform