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

Re: [PATCH] Fix XEN_SYSCTL_numainfo[node].memsize for memory holes


  • To: Bernhard Kaindl <bernhard.kaindl@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 24 Sep 2024 16:07:39 +0200
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 24 Sep 2024 14:07:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 24.09.2024 12:14, Bernhard Kaindl wrote:
> Fix a long-standing issue (known at since 2014) with the numainfo call.
> 
> The Hypercall `XEN_SYSCTL_numainfo` returns `memsize` for each NUMA node:
> 
> xl info -n:
> node:    memsize    memfree    distances
>    0:  -> 67584 <-   60672      10,21  <- memsize is off by 2048 MB
>    1:     65536      60958      21,10
> 
> So far, `memsize` is calculated from `NODE_DATA->node_spanned_pages`.
> It includes memory holes, leading to wrong memsize on x86.

Depending on what "memsize" means, it is or is not wrong that way. I'm
not sure we can change it like that, at the very least not without
bumping the interface version and proving that in-tree uses (if any)
are either unaffected or improved.

> This patch gets the sum of E820_RAM entries for each NUMA node on boot,
> stores it in NODE_DATA->node_present_pages and uses it for `memsize`.
> 
> It also increases it like `total_pages` on memory_add() for memory hotplug.
> 
> The new NODE_DATA->node_present_pages can be slighly lower than the
> physical node's RAM due to reserved memory for some of the NUMA nodes.

The introduction and maintenance of ->node_present_pages wants to be a
separate, prereq change imo.

> --- a/xen/arch/x86/x86_64/mm.c
> +++ b/xen/arch/x86/x86_64/mm.c
> @@ -1333,6 +1333,8 @@ int memory_add(unsigned long spfn, unsigned long epfn, 
> unsigned int pxm)
>      /* We can't revert any more */
>      share_hotadd_m2p_table(&info);
>      transfer_pages_to_heap(&info);
> +    /* Update the node's present pages (like the total_pages of the system) 
> */
> +    NODE_DATA(node)->node_present_pages += epfn - spfn;

Nit: Blank line ahead of the insertion please.

> --- a/xen/common/numa.c
> +++ b/xen/common/numa.c
> @@ -504,10 +504,22 @@ void __init setup_node_bootmem(nodeid_t nodeid, paddr_t 
> start, paddr_t end)
>  {
>      unsigned long start_pfn = paddr_to_pfn(start);
>      unsigned long end_pfn = paddr_to_pfn(end);
> +    paddr_t map_start, map_end;
> +    int i = 0, err;

arch_get_ram_range()'s first parameter is unsigned int.

>      NODE_DATA(nodeid)->node_start_pfn = start_pfn;
>      NODE_DATA(nodeid)->node_spanned_pages = end_pfn - start_pfn;
>  
> +    /* Add RAM pages within the node to get the present pages for memsize 
> infos */
> +    NODE_DATA(nodeid)->node_present_pages = 0;
> +    while ( (err = arch_get_ram_range(i++, &map_start, &map_end)) != -ENOENT 
> ) {
> +        if ( err || map_start >= end || map_end <= start )
> +            continue;  /* Skip non-RAM and maps outside of the node's memory 
> range */
> +        /* Add memory that is in the node's memory range (within start and 
> end): */
> +        map_start = max(map_start, start);
> +        map_end = min(map_end, end);
> +        NODE_DATA(nodeid)->node_present_pages += (map_end - map_start) >> 
> PAGE_SHIFT;
> +    }

Style (whole block): Brace placement, line length.

I'm also not convinced the actual calculation is correct: Neither map_start
nor map_end need to be page aligned aiui, and hence the present result doesn't
necessarily give the actual number of pages (that are usable, and hence
meaningful to the consumer of the field).

Blank line here please.

> @@ -675,7 +687,7 @@ static void cf_check dump_numa(unsigned char key)
>          mfn_t mfn = _mfn(node_start_pfn(i) + 1);
>  
>          printk("NODE%u start->%lu size->%lu free->%lu\n",
> -               i, node_start_pfn(i), node_spanned_pages(i),
> +               i, node_start_pfn(i), node_present_pages(i),

"size" here really can mean two things. I'd suggest to keep printing
node_spanned_pages() and add printing of node_present_pages().

Jan



 


Rackspace

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