From patchwork Tue Jul 30 01:18:34 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: 11064715 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 2E19C13A4 for ; Tue, 30 Jul 2019 01:18:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C586286DB for ; Tue, 30 Jul 2019 01:18:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1064728718; Tue, 30 Jul 2019 01:18:55 +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 98B05286DB for ; Tue, 30 Jul 2019 01:18:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729656AbfG3BSy (ORCPT ); Mon, 29 Jul 2019 21:18:54 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:38716 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729551AbfG3BSy (ORCPT ); Mon, 29 Jul 2019 21:18:54 -0400 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 x6U191ho012433; Tue, 30 Jul 2019 01:18:36 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=IacZW9DzE9Wd2VUoQjW+SOZ0JUrqHq4Fdg2aX/CFuoI=; b=HWRKaL13Xw0qTF4+63qQ3L6sGieEk3A3sxamY2ZhmV4SD19i7IoYCLGfYyRRNN3wbvmg mCN+mJeQvc3x88Ta9bEbUbDj8HeLh73Sjn9Dpo4DFSx0pLneu4HKO7DWOFfIglL6eKBc k24FXc5cHMLk/t7n9Jms0X8ZflQKdT4XAm/6BFaR0ZryVlUGOEJtqizDt4cY0eY4aT3L JaJSF4IHmd1PSpieFX4GW1+2KcTL5cjlfQ0FXqst22nd/r4zAtU4HhmKkkrIxfnscf3c MHxTgbK+jff6ZHkl7ufFZ/nFyCQwjz3llT1vFmUU/VDb5kbUqnKer5TesdERVSV+RKDS LQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2u0e1tk5my-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Jul 2019 01:18:36 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x6U1ITJL048868; Tue, 30 Jul 2019 01:18:36 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 2u0dxqmrtn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Jul 2019 01:18:36 +0000 Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x6U1IZ2i012436; Tue, 30 Jul 2019 01:18:35 GMT Received: from localhost (/10.159.132.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 29 Jul 2019 18:18:34 -0700 Subject: [PATCH 2/2] xfs: refactor the ioend merging code From: "Darrick J. Wong" To: hch@infradead.org, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Damien.LeMoal@wdc.com, Christoph Hellwig , agruenba@redhat.com Date: Mon, 29 Jul 2019 18:18:34 -0700 Message-ID: <156444951433.2682436.9000719881627179710.stgit@magnolia> In-Reply-To: <156444950159.2682436.1669088240015553674.stgit@magnolia> References: <156444950159.2682436.1669088240015553674.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9333 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1907300011 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9333 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 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-1906280000 definitions=main-1907300010 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: Christoph Hellwig Introduce two nicely abstracted helper, which can be moved to the iomap code later. Also use list_pop_entry and list_first_entry_or_null to simplify the code a bit. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_aops.c | 70 +++++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index f16d5f196c6b..4e4a4d7df5ac 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -116,6 +116,19 @@ xfs_destroy_ioend( } } +static void +xfs_destroy_ioends( + struct xfs_ioend *ioend, + int error) +{ + struct list_head tmp; + + list_replace_init(&ioend->io_list, &tmp); + xfs_destroy_ioend(ioend, error); + while ((ioend = list_pop_entry(&tmp, struct xfs_ioend, io_list))) + xfs_destroy_ioend(ioend, error); +} + /* * Fast and loose check if this write could update the on-disk inode size. */ @@ -230,7 +243,6 @@ STATIC void xfs_end_ioend( struct xfs_ioend *ioend) { - struct list_head ioend_list; struct xfs_inode *ip = XFS_I(ioend->io_inode); xfs_off_t offset = ioend->io_offset; size_t size = ioend->io_size; @@ -275,16 +287,7 @@ xfs_end_ioend( done: if (ioend->io_append_trans) error = xfs_setfilesize_ioend(ioend, error); - list_replace_init(&ioend->io_list, &ioend_list); - xfs_destroy_ioend(ioend, error); - - while (!list_empty(&ioend_list)) { - ioend = list_first_entry(&ioend_list, struct xfs_ioend, - io_list); - list_del_init(&ioend->io_list); - xfs_destroy_ioend(ioend, error); - } - + xfs_destroy_ioends(ioend, error); memalloc_nofs_restore(nofs_flag); } @@ -333,17 +336,18 @@ xfs_ioend_try_merge( struct xfs_ioend *ioend, struct list_head *more_ioends) { - struct xfs_ioend *next_ioend; + struct xfs_ioend *next; - while (!list_empty(more_ioends)) { - next_ioend = list_first_entry(more_ioends, struct xfs_ioend, - io_list); - if (!xfs_ioend_can_merge(ioend, next_ioend)) + INIT_LIST_HEAD(&ioend->io_list); + + while ((next = list_first_entry_or_null(more_ioends, struct xfs_ioend, + io_list))) { + if (!xfs_ioend_can_merge(ioend, next)) break; - list_move_tail(&next_ioend->io_list, &ioend->io_list); - ioend->io_size += next_ioend->io_size; - if (next_ioend->io_append_trans) - xfs_ioend_merge_append_transactions(ioend, next_ioend); + list_move_tail(&next->io_list, &ioend->io_list); + ioend->io_size += next->io_size; + if (next->io_append_trans) + xfs_ioend_merge_append_transactions(ioend, next); } } @@ -366,29 +370,31 @@ xfs_ioend_compare( return 0; } +static void +xfs_sort_ioends( + struct list_head *ioend_list) +{ + list_sort(NULL, ioend_list, xfs_ioend_compare); +} + /* Finish all pending io completions. */ void xfs_end_io( struct work_struct *work) { - struct xfs_inode *ip; + struct xfs_inode *ip = + container_of(work, struct xfs_inode, i_ioend_work); struct xfs_ioend *ioend; - struct list_head completion_list; + struct list_head tmp; unsigned long flags; - ip = container_of(work, struct xfs_inode, i_ioend_work); - spin_lock_irqsave(&ip->i_ioend_lock, flags); - list_replace_init(&ip->i_ioend_list, &completion_list); + list_replace_init(&ip->i_ioend_list, &tmp); spin_unlock_irqrestore(&ip->i_ioend_lock, flags); - list_sort(NULL, &completion_list, xfs_ioend_compare); - - while (!list_empty(&completion_list)) { - ioend = list_first_entry(&completion_list, struct xfs_ioend, - io_list); - list_del_init(&ioend->io_list); - xfs_ioend_try_merge(ioend, &completion_list); + xfs_sort_ioends(&tmp); + while ((ioend = list_pop_entry(&tmp, struct xfs_ioend, io_list))) { + xfs_ioend_try_merge(ioend, &tmp); xfs_end_ioend(ioend); } }