Re: About Transparent Superpages and Non-transparent superapges

2013-09-23 Thread Adrian Chadd
On 23 September 2013 14:30, Sebastian Kuzminsky  wrote:

> On Sep 23, 2013, at 15:24 , Adrian Chadd wrote:
>
> > On 20 September 2013 08:20, Sebastian Kuzminsky 
> wrote:
> >
> > It's transparent for the kernel: all of UMA and
> kmem_malloc()/kmem_free() is backed by 1 gig superpages.
> >
> > .. not entirely true, as I've found out at work. :(
>
> Can you expand on this, Adrian?
>
> Did you compile & boot the github branch i pointed to, and run in to a
> situation where kmem_malloc() returned memory not backed by 1 gig pages, on
> hardware that supports it?
>
>
I haven't done that yet, sorry.

So the direct map is backed by 1GB pages, except when it can't be:

* first 1GB - because of the memory hole(s)
* the 4th GB - because of the PCI IO hole(s)
* the end of RAM - because of memory remapping so you don't lose hundreds
of megabytes of RAM behind said memory/IO/ROM holes, the end of RAM isn't
on a 1GB boundary.

So, those regions seem to get mapped by smaller pages.

I'm still tinkering with this; I'd like to hack things up to (a) get all
the VM structures in the last gig of aligned RAM, so it falls inside a 1GB
direct mapped page, and (b) prefer that 1GB page for kernel allocations, so
things like mbufs, vm_page entries, etc all end up coming from the same 1GB
direct map page.

I _think_ I have an idea of what to do -  I'll create a couple of 1GB sized
freelists in the last two 1GB direct mapped regions at the end of RAM, then
I'll hack up the vm_phys allocator to prefer allocating from those.

The VM structures stuff is a bit more annoying - it gets allocated from the
top of RAM early on during boot; so unless your machine has the last region
of RAM fall exactly on a 1GB boundary, it'll be backed by 4k/2m pages. I
tested this out by setting hw.physmem to force things to be rounded on a
boundary and it helped for a while. Unfortunately the fact that everything
else gets allocated from random places in physical memory meant that I'm
thrashing the TLB cache - there's only 4 1GB slots on Sandy Bridge Xeon;
and with 64gig of RAM I'm seeing a 10-12% miss load when serving lots of
traffic from SSD (all with mbuf and vm structure allocations.)

So, if I can remove that 10% of CPU cycles taken walking pages, I'll be
happy.

Note: I'm a newbie here in the physical mapping code. :-)




-adrian
___
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"


Re: About Transparent Superpages and Non-transparent superapges

2013-09-23 Thread Sebastian Kuzminsky
On Sep 23, 2013, at 15:24 , Adrian Chadd wrote:

> On 20 September 2013 08:20, Sebastian Kuzminsky  wrote:
>  
> It's transparent for the kernel: all of UMA and kmem_malloc()/kmem_free() is 
> backed by 1 gig superpages.
> 
> .. not entirely true, as I've found out at work. :(

Can you expand on this, Adrian?

Did you compile & boot the github branch i pointed to, and run in to a 
situation where kmem_malloc() returned memory not backed by 1 gig pages, on 
hardware that supports it?


-- 
Sebastian Kuzminsky

___
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"


Re: About Transparent Superpages and Non-transparent superapges

2013-09-23 Thread Adrian Chadd
On 20 September 2013 08:20, Sebastian Kuzminsky  wrote:


> It's transparent for the kernel: all of UMA and kmem_malloc()/kmem_free()
> is backed by 1 gig superpages.
>

.. not entirely true, as I've found out at work. :(



-adrian
___
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"


Re: About Transparent Superpages and Non-transparent superapges

2013-09-23 Thread Sebastian Kuzminsky
On Sep 20, 2013, at 19:09 , Cedric Blancher wrote:

> On 20 September 2013 17:20, Sebastian Kuzminsky  wrote:
>> On Sep 19, 2013, at 22:06 , Patrick Dung wrote:
>> 
 We at Line Rate (now F5) are developing support for 1 Gig superpages on 
 amd64.  We're basing our work on 9.1.0 for now.
 
 An early preview is available here:
 
 https://github.com/Seb-LineRate/freebsd/tree/freebsd-9.1.0-1gig-pages-NOT-READY-2
>>> 
>>> That is cool.
>>> 
>>> What type of applications can take advantage of the 1Gb page size?
>>> And is it transparent? Or applications need to be modified?
>> 
>> It's transparent for the kernel: all of UMA and kmem_malloc()/kmem_free() is 
>> backed by 1 gig superpages.
>> 
>> It's not transparent for userspace: applications need to pass a new flag to 
>> mmap() to get 1 gig pages.
> 
> That may be the wrong approach. What happens if x86 gets more
> huge/largepage sizes like SPARC does (hint: Sign NDA with Intel and
> AMD and get surprised, and then allocate 16 more bits for mmap() if
> you wish to stick with your approach)? For example SPARC64 does 8k,
> 64k, 512k, 4M, 32M, 256M, 2GB and 256GB pages (actual page sizes
> differ from MMU to MMU implementation, and can be probed via pagesize
> -a).
> 
> A much better option would be to follow the Solaris API which has APIs
> to enumerate the available page sizes, and then set it either for
> heap, stack or a given address range (the last one is used to use
> largepages for file I/O via mmap()).

I discussed this API with Alan Cox at the FreeBSD Developers' Summit in Ottawa 
in May 2013, and he agreed that this was a good place to start.  The main 
concern he had at the time was that the buddy allocator I implemented in 
kmem_malloc() might need improvements.

The API you describe sounds more flexible and possibly preferable, and I'm open 
to discussing it as an enhancement.


-- 
Sebastian Kuzminsky

___
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"


Re: About Transparent Superpages and Non-transparent superapges

2013-09-20 Thread Cedric Blancher
On 20 September 2013 17:20, Sebastian Kuzminsky  wrote:
> On Sep 19, 2013, at 22:06 , Patrick Dung wrote:
>
>> >We at Line Rate (now F5) are developing support for 1 Gig superpages on 
>> >amd64.  We're basing our work on 9.1.0 for now.
>> >
>> >An early preview is available here:
>> >
>> >https://github.com/Seb-LineRate/freebsd/tree/freebsd-9.1.0-1gig-pages-NOT-READY-2
>>
>> That is cool.
>>
>> What type of applications can take advantage of the 1Gb page size?
>> And is it transparent? Or applications need to be modified?
>
> It's transparent for the kernel: all of UMA and kmem_malloc()/kmem_free() is 
> backed by 1 gig superpages.
>
> It's not transparent for userspace: applications need to pass a new flag to 
> mmap() to get 1 gig pages.

That may be the wrong approach. What happens if x86 gets more
huge/largepage sizes like SPARC does (hint: Sign NDA with Intel and
AMD and get surprised, and then allocate 16 more bits for mmap() if
you wish to stick with your approach)? For example SPARC64 does 8k,
64k, 512k, 4M, 32M, 256M, 2GB and 256GB pages (actual page sizes
differ from MMU to MMU implementation, and can be probed via pagesize
-a).

A much better option would be to follow the Solaris API which has APIs
to enumerate the available page sizes, and then set it either for
heap, stack or a given address range (the last one is used to use
largepages for file I/O via mmap()).

For example ksh93 uses this to use 64k pages for the stack (this
mainly aims at SPARC where 64k stack pages can be a real performance
booster if you shuffle a lot of strings via stack):
---
int main(int argc, char *argv[])
{
#if _lib_memcntl
/* advise larger stack size */
struct memcntl_mha mha;
mha.mha_cmd = MHA_MAPSIZE_STACK;
mha.mha_flags = 0;
mha.mha_pagesize = 64 * 1024;
(void)memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mha, 0, 0);
#endif
return(sh_main(argc, argv, (Shinit_f)0));
}
---

Below is the memcntl(2) manpage describing the API:
---



System Calls   memcntl(2)



NAME
 memcntl - memory management control

SYNOPSIS
 #include 
 #include 

 int memcntl(caddr_t _a_d_d_r, size_t _l_e_n, int
_c_m_d, caddr_t _a_r_g,
  int _a_t_t_r, int _m_a_s_k);


DESCRIPTION
 The memcntl() function allows the calling process to apply a
 variety of control operations over the address space identi-
 fied by the  mappings  established  for  the  address  range
 [_a_d_d_r, _a_d_d_r + _l_e_n).


 The _a_d_d_r argument must be a  multiple  of  the  pagesize  as
 returned by sysconf(3C). The scope of the control operations
 can be further defined with  additional  selection  criteria
 (in  the  form  of  attributes) according to the bit pattern
 contained in _a_t_t_r.


 The following attributes specify page mapping selection cri-
 teria:

 SHARED Page is mapped shared.


 PRIVATEPage is mapped private.



 The following attributes specify page  protection  selection
 criteria.  The  selection criteria are constructed by a bit-
 wise OR operation on  the  attribute  bits  and  must  match
 exactly.

 PROT_READ Page can be read.


 PROT_WRITEPage can be written.


 PROT_EXEC Page can be executed.



 The following criteria may also be specified:




SunOS 5.11  Last change: 10 Apr 20071






System Calls   memcntl(2)



 PROC_TEXTProcess text.


 PROC_DATAProcess data.



 The PROC_TEXT attribute specifies all privately mapped  seg-
 ments  with  read  and execute permission, and the PROC_DATA
 attribute specifies all privately mapped segments with write
 permission.


 Selection criteria can be used to describe various  abstract
 memory objects within the address space on which to operate.
 If an operation shall not be constrained  by  the  selection
 criteria, _a_t_t_r must have the value 0.


 The operation to be performed is identified by the  argument
 _c_m_d.  The  symbolic  names for the operations are defined in
  as follows:

 MC_LOCK

 Lock in memory all pages in the  range  with  attributes
 _a_t_t_r.  A given page may be locked multiple times through
 different mappings; however,  within  a  given  mapping,
 page  locks do not nest. Multiple lock operations on the
 same address in the same process  will  all  be  removed
 with  a  single  unlock  operation. A page locked in one
 process and mapped in another (or visible through a dif-
 ferent  mapping  in  the  locking  process) is locked in
 memory as long as the locking process  does  neither  an
 implicit nor explicit unlock operation. If a locked map-
   

Re: About Transparent Superpages and Non-transparent superapges

2013-09-20 Thread Cedric Blancher
On 19 September 2013 22:34, Sebastian Kuzminsky  wrote:
> On Sep 18, 2013, at 10:08 , Patrick Dung wrote:
>
>> I have seen somewhere that superpages support was being developed in HEAD 
>> too.
>> Any insight on it?
>
>
> We at Line Rate (now F5) are developing support for 1 Gig superpages on 
> amd64.  We're basing our work on 9.1.0 for now.
>
> An early preview is available here:
>
> https://github.com/Seb-LineRate/freebsd/tree/freebsd-9.1.0-1gig-pages-NOT-READY-2

Have you ever asked Roland Mainz  to look at
your work? He worked on MPSS (multiple page size support) on Solaris
and did a lot of the optimisation work there.

Ced
-- 
Cedric Blancher 
Institute Pasteur
___
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"


Re: About Transparent Superpages and Non-transparent superapges

2013-09-20 Thread Cedric Blancher
[repost, the previous email was stuck because I used an old email address]

On 21 September 2013 03:09, Cedric Blancher  wrote:
> On 20 September 2013 17:20, Sebastian Kuzminsky  wrote:
>> On Sep 19, 2013, at 22:06 , Patrick Dung wrote:
>>
>>> >We at Line Rate (now F5) are developing support for 1 Gig superpages on 
>>> >amd64.  We're basing our work on 9.1.0 for now.
>>> >
>>> >An early preview is available here:
>>> >
>>> >https://github.com/Seb-LineRate/freebsd/tree/freebsd-9.1.0-1gig-pages-NOT-READY-2
>>>
>>> That is cool.
>>>
>>> What type of applications can take advantage of the 1Gb page size?
>>> And is it transparent? Or applications need to be modified?
>>
>> It's transparent for the kernel: all of UMA and kmem_malloc()/kmem_free() is 
>> backed by 1 gig superpages.
>>
>> It's not transparent for userspace: applications need to pass a new flag to 
>> mmap() to get 1 gig pages.
>
> That may be the wrong approach. What happens if x86 gets more
> huge/largepage sizes like SPARC does (hint: Sign NDA with Intel and
> AMD and get surprised, and then allocate 16 more bits for mmap() if
> you wish to stick with your approach)? For example SPARC64 does 8k,
> 64k, 512k, 4M, 32M, 256M, 2GB and 256GB pages (actual page sizes
> differ from MMU to MMU implementation, and can be probed via pagesize
> -a).
>
> A much better option would be to follow the Solaris API which has APIs
> to enumerate the available page sizes, and then set it either for
> heap, stack or a given address range (the last one is used to use
> largepages for file I/O via mmap()).
>
> For example ksh93 uses this to use 64k pages for the stack (this
> mainly aims at SPARC where 64k stack pages can be a real performance
> booster if you shuffle a lot of strings via stack):
> ---
> int main(int argc, char *argv[])
> {
> #if _lib_memcntl
> /* advise larger stack size */
> struct memcntl_mha mha;
> mha.mha_cmd = MHA_MAPSIZE_STACK;
> mha.mha_flags = 0;
> mha.mha_pagesize = 64 * 1024;
> (void)memcntl(NULL, 0, MC_HAT_ADVISE, (caddr_t)&mha, 0, 0);
> #endif
> return(sh_main(argc, argv, (Shinit_f)0));
> }
> ---
>
> Below is the memcntl(2) manpage describing the API:
> ---
>
>
>
> System Calls   memcntl(2)
>
>
>
> NAME
>  memcntl - memory management control
>
> SYNOPSIS
>  #include 
>  #include 
>
>  int memcntl(caddr_t _ a_ d_ d_ r, size_t _ l_ e_ n, int
> _ c_ m_ d, caddr_t _ a_ r_ g,
>   int _ a_ t_ t_ r, int _ m_ a_ s_ k);
>
>
> DESCRIPTION
>  The memcntl() function allows the calling process to apply a
>  variety of control operations over the address space identi-
>  fied by the  mappings  established  for  the  address  range
>  [_ a_ d_ d_ r, _ a_ d_ d_ r + _ l_ e_ n).
>
>
>  The _ a_ d_ d_ r argument must be a  multiple  of  the  pagesize  as
>  returned by sysconf(3C). The scope of the control operations
>  can be further defined with  additional  selection  criteria
>  (in  the  form  of  attributes) according to the bit pattern
>  contained in _ a_ t_ t_ r.
>
>
>  The following attributes specify page mapping selection cri-
>  teria:
>
>  SHARED Page is mapped shared.
>
>
>  PRIVATEPage is mapped private.
>
>
>
>  The following attributes specify page  protection  selection
>  criteria.  The  selection criteria are constructed by a bit-
>  wise OR operation on  the  attribute  bits  and  must  match
>  exactly.
>
>  PROT_READ Page can be read.
>
>
>  PROT_WRITEPage can be written.
>
>
>  PROT_EXEC Page can be executed.
>
>
>
>  The following criteria may also be specified:
>
>
>
>
> SunOS 5.11  Last change: 10 Apr 20071
>
>
>
>
>
>
> System Calls   memcntl(2)
>
>
>
>  PROC_TEXTProcess text.
>
>
>  PROC_DATAProcess data.
>
>
>
>  The PROC_TEXT attribute specifies all privately mapped  seg-
>  ments  with  read  and execute permission, and the PROC_DATA
>  attribute specifies all privately mapped segments with write
>  permission.
>
>
>  Selection criteria can be used to describe various  abstract
>  memory objects within the address space on which to operate.
>  If an operation shall not be constrained  by  the  selection
>  criteria, _ a_ t_ t_ r must have the value 0.
>
>
>  The operation to be performed is identified by the  argument
>  _ c_ m_ d.  The  symbolic  names for the operations are defined in
>   as follows:
>
>  MC_LOCK
>
>  Lock in memory all pages in the  range  with  attributes
>  _ a_ t_ t_ r.  A given page may be locked multiple times through
>  different mappings; however,  within  a  given  mapping,
>  page  locks do not nest. Multiple lock operations on the
>  same address in the 

Re: About Transparent Superpages and Non-transparent superapges

2013-09-20 Thread Sebastian Kuzminsky
On Sep 19, 2013, at 22:06 , Patrick Dung wrote:

> >We at Line Rate (now F5) are developing support for 1 Gig superpages on 
> >amd64.  We're basing our work on 9.1.0 for now.
> >
> >An early preview is available here:
> >
> >https://github.com/Seb-LineRate/freebsd/tree/freebsd-9.1.0-1gig-pages-NOT-READY-2
> 
> That is cool.
> 
> What type of applications can take advantage of the 1Gb page size?
> And is it transparent? Or applications need to be modified?

It's transparent for the kernel: all of UMA and kmem_malloc()/kmem_free() is 
backed by 1 gig superpages.

It's not transparent for userspace: applications need to pass a new flag to 
mmap() to get 1 gig pages.

This is useful in applications with high memory pressure, where memory 
bandwidth and TLB misses are a limiting factor.


-- 
Sebastian Kuzminsky

___
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"


Re: About Transparent Superpages and Non-transparent superapges

2013-09-19 Thread Patrick Dung
>From: Sebastian Kuzminsky 
>To: Patrick Dung 
>Cc: "[email protected]" ; 
>"[email protected]" 
>Sent: Friday, September 20, 2013 4:34 AM
>Subject: Re: About Transparent Superpages and Non-transparent superapges
>
>On Sep 18, 2013, at 10:08 , Patrick Dung wrote:
>
>> I have seen somewhere that superpages support was being developed in HEAD 
>> too.
>> Any insight on it?
>
>
>We at Line Rate (now F5) are developing support for 1 Gig superpages on amd64. 
> We're basing our work on 9.1.0 for now.
>
>An early preview is available here:
>
>https://github.com/Seb-LineRate/freebsd/tree/freebsd-9.1.0-1gig-pages-NOT-READY-2
>
>
>-- 
>Sebastian Kuzminsky
>

That is cool.

What type of applications can take advantage of the 1Gb page size?
And is it transparent? Or applications need to be modified?

Thanks,
Patrick Dung
___
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"


Re: About Transparent Superpages and Non-transparent superapges

2013-09-19 Thread Sebastian Kuzminsky
On Sep 18, 2013, at 10:08 , Patrick Dung wrote:

> I have seen somewhere that superpages support was being developed in HEAD too.
> Any insight on it?


We at Line Rate (now F5) are developing support for 1 Gig superpages on amd64.  
We're basing our work on 9.1.0 for now.

An early preview is available here:

https://github.com/Seb-LineRate/freebsd/tree/freebsd-9.1.0-1gig-pages-NOT-READY-2


-- 
Sebastian Kuzminsky

___
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"


Re: About Transparent Superpages and Non-transparent superapges

2013-09-17 Thread Ivan Voras
On 17/09/2013 17:01, Patrick Dung wrote:
> 
> 
> Hello,
> 
> 
> I have posted the question in freebsd-questions but have not get feedback, so 
> I tried to asked in here.
> 
> 1.
> Transparent Superpages was in FreeBSD for a few years.
> I would like to know if there is any benchmark or real world performance 
> experience about this setting.
> 
> 2.
> I have seen somewhere that non-transparent superpages was being developed in 
> HEAD too.
> Any insight on it? Please correct me if it is not the case.

By "non-transparent" do you mean explicit huge pages API which allows
them to be allocated on-demand rather than heuristically, such as was
implemented in Linux for at least 8 years (http://goo.gl/8qZX4D,
https://lwn.net/Articles/375096/) and supported by major software
products (http://goo.gl/prxjjo, http://goo.gl/fQOLwO,
http://goo.gl/pr7Tbb, http://goo.gl/Y9qtWk, http://goo.gl/M0l7LL, etc.)?
I haven't heard about it (but I hope I'm wrong :) ).





signature.asc
Description: OpenPGP digital signature


Re: About Transparent Superpages and Non-transparent superapges

2013-09-17 Thread Patrick Dung


Hello,


I have posted the question in freebsd-questions but have not get feedback, so I 
tried to asked in here.

1.
Transparent Superpages was in FreeBSD for a few years.
I would like to know if there is any benchmark or real world performance 
experience about this setting.

2.
I have seen somewhere that non-transparent superpages was being developed in 
HEAD too.
Any insight on it? Please correct me if it is not the case.

Thanks and regards,
Patrick Dung
___
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[email protected]"