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

Re: [PATCH v4 1/6] x86/PVH: improve Dom0 memory size calculation


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 21 Oct 2021 12:54:43 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AVFV0JJo0REmloxEXJk+jf3B2HhXTqY2T7rLcRdYZ+8=; b=ajg7zX7Hi8uNzEiH+vX9HOy3rclYsFBPFd4ZCPc80Tn0p3NlOt2pAkpIZrefI1S6f0idiJK2Idrb7LrtGqiaRk3bJo+on+KS6sGLJ704mhJ3M1EI68X7tqvkzzmNcliJ7Jx4ysocUybxJtOymT2iQ63WnyaIh6HBhwagApiVGl/BVcKdmi6fg7xS2u5Que79fKne/TH5fX7tfdTGcWV5sUsJeHcooreH+x+y5tDyN8VxtHXiIlvYg0GdPFAdCUM+oGq4HAyk2VU2Nc2/Nrglokc/kiuiIe3235t/lelFoWcCgaJMU3GXM0g+x/UHzpi+TvADmocMP5Iy/RmylK6LWg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f1z1Ehy2JSRYPXVxHWslaZnRm2BIVpGTTBHGs54qSf8mZivc9gEiEMky5htyYSbNosGyAsK0dwQIgME86Y/61vT9wSq67Yj4fhhjEakfoq702uuMGh7O88DueN7uA74gtWXEbSCnpjGavcieyxyVRQwhHrgEwSeXzNu4Jb/nu0XPF37M79LD9ZTs150mgZTgHFskZSNg634C9HoB4wr9f/hXRIK44tdIEfTSEaLQs/MYSi93OG45srPu7G/wD5Ipo1zyF7iaCkIGz1snLCHxYFrCMvBX854fbqTpoAsuuVcJeDevwLxg7FvMaA8kOjsOUOQmnu8gz6Q9C9JoDzeYSg==
  • Authentication-results: citrix.com; dkim=none (message not signed) header.d=none;citrix.com; dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Thu, 21 Oct 2021 10:54:52 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 29.09.2021 15:13, Jan Beulich wrote:
> @@ -337,53 +336,65 @@ unsigned long __init dom0_compute_nr_pag
>          avail -= d->max_vcpus - 1;
>  
>      /* Reserve memory for iommu_dom0_init() (rough estimate). */
> -    if ( is_iommu_enabled(d) )
> +    if ( is_iommu_enabled(d) && !iommu_hwdom_passthrough )
>      {
>          unsigned int s;
>  
>          for ( s = 9; s < BITS_PER_LONG; s += 9 )
> -            avail -= max_pdx >> s;
> +            iommu_pages += max_pdx >> s;
> +
> +        avail -= iommu_pages;
> +    }
> +
> +    nr_pages = get_memsize(&dom0_size, avail);
> +
> +    /*
> +     * If allocation isn't specified, reserve 1/16th of available memory for
> +     * things like DMA buffers. This reservation is clamped to a maximum of
> +     * 128MB.
> +     */
> +    if ( !nr_pages )
> +    {
> +        nr_pages = avail - (pv_shim ? pv_shim_mem(avail)
> +                            : min(avail / 16, 128UL << (20 - PAGE_SHIFT)));
> +        if ( paging_mode_enabled(d) )
> +            /*
> +             * Temporary workaround message until internal (paging) memory
> +             * accounting required to build a pvh dom0 is improved.
> +             */
> +            printk("WARNING: PVH dom0 without dom0_mem set is still 
> unstable. "
> +                   "If you get crashes during boot, try adding a dom0_mem 
> parameter\n");
>      }
>  
> -    need_paging = is_hvm_domain(d) &&
> -        (!iommu_use_hap_pt(d) || !paging_mode_hap(d));
> -    for ( ; ; need_paging = false )
> +    if ( paging_mode_enabled(d) || opt_dom0_shadow )
>      {
> -        nr_pages = get_memsize(&dom0_size, avail);
> -        min_pages = get_memsize(&dom0_min_size, avail);
> -        max_pages = get_memsize(&dom0_max_size, avail);
> +        unsigned long cpu_pages;
>  
>          /*
> -         * If allocation isn't specified, reserve 1/16th of available memory
> -         * for things like DMA buffers. This reservation is clamped to a
> -         * maximum of 128MB.
> +         * Clamp according to min/max limits and available memory
> +         * (preliminary).
>           */
> -        if ( !nr_pages )
> -        {
> -            nr_pages = avail - (pv_shim ? pv_shim_mem(avail)
> -                                 : min(avail / 16, 128UL << (20 - 
> PAGE_SHIFT)));

Just FYI that I've noticed only now that moving this only up is
not enough; the same also ...

> -            if ( is_hvm_domain(d) && !need_paging )
> -                /*
> -                 * Temporary workaround message until internal (paging) 
> memory
> -                 * accounting required to build a pvh dom0 is improved.
> -                 */
> -                printk("WARNING: PVH dom0 without dom0_mem set is still 
> unstable. "
> -                       "If you get crashes during boot, try adding a 
> dom0_mem parameter\n");
> -        }
> -
> -
> -        /* Clamp according to min/max limits and available memory. */
> -        nr_pages = max(nr_pages, min_pages);
> -        nr_pages = min(nr_pages, max_pages);
> +        nr_pages = max(nr_pages, get_memsize(&dom0_min_size, avail));
> +        nr_pages = min(nr_pages, get_memsize(&dom0_max_size, avail));
>          nr_pages = min(nr_pages, avail);
>  
> -        if ( !need_paging )
> -            break;
> +        cpu_pages = dom0_paging_pages(d, nr_pages);
>  
> -        /* Reserve memory for shadow or HAP. */
> -        avail -= dom0_paging_pages(d, nr_pages);
> +        if ( !iommu_use_hap_pt(d) )
> +            avail -= cpu_pages;
> +        else if ( cpu_pages > iommu_pages )
> +            avail -= cpu_pages - iommu_pages;
>      }
>  
> +    nr_pages = get_memsize(&dom0_size, avail);

... is needed here, or else things won't work e.g. without any "dom0_mem=".
I'll introduce a helper function ...

Jan




 


Rackspace

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