Message ID | 20230310060734.8780-1-frank.li@vivo.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp711688wrd; Thu, 9 Mar 2023 22:21:21 -0800 (PST) X-Google-Smtp-Source: AK7set+1GmtGzOASwYLQSw0989/6keI5nFfhJb/0vsF3GsjYRTw0mKZzq4CnfxO4UfsCA1v+fKPi X-Received: by 2002:a05:6a20:244d:b0:cc:e39e:3f64 with SMTP id t13-20020a056a20244d00b000cce39e3f64mr23562868pzc.24.1678429281307; Thu, 09 Mar 2023 22:21:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1678429281; cv=pass; d=google.com; s=arc-20160816; b=x+nd2demDBhAEdILertdpr2FMSLel1sjjqqp7UvARd60HJXwFp8CjRNOse3FdmKGLG +YqxloM0j41mPFLBXIIeU+mFW7IfwdYX1NAaQVYilJ/hgtoCjHJVkV91eskTtrvQwetH m6I/A7kbHWX07Aq2LPdaO2Sj8MerYGg03dS9CsYS/PzhKqUhaRedKjZC0ysce10iBT8c UgxL/JCKgsLawTl3/QlAAyNUufBFKPurMhVAq/WAAFppdYLR1JEMIrd7VAPDVCT/DACz vrMa+kanxhiMk2u50qvt09Z5LJ2PM4f7pSZfMe6PtczBQ9q07z0hMPJrBjDWbjjm78j/ sjbA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=9eGLPo+gwK3BhKaizmVCd0S9rUlfgoSwrRoS3Fp+T4I=; b=x6WoYSxKdfH/TQTunT4do8kmjGb2ErC9fqxxRV6oT2ylD06zoFBOheiIcnNMADG2JQ E7r+WDGL+7xmpaZdc7/16eGvbhY3uhoQ5kALQaj4lSdDzZmSxJjrFhHc0RYeGJgXV6qs /4bu3iVJNarhKiLWeIEglTqr14wIu7p2u7iqB7tzr89gZiFnLLpvDQku2nzjB8EmW0jC e1AFTRogHyohxZeodNRlQpmpKLdzf9kJjWtxjZ8fRFoz7HJh7tbkmKS63xbOVi9azIBS 7O7xA2hybV5NIGXQc2K0cxrsmXxKsKfzBXTQ6aGnBfoZUquI8KLjZXjkFLALe4Pce9gM IUSA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=m5ISxwia; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m13-20020a63580d000000b00503a3e606besi1225384pgb.253.2023.03.09.22.21.05; Thu, 09 Mar 2023 22:21:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=m5ISxwia; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229541AbjCJGH6 (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Fri, 10 Mar 2023 01:07:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjCJGH4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 10 Mar 2023 01:07:56 -0500 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2107.outbound.protection.outlook.com [40.107.117.107]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23868E9833; Thu, 9 Mar 2023 22:07:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eDAXoraXxwmBKkFGjZ2r2+vG0ke36bg9/bs2aYqiw76a+3MKox7SkUx23q9xWMjMelOtgCIBqKl91hNPluRhuhOY7fyTqIOdzKbYLxcurRiWpF1+si8pSgqzZkXiT0VCV+B3Qnt9Z448Zi3Z3mY5oT+D/Vi3pjCgKNj8URs7argT5TOFnTid/oo9FASXv4/VFAdeoXlxPbAHT+lSbTx/3qqR1h79AVyOmsombtBIet4+1v5FgdS8MhdQgGleLdNrjFuBp//zvvOR/E9C6vT2q8PZLV9NiYnKMhP3BVQPtLzY0DTHsqqMAdPuB2nV7c33hzCZu35fvDfbQ++LQ5RxFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9eGLPo+gwK3BhKaizmVCd0S9rUlfgoSwrRoS3Fp+T4I=; b=gPx7p0jZc2buJUsB/CLwCV1g83OCjcW8KNjZBV63MkrmIVf1Xu4y6n3ih2ubqbnIGNiZMqga1VCxiVcTqz8IAT96z0BjwBeUqiL1HaNIn/mlv3W+0pXDr0PYgd+AMerl5dAwPYVCo/qj8nDi52MqpQte6kIjo5G3gqFQ+VTqxerdrCpvkFccpvaj27HDjLk6gS4ZUOolml8dprT/EIR+uspRfCrn2bix7ro3UqLo6WQXIR1tZE5mgDVanszi36WQqHhcSbwHeUGaAGWsJ9PJLHXvxEeGApCUBSes096x5/EuHeW3D4igvPokqpp4MehdHk0EKvxkw42up2ML4QTOlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9eGLPo+gwK3BhKaizmVCd0S9rUlfgoSwrRoS3Fp+T4I=; b=m5ISxwiaV5sbgUZkoB6UlxSNDV+RMApA1rjW5ZXRjDtse7IejRoXJd3agkEtxw9tKUJc3fQYLBj4swLxKdcZMNXzSKuM7hM0BJwqIubB0qwOwVCOY7dix1UUEnlLqm2EnsD5rwKJwtYXD6kRcWmVV2Z7l2mmYhhoZfBTvQbkccTteiX7VX3nSounH16arU5bi3RWm6yBW+F5RqOJBk8jSIlVfo8MG/8GfdVYitp14w+/98AJAY4QewdfNWibLRfmtum85V1EgqPULVL4xHg5ovy4Awpb+pjx5+4GPzmlu0kIsiqYoVdVPIiFK+woRgbGJn6cFPvfR7gFQCloVZXPaw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by TY0PR06MB5626.apcprd06.prod.outlook.com (2603:1096:400:31f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.19; Fri, 10 Mar 2023 06:07:51 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::daf6:5ebb:a93f:1869]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::daf6:5ebb:a93f:1869%9]) with mapi id 15.20.6178.019; Fri, 10 Mar 2023 06:07:51 +0000 From: Yangtao Li <frank.li@vivo.com> To: tytso@mit.edu, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, Yangtao Li <frank.li@vivo.com> Subject: [PATCH] ext4: convert to DIV_ROUND_UP() in mpage_process_page_bufs() Date: Fri, 10 Mar 2023 14:07:34 +0800 Message-Id: <20230310060734.8780-1-frank.li@vivo.com> X-Mailer: git-send-email 2.35.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI1PR02CA0036.apcprd02.prod.outlook.com (2603:1096:4:1f6::20) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|TY0PR06MB5626:EE_ X-MS-Office365-Filtering-Correlation-Id: 464afa8c-926a-4758-2ac8-08db212dc77a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7XiKwmYCuqzcQ0Oq28gGfyJmAbYvdZJNZaysfFJcMOoI2/I9Dv/i7UFO1HRSE2iBeNyWFzfHC+12p7ocDazumpcsW9MVxhTTpFl5TrQAv8ag+lIHAmmToxxlsbfKUESuEe6MZaC6XtHkctCbS0EAj3h2BDFor/bQHIvhgTwUrmPEC47NX0hEftuCWjO5hHMdmURvj4Vpxg7/ix3nemCF6vJ8UXrBQTgfGcaa2NVCzm6I9KJb4eRvvkEMkKRKQlsHZJ9bxdkz33Y0mA/wYLZB9PTbjfC/kcdvjUiXyoxeq1V3kXUjGWfd+gAb3dm/VXxu2ZmS87gQFFpL0OYL/MfNIIcKfry/zZnO/6iLVgMmQdBqs0DhdF3bSJ9TawCkIM8wM35H1+mEJmbN0rjTjO5sMTQgPLJ86ijOx6kQ6JRN1QJVVqgj8J2ue4djrNyErIKn5mVmoDE/Lx3qoWDi4MOguuy7iJoxwRiGqobPZh6my9SwLds8xfz6L0AMXCrBkB361rHtqKAcFgDu6LASrLk4jz037AMRtAEr7pwo2SPJyEiPv9Dgt01Bk1aWnZjEgdf/cjb7nKtr9AXSpjziwCwMxlIELiD+sCo9ytgqqCaD7oz2DasxnvX5ZQlHe9Avg+vlCZZ/I4C8WFLqQlvPajEIsukbUzSJkQIU+io6x9wBtD+YihZU/sO5mFBendZFeY4UxdwVVaZPCWHJH1P5fvtKGQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEZPR06MB5269.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(376002)(39860400002)(346002)(366004)(136003)(396003)(451199018)(36756003)(83380400001)(38100700002)(38350700002)(316002)(478600001)(6486002)(2616005)(107886003)(6506007)(186003)(6512007)(1076003)(26005)(6666004)(5660300002)(4744005)(66556008)(52116002)(66476007)(8936002)(41300700001)(66946007)(4326008)(2906002)(86362001)(8676002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: c7eFvsk47V0yB1J+8pu77pTm/7FlPLrT5jlv7tDNeOSmKLUfjiXjgNcSPeXtuq2aDJQIIJ2Q90McgJeAMG3VUIcxczNYhg6KUndekADm3hj5Vz1b9XS37lVs7TJ2/KEM5YfyxN9MiRlHxLfJqPxjI3dKMFpQ5pKd/W73B3J+opDJsE6CajAGXzBLEGBdlSuBSuDqkvY0BtCr97ZSpYM9gA2HttnX+qX48NYMW8QhyZcJtdUPI/HshSkZyIK5gp+AukeQP2smnBxqLat7ZX6e3ikwRIE0ltnGekytk+doHdiQH09X/aOCCbB/bQrRD5nwb3Nka9EvA7Y5c33WxnZgZjZ8Qvzw5mSpeQQJAhJJ+E3gpAJ30XYEabMvyxI7z+S/R5LDwkufuseDazdQu6ANLgAJvD2mK/5GVqpYuXV8Z3dYosGwXGUCfBiQpY/hl15p7t6ROPV0QNU58WlFz/+xY/K2DP8FZ1Ve7v8iu16YvX4cwxeEX3UnnA7hM3L0imwEI6trKIfYAbEJsGGnXb7cmS+R0yBgK1K6X926+hY1uhwjPi8oO0qVi4ZoGErAEL9xCjBa95P8+As282gIbmGFiwG0Sj8Ho+jBKrk5zmwwMVVZc3HtlIkFg8X/NtHOfluhoB8Ro9Dh2CcihZZQd1RO7Ho+o1ayZRDOWZuNAq0J6FZwnpWqOvqOzBMuIqiyo00IJUpUohKHDRPKqgPtpx84OV1hBnc7vezLcmXs0RM2hDuHIh219W8FcmuCTIqsoZ6xv2e8V6l3JB9BrH+nkxDeT3Ys4RFWCX04uAnt0YlXrUUCMO1BYhenkEdK/+FLgYFsdVLITOtvSWIAD43wIx4+OxPj6imPSJtloHT50mFyt6i2XvFCrVug0oMp004xWAxT20tAva8ay87LN0WwY/mYrA2QoEbLsZBxFbK+Hg/4ae80ixvno3M+3OyKoIuWh+f3LRlH/n9dKvV+5MqHFit5JDgHMlx5bfIsZ5oe1Q037ZeSekTMxg6AKauE7476q3rZurK8I35TzR1yu9fE+ORVWxjaueBLGoofVXinAwvCbiAS+l76oP6x2PieLWzEzjP+ayS2CqXOw3RJ1sHEUIeeRjbvvMjOdFTESYlnrrrkxrrxEWtXdM1D7Sa8NSyJWJxfJ+eGKx8sam4w8AGpnVfbbSyWLgR8j6fuzIZhNPEJm0W0geyiA22QDcFUdo7zDPwQ5+MuIQ9E80g40IYJQ1G6jrGs4HLVaV3WVhkfycgN2zS8lzzw8atGCdMPA7Cw5K5/5dsJmxDdtDidJiLpZ69tBTFQvSkMwTJSZ4RFAKnnhq5zMVNOJosCtetbObp0n6RuoBp8Z+uLXajOWS9lo0CzuuvmcAZ9b1o+xtqDLtXL9kbpyHDd6l4CGPMr4YHeUDAhmqKOIrL2WLXXmW2D6kz0e7ClZ06PVX4euxXWlDn4eKa6o3w3Gw7OwFEz7nOjUp5Rm2+7uxjv35lUdhMQoKyvCOLagc65qbUhmcVh+DA8AqgAf6jFbzGxJb0i0gzUIfTTQvK3P01/Itfu98RT9K1vc1gFBZ2EraapQqAx5bppmDlTLhrRMMQ0Or4aoQqiiEET X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 464afa8c-926a-4758-2ac8-08db212dc77a X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2023 06:07:50.9161 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6Ezy5yvX3+Nws4iu/brKLoI1lHV2K1yRe9Sq53Jnrb/d5gmd+dlYrlpt3LFycGd8NcI8M7hXag1RiW7H9u4u4w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY0PR06MB5626 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759960662191570471?= X-GMAIL-MSGID: =?utf-8?q?1759960662191570471?= |
Series |
ext4: convert to DIV_ROUND_UP() in mpage_process_page_bufs()
|
|
Commit Message
李扬韬
March 10, 2023, 6:07 a.m. UTC
Just for better readability, no code logic change.
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
fs/ext4/inode.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
Comments
On Fri, Mar 10, 2023 at 02:07:34PM +0800, Yangtao Li wrote: > Just for better readability, no code logic change. > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > --- > fs/ext4/inode.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > index d251d705c276..d121cde74522 100644 > --- a/fs/ext4/inode.c > +++ b/fs/ext4/inode.c > @@ -2218,8 +2218,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, > { > struct inode *inode = mpd->inode; > int err; > - ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1) > - >> inode->i_blkbits; > + ext4_lblk_t blocks = DIV_ROUND_UP(i_size_read(inode), i_blocksize(inode)); > Please don't do this. This makes the code compile down to a division, which is far less efficient. I've verified this by checking the assembly generated. - Eric
> Please don't do this. This makes the code compile down to a division, which is > far less efficient. I've verified this by checking the assembly generated. How much is the performance impact? So should the following be modified as shift operations as well? fs/erofs/namei.c:92: int head = 0, back = DIV_ROUND_UP(dir->i_size, EROFS_BLKSIZ) - 1; fs/erofs/zmap.c:252: const unsigned int totalidx = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); fs/erofs/decompressor.c:14:#define LZ4_MAX_DISTANCE_PAGES (DIV_ROUND_UP(LZ4_DISTANCE_MAX, PAGE_SIZE) + 1) fs/erofs/decompressor.c:56: DIV_ROUND_UP(distance, PAGE_SIZE) + 1 : fs/erofs/decompressor.c:70: unsigned long bounced[DIV_ROUND_UP(LZ4_MAX_DISTANCE_PAGES, fs/erofs/data.c:84: nblocks = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); Thx, Yangtao
On 2023/3/10 14:27, Yangtao Li wrote: >> Please don't do this. This makes the code compile down to a division, which is >> far less efficient. I've verified this by checking the assembly generated. > > How much is the performance impact? So should the following be modified as shift operations as well? > > fs/erofs/namei.c:92: int head = 0, back = DIV_ROUND_UP(dir->i_size, EROFS_BLKSIZ) - 1; > fs/erofs/zmap.c:252: const unsigned int totalidx = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); > fs/erofs/decompressor.c:14:#define LZ4_MAX_DISTANCE_PAGES (DIV_ROUND_UP(LZ4_DISTANCE_MAX, PAGE_SIZE) + 1) > fs/erofs/decompressor.c:56: DIV_ROUND_UP(distance, PAGE_SIZE) + 1 : > fs/erofs/decompressor.c:70: unsigned long bounced[DIV_ROUND_UP(LZ4_MAX_DISTANCE_PAGES, > fs/erofs/data.c:84: nblocks = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); Please stop taking EROFS as example on ext4 patches and they will all be changed due to subpage support. > > Thx, > Yangtao
On 2023/3/10 14:35, Gao Xiang wrote: > > > On 2023/3/10 14:27, Yangtao Li wrote: >>> Please don't do this. This makes the code compile down to a division, which is >>> far less efficient. I've verified this by checking the assembly generated. >> >> How much is the performance impact? So should the following be modified as shift operations as well? >> >> fs/erofs/namei.c:92: int head = 0, back = DIV_ROUND_UP(dir->i_size, EROFS_BLKSIZ) - 1; >> fs/erofs/zmap.c:252: const unsigned int totalidx = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); >> fs/erofs/decompressor.c:14:#define LZ4_MAX_DISTANCE_PAGES (DIV_ROUND_UP(LZ4_DISTANCE_MAX, PAGE_SIZE) + 1) >> fs/erofs/decompressor.c:56: DIV_ROUND_UP(distance, PAGE_SIZE) + 1 : >> fs/erofs/decompressor.c:70: unsigned long bounced[DIV_ROUND_UP(LZ4_MAX_DISTANCE_PAGES, >> fs/erofs/data.c:84: nblocks = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); > > Please stop taking EROFS as example on ext4 patches > and they will all be changed due to subpage support. Here EROFS_BLKSIZ == PAGE_SIZE is a constant, so no difference to use shift or division. > >> >> Thx, >> Yangtao
On Thu, Mar 09, 2023 at 10:17:16PM -0800, Eric Biggers wrote: > On Fri, Mar 10, 2023 at 02:07:34PM +0800, Yangtao Li wrote: > > Just for better readability, no code logic change. > > > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > > --- > > fs/ext4/inode.c | 3 +-- > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > > index d251d705c276..d121cde74522 100644 > > --- a/fs/ext4/inode.c > > +++ b/fs/ext4/inode.c > > @@ -2218,8 +2218,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, > > { > > struct inode *inode = mpd->inode; > > int err; > > - ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1) > > - >> inode->i_blkbits; > > + ext4_lblk_t blocks = DIV_ROUND_UP(i_size_read(inode), i_blocksize(inode)); > > > > Please don't do this. This makes the code compile down to a division, which is > far less efficient. I've verified this by checking the assembly generated. Which compiler is doing that?
On Fri, Mar 10, 2023 at 02:27:38PM +0800, Yangtao Li wrote: > > Please don't do this. This makes the code compile down to a division, which is > > far less efficient. I've verified this by checking the assembly generated. > > How much is the performance impact? So should the following be modified as shift operations as well? > > fs/erofs/namei.c:92: int head = 0, back = DIV_ROUND_UP(dir->i_size, EROFS_BLKSIZ) - 1; > fs/erofs/zmap.c:252: const unsigned int totalidx = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); > fs/erofs/decompressor.c:14:#define LZ4_MAX_DISTANCE_PAGES (DIV_ROUND_UP(LZ4_DISTANCE_MAX, PAGE_SIZE) + 1) > fs/erofs/decompressor.c:56: DIV_ROUND_UP(distance, PAGE_SIZE) + 1 : > fs/erofs/decompressor.c:70: unsigned long bounced[DIV_ROUND_UP(LZ4_MAX_DISTANCE_PAGES, > fs/erofs/data.c:84: nblocks = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ); > No, compilers can handle division by a power-of-2 constant just fine. It's just division by a non-constant that is inefficient. - Eric
On Fri, Mar 10, 2023 at 06:37:29AM +0000, Al Viro wrote: > On Thu, Mar 09, 2023 at 10:17:16PM -0800, Eric Biggers wrote: > > On Fri, Mar 10, 2023 at 02:07:34PM +0800, Yangtao Li wrote: > > > Just for better readability, no code logic change. > > > > > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > > > --- > > > fs/ext4/inode.c | 3 +-- > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > > > index d251d705c276..d121cde74522 100644 > > > --- a/fs/ext4/inode.c > > > +++ b/fs/ext4/inode.c > > > @@ -2218,8 +2218,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, > > > { > > > struct inode *inode = mpd->inode; > > > int err; > > > - ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1) > > > - >> inode->i_blkbits; > > > + ext4_lblk_t blocks = DIV_ROUND_UP(i_size_read(inode), i_blocksize(inode)); > > > > > > > Please don't do this. This makes the code compile down to a division, which is > > far less efficient. I've verified this by checking the assembly generated. > > Which compiler is doing that? While we are at it, replace return (1 << node->i_blkbits); with return (1u << node->i_blkbits); and see if that changes the things.
On Fri, Mar 10, 2023 at 06:37:29AM +0000, Al Viro wrote: > On Thu, Mar 09, 2023 at 10:17:16PM -0800, Eric Biggers wrote: > > On Fri, Mar 10, 2023 at 02:07:34PM +0800, Yangtao Li wrote: > > > Just for better readability, no code logic change. > > > > > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > > > --- > > > fs/ext4/inode.c | 3 +-- > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > > > index d251d705c276..d121cde74522 100644 > > > --- a/fs/ext4/inode.c > > > +++ b/fs/ext4/inode.c > > > @@ -2218,8 +2218,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, > > > { > > > struct inode *inode = mpd->inode; > > > int err; > > > - ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1) > > > - >> inode->i_blkbits; > > > + ext4_lblk_t blocks = DIV_ROUND_UP(i_size_read(inode), i_blocksize(inode)); > > > > > > > Please don't do this. This makes the code compile down to a division, which is > > far less efficient. I've verified this by checking the assembly generated. > > Which compiler is doing that? $ gcc --version gcc (GCC) 12.2.1 20230201 i_blocksize(inode) is not a constant, so this should not be particularly surprising. One might hope that a / (1 << b) would be optimized into a >> b, but that doesn't seem to happen. - Eric
On Thu, Mar 09, 2023 at 10:43:55PM -0800, Eric Biggers wrote: > On Fri, Mar 10, 2023 at 06:37:29AM +0000, Al Viro wrote: > > On Thu, Mar 09, 2023 at 10:17:16PM -0800, Eric Biggers wrote: > > > On Fri, Mar 10, 2023 at 02:07:34PM +0800, Yangtao Li wrote: > > > > Just for better readability, no code logic change. > > > > > > > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > > > > --- > > > > fs/ext4/inode.c | 3 +-- > > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > > > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > > > > index d251d705c276..d121cde74522 100644 > > > > --- a/fs/ext4/inode.c > > > > +++ b/fs/ext4/inode.c > > > > @@ -2218,8 +2218,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, > > > > { > > > > struct inode *inode = mpd->inode; > > > > int err; > > > > - ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1) > > > > - >> inode->i_blkbits; > > > > + ext4_lblk_t blocks = DIV_ROUND_UP(i_size_read(inode), i_blocksize(inode)); > > > > > > > > > > Please don't do this. This makes the code compile down to a division, which is > > > far less efficient. I've verified this by checking the assembly generated. > > > > Which compiler is doing that? > > $ gcc --version > gcc (GCC) 12.2.1 20230201 > > i_blocksize(inode) is not a constant, so this should not be particularly > surprising. One might hope that a / (1 << b) would be optimized into a >> b, > but that doesn't seem to happen. It really ought to be a / (1u << b), though...
On Fri, Mar 10, 2023 at 06:46:12AM +0000, Al Viro wrote: > On Thu, Mar 09, 2023 at 10:43:55PM -0800, Eric Biggers wrote: > > On Fri, Mar 10, 2023 at 06:37:29AM +0000, Al Viro wrote: > > > On Thu, Mar 09, 2023 at 10:17:16PM -0800, Eric Biggers wrote: > > > > On Fri, Mar 10, 2023 at 02:07:34PM +0800, Yangtao Li wrote: > > > > > Just for better readability, no code logic change. > > > > > > > > > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > > > > > --- > > > > > fs/ext4/inode.c | 3 +-- > > > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > > > > > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > > > > > index d251d705c276..d121cde74522 100644 > > > > > --- a/fs/ext4/inode.c > > > > > +++ b/fs/ext4/inode.c > > > > > @@ -2218,8 +2218,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, > > > > > { > > > > > struct inode *inode = mpd->inode; > > > > > int err; > > > > > - ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1) > > > > > - >> inode->i_blkbits; > > > > > + ext4_lblk_t blocks = DIV_ROUND_UP(i_size_read(inode), i_blocksize(inode)); > > > > > > > > > > > > > Please don't do this. This makes the code compile down to a division, which is > > > > far less efficient. I've verified this by checking the assembly generated. > > > > > > Which compiler is doing that? > > > > $ gcc --version > > gcc (GCC) 12.2.1 20230201 > > > > i_blocksize(inode) is not a constant, so this should not be particularly > > surprising. One might hope that a / (1 << b) would be optimized into a >> b, > > but that doesn't seem to happen. > > It really ought to be a / (1u << b), though... Sure, that does better: uint64_t f(uint64_t a, int b) { return a / (1U << b); } gcc: 0000000000000000 <f>: 0: 48 89 f8 mov %rdi,%rax 3: 89 f1 mov %esi,%ecx 5: 48 d3 e8 shr %cl,%rax 8: c3 ret clang: 0000000000000000 <f>: 0: 89 f1 mov %esi,%ecx 2: 48 89 f8 mov %rdi,%rax 5: 48 d3 e8 shr %cl,%rax 8: c3 ret But with a signed dividend (which is the case here) it gets messed up: int64_t f(int64_t a, int b) { return a / (1U << b); } gcc: 0000000000000000 <f>: 0: 48 89 f8 mov %rdi,%rax 3: 89 f1 mov %esi,%ecx 5: bf 01 00 00 00 mov $0x1,%edi a: d3 e7 shl %cl,%edi c: 48 99 cqto e: 48 f7 ff idiv %rdi 11: c3 ret clang: 0000000000000000 <f>: 0: 89 f1 mov %esi,%ecx 2: be 01 00 00 00 mov $0x1,%esi 7: d3 e6 shl %cl,%esi 9: 48 89 f8 mov %rdi,%rax c: 48 89 f9 mov %rdi,%rcx f: 48 c1 e9 20 shr $0x20,%rcx 13: 74 06 je 1b <f+0x1b> 15: 48 99 cqto 17: 48 f7 fe idiv %rsi 1a: c3 ret 1b: 31 d2 xor %edx,%edx 1d: f7 f6 div %esi 1f: c3 ret
On Thu, Mar 09, 2023 at 10:54:38PM -0800, Eric Biggers wrote: > On Fri, Mar 10, 2023 at 06:46:12AM +0000, Al Viro wrote: > > On Thu, Mar 09, 2023 at 10:43:55PM -0800, Eric Biggers wrote: > > > On Fri, Mar 10, 2023 at 06:37:29AM +0000, Al Viro wrote: > > > > On Thu, Mar 09, 2023 at 10:17:16PM -0800, Eric Biggers wrote: > > > > > On Fri, Mar 10, 2023 at 02:07:34PM +0800, Yangtao Li wrote: > > > > > > Just for better readability, no code logic change. > > > > > > > > > > > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > > > > > > --- > > > > > > fs/ext4/inode.c | 3 +-- > > > > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > > > > > > > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > > > > > > index d251d705c276..d121cde74522 100644 > > > > > > --- a/fs/ext4/inode.c > > > > > > +++ b/fs/ext4/inode.c > > > > > > @@ -2218,8 +2218,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, > > > > > > { > > > > > > struct inode *inode = mpd->inode; > > > > > > int err; > > > > > > - ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1) > > > > > > - >> inode->i_blkbits; > > > > > > + ext4_lblk_t blocks = DIV_ROUND_UP(i_size_read(inode), i_blocksize(inode)); > > > > > > > > > > > > > > > > Please don't do this. This makes the code compile down to a division, which is > > > > > far less efficient. I've verified this by checking the assembly generated. > > > > > > > > Which compiler is doing that? > > > > > > $ gcc --version > > > gcc (GCC) 12.2.1 20230201 > > > > > > i_blocksize(inode) is not a constant, so this should not be particularly > > > surprising. One might hope that a / (1 << b) would be optimized into a >> b, > > > but that doesn't seem to happen. > > > > It really ought to be a / (1u << b), though... > > Sure, that does better: > > uint64_t f(uint64_t a, int b) > { > return a / (1U << b); > } > > gcc: > 0000000000000000 <f>: > 0: 48 89 f8 mov %rdi,%rax > 3: 89 f1 mov %esi,%ecx > 5: 48 d3 e8 shr %cl,%rax > 8: c3 ret > > clang: > 0000000000000000 <f>: > 0: 89 f1 mov %esi,%ecx > 2: 48 89 f8 mov %rdi,%rax > 5: 48 d3 e8 shr %cl,%rax > 8: c3 ret > > But with a signed dividend (which is the case here) it gets messed up: > > int64_t f(int64_t a, int b) > { > return a / (1U << b); > } *ow* And i_size_read() is long long ;-/ Right.
On Fri, Mar 10, 2023 at 07:05:27AM +0000, Al Viro wrote: > On Thu, Mar 09, 2023 at 10:54:38PM -0800, Eric Biggers wrote: > > On Fri, Mar 10, 2023 at 06:46:12AM +0000, Al Viro wrote: > > > On Thu, Mar 09, 2023 at 10:43:55PM -0800, Eric Biggers wrote: > > > > On Fri, Mar 10, 2023 at 06:37:29AM +0000, Al Viro wrote: > > > > > On Thu, Mar 09, 2023 at 10:17:16PM -0800, Eric Biggers wrote: > > > > > > On Fri, Mar 10, 2023 at 02:07:34PM +0800, Yangtao Li wrote: > > > > > > > Just for better readability, no code logic change. > > > > > > > > > > > > > > Signed-off-by: Yangtao Li <frank.li@vivo.com> > > > > > > > --- > > > > > > > fs/ext4/inode.c | 3 +-- > > > > > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > > > > > > > > > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > > > > > > > index d251d705c276..d121cde74522 100644 > > > > > > > --- a/fs/ext4/inode.c > > > > > > > +++ b/fs/ext4/inode.c > > > > > > > @@ -2218,8 +2218,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, > > > > > > > { > > > > > > > struct inode *inode = mpd->inode; > > > > > > > int err; > > > > > > > - ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1) > > > > > > > - >> inode->i_blkbits; > > > > > > > + ext4_lblk_t blocks = DIV_ROUND_UP(i_size_read(inode), i_blocksize(inode)); > > > > > > > > > > > > > > > > > > > Please don't do this. This makes the code compile down to a division, which is > > > > > > far less efficient. I've verified this by checking the assembly generated. > > > > > > > > > > Which compiler is doing that? > > > > > > > > $ gcc --version > > > > gcc (GCC) 12.2.1 20230201 > > > > > > > > i_blocksize(inode) is not a constant, so this should not be particularly > > > > surprising. One might hope that a / (1 << b) would be optimized into a >> b, > > > > but that doesn't seem to happen. > > > > > > It really ought to be a / (1u << b), though... > > > > Sure, that does better: > > > > uint64_t f(uint64_t a, int b) > > { > > return a / (1U << b); > > } > > > > gcc: > > 0000000000000000 <f>: > > 0: 48 89 f8 mov %rdi,%rax > > 3: 89 f1 mov %esi,%ecx > > 5: 48 d3 e8 shr %cl,%rax > > 8: c3 ret > > > > clang: > > 0000000000000000 <f>: > > 0: 89 f1 mov %esi,%ecx > > 2: 48 89 f8 mov %rdi,%rax > > 5: 48 d3 e8 shr %cl,%rax > > 8: c3 ret > > > > But with a signed dividend (which is the case here) it gets messed up: > > > > int64_t f(int64_t a, int b) > > { > > return a / (1U << b); > > } > > *ow* > > And i_size_read() is long long ;-/ Right. Out of curiosity (and that's already too brittle for practical use) - does DIV_ROUND_UP_ULL() do any better on full example?
Hi Yangtao,
I love your patch! Yet something to improve:
[auto build test ERROR on tytso-ext4/dev]
[also build test ERROR on linus/master v6.3-rc1 next-20230310]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yangtao-Li/ext4-convert-to-DIV_ROUND_UP-in-mpage_process_page_bufs/20230310-140903
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
patch link: https://lore.kernel.org/r/20230310060734.8780-1-frank.li%40vivo.com
patch subject: [PATCH] ext4: convert to DIV_ROUND_UP() in mpage_process_page_bufs()
config: i386-defconfig (https://download.01.org/0day-ci/archive/20230311/202303110211.LXeNm5uw-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/f4d2db5f59592a5688be6e4d2d3dd6f3f94d4f96
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yangtao-Li/ext4-convert-to-DIV_ROUND_UP-in-mpage_process_page_bufs/20230310-140903
git checkout f4d2db5f59592a5688be6e4d2d3dd6f3f94d4f96
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303110211.LXeNm5uw-lkp@intel.com/
All errors (new ones prefixed by >>):
ld: fs/ext4/inode.o: in function `mpage_process_page_bufs':
>> inode.c:(.text+0xbda): undefined reference to `__divdi3'
Hi Yangtao,
I love your patch! Yet something to improve:
[auto build test ERROR on tytso-ext4/dev]
[also build test ERROR on linus/master v6.3-rc1 next-20230310]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yangtao-Li/ext4-convert-to-DIV_ROUND_UP-in-mpage_process_page_bufs/20230310-140903
base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
patch link: https://lore.kernel.org/r/20230310060734.8780-1-frank.li%40vivo.com
patch subject: [PATCH] ext4: convert to DIV_ROUND_UP() in mpage_process_page_bufs()
config: i386-debian-10.3 (https://download.01.org/0day-ci/archive/20230311/202303110358.NxL6UI32-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/f4d2db5f59592a5688be6e4d2d3dd6f3f94d4f96
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yangtao-Li/ext4-convert-to-DIV_ROUND_UP-in-mpage_process_page_bufs/20230310-140903
git checkout f4d2db5f59592a5688be6e4d2d3dd6f3f94d4f96
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303110358.NxL6UI32-lkp@intel.com/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "__divdi3" [fs/ext4/ext4.ko] undefined!
On Fri, Mar 10, 2023 at 07:12:31AM +0000, Al Viro wrote: > > Out of curiosity (and that's already too brittle for practical use) - > does DIV_ROUND_UP_ULL() do any better on full example? 'DIV_ROUND_UP_ULL(i_size_read(inode), i_blocksize(inode))' works properly with clang but not gcc. If i_blocksize() is changed to do '1U << inode->i_blkbits' instead of '1 << inode->i_blkbits', it works with gcc too. - Eric
On Fri, Mar 10, 2023 at 02:07:34PM +0800, Yangtao Li wrote: > Just for better readability, no code logic change. All aside from the arguments over performance, I'm not at *all* convinced by the "it's more readable" argument. So yeah, let's not. We have i_blkbits for a reason, and it's because shifting right is just simpler and easier. BTW, doing a 64-bit division on a 32-bit platforms causes compile failures, which was the cause of the test bot complaint: ld: fs/ext4/inode.o: in function `mpage_process_page_bufs': >> inode.c:(.text+0xbda): undefined reference to `__divdi3' On 32-bit platforms --- i386 in particular --- the 64-bit division results in an out-of-line call to a helper function that is not supplied in the kernel compilation environment, so not only is it slower, it Just Doesn't Work. - Ted
... > On 32-bit platforms --- i386 in particular --- the 64-bit division > results in an out-of-line call to a helper function that is not > supplied in the kernel compilation environment, so not only is it > slower, it Just Doesn't Work. Even on some 64-bit systems a 64bit divide can be significantly slower than a 32-bit divide - even with the same arguments. IIRC Intel x86-64 a 64-bit divide (128-bit dividend) is about twice the clocks of a 32-bit one. On AMD cpu they are much the same. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d251d705c276..d121cde74522 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2218,8 +2218,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, { struct inode *inode = mpd->inode; int err; - ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1) - >> inode->i_blkbits; + ext4_lblk_t blocks = DIV_ROUND_UP(i_size_read(inode), i_blocksize(inode)); if (ext4_verity_in_progress(inode)) blocks = EXT_MAX_BLOCKS;