Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1145196rwi; Fri, 14 Oct 2022 13:40:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7hKms7XchL0qzIf3nGDUpFQGtBJXndJS4VIHIE5p7GW4dRNYmMeRNefT+K6cKa0XocDinp X-Received: by 2002:aa7:9212:0:b0:562:b5f6:f7d7 with SMTP id 18-20020aa79212000000b00562b5f6f7d7mr7289565pfo.70.1665780008817; Fri, 14 Oct 2022 13:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665780008; cv=none; d=google.com; s=arc-20160816; b=bRk8VrD2tGn9bUQb75FdNzlVk7YnMygy930dFpIgzEbJq3Vqs655/vygoN6F9OldGQ 3GI0eaRsio4l+0LtEPuQGlfa50g+ZyHrKd+JbJ2En38WpYVTYDzU/NosPw30Rp7bxt/X lWwFpUUA3Y9dPYcEfbLz544PxhaSr6BjO+IQe38+PzWQ5HOoEJRXKZJZ0scO+CHsClD+ S0Fx9p/DPrCvUWz7ZmQ0WPDWyppn68alt68gRfw2ZOHyGY7UmnqKEYKALtWtgOLBHwTt Prlg1tK1N07m7xhJSD0D+xzLSbMv/19E80HAEtQZwhw2PusJ6cMop+71LtKDmb/gUzyX TEXA== 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=fXVINSNClWyBxx0uD0rSFTQaLRZ/zPD90U9yvTX0edQ=; b=C0abeXpQU3typBatuZss7nHlE0yzkMFxmPStTsjre7owBRwB104ttzE6nplMN9XLgM rgrmm4BsTIRlb2UWOYvh5ONJF3WLMqS2VAwuNZY0btH4z5xcK2NOPvU2lp4UNu3wVGw9 vYaywWSW+kaOEsmvP5tmAYoPEWCJuyi7QQoroGthgAcs3NMuEFVGTDNjUPvjMX1k6C+B F5MSHcZeQsn0yHPUiwaWiXCkD1kZ2zMsSsQqO4IWoDK5vgLaRUSE2iDhVjF1Hfziu8OL K/bFo7MYAFWBvvqgbfm51cb1ACOEf7gKqBfGt2cUZWZECmzojiDOMiFrsho8ElQTaQQy WGkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=J75kUbi6; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h191-20020a6383c8000000b0046ade103856si3592624pge.308.2022.10.14.13.39.47; Fri, 14 Oct 2022 13:40:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@ibm.com header.s=pp1 header.b=J75kUbi6; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231486AbiJNUhG (ORCPT + 99 others); Fri, 14 Oct 2022 16:37:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231485AbiJNUgw (ORCPT ); Fri, 14 Oct 2022 16:36:52 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59F3BDBBDC; Fri, 14 Oct 2022 13:36:51 -0700 (PDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29EIktff000521; Fri, 14 Oct 2022 20:36:46 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=fXVINSNClWyBxx0uD0rSFTQaLRZ/zPD90U9yvTX0edQ=; b=J75kUbi6R+gxKfQGKo3x0ouWfP0tczMGy+cmpBdlYqqqS6JCXcXK0X70IpM9OirOEX98 hnUtUDiAlv7Lplc4kTO9hfTuiPDn5IFaPrcbyJzD8jzuBlo2kdBudhYvzLgq1qHZZISd 2RUkyONn2M/LQTpiaLNtYvHYwI87/djQw+DRJEeFch4g90VMalN2N0LACMSP8SW+Hyzk QTD/bWRkgEt+lG2J3c0dVHgMbf3BJfujTXPo5Q7A6iccSn1o8gz3teBDQNthgxuKyYGr nE8atcLrQ52xtOAit8WyL8b2JUnsXX+1DICNw3KpMTuf3iZ3lNEBvrH/hCKKvXyfc8be 5A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k7bb1xved-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Oct 2022 20:36:46 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29EJLBse026203; Fri, 14 Oct 2022 20:36:45 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 3k7bb1xvdj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Oct 2022 20:36:45 +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 29EKahFL016746; Fri, 14 Oct 2022 20:36:43 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06ams.nl.ibm.com with ESMTP id 3k30fjhws2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Oct 2022 20:36:42 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29EKVo4U47579610 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 14 Oct 2022 20:31:50 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D11734203F; Fri, 14 Oct 2022 20:36:40 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 80E6942041; Fri, 14 Oct 2022 20:36:38 +0000 (GMT) Received: from li-bb2b2a4c-3307-11b2-a85c-8fa5c3a69313.ibm.com (unknown [9.43.122.214]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 14 Oct 2022 20:36:38 +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 , rookxu , Ritesh Harjani Subject: [PATCH v2 2/8] ext4: Refactor code related to freeing PAs Date: Sat, 15 Oct 2022 02:06:24 +0530 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 4QHAYL48USobKgW8ok9PDBaPLlVWe4jG X-Proofpoint-ORIG-GUID: xwZEyGmWgZQk8Yq39LkyMT1TbXvr00hA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-14_11,2022-10-14_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 adultscore=0 clxscore=1015 impostorscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 suspectscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210140112 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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: X-Mailing-List: linux-ext4@vger.kernel.org This patch makes the following changes: * Rename ext4_mb_pa_free to ext4_mb_pa_put_free to better reflect its purpose * Add new ext4_mb_pa_free() which only handles freeing * Refactor ext4_mb_pa_callback() to use ext4_mb_pa_free() There are no functional changes in this patch Signed-off-by: Ojaswin Mujoo Reviewed-by: Ritesh Harjani (IBM) Reviewed-by: Jan Kara --- fs/ext4/mballoc.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 6fbddabab64f..45cb92510e5c 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4530,16 +4530,22 @@ static void ext4_mb_mark_pa_deleted(struct super_block *sb, } } -static void ext4_mb_pa_callback(struct rcu_head *head) +static inline void ext4_mb_pa_free(struct ext4_prealloc_space *pa) { - struct ext4_prealloc_space *pa; - pa = container_of(head, struct ext4_prealloc_space, u.pa_rcu); - + BUG_ON(!pa); BUG_ON(atomic_read(&pa->pa_count)); BUG_ON(pa->pa_deleted == 0); kmem_cache_free(ext4_pspace_cachep, pa); } +static void ext4_mb_pa_callback(struct rcu_head *head) +{ + struct ext4_prealloc_space *pa; + + pa = container_of(head, struct ext4_prealloc_space, u.pa_rcu); + ext4_mb_pa_free(pa); +} + /* * drops a reference to preallocated space descriptor * if this was the last reference and the space is consumed @@ -5066,14 +5072,20 @@ static int ext4_mb_pa_alloc(struct ext4_allocation_context *ac) return 0; } -static void ext4_mb_pa_free(struct ext4_allocation_context *ac) +static void ext4_mb_pa_put_free(struct ext4_allocation_context *ac) { struct ext4_prealloc_space *pa = ac->ac_pa; BUG_ON(!pa); ac->ac_pa = NULL; WARN_ON(!atomic_dec_and_test(&pa->pa_count)); - kmem_cache_free(ext4_pspace_cachep, pa); + /* + * current function is only called due to an error or due to + * len of found blocks < len of requested blocks hence the PA has not + * been added to grp->bb_prealloc_list. So we don't need to lock it + */ + pa->pa_deleted = 1; + ext4_mb_pa_free(pa); } #ifdef CONFIG_EXT4_DEBUG @@ -5622,13 +5634,13 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, * So we have to free this pa here itself. */ if (*errp) { - ext4_mb_pa_free(ac); + ext4_mb_pa_put_free(ac); ext4_discard_allocated_blocks(ac); goto errout; } if (ac->ac_status == AC_STATUS_FOUND && ac->ac_o_ex.fe_len >= ac->ac_f_ex.fe_len) - ext4_mb_pa_free(ac); + ext4_mb_pa_put_free(ac); } if (likely(ac->ac_status == AC_STATUS_FOUND)) { *errp = ext4_mb_mark_diskspace_used(ac, handle, reserv_clstrs); @@ -5647,7 +5659,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, * If block allocation fails then the pa allocated above * needs to be freed here itself. */ - ext4_mb_pa_free(ac); + ext4_mb_pa_put_free(ac); *errp = -ENOSPC; } -- 2.31.1