public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Robert Beckett <bob.beckett@collabora.com>
Cc: dm-devel <dm-devel@lists.linux.dev>,
	 linux-block <linux-block@vger.kernel.org>,
	kernel <kernel@collabora.com>
Subject: Re: deadlock when swapping to encrypted swapfile
Date: Mon, 8 Sep 2025 21:56:23 +0200 (CEST)	[thread overview]
Message-ID: <cfdb2d15-70b8-1f44-853f-3d0a315d28d3@redhat.com> (raw)
In-Reply-To: <1992a9545eb.1ec14bf0659281.6434647558731823661@collabora.com>



On Mon, 8 Sep 2025, Robert Beckett wrote:

> Hi,
> 
> While testing resiliency of encrypted swap using dmcrypt we encounter easily reproducible deadlocks.
> The setup is a simple 1GB encrypted swap file [1] with a little mem chewer program [2] to consume all ram.
> 
> Usually the first run will oomkill the memchewer successfully.
> However, after 1-3 runs typically, it will deadlock the machine.
> 
> Using softdog and the lockup detectors it looks like [3] it looks like the dmcrypt_write thread
> is stuck for over 2 minutes while everything else is waiting on the swap bio limiter [4]
> 
> I wondered whether it might be hitting tag exhaustion in blk_mq_get_tag, but adding trace debug and
> enabling the block trace events seems to suggest that generally progress is being made [5].
> 
> Also note lockdep doesn't complain.
> 
> Looks to me like a soft lockup possibly due to swap out hitting similar or same issue as [4] but
> not self inflicted this time. However, once general memory exhaustion occurs, it seems to result
> in the same issue.
> 
> I'm not intimately familiar with the dm and block-mq code, so I'd appreciate any help in
> debugging it further or a fix.
> I guess the main question is: why doesn't it oomkill? oomkill seems like a
> sensible action in this scenario. Any advice on making oomkill more reliable here?
> Would [4] need to be tweaked in any way for swap files vs partition?
> 
> Thanks
> 
> Bob

Hi

What happens if you lower /sys/module/dm_mod/parameters/swap_bios? Does it 
help?

The general problem with swapping to encrypted device is that for each 
swapped-out page, the dm-crypt driver needs to allocate another page that 
holds the encrypted data. So, the harder it tries to swap, the more memory 
it consumes. The device mapper stack uses mempools, so that it should work 
in case of total memory exhaustion, but perhaps some kernel part doesn't 
use them and deadlocks. I could try to reproduce it.

Mikulas


  reply	other threads:[~2025-09-08 19:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-08 18:27 deadlock when swapping to encrypted swapfile Robert Beckett
2025-09-08 19:56 ` Mikulas Patocka [this message]
2025-09-09 14:37 ` Mikulas Patocka
2025-09-09 16:50   ` Robert Beckett
2025-09-10 11:26     ` Mikulas Patocka
2025-09-10 15:24       ` Robert Beckett
2025-09-10 17:45         ` Bryn M. Reeves
2025-09-11 16:56         ` Mikulas Patocka
2025-09-11 17:12           ` Robert Beckett

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=cfdb2d15-70b8-1f44-853f-3d0a315d28d3@redhat.com \
    --to=mpatocka@redhat.com \
    --cc=bob.beckett@collabora.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=kernel@collabora.com \
    --cc=linux-block@vger.kernel.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