|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v4 10/17] xen: mapcache: Break out xen_map_cache_init_single()
On Tue, 30 Apr 2024, Edgar E. Iglesias wrote:
> From: "Edgar E. Iglesias" <edgar.iglesias@xxxxxxx>
>
> Break out xen_map_cache_init_single() in preparation for
> adding multiple map caches.
>
> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xxxxxxx>
Reviewed-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>
> ---
> hw/xen/xen-mapcache.c | 53 ++++++++++++++++++++++++++-----------------
> 1 file changed, 32 insertions(+), 21 deletions(-)
>
> diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c
> index dd08cd296b..72a7e25e3e 100644
> --- a/hw/xen/xen-mapcache.c
> +++ b/hw/xen/xen-mapcache.c
> @@ -93,23 +93,44 @@ static inline int test_bits(int nr, int size, const
> unsigned long *addr)
> return 0;
> }
>
> -void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque)
> +static MapCache *xen_map_cache_init_single(phys_offset_to_gaddr_t f,
> + void *opaque,
> + unsigned long max_size)
> {
> unsigned long size;
> - struct rlimit rlimit_as;
> + MapCache *mc;
> +
> + mc = g_new0(MapCache, 1);
> +
> + mc->phys_offset_to_gaddr = f;
> + mc->opaque = opaque;
> + qemu_mutex_init(&mc->lock);
> +
> + QTAILQ_INIT(&mc->locked_entries);
>
> - mapcache = g_new0(MapCache, 1);
> + mc->max_mcache_size = max_size;
>
> - mapcache->phys_offset_to_gaddr = f;
> - mapcache->opaque = opaque;
> - qemu_mutex_init(&mapcache->lock);
> + mc->nr_buckets =
> + (((mc->max_mcache_size >> XC_PAGE_SHIFT) +
> + (1UL << (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)) - 1) >>
> + (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT));
>
> - QTAILQ_INIT(&mapcache->locked_entries);
> + size = mc->nr_buckets * sizeof(MapCacheEntry);
> + size = (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1);
> + trace_xen_map_cache_init(mc->nr_buckets, size);
> + mc->entry = g_malloc0(size);
> + return mc;
> +}
> +
> +void xen_map_cache_init(phys_offset_to_gaddr_t f, void *opaque)
> +{
> + struct rlimit rlimit_as;
> + unsigned long max_mcache_size;
>
> if (geteuid() == 0) {
> rlimit_as.rlim_cur = RLIM_INFINITY;
> rlimit_as.rlim_max = RLIM_INFINITY;
> - mapcache->max_mcache_size = MCACHE_MAX_SIZE;
> + max_mcache_size = MCACHE_MAX_SIZE;
> } else {
> getrlimit(RLIMIT_AS, &rlimit_as);
> rlimit_as.rlim_cur = rlimit_as.rlim_max;
> @@ -119,24 +140,14 @@ void xen_map_cache_init(phys_offset_to_gaddr_t f, void
> *opaque)
> " memory is not infinity");
> }
> if (rlimit_as.rlim_max < MCACHE_MAX_SIZE + NON_MCACHE_MEMORY_SIZE) {
> - mapcache->max_mcache_size = rlimit_as.rlim_max -
> - NON_MCACHE_MEMORY_SIZE;
> + max_mcache_size = rlimit_as.rlim_max - NON_MCACHE_MEMORY_SIZE;
> } else {
> - mapcache->max_mcache_size = MCACHE_MAX_SIZE;
> + max_mcache_size = MCACHE_MAX_SIZE;
> }
> }
>
> + mapcache = xen_map_cache_init_single(f, opaque, max_mcache_size);
> setrlimit(RLIMIT_AS, &rlimit_as);
> -
> - mapcache->nr_buckets =
> - (((mapcache->max_mcache_size >> XC_PAGE_SHIFT) +
> - (1UL << (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT)) - 1) >>
> - (MCACHE_BUCKET_SHIFT - XC_PAGE_SHIFT));
> -
> - size = mapcache->nr_buckets * sizeof (MapCacheEntry);
> - size = (size + XC_PAGE_SIZE - 1) & ~(XC_PAGE_SIZE - 1);
> - trace_xen_map_cache_init(mapcache->nr_buckets, size);
> - mapcache->entry = g_malloc0(size);
> }
>
> static void xen_remap_bucket(MapCache *mc,
> --
> 2.40.1
>
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |