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: Tue, 9 Sep 2025 16:37:09 +0200 (CEST) [thread overview]
Message-ID: <2d517844-b7bf-3930-e811-e073ec347d4a@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.
>
> [1] Swap file setup
> ```
> $ swapoff /home/swapfile
> $ echo 'swap /home/swapfile /dev/urandom swap,cipher=aes-cbc-essiv:sha256,size=256' >> /etc/crypttab
> $ systemctl daemon-reload
> $ systemctl start systemd-cryptsetup@swap.service
> $ swapon /dev/mapper/swap
> ```
I have tried to swap on encrypted block device and it worked for me.
I've just realized that you are swapping to a file with the loopback
driver on the top of it and with the dm-crypt device on the top of the
loopback device.
This can't work in principle - the problem is that the filesystem needs to
allocate memory when you write to it, so it deadlocks when the machine
runs out of memory and needs to write back some pages. There is no easy
fix - fixing this would require major rewrite of the VFS layer.
When you swap to a file directly, the kernel bypasses the filesystem, so
it should work - but when you put encryption on the top of a file, there
is no way how to bypass the filesystem.
So, I suggest to create a partition or a logical volume for swap and put
dm-crypt on the top of it.
Mikulas
next prev parent reply other threads:[~2025-09-09 14:37 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
2025-09-09 14:37 ` Mikulas Patocka [this message]
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=2d517844-b7bf-3930-e811-e073ec347d4a@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