From patchwork Fri Apr 13 20:28:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10340741 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 7C786600D0 for ; Fri, 13 Apr 2018 20:29:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D9EB288A7 for ; Fri, 13 Apr 2018 20:29:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5234E28A03; Fri, 13 Apr 2018 20:29:06 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, 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 CD322288A7 for ; Fri, 13 Apr 2018 20:29:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751676AbeDMU3E (ORCPT ); Fri, 13 Apr 2018 16:29:04 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:45153 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751553AbeDMU26 (ORCPT ); Fri, 13 Apr 2018 16:28:58 -0400 Received: by mail-qk0-f195.google.com with SMTP id f9so2517071qkm.12 for ; Fri, 13 Apr 2018 13:28:58 -0700 (PDT) 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=/1V3Nq8tRBX1FqXWX6Wf2eU+3gK0uUOEe8g9vzvWwPQ=; b=uTsnNpg8kYqhmnTa84rX8ddg7tSCrbla/JmJkWcmR0jV/Ug0HurahTnj1h/D6E9mHY ePz4JVUAFdzhD59dywWBD0ra3M833d9y8jelTNLzvxHJRFLszYnVunOYLMaHCZ/hrqNG CrLQB2/g7VqXnteJSFicRdIN1YzaWo0hWy2QzYlZ+d/grva92rX61FgROGy3az8m6D1z rxk26bsruEBihLFCOgu3XaNxdpJ3BgbKvMKb6pe/BvjWhZEO5o6XbfLWcs3E16qJitEo d14nxy5Ox5TBtSGFRZI7FGIfUa1KEHQDvft/sKF1rX1f+y4bHXA+DWg+b/LvfyxGkTpx Fw6Q== 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=/1V3Nq8tRBX1FqXWX6Wf2eU+3gK0uUOEe8g9vzvWwPQ=; b=LKjfhQUW+5iexfec3/stm9XLKFqj28BKneKDnKVpitbBeH0R7U9J8AHxNS6OWzNWPy 05dCZpyWqW0R1zgWhKKMXJqT9+dzQjwHh4eEsyYmWryjuwPApZDjRUOBNW0/M9VVt8Hs wTMEiPy/oH5me7fAIaa66OGlhofMP8TpihAHXfTyFtMsgNcE2A7Y4VxC+ybkXv1vDJvH ALa4BB+ihnDEUdOM1OcZ1bPf7csBXBEopyUy8cnxPSff9oAZacijv9mfed2vP6MTEuQo wVPoIvHnsTWkJqvbbi2zg5koNjJUZcP65OQyvrWp+arWNzQBaRyM+IcP5I/TlhynGwCR 8ZiA== X-Gm-Message-State: ALQs6tDqtBGUHVEDpZ/e2bw5oDY5zixHfzDaJ/8DQy7n3XfhFc5SDElw bzsJQn/g1y+bUm9d5f9VsOCN2BAM X-Google-Smtp-Source: AIpwx4+FdlrA4Qx7BZvYtgeLvveNyTGivDDgrJVeiSoFiEj48H2CsxRgP2GwQzkQOSu8Db3yE9Lv0Q== X-Received: by 10.55.123.3 with SMTP id w3mr1311871qkc.220.1523651337712; Fri, 13 Apr 2018 13:28:57 -0700 (PDT) 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 j1sm2018170qtc.53.2018.04.13.13.28.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Apr 2018 13:28:56 -0700 (PDT) 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: Fri, 13 Apr 2018 16:28:55 -0400 Message-Id: <20180413202855.10453-1-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 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 | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index fb32394fd830..1054dc0158b5 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -593,8 +593,9 @@ 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); @@ -617,6 +618,9 @@ 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); @@ -676,7 +680,15 @@ 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; + spin_unlock(&tree->lock); + goto again; + } + err = -ENOMEM; + goto out; + } err = split_state(tree, state, prealloc, start); if (err) extent_io_tree_panic(tree, err); @@ -699,7 +711,15 @@ 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; + spin_unlock(&tree->lock); + goto again; + } + err = -ENOMEM; + goto out; + } err = split_state(tree, state, prealloc, end + 1); if (err) extent_io_tree_panic(tree, err); @@ -734,7 +754,7 @@ int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, if (prealloc) free_extent_state(prealloc); - return 0; + return err; }