From nobody Thu Apr 2 11:46:16 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35DBDC07E9D for ; Mon, 26 Sep 2022 07:07:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233912AbiIZHHL (ORCPT ); Mon, 26 Sep 2022 03:07:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233795AbiIZHG5 (ORCPT ); Mon, 26 Sep 2022 03:06:57 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8BD231345; Mon, 26 Sep 2022 00:06:52 -0700 (PDT) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28Q4ZOvs022149; Mon, 26 Sep 2022 07:06:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=WCaGnJR/nP95v1L/TPEC5EtqwHoBOZ14pf7HGb7yqys=; b=H6agPsyW1QmxpfTl1ksR/qFER1/tJsKFduq/+N7ilh1B3npHSvT4RTSh5BkDhoRabvg6 yUUpHg9DZk5YLr+Z6SPb3ujZTjnGiE80GkINmh5/nmlQ4rFvYr4aH/SXYsDX5zBlwIfO tnuWoUiOSE6UufNU+Z7IaX5DMtNKZ0GnmU+BiVSGOsaRJgB6K/+lZ1cULHKnl+KSsG6/ dM/2VseG2MvMULoN04JeYj/xvc3ZBDoeHu01WATOmOaB5gBLAEJMgHzH62LRH3/YmrB/ tJj6G5Z0dg5KwGO1sj43+0gvpYOrJ3dGva21LQV+HEQbxi+GzSo1aDLUDXmhtApIqYHD LA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jtb7bdabb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Sep 2022 07:06:48 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 28Q5QqPp014269; Mon, 26 Sep 2022 07:06:47 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jtb7bda9q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Sep 2022 07:06:47 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28Q75XEx014722; Mon, 26 Sep 2022 07:06:45 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma06ams.nl.ibm.com with ESMTP id 3jss5j21r1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Sep 2022 07:06:44 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28Q76g1r18350340 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Sep 2022 07:06:42 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8E1E711C04A; Mon, 26 Sep 2022 07:06:42 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B315E11C050; Mon, 26 Sep 2022 07:06:39 +0000 (GMT) Received: from li-bb2b2a4c-3307-11b2-a85c-8fa5c3a69313.ibm.com (unknown [9.43.30.221]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 26 Sep 2022 07:06:39 +0000 (GMT) From: Ojaswin Mujoo To: linux-ext4@vger.kernel.org, "Theodore Ts'o" Cc: Ritesh Harjani , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Dilger , Jan Kara , Ritesh Harjani Subject: [RFC v2 3/8] ext4: Refactor code in ext4_mb_normalize_request() and ext4_mb_use_preallocated() Date: Mon, 26 Sep 2022 12:34:54 +0530 Message-Id: <8ec3ed728f046495c39f01881b57ef12fdabeb2a.1664172580.git.ojaswin@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: _D04IJcON_a8YMcIGnavoA6QcsVoqi6n X-Proofpoint-GUID: _Ha7nZgbIEuKJg69tudfPim2erDf-GUD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-26_04,2022-09-22_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 mlxlogscore=999 bulkscore=0 clxscore=1015 malwarescore=0 spamscore=0 adultscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209260043 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Change some variable names to be more consistent and refactor some of the code to make it easier to read. There are no functional changes in this patch Signed-off-by: Ojaswin Mujoo Reviewed-by: Ritesh Harjani (IBM) --- fs/ext4/mballoc.c | 97 ++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 8be6f8765a6f..84950df709bb 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4000,7 +4000,8 @@ ext4_mb_normalize_request(struct ext4_allocation_cont= ext *ac, loff_t orig_size __maybe_unused; ext4_lblk_t start; struct ext4_inode_info *ei =3D EXT4_I(ac->ac_inode); - struct ext4_prealloc_space *pa; + struct ext4_prealloc_space *tmp_pa; + ext4_lblk_t tmp_pa_start, tmp_pa_end; =20 /* do normalize only data requests, metadata requests do not need preallocation */ @@ -4103,56 +4104,53 @@ ext4_mb_normalize_request(struct ext4_allocation_co= ntext *ac, =20 /* check we don't cross already preallocated blocks */ rcu_read_lock(); - list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) { - ext4_lblk_t pa_end; - - if (pa->pa_deleted) + list_for_each_entry_rcu(tmp_pa, &ei->i_prealloc_list, pa_inode_list) { + if (tmp_pa->pa_deleted) continue; - spin_lock(&pa->pa_lock); - if (pa->pa_deleted) { - spin_unlock(&pa->pa_lock); + spin_lock(&tmp_pa->pa_lock); + if (tmp_pa->pa_deleted) { + spin_unlock(&tmp_pa->pa_lock); continue; } =20 - pa_end =3D pa->pa_lstart + EXT4_C2B(EXT4_SB(ac->ac_sb), - pa->pa_len); + tmp_pa_start =3D tmp_pa->pa_lstart; + tmp_pa_end =3D tmp_pa->pa_lstart + EXT4_C2B(sbi, tmp_pa->pa_len); =20 /* PA must not overlap original request */ - BUG_ON(!(ac->ac_o_ex.fe_logical >=3D pa_end || - ac->ac_o_ex.fe_logical < pa->pa_lstart)); + BUG_ON(!(ac->ac_o_ex.fe_logical >=3D tmp_pa_end || + ac->ac_o_ex.fe_logical < tmp_pa_start)); =20 /* skip PAs this normalized request doesn't overlap with */ - if (pa->pa_lstart >=3D end || pa_end <=3D start) { - spin_unlock(&pa->pa_lock); + if (tmp_pa_start >=3D end || tmp_pa_end <=3D start) { + spin_unlock(&tmp_pa->pa_lock); continue; } - BUG_ON(pa->pa_lstart <=3D start && pa_end >=3D end); + BUG_ON(tmp_pa_start <=3D start && tmp_pa_end >=3D end); =20 /* adjust start or end to be adjacent to this pa */ - if (pa_end <=3D ac->ac_o_ex.fe_logical) { - BUG_ON(pa_end < start); - start =3D pa_end; - } else if (pa->pa_lstart > ac->ac_o_ex.fe_logical) { - BUG_ON(pa->pa_lstart > end); - end =3D pa->pa_lstart; + if (tmp_pa_end <=3D ac->ac_o_ex.fe_logical) { + BUG_ON(tmp_pa_end < start); + start =3D tmp_pa_end; + } else if (tmp_pa_start > ac->ac_o_ex.fe_logical) { + BUG_ON(tmp_pa_start > end); + end =3D tmp_pa_start; } - spin_unlock(&pa->pa_lock); + spin_unlock(&tmp_pa->pa_lock); } rcu_read_unlock(); size =3D end - start; =20 /* XXX: extra loop to check we really don't overlap preallocations */ rcu_read_lock(); - list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) { - ext4_lblk_t pa_end; + list_for_each_entry_rcu(tmp_pa, &ei->i_prealloc_list, pa_inode_list) { + spin_lock(&tmp_pa->pa_lock); + if (tmp_pa->pa_deleted =3D=3D 0) { + tmp_pa_start =3D tmp_pa->pa_lstart; + tmp_pa_end =3D tmp_pa->pa_lstart + EXT4_C2B(sbi, tmp_pa->pa_len); =20 - spin_lock(&pa->pa_lock); - if (pa->pa_deleted =3D=3D 0) { - pa_end =3D pa->pa_lstart + EXT4_C2B(EXT4_SB(ac->ac_sb), - pa->pa_len); - BUG_ON(!(start >=3D pa_end || end <=3D pa->pa_lstart)); + BUG_ON(!(start >=3D tmp_pa_end || end <=3D tmp_pa_start)); } - spin_unlock(&pa->pa_lock); + spin_unlock(&tmp_pa->pa_lock); } rcu_read_unlock(); =20 @@ -4362,7 +4360,8 @@ ext4_mb_use_preallocated(struct ext4_allocation_conte= xt *ac) int order, i; struct ext4_inode_info *ei =3D EXT4_I(ac->ac_inode); struct ext4_locality_group *lg; - struct ext4_prealloc_space *pa, *cpa =3D NULL; + struct ext4_prealloc_space *tmp_pa, *cpa =3D NULL; + ext4_lblk_t tmp_pa_start, tmp_pa_end; ext4_fsblk_t goal_block; =20 /* only data can be preallocated */ @@ -4371,18 +4370,20 @@ ext4_mb_use_preallocated(struct ext4_allocation_con= text *ac) =20 /* first, try per-file preallocation */ rcu_read_lock(); - list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) { + list_for_each_entry_rcu(tmp_pa, &ei->i_prealloc_list, pa_inode_list) { =20 /* all fields in this condition don't change, * so we can skip locking for them */ - if (ac->ac_o_ex.fe_logical < pa->pa_lstart || - ac->ac_o_ex.fe_logical >=3D (pa->pa_lstart + - EXT4_C2B(sbi, pa->pa_len))) + tmp_pa_start =3D tmp_pa->pa_lstart; + tmp_pa_end =3D tmp_pa->pa_lstart + EXT4_C2B(sbi, tmp_pa->pa_len); + + if (ac->ac_o_ex.fe_logical < tmp_pa_start || + ac->ac_o_ex.fe_logical >=3D tmp_pa_end) continue; =20 /* non-extent files can't have physical blocks past 2^32 */ if (!(ext4_test_inode_flag(ac->ac_inode, EXT4_INODE_EXTENTS)) && - (pa->pa_pstart + EXT4_C2B(sbi, pa->pa_len) > + (tmp_pa->pa_pstart + EXT4_C2B(sbi, tmp_pa->pa_len) > EXT4_MAX_BLOCK_FILE_PHYS)) { /* * Since PAs don't overlap, we won't find any @@ -4392,16 +4393,16 @@ ext4_mb_use_preallocated(struct ext4_allocation_con= text *ac) } =20 /* found preallocated blocks, use them */ - spin_lock(&pa->pa_lock); - if (pa->pa_deleted =3D=3D 0 && pa->pa_free) { - atomic_inc(&pa->pa_count); - ext4_mb_use_inode_pa(ac, pa); - spin_unlock(&pa->pa_lock); + spin_lock(&tmp_pa->pa_lock); + if (tmp_pa->pa_deleted =3D=3D 0 && tmp_pa->pa_free) { + atomic_inc(&tmp_pa->pa_count); + ext4_mb_use_inode_pa(ac, tmp_pa); + spin_unlock(&tmp_pa->pa_lock); ac->ac_criteria =3D 10; rcu_read_unlock(); return true; } - spin_unlock(&pa->pa_lock); + spin_unlock(&tmp_pa->pa_lock); } rcu_read_unlock(); =20 @@ -4425,16 +4426,16 @@ ext4_mb_use_preallocated(struct ext4_allocation_con= text *ac) */ for (i =3D order; i < PREALLOC_TB_SIZE; i++) { rcu_read_lock(); - list_for_each_entry_rcu(pa, &lg->lg_prealloc_list[i], + list_for_each_entry_rcu(tmp_pa, &lg->lg_prealloc_list[i], pa_inode_list) { - spin_lock(&pa->pa_lock); - if (pa->pa_deleted =3D=3D 0 && - pa->pa_free >=3D ac->ac_o_ex.fe_len) { + spin_lock(&tmp_pa->pa_lock); + if (tmp_pa->pa_deleted =3D=3D 0 && + tmp_pa->pa_free >=3D ac->ac_o_ex.fe_len) { =20 cpa =3D ext4_mb_check_group_pa(goal_block, - pa, cpa); + tmp_pa, cpa); } - spin_unlock(&pa->pa_lock); + spin_unlock(&tmp_pa->pa_lock); } rcu_read_unlock(); } --=20 2.31.1