Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2637560ybk; Tue, 12 May 2020 04:33:58 -0700 (PDT) X-Google-Smtp-Source: APiQypIGLt40cAoXMy5hY7Tb8J31Fu2GwZt9TatCA+Ru/amWhqRmO4vtNAfqQNjboNyJ7ULDhxKg X-Received: by 2002:a50:e002:: with SMTP id e2mr18032459edl.179.1589283238790; Tue, 12 May 2020 04:33:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589283238; cv=none; d=google.com; s=arc-20160816; b=yOGAXj6Qb+62+EeOLBV3iguGWFoJCmNWKzrG36ixT/26hGhwpRpslK94SIp9zmWgq7 YiE5zvTpdLkWAtEGHFPNrkZH3ba1SntSg2/oxDozRZYeMaKHgftEAHGDgTdHJ+I+c6zQ QvDZ4+h30ETrx6pM9SH0R4ZgkZe7V3slAKdPpMQcrCy2q/2nVdc9opJESnXwcddIHoS7 Xhk56Gb4R1ZmsnqeJYe9gWw1S39HfD52pafpPCG7j4qWDKVD2EGoE9rOnM8bNxF1Efa1 mPIfgh0431r8Adl0reOWTRI+N6TtAGtZWmKwsR/jVnI7nhdHn5CPwRcx3pLRi8ImCUI4 NrTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject; bh=qbcoBuWcAx3rha4xwUCsRaLHDHQzKcLmHNP02B/t55o=; b=exd53wllGk3e8/bjtWRBcT5Sc9wJr6/SUW7r7qzR0PBJoUfY9bGwXG8hlwYsoWyT14 HuU2ITM6pOekZ50Ekt/hmWb5yMcfq5/ocGHSDWI6xE2KzBJPKsKx6NzwhEbV7kjGA6YU CVRmpYLlbBOLF+9e/QgqvI0cjn/U18ae/HvYceKCy9vdiO5wo7X01taugzRUFjdpoZs4 wnufsDO54TorSXbkQpo8+IkVxkTMGOPQ5ErkhABU8c9qx2me/R6ANCORSRZk9iUoScdX 8ZkhnVTmNT8E4XoXzR5lM05DXvEJcX04A9G9hYp8j1oDhUgZYijdARCCZ0EMlT4IpNoQ mq1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b44si5236281edf.469.2020.05.12.04.33.05; Tue, 12 May 2020 04:33:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729349AbgELLdD (ORCPT + 99 others); Tue, 12 May 2020 07:33:03 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:16362 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726187AbgELLdD (ORCPT ); Tue, 12 May 2020 07:33:03 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04CBX0FZ114575; Tue, 12 May 2020 07:33:00 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 30ws2f8d2y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 May 2020 07:33:00 -0400 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 04CBOfnx062260; Tue, 12 May 2020 07:32:19 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 30ws2f8d21-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 May 2020 07:32:19 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 04CBPMta005751; Tue, 12 May 2020 11:32:17 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03ams.nl.ibm.com with ESMTP id 30wm55pbn8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 12 May 2020 11:32:17 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 04CBWFd856557718 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 May 2020 11:32:15 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 007954C04A; Tue, 12 May 2020 11:32:15 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 309FC4C046; Tue, 12 May 2020 11:32:14 +0000 (GMT) Received: from localhost.localdomain (unknown [9.79.181.98]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 12 May 2020 11:32:13 +0000 (GMT) Subject: Re: [PATCH] ext4: rework map struct instantiation in ext4_ext_map_blocks() To: Eric Whitney , linux-ext4@vger.kernel.org Cc: tytso@mit.edu References: <20200510155805.18808-1-enwlinux@gmail.com> From: Ritesh Harjani Date: Tue, 12 May 2020 17:02:13 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20200510155805.18808-1-enwlinux@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Message-Id: <20200512113214.309FC4C046@d06av22.portsmouth.uk.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.676 definitions=2020-05-12_03:2020-05-11,2020-05-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 mlxlogscore=999 bulkscore=0 clxscore=1015 impostorscore=0 adultscore=0 phishscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2005120082 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On 5/10/20 9:28 PM, Eric Whitney wrote: > The path performing block allocations in ext4_ext_map_blocks() contains > code trimming the length of a new extent that is repeated later > in the function. This code is both redundant and unnecessary as the > exact length of the new extent has already been calculated. Rewrite the > instantiation of the map struct in this case to use the available > values, avoiding the overhead of unnecessary conversions and improving > clarity. Add another map struct instantiation tailored specifically to > the separate case for an existing written extent. Remove an old comment > that no longer appears applicable to the current code. > > Signed-off-by: Eric Whitney Yes, the previous code around looks to be confusing. One thing which I also checked was that, when we insert this new extent into the tree (via ext4_ext_insert_extent()) and even if this extent could be merged with a nearby extent, the length or pblock of this extent is not modified for the caller. So again doing such below calculations (line 4250 - 4254) were redundant and it's better that this patch got rid of it. This patch hence looks logically correct to me. 4250 /* previous routine could use block we allocated */ 4251 newblock = ext4_ext_pblock(&newex); 4252 allocated = ext4_ext_get_actual_len(&newex); 4253 if (allocated > map->m_len) 4254 allocated = map->m_len; Feel free to add: Reviewed-by: Ritesh Harjani > --- > fs/ext4/extents.c | 50 +++++++++++++++++++++++------------------------ > 1 file changed, 25 insertions(+), 25 deletions(-) > > diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c > index f2b577b315a0..c01a204ce60b 100644 > --- a/fs/ext4/extents.c > +++ b/fs/ext4/extents.c > @@ -4024,7 +4024,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, > struct ext4_ext_path *path = NULL; > struct ext4_extent newex, *ex, *ex2; > struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); > - ext4_fsblk_t newblock = 0; > + ext4_fsblk_t newblock = 0, pblk; > int err = 0, depth, ret; > unsigned int allocated = 0, offset = 0; > unsigned int allocated_clusters = 0; > @@ -4040,7 +4040,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, > if (IS_ERR(path)) { > err = PTR_ERR(path); > path = NULL; > - goto out2; > + goto out; > } > > depth = ext_depth(inode); > @@ -4056,7 +4056,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, > (unsigned long) map->m_lblk, depth, > path[depth].p_block); > err = -EFSCORRUPTED; > - goto out2; > + goto out; > } > > ex = path[depth].p_ext; > @@ -4090,8 +4090,14 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, > (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) { > err = convert_initialized_extent(handle, > inode, map, &path, &allocated); > - goto out2; > + goto out; > } else if (!ext4_ext_is_unwritten(ex)) { > + map->m_flags |= EXT4_MAP_MAPPED; > + map->m_pblk = newblock; > + if (allocated > map->m_len) > + allocated = map->m_len; > + map->m_len = allocated; > + ext4_ext_show_leaf(inode, path); > goto out; > } > > @@ -4102,7 +4108,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, > err = ret; > else > allocated = ret; > - goto out2; > + goto out; > } > } > > @@ -4127,7 +4133,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, > map->m_pblk = 0; > map->m_len = min_t(unsigned int, map->m_len, hole_len); > > - goto out2; > + goto out; > } > > /* > @@ -4151,12 +4157,12 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, > ar.lleft = map->m_lblk; > err = ext4_ext_search_left(inode, path, &ar.lleft, &ar.pleft); > if (err) > - goto out2; > + goto out; > ar.lright = map->m_lblk; > ex2 = NULL; > err = ext4_ext_search_right(inode, path, &ar.lright, &ar.pright, &ex2); > if (err) > - goto out2; > + goto out; > > /* Check if the extent after searching to the right implies a > * cluster we can use. */ > @@ -4217,7 +4223,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, > ar.flags |= EXT4_MB_USE_RESERVED; > newblock = ext4_mb_new_blocks(handle, &ar, &err); > if (!newblock) > - goto out2; > + goto out; > ext_debug("allocate new block: goal %llu, found %llu/%u\n", > ar.goal, newblock, allocated); > allocated_clusters = ar.len; > @@ -4227,7 +4233,8 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, > > got_allocated_blocks: > /* try to insert new extent into found leaf and return */ > - ext4_ext_store_pblock(&newex, newblock + offset); > + pblk = newblock + offset; > + ext4_ext_store_pblock(&newex, pblk); > newex.ee_len = cpu_to_le16(ar.len); > /* Mark unwritten */ > if (flags & EXT4_GET_BLOCKS_UNWRIT_EXT) { > @@ -4252,16 +4259,9 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, > EXT4_C2B(sbi, allocated_clusters), > fb_flags); > } > - goto out2; > + goto out; > } > > - /* previous routine could use block we allocated */ > - newblock = ext4_ext_pblock(&newex); > - allocated = ext4_ext_get_actual_len(&newex); > - if (allocated > map->m_len) > - allocated = map->m_len; > - map->m_flags |= EXT4_MAP_NEW; > - > /* > * Reduce the reserved cluster count to reflect successful deferred > * allocation of delayed allocated clusters or direct allocation of > @@ -4307,14 +4307,14 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, > ext4_update_inode_fsync_trans(handle, inode, 1); > else > ext4_update_inode_fsync_trans(handle, inode, 0); > -out: > - if (allocated > map->m_len) > - allocated = map->m_len; > + > + map->m_flags |= (EXT4_MAP_NEW | EXT4_MAP_MAPPED); > + map->m_pblk = pblk; > + map->m_len = ar.len; > + allocated = map->m_len; > ext4_ext_show_leaf(inode, path); > - map->m_flags |= EXT4_MAP_MAPPED; > - map->m_pblk = newblock; > - map->m_len = allocated; > -out2: > + > +out: > ext4_ext_drop_refs(path); > kfree(path); >