[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH DO NOT APPLY] docs: Document allocator properties and the rubric for using them


  • To: Julien Grall <julien@xxxxxxx>
  • From: George Dunlap <George.Dunlap@xxxxxxxxxx>
  • Date: Tue, 9 Mar 2021 11:36:04 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BQa+/sW453AuTNDdYzeUGNI9zmj6jgy0kc3xvrcAsVQ=; b=C91PDQk2K3QRK/QCCL++K/3tX3Fv0uuYXIIjiTqZtnP2/z9XgrDn+YIunm62IVkORREMMi4MljWBJQxe+UW3S/HK6/PbJ2jnXeKZWCse8vKzZJPWgPMCJasjOxklBe+2m0oFLUAyE5Z01IjWiK5xVMQ5vwFRI4Hzhc0W6Um6aJfM5V0BUoAMBzpCZI+b53/gBvTiQ/75tzy+NRIzQyjzjTS+bWjTlucVeHx4b7tkDxidjb4Fu9eRXyyGGXe1p+UCK+iwJrFv1t8Dsz2cJkzO4393/XI2mbYZUuewQW07itkiYlKIWBvcdfGIyYgJMElBgDKFV6lyQsUZvbC/ReVcPA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AyjllgFCWcwrNjNfX8DBtj5k4bQZIW07vGMv34gZzXc2AF7PAB5KOKOufSysMUg/9KgzGTWaJ4Q8K/LOh54qu5IPbYRhKHFW44eg+Dkb+C4A9Uro0X4kCfEB8XZpWOfx6TobdY2vnS0pdnlvdA8D74MhkdS4WUSt9Q4I8zp/YZ7PsGPpcILh6b6v3u4OjI+QTILwRKJBUo1jl2iaHgT14gTImgMDTDx/57K0xjCuHpZphxeKGwU08Zz0Kgh8a3h1DMAsew7oUQ5npwweHrG4DNOlsWeXQPW085VPEB1TI8qBSF452FWPrvq6sU84NctVfSxeogRYEMUy7AYjIPQMFA==
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: "open list:X86" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Tue, 09 Mar 2021 11:36:22 +0000
  • Ironport-sdr: 3eOlW1m6YgdrVKaAgstg6OCLcxsMEgqJCl3yYAGu48Uzr3L7MtjhpjrIAjJwZg2EqawUlhvuKA Uha4XgSFa7Lzqa6BJxmaVg2Dqg3JuIh+Vwjg02wanys7ul3cXMu5RhiXflQo3DzRy+Ej9flh0J 0ibCyLeD57jw9l2Rr9AH1zr4uX7TL9HCg5q6PbAWjXNNAdI6kyDLwwzpQEN/G8QQwAjSr8eWVo IUGhmFwvgsQ4awzm71uszcmMB821FaP/eZLIcJ4YMWIUgiDdC9uuI9iRnZbltXo56WsU34SjeZ vLo=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHXBE6IzoDpW0Psi0SLnVWLvJvx9Kpam+MAgAAFtoCAAAB2AIAc3P2AgAQpHIA=
  • Thread-topic: [PATCH DO NOT APPLY] docs: Document allocator properties and the rubric for using them


> On Mar 6, 2021, at 8:03 PM, Julien Grall <julien@xxxxxxx> wrote:
> 
> Hi George,
> 
> On 16/02/2021 11:17, George Dunlap wrote:
>>> On Feb 16, 2021, at 11:16 AM, George Dunlap <george.dunlap@xxxxxxxxxx> 
>>> wrote:
>>> 
>>> 
>>> 
>>>> On Feb 16, 2021, at 10:55 AM, Julien Grall <julien@xxxxxxx> wrote:
>>>> 
>>>> Hi George,
>>>> 
>>>> On 16/02/2021 10:28, George Dunlap wrote:
>>>>> Document the properties of the various allocators and lay out a clear
>>>>> rubric for when to use each.
>>>>> Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxx>
>>>>> ---
>>>>> This doc is my understanding of the properties of the current
>>>>> allocators (alloc_xenheap_pages, xmalloc, and vmalloc), and of Jan's
>>>>> proposed new wrapper, xvmalloc.
>>>>> xmalloc, vmalloc, and xvmalloc were designed more or less to mirror
>>>>> similar functions in Linux (kmalloc, vmalloc, and kvmalloc
>>>>> respectively).
>>>>> CC: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
>>>>> CC: Jan Beulich <jbeulich@xxxxxxxx>
>>>>> CC: Roger Pau Monne <roger.pau@xxxxxxxxxx>
>>>>> CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
>>>>> CC: Julien Grall <julien@xxxxxxx>
>>>>> ---
>>>>> .../memory-allocation-functions.rst           | 118 ++++++++++++++++++
>>>>> 1 file changed, 118 insertions(+)
>>>>> create mode 100644 docs/hypervisor-guide/memory-allocation-functions.rst
>>>>> diff --git a/docs/hypervisor-guide/memory-allocation-functions.rst 
>>>>> b/docs/hypervisor-guide/memory-allocation-functions.rst
>>>>> new file mode 100644
>>>>> index 0000000000..15aa2a1a65
>>>>> --- /dev/null
>>>>> +++ b/docs/hypervisor-guide/memory-allocation-functions.rst
>>>>> @@ -0,0 +1,118 @@
>>>>> +.. SPDX-License-Identifier: CC-BY-4.0
>>>>> +
>>>>> +Xenheap memory allocation functions
>>>>> +===================================
>>>>> +
>>>>> +In general Xen contains two pools (or "heaps") of memory: the *xen
>>>>> +heap* and the *dom heap*.  Please see the comment at the top of
>>>>> +``xen/common/page_alloc.c`` for the canonical explanation.
>>>>> +
>>>>> +This document describes the various functions available to allocate
>>>>> +memory from the xen heap: their properties and rules for when they 
>>>>> should be
>>>>> +used.
>>>>> +
>>>>> +
>>>>> +TLDR guidelines
>>>>> +---------------
>>>>> +
>>>>> +* By default, ``xvmalloc`` (or its helper cognates) should be used
>>>>> +  unless you know you have specific properties that need to be met.
>>>>> +
>>>>> +* If you need memory which needs to be physically contiguous, and may
>>>>> +  be larger than ``PAGE_SIZE``...
>>>>> +
>>>>> +  - ...and is order 2, use ``alloc_xenheap_pages``.
>>>>> +
>>>>> +  - ...and is not order 2, use ``xmalloc`` (or its helper cognates)..
>>>>> +
>>>>> +* If you don't need memory to be physically contiguous, and know the
>>>>> +  allocation will always be larger than ``PAGE_SIZE``, you may use
>>>>> +  ``vmalloc`` (or one of its helper cognates).
>>>>> +
>>>>> +* If you know that allocation will always be less than ``PAGE_SIZE``,
>>>>> +  you may use ``xmalloc``.
>>>> 
>>>> AFAICT, the determining factor is PAGE_SIZE. This is a single is a single 
>>>> value on x86 (e.g. 4KB) but on other architecture this may be multiple 
>>>> values.
>>>> 
>>>> For instance, on Arm, this could be 4KB, 16KB, 64KB (note that only the 
>>>> former is so far supported on Xen).
>>>> 
>>>> For Arm and common code, it feels to me we can't make a clear decision 
>>>> based on PAGE_SIZE. Instead, I continue to think that the decision should 
>>>> only be based on physical vs virtually contiguous.
>>>> 
>>>> We can then add further rules for x86 specific code if the maintainers 
>>>> want.
>>> 
>>> Sorry my second mail was somewhat delayed — my intent was: 1) post the 
>>> document I’d agreed to write, 2) say why I think the proposal is a bad 
>>> idea. :-)
> 
> No worry, I jumped too quickly in the discussion :).
> 
>>> 
>>> Re page size — the vast majority of time we’re talking “knowing” that the 
>>> size is less than 4k.  If we’re confident that no architecture will ever 
>>> have a page size less than 4k, then we know that all allocations less than 
>>> 4k will always be less than PAGE_SIZE.  Obviously larger page sizes then 
>>> becomes an issue.
>>> 
>>> But in any case — unless we have BUG_ON(size > PAGE_SIZE), we’re going to 
>>> have to have a fallback, which is going to cost one precious conditional, 
>>> making the whole exercise pointless.
>> Er, just in case it wasn’t clear — I agree with this:
>>>> I continue to think that the decision should only be based on physical vs 
>>>> virtually contiguous.
> 
> We have two opposite proposal with no clear way to reconciliate them. Should 
> we request a vote on the two proposals?

Let me write up an alternate proposal with Jan’s feedback; then if he still 
thinks his way is better we can vote.

 -George

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.