Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6541939ybx; Mon, 11 Nov 2019 10:39:06 -0800 (PST) X-Google-Smtp-Source: APXvYqyF/8RfKSG5qNPtFMyW12BFtCf19iipkc+hstS8lkS4dV05FgFDY9HI03pEoh7Rl662RXDK X-Received: by 2002:a17:906:4913:: with SMTP id b19mr23683348ejq.61.1573497545904; Mon, 11 Nov 2019 10:39:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573497545; cv=none; d=google.com; s=arc-20160816; b=v3pq2Xo8y3gFW9JuYbJS6+jaNRmj2IT2+w8/Vy/oyE/1dQYJbp7i60ARnE/DplhW4w lRtZilOJ8oVal+y55kavlZeSnrnB65hN3UislcM43SbkbnLdwLWManAJtr1yEOuA9ujO IYkMDAr8zXIRMCohNp5+6bVF57vqHTN4uABus1AZa632N+Ew9m6x+0Jm0qfw4emdCSgP wctEkXiwDnw0sVqe82NsXEr088XmVjkXP89k02lZmGdVCHFrD1UVGF/50CRxgCKPOQh8 dbQzMr7l5aF7OawV/84M9SLf6MkhaM5X8iylkmrZ2ExS2r+V1Q25A3x1n3bNmDQzMf5g 9ZpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C0FlQuqCctI+q4iDnpHp+ILHnEA2mcONg4W5ZprwkGI=; b=D7GYH7lTyzl6W0UJTFGOKME1OAT58/Gh3C6TsKdp/03SY31dJHakWGhTAhQ+bDnX3D 4A+PnSQsE8xq6MUa0P3VHbv4hXXA3ip2vvsYcGnlDZCLOUyfhmpJjdW/29jnSyd7nac4 n69aMVejmg8H5Y6AAanzcW2B67/czzXFsxFJQmrCwLWZWMDNg7dtgLoakgN6++fNDOSB q1B1ep9j/65QO/AMiopTu1bl0nra/uaTWOnFvZ+0FLi4gKM0pnjjN/7DyAcHyZcHQNFi yW/vnwqQS4PP3t8varR4Hj7FHr+miOQkj1MqIuFSsdt2AmBrsDD7XussMiPIRGDaW4uF AoTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=C1TUjsMi; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g15si12153038edl.95.2019.11.11.10.38.41; Mon, 11 Nov 2019 10:39:05 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=C1TUjsMi; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728390AbfKKSek (ORCPT + 99 others); Mon, 11 Nov 2019 13:34:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:52340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727669AbfKKSej (ORCPT ); Mon, 11 Nov 2019 13:34:39 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AF7A02173B; Mon, 11 Nov 2019 18:34:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573497278; bh=MnjhQlZwaODzj+JadDJkhh9j+AWvo5XL4w5QwgNBMyU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C1TUjsMiHRmN54qOTWn3ChepzgpGW4sHzAwCPhUk4uAr1URLxwWsHmhVzsFH0odb8 UDNNfmunMAf0C+1y4rIuEppHyYfZLvcux3372P7uMrGN46k81cAvb0BrRJUdbZXaEd DJyaKGXTAzrrHj9Leedjl39UB9d0lcY46sHXVtI8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Konstantin Khlebnikov , Dennis Zhou , Tejun Heo , Jens Axboe Subject: [PATCH 4.9 65/65] cgroup,writeback: dont switch wbs immediately on dead wbs if the memcg is dead Date: Mon, 11 Nov 2019 19:29:05 +0100 Message-Id: <20191111181356.971940684@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181331.917659011@linuxfoundation.org> References: <20191111181331.917659011@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tejun Heo commit 65de03e251382306a4575b1779c57c87889eee49 upstream. cgroup writeback tries to refresh the associated wb immediately if the current wb is dead. This is to avoid keeping issuing IOs on the stale wb after memcg - blkcg association has changed (ie. when blkcg got disabled / enabled higher up in the hierarchy). Unfortunately, the logic gets triggered spuriously on inodes which are associated with dead cgroups. When the logic is triggered on dead cgroups, the attempt fails only after doing quite a bit of work allocating and initializing a new wb. While c3aab9a0bd91 ("mm/filemap.c: don't initiate writeback if mapping has no dirty pages") alleviated the issue significantly as it now only triggers when the inode has dirty pages. However, the condition can still be triggered before the inode is switched to a different cgroup and the logic simply doesn't make sense. Skip the immediate switching if the associated memcg is dying. This is a simplified version of the following two patches: * https://lore.kernel.org/linux-mm/20190513183053.GA73423@dennisz-mbp/ * http://lkml.kernel.org/r/156355839560.2063.5265687291430814589.stgit@buzz Cc: Konstantin Khlebnikov Fixes: e8a7abf5a5bd ("writeback: disassociate inodes from dying bdi_writebacks") Acked-by: Dennis Zhou Signed-off-by: Tejun Heo Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/fs-writeback.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -582,10 +582,13 @@ void wbc_attach_and_unlock_inode(struct spin_unlock(&inode->i_lock); /* - * A dying wb indicates that the memcg-blkcg mapping has changed - * and a new wb is already serving the memcg. Switch immediately. + * A dying wb indicates that either the blkcg associated with the + * memcg changed or the associated memcg is dying. In the first + * case, a replacement wb should already be available and we should + * refresh the wb immediately. In the second case, trying to + * refresh will keep failing. */ - if (unlikely(wb_dying(wbc->wb))) + if (unlikely(wb_dying(wbc->wb) && !css_is_dying(wbc->wb->memcg_css))) inode_switch_wbs(inode, wbc->wb_id); }