[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 09:31:18 +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=Nc4atuQRDf18BRl0hsptpo1e0vwUx9fKw/Ehn4nEZxA=; b=DnoeVmhWdSpeakhGpGs2KRkZtXozAA4z+X/yMuroJO6tqPRSitFV/8f3+qFIINku7wo480wYf1O0Lq15rnziw5qAuzAKNYIBQSx+OcFNu/j9ybTrHbq5I6gBEtmcck9um2d8Egfj+Y1dWuBdX3L6eedEesfNuXgDYSzpfSkjF8pBNnZFclZo3ZyWu7IrJC3LnSTIg8JBj8XVgII4R2pOJ0FJX3AdV7Xf5Aih53XBDfdZdY6YACWtd7RnAlv4gvzo7f18E0KPMyLmGBG4Z/k7DWy8sXJLEP5E7oq2ymOKlKgz8s6Tw9RKcMerhqS9mVWCiPJJQZ88gZYDSt2Vun5KpQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dwPjYw0VcT500mvqG53xfcszdHW79Hjm72mm/4BUkZ5ZfhkUUfmDOeE/28BJMGoXPfa5OOFx9o4cbqIv5wuWu7eP+rtpGP1GNDvNcnOX0eWQHS8sZhyPmeFwzckgBVCeVSbuLLbVOf2RwghkUKhYkQxlwyV5mRZREctKduxbvTwW6GbFFX8QXNaLq9gumjmVOxQzSumAkAkJoC9rSNA0Tro9DG+YEz2T+w+DGgRwQdSKoANStPGsSFJO6ZRPiXNQ/s/iZyd+SpjVMzxDjLgUq0KBXHtOy6eFqxri9DwUkPh/uIHZcftsuABrXzsvpvQ7MEBLv0gyoY0tkNOE70G7Uw==
  • Cc: <wei.chen@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "Bertrand Marquis" <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Mon, 11 Dec 2023 08:31:46 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Julien,

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. Maybe we could have 
*nr_banks in membanks that would point
to nr_banks in meminfo/shm_meminfo? At some point we still need to set 
common.max_banks to e.g. NR_MEM_BANKS.

~Michal



 


Rackspace

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