Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9418548ybi; Wed, 10 Jul 2019 09:56:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjzjv+Lo0CtCvNqpnZXnignGQMF1KhKNz3iV7l3GauxaMletuJ677kltf86KCXAQltlliG X-Received: by 2002:a17:90a:b883:: with SMTP id o3mr8065296pjr.50.1562777775755; Wed, 10 Jul 2019 09:56:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562777775; cv=none; d=google.com; s=arc-20160816; b=bgKS/QLcwd80kxukDn/R8MT4qK3MMdgdm9Z97hLAlW0Akuvb3havZV4VdUx6iyaj1l fCZeKyDdmTamkMI7slZitPWFUgw4VSuyrtXioWblVZT2cJ69W2015+c+X9G9Pb3o+FQc kF11EIbUJRDZ0jdVIEmQjf/NGlcYAoJzk6e8jJs2pn2DEsqBM0PLL8hlcVWrQBdMR0XI UjBmzN8TmvuW8+uz4c/hr9lrlPIU1G9I0QX9225JhjgNyMnA19XvRHRukLgQ38o1Tp9x 9e9HIlKxGbRDxh+8hdRh4L5t4f1NP6DobO87R6FiykO5bcpNszS9BxrUO/aNihu9jlZz FM7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=FsTC5YnPPj+BV2txfxELpq2HsyTyJOSxp4zZ8r+4QyM=; b=FVeQXRJP3J3+CDZVAVajk/+78tJfBqsKPxD3FGCM6E8LRg4Y4lu/aT5dZpSTrUiiuY UXqak4Q9cSqDxs14yzLRB7AIr59FKE3I/lW6RtySde5SvOMg3IzbGSxu45TZRf8EGAbq dF8n8hs/oBJfCQP1zVPXrwVT88PQtLPsEyX0gkRHMFQhqGwZ+JEZItvdvOlRcm+78fFK +9Ji9cdpQRxDaWsDed6Eo/uSVLn6PudCSamWuvuBSLgQciK0Nzrk5VVpg/XEW1UK94Au IUm6pAcndCOXf9pzkVehv8usT/+hUVAqVmzjFGALGpDZm0ZFjT0AmLR8Zm5HUYXpPdjx 1VRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x8si2685410pgi.136.2019.07.10.09.55.59; Wed, 10 Jul 2019 09:56:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728269AbfGJPrB (ORCPT + 99 others); Wed, 10 Jul 2019 11:47:01 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:55765 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727254AbfGJPrA (ORCPT ); Wed, 10 Jul 2019 11:47:00 -0400 Received: from mail-wm1-f72.google.com ([209.85.128.72]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hlEo6-00077v-Kb for linux-kernel@vger.kernel.org; Wed, 10 Jul 2019 15:46:58 +0000 Received: by mail-wm1-f72.google.com with SMTP id l16so881962wmg.2 for ; Wed, 10 Jul 2019 08:46:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=FsTC5YnPPj+BV2txfxELpq2HsyTyJOSxp4zZ8r+4QyM=; b=Ah3gp3PEyjzd8G9Dkt5NMK541sonSI24VH6/xjEngc8RFUwnk8QqcL0vyzhakIRfjp crmynCBWe08wgzH2IeGRjWlt9TtQ4j60OAPoqFj66r7mlS8jKzNUv04lR9flu+mnu3Ar zA6sdv7uNouGDY2quJejPsJgrF69eycugd0OZSwCDOfzWjnfRpe2Mx7fLER8Eeggfnfl f8IJw5Js9fg7Pzl3yD4VtSxCQGQN7jIBgONu5E9aKU/UgE5m2YWJl8PpV0F7piRoaZrg 5zZbRkKbILlunQO8ghsKlLxqzokhsKYcK69nU5c1BVrODjdLXHiWJchFlgBeXf+oxAt4 KK1A== X-Gm-Message-State: APjAAAWfcllFaKFuxWh1IB1zdj2MkIYEZDMxTNay4uqpzWlf5lYkpY04 nclGnHlK0UcT1qlJAVyieXZqBtm5Qlu9ZRlLtI2er7beP3rjt0UXg8RjugexwIhKbdwNkbJSE1w GHUBnekmQYjMbTMhF4m2YYAT2K9MhwBBdxTRw9lHSCg== X-Received: by 2002:adf:f601:: with SMTP id t1mr11781332wrp.337.1562773618045; Wed, 10 Jul 2019 08:46:58 -0700 (PDT) X-Received: by 2002:adf:f601:: with SMTP id t1mr11781317wrp.337.1562773617742; Wed, 10 Jul 2019 08:46:57 -0700 (PDT) Received: from localhost (host1-198-dynamic.8-87-r.retail.telecomitalia.it. [87.8.198.1]) by smtp.gmail.com with ESMTPSA id f17sm2451979wmf.27.2019.07.10.08.46.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 10 Jul 2019 08:46:57 -0700 (PDT) Date: Wed, 10 Jul 2019 17:46:56 +0200 From: Andrea Righi To: Coly Li Cc: Kent Overstreet , linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] bcache: fix deadlock in bcache_allocator() Message-ID: <20190710154656.GA7572@xps-13> References: <20190710093117.GA2792@xps-13> <82f1c5a9-9da4-3529-1ca5-af724d280580@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <82f1c5a9-9da4-3529-1ca5-af724d280580@suse.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 10, 2019 at 11:11:37PM +0800, Coly Li wrote: > On 2019/7/10 5:31 下午, Andrea Righi wrote: > > bcache_allocator() can call the following: > > > > bch_allocator_thread() > > -> bch_prio_write() > > -> bch_bucket_alloc() > > -> wait on &ca->set->bucket_wait > > > > But the wake up event on bucket_wait is supposed to come from > > bch_allocator_thread() itself => deadlock: > > > > [ 242.888435] INFO: task bcache_allocato:9015 blocked for more than 120 seconds. > > [ 242.893786] Not tainted 4.20.0-042000rc3-generic #201811182231 > > [ 242.896669] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. > > [ 242.900428] bcache_allocato D 0 9015 2 0x80000000 > > [ 242.900434] Call Trace: > > [ 242.900448] __schedule+0x2a2/0x880 > > [ 242.900455] ? __schedule+0x2aa/0x880 > > [ 242.900462] schedule+0x2c/0x80 > > [ 242.900480] bch_bucket_alloc+0x19d/0x380 [bcache] > > [ 242.900503] ? wait_woken+0x80/0x80 > > [ 242.900519] bch_prio_write+0x190/0x340 [bcache] > > [ 242.900530] bch_allocator_thread+0x482/0xd10 [bcache] > > [ 242.900535] kthread+0x120/0x140 > > [ 242.900546] ? bch_invalidate_one_bucket+0x80/0x80 [bcache] > > [ 242.900549] ? kthread_park+0x90/0x90 > > [ 242.900554] ret_from_fork+0x35/0x40 > > > > Fix by making the call to bch_prio_write() non-blocking, so that > > bch_allocator_thread() never waits on itself. > > > > Moreover, make sure to wake up the garbage collector thread when > > bch_prio_write() is failing to allocate buckets. > > > > BugLink: https://bugs.launchpad.net/bugs/1784665 > > Signed-off-by: Andrea Righi > > Hi Andrea, > Hi Coly, > >From the BugLink, it seems several critical bcache fixes are missing. > Could you please to try current 5.3-rc kernel, and try whether such > problem exists or not ? Sure, I'll do a test with the latest 5.3-rc kernel. I just wanna mention that I've been able to reproduce this problem after backporting all the fixes (even those from linux-next), but I agree that testing 5.3-rc is a better idea (I may have introduced bugs while backporting stuff). > > For this patch itself, it looks good except that I am not sure whether > invoking garbage collection is a proper method. Because bch_prio_write() > is called right after garbage collection gets done, jump back to > retry_invalidate: again may just hide a non-space long time waiting > condition. Honestly I was thinking the same, but if I don't call the garbage collector bch_allocator_thread() gets stuck forever (or for a very very long time) in the retry_invalidate loop... > > Could you please give me some hint, on how to reproduce such hang > timeout situation. If I am lucky to reproduce such problem on 5.3-rc > kernel, it may be very helpful to understand what exact problem your > patch fixes. Fortunately I have a reproducer, here's the script that I'm using: --- #!/bin/bash -x BACKING=/sys/class/block/bcache0 CACHE=/sys/fs/bcache/*-*-* while true; do echo "1" | tee ${BACKING}/bcache/stop echo "1" | tee ${CACHE}/stop udevadm settle [ ! -e "${BACKING}" -a ! -e "${CACHE}" ] && break sleep 1 done wipefs --all --force /dev/vdc2 wipefs --all --force /dev/vdc1 wipefs --all --force /dev/vdc wipefs --all --force /dev/vdd blockdev --rereadpt /dev/vdc blockdev --rereadpt /dev/vdd udevadm settle # create ext4 fs over bcache parted /dev/vdc --script mklabel msdos || exit 1 udevadm settle --exit-if-exists=/dev/vdc parted /dev/vdc --script mkpart primary 2048s 2047999s || exit 1 udevadm settle --exit-if-exists=/dev/vdc1 parted /dev/vdc --script mkpart primary 2048000s 20922367s || exit 1 udevadm settle --exit-if-exists=/dev/vdc2 make-bcache -C /dev/vdd || exit 1 while true; do udevadm settle CSET=`ls /sys/fs/bcache | grep -- -` [ -n "$CSET" ] && break; sleep 1 done make-bcache -B /dev/vdc2 || exit 1 while true; do udevadm settle [ -e "${BACKING}" ] && break sleep 1; done echo $CSET | tee ${BACKING}/bcache/attach udevadm settle --exit-if-exists=/dev/bcache0 bcache-super-show /dev/vdc2 udevadm settle mkfs.ext4 -F -L boot-fs -U e9f00d20-95a0-11e8-82a2-525400123401 /dev/vdc1 udevadm settle mkfs.ext4 -F -L root-fs -U e9f00d21-95a0-11e8-82a2-525400123401 /dev/bcache0 || exit 1 blkid --- I just run this as root in a busy loop (something like `while :; do ./test.sh; done`) on a kvm instance with two extra disks (in addition to the root disk). The extra disks are created as following: qemu-img create -f qcow2 disk1.qcow 10G qemu-img create -f qcow2 disk2.qcow 2G I'm using these particular sizes, but I think we can reproduce the same problem also using different sizes. Thanks, -Andrea