[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: Jan Beulich <JBeulich@xxxxxxxx>
  • From: George Dunlap <George.Dunlap@xxxxxxxxxx>
  • Date: Fri, 12 Mar 2021 14:32:09 +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=F9zmieDEj7O7bFb35FrXJgCrlhxvLbHXtkvrl5oXUds=; b=NjGL6gynPXEP+8XQ7YsvimxUvasf3MqcQCtYhmv9VTnvo3lunPk6tPQz/hBELfA+pUnjPbfIimkMtXJg3LCpqXjEdga9XdRFTnbwqoH15Tony1POG30LN1SKo5+1INm33isBN+Juxu4j4/QAuTxcwGZMntVTsOEDO1UIzMOkQHsBEwUYWWzbT8DSCpj1VvakqaSYhoGGbSUR4g20oO+9Qcsyl4uVYSOSzPsRo2lIRLN5JH1rd+6VWd51nsB72rJIVoWSG3lXxdGyVAvhhsvVHPUCGwEDcg8TOdYNH/PKoD6rXVnFi5OtlVpIecYcgY6V0xD6Kff62d0sk6E5CoIbMg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NjzsFduRYAyifaGHrYi0zfRHN5cZk5NsexePCSHo5egghXt3GjbhJS8j5RjPjjcFdi5n+faX6bsEAdA7/PmsvDtZuXFGwGxZHJ5eDsRtC29wtMqvkYis22niCJhA8od4XgMslUi8dKePQrYpNrwW/ullb4wYyCwJPei+4HwnqFHaHMZVlBdpVlMAcnwLgvWPRDgtE6Jsk7SW65d/xgoaBn85tQ8wjm5LPVAQnKKZDiHauhciiWlyHjhyt7Ha/zQ761Km8Qx3P5T3QxxzrAhFsJ2+W9KL4HXcHeDmBS15Mvnku+jTBUceVJcNPakEceAmcJJL5HOHnorxlEJKW48/lQ==
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "Julien Grall" <julien@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Fri, 12 Mar 2021 14:32:45 +0000
  • Ironport-hdrordr: A9a23:m+L1QaNFEH4UhsBcT7rx55DYdL4zR+YMi2QD/3taDTRIb82VkN 2vlvwH1RnyzA0cQm0khMroAsa9aFvm39pQ7ZMKNbmvGDPntmyhMZ144eLZrwHIMxbVstRQ3a IIScVDIfX7B1RikILe6A63D94vzLC8gd2VrM31pk0dKD1CQadm8gt/F0K6PyRNNUd7LLA+E4 eR4dcCgjKmd2geYMjTPAh4Y8HoodrXmJX6JSMcDxk85wWUyR+u4rj2Ex+Xty1uEg9n67Ek7G TDjkjF9ryu2svLhSP0+k3yy9BtmNXnwsZeH8DksKYoAxjllwrAXvUZZ5SspzYwydvfi2oCsN 6JmBs4OtQ21nW5RBDOnTLI+y3NlAkj8GXjz1jwuwqineXcSCghA8RMwaJ1GyGpk3YIh9133K JV02/xjfM+Znmg/BjV3NTGWwpnkUC5uxMZ4JUupkdSTJcEb/tppZEflXklSqsoJj7w64wsDY BVfaXhzctWal+TYjT4uWRi0bWXLxIONyqGWUQLt4ip1SFXlhlCviwl7fEY901wlq4Vet1h3a DpI65onLZBQos9dqRmHtoMRsOxFyjkXQ/MGHj6GyWlKIg3f1b277Ln6rQ84++nPLYSyoEppZ jHWFRE8UYvZkPVD9GU1pEjyGGOfEyNGRDWju1O7ZlwvbPxAJDxNzeYdVwom8y859ISH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• Ironport-sdr: ELN8MqbEK2/pEDkBHR5xbscg+hjKyRSicJj7VxwSIV39R/2a4aeA/tyw2aDA8uioljz1Q5A3c4 RFqXMHgo6wizQpsKts4wcr7/6Aa464jRdsn3GjbXWbmLdBUZC4FJoxZeiIw/e9wwbPZ1vg1W4i 0fbksljtl784CinoLVEZ1vzzqn/g7pAHm9JAy3arhDKQ+Dpv3VUVjSv6b2VwdhJpAdBiS0WXEV b40KcIju/dRoHuaGYzopifGMiItCDzyA2nP1xdBiF5Tbjp5GKORTdXw5NVKOYzvBbweqC3CvR/ uew=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHXBE6IzoDpW0Psi0SLnVWLvJvx9Kpa6FyAgCWn/QA=
  • Thread-topic: [PATCH DO NOT APPLY] docs: Document allocator properties and the rubric for using them


> On Feb 16, 2021, at 3:29 PM, Jan Beulich <JBeulich@xxxxxxxx> wrote:
> 
> On 16.02.2021 11:28, George Dunlap wrote:
>> --- /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.
> 
> Irrespective of your subsequent indication of you disliking the
> proposal (which I understand only affects the guidelines further
> down anyway) I'd like to point out that vmalloc() does not
> allocate from the Xen heap. Therefore a benefit of always
> recommending use of xvmalloc() would be that the function could
> fall back to vmalloc() (and hence the larger domain heap) when
> xmalloc() failed.

OK, that’s good to know.

So just trying to think this through: address space is limiting factor for how 
big the xenheap can be, right?  Presumably “vmap” space is also limited, and 
will be much smaller?  So in a sense the “fallback” is less about getting more 
memory, but about using up that extra little bit of virtual address space?

Another question that raises:  Are there times when it’s advantageous to 
specify which heap to allocate from?  If there are good reasons for allocations 
to be in the xenheap or in the domheap / vmap area, then the guidelines should 
probably say that as well.

And, of course, will the whole concept of the xenheap / domheap split go away 
if we ever get rid of the 1:1 map?

> 
>> +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)..
> 
> ITYM "an exact power of 2 number of pages"?

Yes, I’ll fix that.

> 
>> +* 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``.
> 
> As per Julien's and your own replies, this wants to be "minimum
> possible page size", which of course depends on where in the
> tree the piece of code is to live. (It would be "maximum
> possible page size" in the earlier paragraph.)

I’ll see if I can clarify this.

> 
>> +Properties of various allocation functions
>> +------------------------------------------
>> +
>> +Ultimately, the underlying allocator for all of these functions is
>> +``alloc_xenheap_pages``.  They differ on several different properties:
>> +
>> +1. What underlying allocation sizes are.  This in turn has an effect
>> +   on:
>> +
>> +   - How much memory is wasted when requested size doesn't match
>> +
>> +   - How such allocations are affected by memory fragmentation
>> +
>> +   - How such allocations affect memory fragmentation
>> +
>> +2. Whether the underlying pages are physically contiguous
>> +
>> +3. Whether allocation and deallocation require the cost of mapping and
>> +   unmapping
>> +
>> +``alloc_xenheap_pages`` will allocate a physically contiguous set of
>> +pages on orders of 2.  No mapping or unmapping is done.
> 
> That's the case today, but meant to change rather sooner than later
> (when the 1:1 map disappears).

Is that the kind of thing we want to add into this document?  I suppose it 
would be good to make the guidelines now such that they produce code which is 
as easy as possible to adapt to the new way of doing things.

 -George

 


Rackspace

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