Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp858628ybt; Fri, 19 Jun 2020 16:03:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNuw2/25nHzBbmg4tGx3r7ln5uBQy3gdPbqUse5lvmMR58pXbaznKbeTVI9q1Hvzzs0mgd X-Received: by 2002:a05:6402:1d96:: with SMTP id dk22mr5812642edb.258.1592607809672; Fri, 19 Jun 2020 16:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592607809; cv=none; d=google.com; s=arc-20160816; b=esGpXadtRQdVECdLSCh4IN4XIlTavTxP+VKq8xVRUPLcIvgXCfDDqmHTzIiFn0Tt/7 sbk+t+Uz8/Luej/tdPhfC+qqvdeW5BUBh0QvtEuQKUGA7OAKLA0gESlVcL31yrxqDrKy rDT+sAK139V3hdXb232W2cuW9/hTVq1VigmIkwCYaoJdUy9iq4dkKXGZQuvsTc00DHDk vgsAJE5rmmqhy2q+9uQs7J1A0lDrHwRw4i/zcoI3Zc88FdbbJe6UVaU5FuYQHTkYH7wB ywUXaL3tW6JB3FHnFXoa+LUstMS24f2hvJoJ5m+gAbZh9llVgeJikYMo6jUPlHh7fe9Z MDSQ== 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=npWjLC9jC3GL+jeOHyGRHeHAgJfyUJvJNqsgDeHoJGM=; b=etPIIBGnDszVNqJmNox5Re4/Xda4ysyWtT8NGn8NCq+SO5dp9YY3dhuBg/6TpdjVGB wRsQ11Iy6bqZnumOAkaHiipXPcZGSuXW/H9q8nIuIyYtmv7Bl4Q2pyv+BnLvCmCQZILl IXqdD7bt1+HlVLmM6lBNT8OEUQbyHcR1zENj0IKNYTFDRxTEUIzf4EeFcOD0O691m/Kt IyYNFbW3hxSYW24aN6zFQHtYcLWxbs2LN2hkXYn1uVbOZHSPTa8iKVkdTNpIIAOt7KIt DKb76jQFg/kogF+0i3HOnuN8cVM8Xb4v9qI6YQPyz0ShLiBtYzwyLP5AakWSC6vgV6zr dBfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eOgBuiXv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n18si4730096edq.195.2020.06.19.16.03.07; Fri, 19 Jun 2020 16:03:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eOgBuiXv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393780AbgFSPbH (ORCPT + 99 others); Fri, 19 Jun 2020 11:31:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:34946 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391325AbgFSPbA (ORCPT ); Fri, 19 Jun 2020 11:31:00 -0400 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 641CC206B7; Fri, 19 Jun 2020 15:30:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592580658; bh=bHkNN74cdzXa9vVkD8gRknfG06ao0SH0hSvjcOVtP5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eOgBuiXvtJMznWM9ab+A2Ebbsx302bgOuHggIE/+QV8TpBUhqPT3ZRy2R1PmzRLre rAgVYlJSgjeSD7Vq4C/t7zuOZtfds30ksenWJUybXSqQvTdljpsqaiQWcZQleX8F0r 1q5iypnttrfbuLmdJZ9W/LhQEzGbXFAYjkwR4J6Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andreas Dilger , Jan Kara , Theodore Tso Subject: [PATCH 5.7 333/376] jbd2: avoid leaking transaction credits when unreserving handle Date: Fri, 19 Jun 2020 16:34:11 +0200 Message-Id: <20200619141726.093088973@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141710.350494719@linuxfoundation.org> References: <20200619141710.350494719@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: Jan Kara commit 14ff6286309e2853aed50083c9a83328423fdd8c upstream. When reserved transaction handle is unused, we subtract its reserved credits in __jbd2_journal_unreserve_handle() called from jbd2_journal_stop(). However this function forgets to remove reserved credits from transaction->t_outstanding_credits and thus the transaction space that was reserved remains effectively leaked. The leaked transaction space can be quite significant in some cases and leads to unnecessarily small transactions and thus reducing throughput of the journalling machinery. E.g. fsmark workload creating lots of 4k files was observed to have about 20% lower throughput due to this when ext4 is mounted with dioread_nolock mount option. Subtract reserved credits from t_outstanding_credits as well. CC: stable@vger.kernel.org Fixes: 8f7d89f36829 ("jbd2: transaction reservation support") Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara Link: https://lore.kernel.org/r/20200520133119.1383-3-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/jbd2/transaction.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -541,17 +541,24 @@ handle_t *jbd2_journal_start(journal_t * } EXPORT_SYMBOL(jbd2_journal_start); -static void __jbd2_journal_unreserve_handle(handle_t *handle) +static void __jbd2_journal_unreserve_handle(handle_t *handle, transaction_t *t) { journal_t *journal = handle->h_journal; WARN_ON(!handle->h_reserved); sub_reserved_credits(journal, handle->h_total_credits); + if (t) + atomic_sub(handle->h_total_credits, &t->t_outstanding_credits); } void jbd2_journal_free_reserved(handle_t *handle) { - __jbd2_journal_unreserve_handle(handle); + journal_t *journal = handle->h_journal; + + /* Get j_state_lock to pin running transaction if it exists */ + read_lock(&journal->j_state_lock); + __jbd2_journal_unreserve_handle(handle, journal->j_running_transaction); + read_unlock(&journal->j_state_lock); jbd2_free_handle(handle); } EXPORT_SYMBOL(jbd2_journal_free_reserved); @@ -722,7 +729,8 @@ static void stop_this_handle(handle_t *h atomic_sub(handle->h_total_credits, &transaction->t_outstanding_credits); if (handle->h_rsv_handle) - __jbd2_journal_unreserve_handle(handle->h_rsv_handle); + __jbd2_journal_unreserve_handle(handle->h_rsv_handle, + transaction); if (atomic_dec_and_test(&transaction->t_updates)) wake_up(&journal->j_wait_updates);