From patchwork Thu Nov 9 17:53:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10051613 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9476C601EA for ; Thu, 9 Nov 2017 17:53:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 831512AFCC for ; Thu, 9 Nov 2017 17:53:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77DC52AFD6; Thu, 9 Nov 2017 17:53:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB4A52AFCC for ; Thu, 9 Nov 2017 17:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752963AbdKIRxR (ORCPT ); Thu, 9 Nov 2017 12:53:17 -0500 Received: from mail-qk0-f196.google.com ([209.85.220.196]:45347 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751065AbdKIRxQ (ORCPT ); Thu, 9 Nov 2017 12:53:16 -0500 Received: by mail-qk0-f196.google.com with SMTP id p19so3576541qke.2 for ; Thu, 09 Nov 2017 09:53:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=cwYOuYf8Fb8KWfsMdHMDv6wAR2zFfSLMzepH9ozAawA=; b=evyBGRJVCLjuKx842PrnuJtnj4rbUuMeDz4CBr5dL1tu3ON7T5ndcQSYs9dhjLVQrQ e6PWm/ol5xUODkMDANFPU3M1Em2k7LxEMke963ExadhN/lhj08tnOnIPP+t7gR7teXOD Mb71v5ex0GCWTPZdWpuJrbKp5mBOjU7EPCf6sc7EJ3WW+RSG2xflb0HLFPC7frCZ81sA juK8R35nnjFoQem0LT7t1wb7YxIHIZx2h/jhNC99IOynoHGeXLD918sQji3qwoUzv7En uxY+i662CLUDfbvlvduP/yfnH3a6QaL4ALx6y03pUgqY129vVRPOAG4x/TBDXO9WTSmI uZJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=cwYOuYf8Fb8KWfsMdHMDv6wAR2zFfSLMzepH9ozAawA=; b=toiY4K5gthJB4GSdmFkP8Ogpiwkmur8ZVTcm4RUB3RzPJFdqvGyYz7h81R2V5Pfcar ZriAG7XQf+h4mGQh5GUN32IJAS5uiBksipTx0AJH+BJPSHcOxZbEMHpne8druXrny8dR scyIEdUTUmzKHUD+YKxatXLQWcm9bqxSmIkA1GFj47kmgszak7kyqCWcht6fwDxyuMru ewVD9kjtU2R+mGuFfVj1IeUvsi3zMFIQgYreDc19AIaYp7nWiL3TipjvS6z/6kGa9iAz X3iZTzTyHK7r2Skns25bj8PuuPPMPMeq7vA6Y5VNNZVYfRA+MzzLuejw0+41P1aQt32K Flnw== X-Gm-Message-State: AJaThX4WBKbGlBFzlvLC+wusimrPyRnEVocS7pwomAliRG7yaqOSPibu vBj3ukYw9KikZ77yzhlnMtM3bjUH X-Google-Smtp-Source: ABhQp+RB3zLzEh8d1XOBymp/azoiheFLod7mLL+nz+6Eq6R/BwOeOWYNSRgw6h0WwnqxfH/L58CAaA== X-Received: by 10.55.4.148 with SMTP id 142mr2173271qke.121.1510249995561; Thu, 09 Nov 2017 09:53:15 -0800 (PST) Received: from localhost (cpe-2606-A000-4381-1201-225-22FF-FEB3-E51A.dyn6.twc.com. [2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id u83sm4529060qkl.13.2017.11.09.09.53.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 09:53:14 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Josef Bacik Subject: [PATCH] btrfs: don't bug_on with enomem in __clear_state_bit Date: Thu, 9 Nov 2017 12:53:14 -0500 Message-Id: <1510249994-6023-1-git-send-email-josef@toxicpanda.com> X-Mailer: git-send-email 2.7.5 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Josef Bacik Since we're allocating under atomic we could every easily enomem, so if that's the case and we can block then loop around and try to allocate the prealloc not under a lock. We also saw this happen during try_to_release_page in production, in which case it's completely valid to return ENOMEM so we can tell try_to_release_page that we can't release this page. Signed-off-by: Josef Bacik --- fs/btrfs/extent_io.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index dd941885b9c3..6d1de1a81dc8 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -590,8 +590,9 @@ static int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, struct extent_state *prealloc = NULL; struct rb_node *node; u64 last_end; - int err; + int err = 0; int clear = 0; + bool need_prealloc = false; btrfs_debug_check_extent_io_range(tree, start, end); @@ -614,6 +615,9 @@ static int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, * If we end up needing a new extent state we allocate it later. */ prealloc = alloc_extent_state(mask); + if (!prealloc && need_prealloc) + return -ENOMEM; + need_prealloc = false; } spin_lock(&tree->lock); @@ -673,7 +677,14 @@ static int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, if (state->start < start) { prealloc = alloc_extent_state_atomic(prealloc); - BUG_ON(!prealloc); + if (!prealloc) { + if (gfpflags_allow_blocking(mask)) { + need_prealloc = true; + goto again; + } + err = -ENOMEM; + goto out; + } err = split_state(tree, state, prealloc, start); if (err) extent_io_tree_panic(tree, err); @@ -696,7 +707,14 @@ static int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, */ if (state->start <= end && state->end > end) { prealloc = alloc_extent_state_atomic(prealloc); - BUG_ON(!prealloc); + if (!prealloc) { + if (gfpflags_allow_blocking(mask)) { + need_prealloc = true; + goto again; + } + err = -ENOMEM; + goto out; + } err = split_state(tree, state, prealloc, end + 1); if (err) extent_io_tree_panic(tree, err); @@ -731,7 +749,7 @@ static int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, if (prealloc) free_extent_state(prealloc); - return 0; + return err; }