From: "Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: Jan Kara <jack@suse.cz>, Vlastimil Babka <vbabka@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
Matthew Wilcox <willy@infradead.org>,
Michal Hocko <mhocko@suse.com>,
stable@vger.kernel.org, regressions@lists.linux.dev,
Alasdair Kergon <agk@redhat.com>,
Mike Snitzer <snitzer@kernel.org>,
dm-devel@lists.linux.dev, linux-mm@kvack.org
Subject: Re: Intermittent storage (dm-crypt?) freeze - regression 6.4->6.5
Date: Thu, 2 Nov 2023 01:38:40 +0100 [thread overview]
Message-ID: <ZULvkPhcpgAVyI8w@mail-itl> (raw)
In-Reply-To: <ebbc7ca7-5169-dbdc-9ea8-c6d8c3ae31e2@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4542 bytes --]
On Tue, Oct 31, 2023 at 06:24:19PM +0100, Mikulas Patocka wrote:
>
>
> On Tue, 31 Oct 2023, Mikulas Patocka wrote:
>
> >
> >
> > On Tue, 31 Oct 2023, Marek Marczykowski-Górecki wrote:
> >
> > > On Tue, Oct 31, 2023 at 03:01:36PM +0100, Jan Kara wrote:
> > > > On Tue 31-10-23 04:48:44, Marek Marczykowski-Górecki wrote:
> > > > > Then tried:
> > > > > - PAGE_ALLOC_COSTLY_ORDER=4, order=4 - cannot reproduce,
> > > > > - PAGE_ALLOC_COSTLY_ORDER=4, order=5 - cannot reproduce,
> > > > > - PAGE_ALLOC_COSTLY_ORDER=4, order=6 - freeze rather quickly
> > > > >
> > > > > I've retried the PAGE_ALLOC_COSTLY_ORDER=4,order=5 case several times
> > > > > and I can't reproduce the issue there. I'm confused...
> > > >
> > > > And this kind of confirms that allocations > PAGE_ALLOC_COSTLY_ORDER
> > > > causing hangs is most likely just a coincidence. Rather something either in
> > > > the block layer or in the storage driver has problems with handling bios
> > > > with sufficiently high order pages attached. This is going to be a bit
> > > > painful to debug I'm afraid. How long does it take for you trigger the
> > > > hang? I'm asking to get rough estimate how heavy tracing we can afford so
> > > > that we don't overwhelm the system...
> > >
> > > Sometimes it freezes just after logging in, but in worst case it takes
> > > me about 10min of more or less `tar xz` + `dd`.
> >
> > Hi
> >
> > I would like to ask you to try this patch. Revert the changes to "order"
> > and "PAGE_ALLOC_COSTLY_ORDER" back to normal and apply this patch on a
> > clean upstream kernel.
> >
> > Does it deadlock?
> >
> > There is a bug in dm-crypt that it doesn't account large pages in
> > cc->n_allocated_pages, this patch fixes the bug.
This patch did not help.
> If the previous patch didn't fix it, try this patch (on a clean upstream
> kernel).
>
> This patch allocates large pages, but it breaks them up into single-page
> entries when adding them to the bio.
But this does help.
> If this patch deadlocks, it is a sign that allocating large pages causes
> the problem.
>
> If this patch doesn't deadlock, it is a sign that processing a bio with
> large pages is the problem.
>
> Mikulas
>
> ---
> drivers/md/dm-crypt.c | 26 ++++++++++++++++++++++----
> 1 file changed, 22 insertions(+), 4 deletions(-)
>
> Index: linux-stable/drivers/md/dm-crypt.c
> ===================================================================
> --- linux-stable.orig/drivers/md/dm-crypt.c 2023-10-31 17:16:03.000000000 +0100
> +++ linux-stable/drivers/md/dm-crypt.c 2023-10-31 17:21:14.000000000 +0100
> @@ -1700,11 +1700,16 @@ retry:
> order = min(order, remaining_order);
>
> while (order > 0) {
> + if (unlikely(percpu_counter_read_positive(&cc->n_allocated_pages) + (1 << order) > dm_crypt_pages_per_client))
> + goto decrease_order;
> pages = alloc_pages(gfp_mask
> | __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN | __GFP_COMP,
> order);
> - if (likely(pages != NULL))
> + if (likely(pages != NULL)) {
> + percpu_counter_add(&cc->n_allocated_pages, 1 << order);
> goto have_pages;
> + }
> +decrease_order:
> order--;
> }
>
> @@ -1719,8 +1724,13 @@ retry:
>
> have_pages:
> size_to_add = min((unsigned)PAGE_SIZE << order, remaining_size);
> - __bio_add_page(clone, pages, size_to_add, 0);
> remaining_size -= size_to_add;
> + while (size_to_add) {
> + unsigned this_step = min(size_to_add, (unsigned)PAGE_SIZE);
> + __bio_add_page(clone, pages, this_step, 0);
> + size_to_add -= this_step;
> + pages++;
> + }
> }
>
> /* Allocate space for integrity tags */
> @@ -1739,13 +1749,21 @@ have_pages:
> static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone)
> {
> struct folio_iter fi;
> + unsigned skip = 0;
>
> if (clone->bi_vcnt > 0) { /* bio_for_each_folio_all crashes with an empty bio */
> bio_for_each_folio_all(fi, clone) {
> - if (folio_test_large(fi.folio))
> + if (skip) {
> + skip--;
> + continue;
> + }
> + if (folio_test_large(fi.folio)) {
> + skip = (1 << folio_order(fi.folio)) - 1;
> + percpu_counter_sub(&cc->n_allocated_pages, 1 << folio_order(fi.folio));
> folio_put(fi.folio);
> - else
> + } else {
> mempool_free(&fi.folio->page, &cc->page_pool);
> + }
> }
> }
> }
--
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2023-11-02 0:38 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <ZTNH0qtmint/zLJZ@mail-itl>
[not found] ` <e427823c-e869-86a2-3549-61b3fdf29537@redhat.com>
[not found] ` <ZTiHQDY54E7WAld+@mail-itl>
[not found] ` <ZTiJ3CO8w0jauOzW@mail-itl>
2023-10-25 10:13 ` Mikulas Patocka
2023-10-27 17:32 ` Mikulas Patocka
2023-10-28 9:23 ` Matthew Wilcox
2023-10-28 15:14 ` Mike Snitzer
2023-10-29 11:15 ` Marek Marczykowski-Górecki
2023-10-29 20:02 ` Vlastimil Babka
2023-10-30 7:37 ` Mikulas Patocka
2023-10-30 8:37 ` Vlastimil Babka
2023-10-30 11:22 ` Mikulas Patocka
2023-10-30 11:30 ` Vlastimil Babka
2023-10-30 11:37 ` Mikulas Patocka
2023-10-30 12:25 ` Jan Kara
2023-10-30 13:30 ` Marek Marczykowski-Górecki
2023-10-30 14:08 ` Mikulas Patocka
2023-10-30 15:56 ` Jan Kara
2023-10-30 16:51 ` Marek Marczykowski-Górecki
2023-10-30 17:50 ` Mikulas Patocka
2023-10-31 3:48 ` Marek Marczykowski-Górecki
2023-10-31 14:01 ` Jan Kara
2023-10-31 15:42 ` Marek Marczykowski-Górecki
2023-10-31 17:17 ` Mikulas Patocka
2023-10-31 17:24 ` Mikulas Patocka
2023-11-02 0:38 ` Marek Marczykowski-Górecki [this message]
2023-11-02 9:28 ` Mikulas Patocka
2023-11-02 11:45 ` Marek Marczykowski-Górecki
2023-11-02 17:06 ` Mikulas Patocka
2023-11-03 15:01 ` Marek Marczykowski-Górecki
2023-11-03 15:10 ` Keith Busch
2023-11-03 16:15 ` Marek Marczykowski-Górecki
2023-11-03 16:54 ` Keith Busch
2023-11-03 20:30 ` Marek Marczykowski-G'orecki
2023-11-03 22:42 ` Keith Busch
2023-11-04 9:27 ` Mikulas Patocka
2023-11-04 13:59 ` Keith Busch
2023-11-06 7:10 ` Christoph Hellwig
2023-11-06 14:59 ` [PATCH] swiotlb-xen: provide the "max_mapping_size" method Mikulas Patocka
2023-11-06 15:16 ` Keith Busch
2023-11-06 15:30 ` Mike Snitzer
2023-11-06 17:12 ` [PATCH v2] " Mikulas Patocka
2023-11-07 4:18 ` Stefano Stabellini
2023-11-08 7:31 ` Christoph Hellwig
2023-11-06 7:08 ` Intermittent storage (dm-crypt?) freeze - regression 6.4->6.5 Christoph Hellwig
2023-11-02 12:21 ` Jan Kara
2023-11-01 1:27 ` Ming Lei
[not found] ` <ZUG0gcRhUlFm57qN@mail-itl>
[not found] ` <ZUG016NyTms2073C@mail-itl>
2023-11-01 2:35 ` Marek Marczykowski-Górecki
2023-11-01 3:24 ` Ming Lei
2023-11-01 10:15 ` Hannes Reinecke
2023-11-01 10:26 ` Jan Kara
2023-11-01 11:23 ` Ming Lei
2023-11-02 14:02 ` Keith Busch
2023-11-01 12:16 ` Mikulas Patocka
2023-10-30 11:28 ` Jan Kara
2023-10-30 11:49 ` Mikulas Patocka
2023-10-30 12:11 ` Jan Kara
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=ZULvkPhcpgAVyI8w@mail-itl \
--to=marmarek@invisiblethingslab.com \
--cc=agk@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=dm-devel@lists.linux.dev \
--cc=jack@suse.cz \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=mpatocka@redhat.com \
--cc=regressions@lists.linux.dev \
--cc=snitzer@kernel.org \
--cc=stable@vger.kernel.org \
--cc=vbabka@suse.cz \
--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