xen/mm: Alter get_outstanding_claims() to return information by value
cover xen/mm: Alter get_outstanding_claims() to return information by value
Changes to help unwedge the XenServer patchqueue following commit 44adbac3c7a6 ("xen/mm: Introduce per-node free page counter").
Andrew Cooper (2):
xen/mm: Alter get_outstanding_claims() to return information by value xen/mm: Return claim information from avail_node_heap_pages()
xen/common/numa.c | 2 +- xen/common/page_alloc.c | 18 ++++++++++++------ xen/common/sysctl.c | 10 +++++++--- xen/include/xen/mm.h | 8 ++++++-- 4 files changed, 26 insertions(+), 12 deletions(-)
Signature · 1 line
2.39.5
PATCH 1/2 xen/mm: Alter get_outstanding_claims() to return information by value
A void function with two output parameters is a weird choice. Instead, return a two-element structure.
No functional change.
---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Bernhard Kaindl <[email protected]>
Slightly RFC. claim_info_t name subject to improvement, but see next patch.
This is to help unwedge the XenServer patchqueue following commit 44adbac3c7a6 ("xen/mm: Introduce per-node free page counter").
--- xen/common/page_alloc.c | 10 +++++++--- xen/common/sysctl.c | 8 ++++++-- xen/include/xen/mm.h | 6 +++++- 3 files changed, 18 insertions(+), 6 deletions(-)
xen/common/page_alloc.c +7 -3
@@ -582,12 +582,16 @@ int domain_set_outstanding_pages(struct domain *d, unsigned long pages) }#ifdef CONFIG_SYSCTL -void get_outstanding_claims (uint64_t *free_pages,uint64_t *outstanding_pages) +claim_info_t get_outstanding_claims (void ) { +claim_info_t info; +spin_lock (&heap_lock); - *outstanding_pages = outstanding_claims; - *free_pages =avail_heap_pages (MEMZONE_XEN +1 ,NR_ZONES -1 ,-1 ); + info.avail =avail_heap_pages (MEMZONE_XEN +1 ,NR_ZONES -1 ,-1 ); + info.claimed = outstanding_claims;spin_unlock (&heap_lock); + +return info; }#endif /* CONFIG_SYSCTL */
xen/common/sysctl.c +6 -2
@@ -248,6 +248,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)case XEN_SYSCTL_physinfo: {struct xen_sysctl_physinfo *pi = &op->u.physinfo; +claim_info_t claim_info;memset (pi,0 ,sizeof (*pi)); pi->threads_per_core =
@@ -259,8 +260,11 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) pi->max_node_id =MAX_NUMNODES -1 ; pi->max_cpu_id = nr_cpu_ids -1 ; pi->total_pages = total_pages; -/* Protected by lock */ -get_outstanding_claims (&pi->free_pages, &pi->outstanding_pages); + + claim_info =get_outstanding_claims (); + pi->free_pages = claim_info.avail; + pi->outstanding_pages = claim_info.claimed; + pi->scrub_pages =0 ; pi->cpu_khz = cpu_khz; pi->max_mfn =get_upper_mfn_bound ();
xen/include/xen/mm.h +5 -1
@@ -132,7 +132,11 @@ int populate_pt_range(unsigned long virt, unsigned long nr_mfns);unsigned long __must_check domain_adjust_tot_pages (struct domain *d,long pages);int domain_set_outstanding_pages (struct domain *d,unsigned long pages); -void get_outstanding_claims (uint64_t *free_pages,uint64_t *outstanding_pages); + +typedef struct { +unsigned long avail, claimed; +}claim_info_t ; +claim_info_t get_outstanding_claims (void );/* Domain suballocator. These functions are *not* interrupt-safe.*/ void init_domheap_pages (paddr_t ps,paddr_t pe);
Signature · 1 line
2.39.5
Quoted 2 lines · Andrew Cooper
A void function with two output parameters is a weird choice. Instead, return a two-element structure.
Hmm. Generally in reviews I'm trying to recommend against returning of structures by value. I don't like this very much here either, and it is (slightly) harder to use ...
Quoted 11 lines
xen/common/sysctl.c +1
-0@@ -248,6 +248,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)case XEN_SYSCTL_physinfo: {struct xen_sysctl_physinfo *pi = &op->u.physinfo; +claim_info_t claim_info;memset (pi,0 ,sizeof (*pi)); pi->threads_per_core =
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 266
Quoted 9 lines
xen/common/sysctl.c +4
-2@@ -259,8 +260,11 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) pi->max_node_id =MAX_NUMNODES -1 ; pi->max_cpu_id = nr_cpu_ids -1 ; pi->total_pages = total_pages; -/* Protected by lock */ -get_outstanding_claims (&pi->free_pages, &pi->outstanding_pages); + + claim_info =get_outstanding_claims (); + pi->free_pages = claim_info.avail; + pi->outstanding_pages = claim_info.claimed;
... here. If others think this is the way to go, so be it. But I'm not in favor.
Jan
RFC PATCH 2/2 xen/mm: Return claim information from avail_node_heap_pages()
In reply to Andrew CooperFully RFC.
With per-node claims, avail_node_heap_pages() becomes:
claim_info_t avail_node_heap_pages(unsigned int nodeid)
{
claim_info_t info = {};
if ( nodeid < MAX_NUMNODES && node_online(nodeid) )
{
spin_lock(&heap_lock);
info.avail = node_avail_pages[nodeid];
info.claimed = node_outstanding_claims[nodeid];
spin_unlock(&heap_lock);
}
return info;
}along with modifications to the callers. I'm not intending to submit this patch as-is, but it is present to help judge the naming.
---
CC: Anthony PERARD <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Julien Grall <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Bernhard Kaindl <[email protected]>
--- xen/common/numa.c | 2 +- xen/common/page_alloc.c | 8 +++++--- xen/common/sysctl.c | 2 +- xen/include/xen/mm.h | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-)
xen/common/numa.c +1 -1
@@ -713,7 +713,7 @@ static void cf_check dump_numa(unsigned char key)printk ("NODE%u start->%lu size->%lu free->%lu\n" , i,node_start_pfn (i),node_spanned_pages (i), -avail_node_heap_pages (i)); +avail_node_heap_pages (i).avail);/* Sanity check mfn_to_nid() */ if (node_spanned_pages (i) >1 &&mfn_to_nid (mfn) != i ) printk("mfn_to_nid(%"PRI_mfn") -> %d should be %u\n",
xen/common/page_alloc.c +5 -3
@@ -2852,12 +2852,14 @@ unsigned long avail_domheap_pages_region(return avail_heap_pages (zone_lo, zone_hi, node); } -unsigned long avail_node_heap_pages (unsigned int nodeid) +claim_info_t avail_node_heap_pages (unsigned int nodeid) { +claim_info_t info = {}; +if ( nodeid <MAX_NUMNODES &&node_online (nodeid) ) -return node_avail_pages[nodeid]; + info.avail = node_avail_pages[nodeid]; -return 0 ; +return info; }
xen/common/sysctl.c +1 -1
@@ -315,7 +315,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)if (node_online (i) ) { meminfo.memsize =node_spanned_pages (i) <<PAGE_SHIFT ; - meminfo.memfree =avail_node_heap_pages (i) <<PAGE_SHIFT ; + meminfo.memfree =avail_node_heap_pages (i).avail <<PAGE_SHIFT ; }else meminfo.memsize = meminfo.memfree =XEN_INVALID_MEM_SZ ;
xen/include/xen/mm.h +1 -1
@@ -137,6 +137,7 @@ typedef struct {unsigned long avail, claimed; } claim_info_t;claim_info_t get_outstanding_claims (void ); +claim_info_t avail_node_heap_pages (unsigned int nodeid);/* Domain suballocator. These functions are *not* interrupt-safe.*/ void init_domheap_pages (paddr_t ps,paddr_t pe);
@@ -145,7 +146,6 @@ struct page_info *alloc_domheap_pages(void free_domheap_pages (struct page_info *pg,unsigned int order);unsigned long avail_domheap_pages_region (unsigned int node,unsigned int min_width,unsigned int max_width); -unsigned long avail_node_heap_pages (unsigned int nodeid);#define alloc_domheap_page (d,f) (alloc_domheap_pages(d,0,f))#define free_domheap_page (p) (free_domheap_pages(p,0))
Signature · 1 line
2.39.5
Re: [PATCH RFC 2/2] xen/mm: Return claim information from avail_node_heap_pages()
Quoted 8 lines · Andrew Cooper
xen/common/page_alloc.c +1
-1@@ -2852,12 +2852,14 @@ unsigned long avail_domheap_pages_region(return avail_heap_pages (zone_lo, zone_hi, node); } -unsigned long avail_node_heap_pages (unsigned int nodeid) +claim_info_t avail_node_heap_pages (unsigned int nodeid)
xen/common/page_alloc.c unsigned long avail_domheap_pages_region( · line 2863
Quoted 10 lines
xen/common/page_alloc.c +4
-2{ +claim_info_t info = {}; +if ( nodeid <MAX_NUMNODES &&node_online (nodeid) ) -return node_avail_pages[nodeid]; + info.avail = node_avail_pages[nodeid]; -return 0 ; +return info; }
Why would this be? What use is a compound return value consisting of two pieces, only one of which is ever going to be non-zero? In the form shown for per-node claims that effect goes away, yet at that point the function name doesn't really reflect its purpose anymore.
As to the naming of claim_info_t - that's perhaps good enough if really we want to go with the return-by-value approach.
Jan