All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Philipp Falk <philipp.falk@thinkparq.com>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: Throughput drop and high CPU load on fast NVMe drives
Date: Tue, 22 Jun 2021 18:36:43 +0100	[thread overview]
Message-ID: <YNIfq8dCLEu/Wkc0@casper.infradead.org> (raw)
In-Reply-To: <YNIaztBNK+I5w44w@xps13>

On Tue, Jun 22, 2021 at 07:15:58PM +0200, Philipp Falk wrote:
> We are facing a performance issue on XFS and other filesystems running on
> fast NVMe drives when reading large amounts of data through the page cache
> with fio.
> 
> Streaming read performance starts off near the NVMe hardware limit until
> around the total size of system memory worth of data has been read.
> Performance then drops to around half the hardware limit and CPU load
> increases significantly. Using perf, we were able to establish that most of
> the CPU load is caused by a spin lock in native_queued_spin_lock_slowpath:
[...]
> When direct I/O is used, hardware level read throughput is sustained during
> the entire experiment and CPU load stays low. Threads stay in D state most
> of the time.
> 
> Very similar results are described around half-way through this article
> [1].
> 
> Is this a known issue with the page cache and high throughput I/O? Is there
> any tuning that can be applied to get around the CPU bottleneck? We have
> tried disabling readahead on the drives, which lead to very bad throughput
> (~-90%). Various other scheduler related tuning was tried as well but the
> results were always similar.

Yes, this is a known issue.  Here's what's happening:

 - The machine hits its low memory watermarks and starts trying to
   reclaim.  There's one kswapd per node, so both nodes go to work
   trying to reclaim memory (each kswapd tries to handle the memory
   attached to its node)
 - But all the memory is allocated to the same file, so both kswapd
   instances try to remove the pages from the same file, and necessarily
   contend on the same spinlock.
 - The process trying to stream the file is also trying to acquire this
   spinlock in order to add its newly-allocated pages to the file.

What you can do is force the page cache to only allocate memory from the
local node.  That means this workload will only use half the memory in
the machine, but it's a streaming workload, so that shouldn't matter?

The only problem is, I'm not sure what the user interface is to make
that happen.  Here's what it looks like inside the kernel:

        if (cpuset_do_page_mem_spread()) {
                unsigned int cpuset_mems_cookie;
                do {
                        cpuset_mems_cookie = read_mems_allowed_begin();
                        n = cpuset_mem_spread_node();
                        page = __alloc_pages_node(n, gfp, 0);
                } while (!page && read_mems_allowed_retry(cpuset_mems_cookie));

so it's something to do with cpusets?


  reply	other threads:[~2021-06-22 17:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 17:15 Throughput drop and high CPU load on fast NVMe drives Philipp Falk
2021-06-22 17:36 ` Matthew Wilcox [this message]
2021-06-23 11:33   ` Philipp Falk

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=YNIfq8dCLEu/Wkc0@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=philipp.falk@thinkparq.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.