From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E0EEC4332F for ; Tue, 31 Oct 2023 17:24:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5EF58D0020; Tue, 31 Oct 2023 13:24:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B0EBB8D0012; Tue, 31 Oct 2023 13:24:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FE068D0020; Tue, 31 Oct 2023 13:24:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 917488D0012 for ; Tue, 31 Oct 2023 13:24:29 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6990980302 for ; Tue, 31 Oct 2023 17:24:29 +0000 (UTC) X-FDA: 81406430658.04.73E9A5D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 87AC120003 for ; Tue, 31 Oct 2023 17:24:27 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K6u736A5; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of mpatocka@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mpatocka@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698773067; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HLanOpI8RfAvOTY5kOuVRF9a/IYXbIbMQg6yPwFdFS0=; b=C/3KJ/+17SDqqeDIrL2BsOPELzKQjC+4HyXGOyBpZnxRu+R1c0ZBBi8x/b2xxWJDBoI9yi 0pw2iGxXf2D/iKXToWgIiRlgn/bp+GWD4ESNPpAHjsOBDwFXM2uiZsCCJXANBIgIR7CKjE YKvmamB9QLZ+SNxTwC8CJphAwqIjdO8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K6u736A5; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of mpatocka@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=mpatocka@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698773067; a=rsa-sha256; cv=none; b=TD1g+fd2tJ4GEvIf4hHq53p2tRo5GLsVPyzTYj4V/l9y+UcK/xwOEggPj9saab7FWpDLTL 70dPBuEebP84FgfsgPgW0bjgraJCpu0q+KiL1X7vXVIegHIT2RJofKaB7nOqHRSwnHI9wi JMjwR/f1k6ijTKhLZZsUAOvcqtPIbds= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698773066; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HLanOpI8RfAvOTY5kOuVRF9a/IYXbIbMQg6yPwFdFS0=; b=K6u736A54O+LqQzN+X7GCGVxzI8hK0ppyCCch1y5ETkOoD3MvTM4wgQJzKOXTeCvdeGWXY t/KpFohIS1TMAHJ2vUVV2yMMW1dVSog4WLwELuvmqh05bB3T6IUIPsJ4sxV5FyvK61w59s TQDKSpV9ggPp6jUzh3Tjo2xUMt/Ev58= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-173-94IZp1Z1OZik0zdRsm7hOw-1; Tue, 31 Oct 2023 13:24:20 -0400 X-MC-Unique: 94IZp1Z1OZik0zdRsm7hOw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EECB9917D85; Tue, 31 Oct 2023 17:24:19 +0000 (UTC) Received: from file1-rdu.file-001.prod.rdu2.dc.redhat.com (unknown [10.11.5.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D17912026D4C; Tue, 31 Oct 2023 17:24:19 +0000 (UTC) Received: by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix, from userid 12668) id BEFAD30C2A86; Tue, 31 Oct 2023 17:24:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix) with ESMTP id BBC3A3FB77; Tue, 31 Oct 2023 18:24:19 +0100 (CET) Date: Tue, 31 Oct 2023 18:24:19 +0100 (CET) From: Mikulas Patocka To: =?ISO-8859-15?Q?Marek_Marczykowski-G=F3recki?= cc: Jan Kara , Vlastimil Babka , Andrew Morton , Matthew Wilcox , Michal Hocko , stable@vger.kernel.org, regressions@lists.linux.dev, Alasdair Kergon , Mike Snitzer , dm-devel@lists.linux.dev, linux-mm@kvack.org Subject: Re: Intermittent storage (dm-crypt?) freeze - regression 6.4->6.5 In-Reply-To: <8a35cdea-3a1a-e859-1f7c-55d1c864a48@redhat.com> Message-ID: References: <3514c87f-c87f-f91f-ca90-1616428f6317@redhat.com> <1a47fa28-3968-51df-5b0b-a19c675cc289@suse.cz> <20231030122513.6gds75hxd65gu747@quack3> <20231030155603.k3kejytq2e4vnp7z@quack3> <98aefaa9-1ac-a0e4-fb9a-89ded456750@redhat.com> <20231031140136.25bio5wajc5pmdtl@quack3> <8a35cdea-3a1a-e859-1f7c-55d1c864a48@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="185210117-1983441990-1698773059=:87896" X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Rspamd-Queue-Id: 87AC120003 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 6obt39i5ea6ty7xh985ydjscyqsywu4c X-HE-Tag: 1698773067-108173 X-HE-Meta: U2FsdGVkX1/0hEPJGRfnjs7lCWAF9W5FOA7JcC5wnQdT6f9RgJaIyOSucdOo8SJkvtNPfvSteCgRshu/yP3lNuWEhfqMv3+OGhn5dfwOlwMCDYeDSyW58yz1KtroekRUs46f+1ju/GBeH4FAbH5qmg8p7W7vi9rsCepa2BoEPOnhakHpk7TWHx0SRD19AO0ZUVm+clRg2Abo1Mcxo63d8W32yaiB3r1R3kk707Tg7OJrUAZeCDL6BNCvBc5cxBvQSt80L8/8088ZgBXpknhVNeoAt43iprbIO0fIPY4VMV5YSd/8LCettA7KgwxofWNw3wiA4CQOjDQXv7ZwepdwTk5KwkhO1X7gYeFBa2OG7pb3S+AljulOp1hVcoAoPpsmIMPULifRJdAYdBTrSWWpJEGfIQhYTEmcxCNx9a87m9KF3MgB7KZeKl1z4i3/pB6uy9TeX2P9nLS0FhZAV/iWbtlI0nRyhLeI7tZGHpl1Z5uDvI4bwl+LKdoLv1GWb1E5H+E6wRJ/I+4IS4OWPsf8c61NZPUh0EUG/ucK7DjOWiPTsw7GkaJ2/XGpTuRRYqN44iL3m9yliNpJp0P4VCjxTx63Hj0TcoHOPa2FEmTGEDJ1a2psnfGqH5Uh01crTC5XWGm5mu4qgEJZb4slRy36/WtAcIkiskjMhYbSz5rgD6vEOQBu3JUi1qndE0qcMZZf2tIyuCBxUSgc2z3nlt0OnYLDC2crimWdMomHEYN1nvOPeddil1sn2mjfZ+Cfz0lR/CoizKJmt4lFvJ2lk19xC2XGR1CYYt9549vC/WP0wizcnHV+4jFurdidxpWid2fwjnLHkjLipKb7jeTp/99I4EG1SQ+zbRSH7qHv28QXJgDL1w3aqsMqVTMVDlKAw3/bpGhMlxVMJo8Fy8ywm4T3lnrrMTrm2WFfEux/OswcBX/RU/5i2hmEL+o+9jF87eRRCGNEt1YjLibyc4CFos4 iz2vGEKl 6n9iVf6PVQYCJm1VNzmHckJLs3fVBr7tLBqYifTD/FjOsY30Ey4H0RcjlN6zdBtOcUMF5TaRwj5kvnni4F9hAg6JfRehuaftJww1QjROF0LYSe0YOpljdE0xnWM8TLJsZNUqKdmn+L4Qu8F7CKiHzkEaJYOe92NaGz5I+MTN4H+y5VM+i1QwHPEv2p1u3jHwvFtNCNjyEFIYrk5E0+bscFgueC+PMPGEoy3nl2TGftR+qjtl0Iog2rpiY7H+KCHsYtj4yh6zzZrVDsxZEFqsSUfxP7g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --185210117-1983441990-1698773059=:87896 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT 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. > > Mikulas 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. 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); + } } } } --185210117-1983441990-1698773059=:87896--