public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* deadlock when swapping to encrypted swapfile
@ 2025-09-08 18:27 Robert Beckett
  2025-09-08 19:56 ` Mikulas Patocka
  2025-09-09 14:37 ` Mikulas Patocka
  0 siblings, 2 replies; 9+ messages in thread
From: Robert Beckett @ 2025-09-08 18:27 UTC (permalink / raw)
  To: dm-devel, linux-block, Mikulas Patocka; +Cc: kernel

[-- Attachment #1: Type: text/plain, Size: 1834 bytes --]

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


[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
```

[2] See attached memchewer.c
[3] See attached dmesg-pstore.202509081711-0.bz2
[4] https://lore.kernel.org/dm-devel/alpine.LRH.2.02.2102101518320.18125@file01.intranet.prod.int.rdu2.redhat.com/
[5] See attached dmesg-pstore.202509081649-0.bz2

[-- Attachment #2: memchewer.c --]
[-- Type: application/octet-stream, Size: 525 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

const int mb = 512;
const int sleep_ms = 2000;

int main(void)
{
    size_t bufsize = (size_t) mb * 1024 * 1024;
    int count = 0;
    while (1) {
        char *buf = malloc(bufsize);
        if (buf == NULL) {
            puts("Not enough memory");
            return 1;
        }
        memset(buf, count % 256, bufsize);
        printf("Total memory allocated: %d MB\n", ++count * mb);
        usleep((useconds_t) 1000 * sleep_ms);
    }
}

[-- Attachment #3: dmesg-pstore.202509081711-0.bz2 --]
[-- Type: application/octet-stream, Size: 173643 bytes --]

[-- Attachment #4: dmesg-pstore.202509081649-0.bz2 --]
[-- Type: application/octet-stream, Size: 381885 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-09-11 17:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox