From patchwork Fri Mar 1 23:29:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10836255 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 358601575 for ; Fri, 1 Mar 2019 23:29:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D89D2E050 for ; Fri, 1 Mar 2019 23:29:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11C5D2E062; Fri, 1 Mar 2019 23:29:21 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 A5DDA2E050 for ; Fri, 1 Mar 2019 23:29:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726232AbfCAX3U (ORCPT ); Fri, 1 Mar 2019 18:29:20 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:47900 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725966AbfCAX3U (ORCPT ); Fri, 1 Mar 2019 18:29:20 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x21NTIGI126726 for ; Fri, 1 Mar 2019 23:29:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=JhltF2LAXQOfmrA+WzvDOismGkeHtXYJ+VaZ/kAS2tY=; b=hoWOIBeecG39GLwwuv7Q0fyA3sH7S76DCc+aplG2EMR844M5fS97uFcBYEY6cmE/aGrb BARxfhaU70ozCLhApMTXide2djJJiKGPoGgJj2cCXg4iE7iG9FPkc1m8DzHGRXwjlY1/ QkZLvOk4U8LPsRk9AbKaw9UAaFSEPpAyqbIdVQMNpW91ZGKPy56QEIPVcOkvz+T8XYMJ WUCoKcyJ6Q/WacYd6GplUKMP+kJHJwdrvkQmB2U2aPkHTaxzXABFr0knJOBZKh8R2/49 urttX9mh6mJ1owvjZv6FxRWzjOldxD0YrQ2toK4D/7A0nWig6WNXf6O3wjJfjLOzJeN2 tw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2qtwkut94p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 01 Mar 2019 23:29:18 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x21NTHVG003193 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 1 Mar 2019 23:29:18 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x21NTHMX022229 for ; Fri, 1 Mar 2019 23:29:17 GMT Received: from localhost (/10.159.229.175) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 01 Mar 2019 15:29:17 -0800 Subject: [PATCH 23/23] libxfs: free buffer and inode log items when cancelling a transaction From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Fri, 01 Mar 2019 15:29:16 -0800 Message-ID: <155148295652.16677.2568753166058619886.stgit@magnolia> In-Reply-To: <155148280859.16677.6057998944865066232.stgit@magnolia> References: <155148280859.16677.6057998944865066232.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9182 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903010162 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong When we're cancelling a transaction, cancel the log items instead of leaking them, now that we no longer recycle them. Signed-off-by: Darrick J. Wong --- libxfs/trans.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/libxfs/trans.c b/libxfs/trans.c index 0f9f12b6..c36837b1 100644 --- a/libxfs/trans.c +++ b/libxfs/trans.c @@ -24,6 +24,7 @@ STATIC struct xfs_trans *xfs_trans_dup(struct xfs_trans *tp); static int xfs_trans_reserve(struct xfs_trans *tp, struct xfs_trans_res *resp, uint blocks, uint rtextents); static int __xfs_trans_commit(struct xfs_trans *tp, bool regrant); +static void trans_cancel(struct xfs_trans *tp); /* * Simple transaction interface @@ -326,6 +327,7 @@ libxfs_trans_cancel( if (tp->t_flags & XFS_TRANS_PERM_LOG_RES) xfs_defer_cancel(tp); + trans_cancel(tp); xfs_trans_free_items(tp); xfs_trans_free(tp); @@ -878,6 +880,55 @@ inode_item_done( kmem_zone_free(xfs_ili_zone, iip); } +static void +inode_item_cancel( + struct xfs_inode_log_item *iip) +{ + struct xfs_inode *ip; + + ip = iip->ili_inode; + ASSERT(ip != NULL); + + if (iip->ili_fields & XFS_ILOG_ALL) { +#ifdef XACT_DEBUG + fprintf(stderr, "cancelling dirty inode %lu\n", ip->i_ino); +#endif + } + + ip->i_transp = NULL; /* disassociate from transaction */ + ip->i_itemp = NULL; + kmem_zone_free(xfs_ili_zone, iip); +} + +static void +buf_item_cancel( + struct xfs_buf_log_item *bip) +{ + struct xfs_buf *bp; + int hold; + extern kmem_zone_t *xfs_buf_item_zone; + + bp = bip->bli_buf; + ASSERT(bp != NULL); + + hold = (bip->bli_flags & XFS_BLI_HOLD); + if (bip->bli_flags & XFS_BLI_DIRTY) { +#ifdef XACT_DEBUG + fprintf(stderr, "cancelling dirty buffer %p (hold=%d)\n", + bp, hold); +#endif + } + if (hold) + bip->bli_flags &= ~XFS_BLI_HOLD; + else + libxfs_putbuf(bp); + + /* release the buf item */ + bp->b_log_item = NULL; /* remove log item */ + bp->b_transp = NULL; /* remove xact ptr */ + kmem_zone_free(xfs_buf_item_zone, bip); +} + static void buf_item_done( xfs_buf_log_item_t *bip) @@ -928,6 +979,27 @@ trans_committed( } } +static void +trans_cancel( + struct xfs_trans *tp) +{ + struct xfs_log_item *lip, *next; + + list_for_each_entry_safe(lip, next, &tp->t_items, li_trans) { + xfs_trans_del_item(lip); + + if (lip->li_type == XFS_LI_BUF) + buf_item_cancel((xfs_buf_log_item_t *)lip); + else if (lip->li_type == XFS_LI_INODE) + inode_item_cancel((xfs_inode_log_item_t *)lip); + else { + fprintf(stderr, _("%s: unrecognised log item type\n"), + progname); + ASSERT(0); + } + } +} + static void buf_item_unlock( xfs_buf_log_item_t *bip) @@ -1033,6 +1105,7 @@ __xfs_trans_commit( return 0; out_unreserve: + trans_cancel(tp); xfs_trans_free_items(tp); xfs_trans_free(tp); return error;