linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: "Uladzislau Rezki (Sony)" <urezki@gmail.com>
Cc: linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>,
	Baoquan He <bhe@redhat.com>, Lorenzo Stoakes <lstoakes@gmail.com>,
	Christoph Hellwig <hch@infradead.org>,
	Matthew Wilcox <willy@infradead.org>,
	Dave Chinner <david@fromorbit.com>,
	Oleksiy Avramchenko <oleksiy.avramchenko@sony.com>
Subject: Re: [PATCH 1/1] mm: vmalloc: Remove a global vmap_blocks xarray
Date: Thu, 23 Mar 2023 14:12:53 -0700	[thread overview]
Message-ID: <20230323141253.d5a626f5cbe03adec3d88add@linux-foundation.org> (raw)
In-Reply-To: <20230323192111.1501308-1-urezki@gmail.com>

On Thu, 23 Mar 2023 20:21:11 +0100 "Uladzislau Rezki (Sony)" <urezki@gmail.com> wrote:

> A global vmap_blocks-xarray array can be contented under
> heavy usage of the vm_map_ram()/vm_unmap_ram() APIs. The
> lock_stat shows that a "vmap_blocks.xa_lock" lock is a
> second in a top-list when it comes to contentions:
> 
> ...
> 
> This patch does not fix vmap_area_lock/free_vmap_area_lock and
> purge_vmap_area_lock bottle-necks, it is rather a separate rework.
> 
> ...
>
>  static DEFINE_PER_CPU(struct vmap_block_queue, vmap_block_queue);
>  
> ...
>
> +static struct vmap_block_queue *
> +addr_to_vbq(unsigned long addr)
> +{
> +	int cpu = (addr / VMAP_BLOCK_SIZE) % num_possible_cpus();
> +	return &per_cpu(vmap_block_queue, cpu);
> +}

Seems strange.  vmap_block_queue is not a per-cpu thing in this usage. 
Instead it's a hash table, indexed off the (hashed) address, not off
smp_processor_id().

Yet in other places, vmap_block_queue *is* used in the conventional
cpu-local fashion.

So we can have CPU A using the cpu-local entry in vmap_block_queue
while CPU B is simultaneously using it, having looked it up via `addr'.

AFAICT this all works OK, no races.

But still, what it's doing is mixing an addr-indexed hashtable with the
CPU-indexed array in surprising ways.  It would be clearer to make the
vmap_blocks array a separate thing from the per-cpu array, although it
would presumably use a bit more memory.

Can we please at least get a big fat comment in an appropriate place
which explains all this to the reader?


  reply	other threads:[~2023-03-23 21:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23 19:21 Uladzislau Rezki (Sony)
2023-03-23 21:12 ` Andrew Morton [this message]
2023-03-27  7:15   ` Uladzislau Rezki
2023-03-23 21:46 ` Lorenzo Stoakes
2023-03-27  7:36   ` Uladzislau Rezki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230323141253.d5a626f5cbe03adec3d88add@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=david@fromorbit.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=oleksiy.avramchenko@sony.com \
    --cc=urezki@gmail.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox