Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp320520rdb; Thu, 30 Nov 2023 05:54:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEF8WvGS1M9B6jDkqP8nUV8wwLOnJl6BcDBQd7Tpnsd+EsbDBoaS538kx9v6QD/xwNHMbe X-Received: by 2002:a05:6870:2888:b0:1fa:1c34:98e9 with SMTP id gy8-20020a056870288800b001fa1c3498e9mr24340004oab.30.1701352455202; Thu, 30 Nov 2023 05:54:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701352455; cv=none; d=google.com; s=arc-20160816; b=fyRKEZ1QLij5E1RbiLabGbDmx0OWFrmgrS8CMcCjzuJ/dGRRgsve/6cfY/MnmWjaCq IDUhzMAZAGFN4/b5uITl/MIx6799n9Lnbfe5TowV2sBelby1HwK6xaofRbQg0c8aPTqb dIurGjVdUe1SVYmsbaLhA2RPqsmlTYa3XwQSjXXRfHf/VGzgNjNaTxMMGVa1cMh9zu2O lRyvKM0TFKqrQfnEsitPtXBEEOMQZqYDdaFuc/QvWqvdOHuduBocIZwpiFzX+rPs7DXf JQTbr8nWFAS0ljzUDnkfPFLjJQWV/c6ni3O1SpaJNr5i1vTenc/Ei2rCrnNnQLdhZTth 73fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GEbojckG87Zkl5i2XvaH4H480xxiwFF4r2OKYlabK54=; fh=o0c9oRQqGcw+lX35liWyz4mGWjDo/97N/+E1+y9wprk=; b=ahiX/t0KqKjiX/foUipPhjxtp+iWv/MlYVthgi998kuAmSJygRE932Lz+3OdXTGlOo gaVIM71TnLYZORmhWU/PptnHU1fYPdVs3N3SsNWQjQ6jAdRyC82sbdn1OUXUZNeeizhA 9pT3IhLZvBgJiEV5lHh5FAfUvDfRmieUIGKHs+ujfO0sEBO7+7V5Srx4vYkLIMG6vKCC j5kCCwW6U3xAt3x1Iu+IJFEi3GXkKhn4EFCn5iHKBl74Bm0DbopaivCMdwRojeHcb5uB OEaU54HFLj98C5P9PFcb3mHr++HzPc/kuDDpuE44JDT8VO47l1yfruVWvgtlh5KMubTi V1vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=bNsP7bGw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id g23-20020a63fa57000000b005c218df2842si1320806pgk.900.2023.11.30.05.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:54:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=bNsP7bGw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8FFD1826EE89; Thu, 30 Nov 2023 05:54:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345868AbjK3Nx4 (ORCPT + 99 others); Thu, 30 Nov 2023 08:53:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345800AbjK3Nxj (ORCPT ); Thu, 30 Nov 2023 08:53:39 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C273173E; Thu, 30 Nov 2023 05:53:40 -0800 (PST) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AUDnWpb001333; Thu, 30 Nov 2023 13:53:35 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=GEbojckG87Zkl5i2XvaH4H480xxiwFF4r2OKYlabK54=; b=bNsP7bGwRrqT00WlGk/iKOOA7N4n/iq5dA7a85ARavnDOx+4XDUHbnxWyWJLW6k99Z3r CGgG4d5lpUY0H2eQj8oulrRYCCawLy7oc6FdnMvvt7SuAqoFlO9ZE+ZckdC2Pu9APDA+ fZIyJqW3wXuZvt1lHmpctR1PX/eTluy9SYOsVDAJZQBi5cr8dsV1D0S3qptmq14rIGo2 PLjbhX4nLoxLctKffsZGhRwlhs4rlpY2H8+sY/C3Ch/a/AUfWhU5iyZxhvbZ+sHkBiLR JBRmqy1HIGtnCXeKEkJ2zOY74PoNnNcr4J0QErquGSI/iMu47Iu3r/VZ6B7lnJik2e0s yg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3upu2vh3g4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Nov 2023 13:53:34 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3AUDowTQ006599; Thu, 30 Nov 2023 13:53:34 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3upu2vh3fh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Nov 2023 13:53:34 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3AUDnBJU008115; Thu, 30 Nov 2023 13:53:33 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3ukvrkx98c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 30 Nov 2023 13:53:33 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3AUDrVvQ18416372 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Nov 2023 13:53:31 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E89C22004B; Thu, 30 Nov 2023 13:53:30 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5E8CD20043; Thu, 30 Nov 2023 13:53:28 +0000 (GMT) Received: from li-bb2b2a4c-3307-11b2-a85c-8fa5c3a69313.ibm.com.com (unknown [9.43.76.38]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 30 Nov 2023 13:53:28 +0000 (GMT) From: Ojaswin Mujoo To: linux-ext4@vger.kernel.org, "Theodore Ts'o" Cc: Ritesh Harjani , linux-kernel@vger.kernel.org, "Darrick J . Wong" , linux-block@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, John Garry , dchinner@redhat.com Subject: [RFC 2/7] ext4: Factor out size and start prediction from ext4_mb_normalize_request() Date: Thu, 30 Nov 2023 19:23:11 +0530 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: qy_SkSW57mW-hjhbyF5qADthnI7ePZDv X-Proofpoint-ORIG-GUID: p6EWJrk5DgzIlF1RQ43yQLDbmbht6XtD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-30_12,2023-11-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 mlxlogscore=984 adultscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2311300102 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 30 Nov 2023 05:54:11 -0800 (PST) As a part of trimming down the size of ext4_mb_normalize_request(), factor out the logic to predict normalized start and size to a separate function ext4_mb_pa_predict_size(). This is no functional change in this patch. Signed-off-by: Ojaswin Mujoo --- fs/ext4/mballoc.c | 95 ++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 39 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 0b0aff458efd..3eb7b639d36e 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4394,6 +4394,58 @@ ext4_mb_pa_adjust_overlap(struct ext4_allocation_context *ac, *end = new_end; } +static void ext4_mb_pa_predict_size(struct ext4_allocation_context *ac, + loff_t *start, loff_t *size) +{ + struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); + loff_t new_size = *size; + loff_t new_start = *start; + int bsbits, max; + + bsbits = ac->ac_sb->s_blocksize_bits; + /* max size of free chunks */ + max = 2 << bsbits; + +#define NRL_CHECK_SIZE(req, size, max, chunk_size) \ + (req <= (size) || max <= (chunk_size)) + + if (new_size <= 16 * 1024) { + new_size = 16 * 1024; + } else if (new_size <= 32 * 1024) { + new_size = 32 * 1024; + } else if (new_size <= 64 * 1024) { + new_size = 64 * 1024; + } else if (new_size <= 128 * 1024) { + new_size = 128 * 1024; + } else if (new_size <= 256 * 1024) { + new_size = 256 * 1024; + } else if (new_size <= 512 * 1024) { + new_size = 512 * 1024; + } else if (new_size <= 1024 * 1024) { + new_size = 1024 * 1024; + } else if (NRL_CHECK_SIZE(new_size, 4 * 1024 * 1024, max, 2 * 1024)) { + new_start = ((loff_t)ac->ac_o_ex.fe_logical >> + (21 - bsbits)) << 21; + new_size = 2 * 1024 * 1024; + } else if (NRL_CHECK_SIZE(new_size, 8 * 1024 * 1024, max, 4 * 1024)) { + new_start = ((loff_t)ac->ac_o_ex.fe_logical >> + (22 - bsbits)) << 22; + new_size = 4 * 1024 * 1024; + } else if (NRL_CHECK_SIZE(EXT4_C2B(sbi, ac->ac_o_ex.fe_len), + (8<<20)>>bsbits, max, 8 * 1024)) { + new_start = ((loff_t)ac->ac_o_ex.fe_logical >> + (23 - bsbits)) << 23; + new_size = 8 * 1024 * 1024; + } else { + new_start = (loff_t) ac->ac_o_ex.fe_logical << bsbits; + new_size = (loff_t) EXT4_C2B(sbi, + ac->ac_o_ex.fe_len) << bsbits; + } + + *size = new_size; + *start = new_start; +} + /* * Normalization means making request better in terms of * size and alignment @@ -4404,7 +4456,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac, { struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); struct ext4_super_block *es = sbi->s_es; - int bsbits, max; + int bsbits; loff_t size, start_off, end; loff_t orig_size __maybe_unused; ext4_lblk_t start; @@ -4438,47 +4490,12 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac, size = i_size_read(ac->ac_inode); orig_size = size; - /* max size of free chunks */ - max = 2 << bsbits; - -#define NRL_CHECK_SIZE(req, size, max, chunk_size) \ - (req <= (size) || max <= (chunk_size)) - /* first, try to predict filesize */ /* XXX: should this table be tunable? */ start_off = 0; - if (size <= 16 * 1024) { - size = 16 * 1024; - } else if (size <= 32 * 1024) { - size = 32 * 1024; - } else if (size <= 64 * 1024) { - size = 64 * 1024; - } else if (size <= 128 * 1024) { - size = 128 * 1024; - } else if (size <= 256 * 1024) { - size = 256 * 1024; - } else if (size <= 512 * 1024) { - size = 512 * 1024; - } else if (size <= 1024 * 1024) { - size = 1024 * 1024; - } else if (NRL_CHECK_SIZE(size, 4 * 1024 * 1024, max, 2 * 1024)) { - start_off = ((loff_t)ac->ac_o_ex.fe_logical >> - (21 - bsbits)) << 21; - size = 2 * 1024 * 1024; - } else if (NRL_CHECK_SIZE(size, 8 * 1024 * 1024, max, 4 * 1024)) { - start_off = ((loff_t)ac->ac_o_ex.fe_logical >> - (22 - bsbits)) << 22; - size = 4 * 1024 * 1024; - } else if (NRL_CHECK_SIZE(EXT4_C2B(sbi, ac->ac_o_ex.fe_len), - (8<<20)>>bsbits, max, 8 * 1024)) { - start_off = ((loff_t)ac->ac_o_ex.fe_logical >> - (23 - bsbits)) << 23; - size = 8 * 1024 * 1024; - } else { - start_off = (loff_t) ac->ac_o_ex.fe_logical << bsbits; - size = (loff_t) EXT4_C2B(sbi, - ac->ac_o_ex.fe_len) << bsbits; - } + + ext4_mb_pa_predict_size(ac, &start_off, &size); + size = size >> bsbits; start = start_off >> bsbits; -- 2.39.3