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

Re: [PATCH v5 04/11] xen/arm: introduce allocate_domheap_memory and guest_physmap_memory


  • To: Julien Grall <julien@xxxxxxx>, Penny Zheng <Penny.Zheng@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Mon, 11 Dec 2023 11:12:29 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=xen.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Au7wQlt730Wqd0eMPM5g1A42KhGIkWWma489cS77DUk=; b=XahkgHFSiYXrDIU4vvrCONv/1h9jf0ot1IA21kOrNEhluqOjV6y4i4wIWkocuuTB+mYU4Sp8TNzb52skLqXJmOj/vdzaVkh2ul2XEva4KiW06w5BesKix7QLR4fdiWxGicn9A+5RtR/ge+mUVzc/084ZDoq8Vz1iumJyCu1qRCMuzzBpTve1l1ld5kxiwqHEZlP+TAMVMmOPIG+iZdF4zp5J6EBQX8h98Qymnt0mSTxS5mXX1+pgfX4iDPBR0TfH5JlvCnovxOLIRqUORlNulOweDE6caP/n4xtTGFCyMdMEiEh9PCi9NnajCzKo94Rwuo2jUhF2dXimBVcxRAOLCw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mEYtM8X1+q8T1ILOKw1gS4E6Jxq6ZluMZO0A7eEh1K/pr1UozUtIrr8edyEKVjr7y/KBwO5Lpuosa2YMFkeMtIqihs52kkJno2ZulgbNSSEDZ/HrNHzPELDBLF9XHHzPZZ+vv+kS2pvLHO5W6yTUvqpIGmkSrkGhcelzCwRvDICzGl993zzWPfsksgq8GoLzLFtonbC1B0X1/JzBYnfJQcw+5zusvlmbV8miCm3HdBpf9PYwqpcEiSjFek9NuxR/dz4ZMCayw/uBqem1uPBdGkQAyNCfzVbkAEcKpTuh/c3mo9/BcJvxHABSo47Na54gXh72TkKdPnfmxPjai8eCMQ==
  • Cc: <wei.chen@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "Bertrand Marquis" <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Mon, 11 Dec 2023 10:12:50 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 11/12/2023 11:01, Julien Grall wrote:
> 
> 
> Hi Michal,
> 
> On 11/12/2023 08:31, Michal Orzel wrote:
>> On 08/12/2023 16:09, Julien Grall wrote:
>>>
>>>
>>> Hi,
>>>
>>> On 07/12/2023 09:38, Michal Orzel wrote:
>>>> Hi Penny,
>>>>
>>>> On 06/12/2023 10:06, Penny Zheng wrote:
>>>>>
>>>>>
>>>>> We split the code of allocate_bank_memory into two parts,
>>>>> allocate_domheap_memory and guest_physmap_memory.
>>>>>
>>>>> One is about allocating guest RAM from heap, which could be re-used later 
>>>>> for
>>>>> allocating static shared memory from heap when host address is not 
>>>>> provided.
>>>>> The other is building up guest P2M mapping.
>>>>>
>>>>> We also define a set of MACRO helpers to access common fields in data
>>>>> structure of "meminfo" type, e.g. "struct meminfo" is one of them, and
>>>>> later new "struct shm_meminfo" is also one of them.
>>>>> This kind of structures must have the following characteristics:
>>>>> - an array of "struct membank"
>>>>> - a member called "nr_banks" indicating current array size
>>>>> - a field indicating the maximum array size
>>>>> When introducing a new data structure, according callbacks with function 
>>>>> type
>>>>> "retrieve_fn" shall be defined for using MACRO helpers.
>>>>> This commit defines callback "retrieve_meminfo" for data structure
>>>>> "struct meminfo".
>>>> This patch introduces quite a bit of complexity with all these helpers, so 
>>>> adding a rationale is crucial.
>>>> AFAIU, all of this is because we don't want to reuse struct meminfo where 
>>>> NR_MEM_BANKS is defined as 256,
>>>> which is a lot more than we need for shmem. Am I right?
>>>
>>> +1.
>>>
>>>>
>>>> I would like others to share the opinion here as well.
>>>
>>> If possible, I'd like to reduce the footprint of the shared memory. But
>>> this should be balanced with the complexity of the code.
>>>
>>> Briefly looking at the patch series, we have two structures:
>>>
>>> struct meminfo {
>>>       unsigned int nr_banks;
>>>       struct membank bank[NR_MEM_BANKS];
>>> };
>>>
>>> struct shm_meminfo {
>>>       unsigned int nr_banks;
>>>       struct membank bank[NR_SHM_BANKS];
>>>       paddr_t tot_size;
>>> };
>>>
>>> IIUC, the logic is mostly to be able to know the maximum size of the
>>> array and also the number of slots already used.
>>>
>>> So we could have the following common structure:
>>>
>>> struct membanks {
>>>      unsigned int nr_banks;
>>>      unsigned int max_banks;
>>>      struct membank *banks;
>>> }
>>>
>>> Then the definition for the two other structures could be:
>>>
>>> struct meminfo {
>>>       struct membank holders[NR_MEM_BANKS];
>>>
>>>       struct membanks banks;
>>> }
>>>
>>> struct shm_meminfo {
>>>       struct membank holders[NR_SHM_BANKS];
>>>
>>>       struct membanks banks;
>>>
>>>       paddr_t tot_size;
>>> }
>>>
>>> And then 'banks.banks' would point to the 'holders'. And 'max_banks'
>>> would be set to the maximum.
>>>
>>> There might be other way to make the structure more nicer. Like (untested):
>>>
>>> struct membanks {
>>>       unsigned int nr_banks;
>>>       unsigned int max_banks;
>>>       struct membank[];
>>> }
>>>
>>> struct meminfo {
>>>       struct membanks common;
>>>       // We should ensure there are no padding
>>>       struct membank[NR_MEM_BANKS];
>>> }
>>>
>>> We would then pass &meminfo.common to allocate_domainheap_memory().
>>>
>>> With that there should be no need for extra helpers.
>>>
>>> What do you think?
>> I would go for flexible array member solution which looks much nicer and as 
>> far as I can tell
>> would solve the issue with extra helpers.
>>
>> The only problem is that there are quite a lot of places where we reference 
>> nr_banks of meminfo e.g. mem.nr_banks
>> which we would need to modify to mem.common.nr_banks.
> 
> Possibly yes. But it is not clear what's the problem here. Are you
> concerned about the churn? Or is it just a long name?
I am concerned about the churn. I did a grep and we have almost 100 instances 
of e.g. mem{.,->}nr_banks,
which in our solution would need to be replaced with mem{.,->}common.nr_banks. 
That said ...

> 
> At least in the case of meminfo. We could possibly replace all the use
> with a pointer to "struct membank common". This would reduce the amount
> of churn and the expression length.
this could help to limit the overall churn.

~Michal



 


Rackspace

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