From patchwork Fri Mar 17 07:15:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 71112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp196598wrt; Fri, 17 Mar 2023 00:32:57 -0700 (PDT) X-Google-Smtp-Source: AK7set8tIKn432Rr2QEe1bmSr+k9QUdLefcAra2Mc+Yvd+QmF5UTQW1di7wvG8U8bFgc94+Mp+JX X-Received: by 2002:a17:903:514:b0:19e:b5d3:170d with SMTP id jn20-20020a170903051400b0019eb5d3170dmr6004894plb.0.1679038376858; Fri, 17 Mar 2023 00:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679038376; cv=none; d=google.com; s=arc-20160816; b=zLcxxwlKseTCIBpKN86V03VwZwrjr11KxZ2J5/jrq8BvMj6INRHGxJk2g3EdXx/rbN qp0kU+Ce8dzdttmJIWXeN41whwz7AaHjn71pw1Pmyd4azoorfb10hJRc1MdOdPEHJ6me TPy4F/ClDpJBFfULBj9JX705TBad66Syru4BfS4WoiU98+dLrHY12dGAJmYN9mfddT9D cubti0SVlH1RBdXwA7NPClSVRjjo0ownPgSKQ+M8wwOtMctSbUt30+bTwnH0dP/T3HfI Q/7ATdsVmHHtAevSSg9OvazpTVLmZpr7t8Wd9e+oh7mGhN7xnPvJKWfSAvkyGpLdHwIH ReZA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=KShndDmtpL/wghNsEWsMIclWE+/Ioe4uetwa8XAxyPI=; b=HFbhjaiumUtW9laLWpdOXs/UJKkD1YK2OeQJBD92HtJBv+z8V8K3TR72gG7+lqPwCF BRzx83zppw59klvLi8r2Vd0fMue3X68JNT5Flutak38fPjeUFUc7PPnMjdrx+RmkB1/f 5hU+Mnk5DSrEsxUJyR6FAf4lvQr9q9dVhCE0/7xAwygIpxY9UsqcBPu9NdMenZOI2FtV +JuaTrVs8wo9QVKeGbSDXXyoem2OYBlaqLFSlhse8qya8FVj9gD0RTrbNqkpY74L2vuY sW5W3EoBIb/fCiePRhInK/1ex98kYf0OBkbZuBk+lhazByH/29cLD0h+eWAVqo3M/t21 NAFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XiSV7Xe+; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a170902e54600b0019fe9a63cf2si1745871plf.609.2023.03.17.00.32.44; Fri, 17 Mar 2023 00:32:56 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=XiSV7Xe+; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230290AbjCQHQJ (ORCPT + 99 others); Fri, 17 Mar 2023 03:16:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230182AbjCQHQH (ORCPT ); Fri, 17 Mar 2023 03:16:07 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 850AF10CD; Fri, 17 Mar 2023 00:16:02 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id z21so16809239edb.4; Fri, 17 Mar 2023 00:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679037361; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KShndDmtpL/wghNsEWsMIclWE+/Ioe4uetwa8XAxyPI=; b=XiSV7Xe+j4vAxn8Wn4s4HU1BPZR7kJx3q/rQBuzCQwnmSdrOu9xRPQuKrmRBH4cLCL KGgGVXCXRSCwoIjqKs3+JX+kLFft3tK1u0CNFBcx0hrgCN2VLx8nutygse61czoRwx60 Yr3FOjsEdDu2qv/SrKqGepBb6tdPnXvPpPid4Y4KRZvdfH/yNDjcyGDCvwQl11CK+Hpc QkcJRYb3LPv1A+PAZEN35erFcLIeH5WrWoDIY0GQ5fGOH/MHhz/H9jXlVjPT4DBassN7 LYj3b8Cw6apyNBXUXPxv4P2ekzd6pe5n0IQlG6j8mA9Qrt4iBXeMJBvSXW0G7IfcZGLU 69Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679037361; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KShndDmtpL/wghNsEWsMIclWE+/Ioe4uetwa8XAxyPI=; b=x3PtkVDHznsiLizYHMXW/U5x0aTCsIfh1QIX1sY9BQ74zfjs2SSZpysO0a0MhtGRk9 FpwEMVLgnnO+FzMKwDjzWwwRQ+cGXkwwuxnNTzk7ob9JxQD53eQA167ptS//Vmt8HYuw ONfe2Z3SIE9i6T/oP4bfmwfQcE00zH03+gv+7OdEaK1ipIEOj8Hmjrrq7EcjDKDd3rUO dH+vDyYp4xT7OR3vzTUQfemBKKhLDkyYJt557grvl9hjzAq0ZDnKQgM8/A7cEnLkZ8SD MEfSYxXuu9I84WYgy2jBK/x8QTLMfvh7I8OV+/aIY/NuHQz3KU2MmGYYuOq50fGFXl1A 16UQ== X-Gm-Message-State: AO0yUKWDN1i3R/fsy00F2w5yvR4ILpU93PJ7Zq/CDrXZG4n8KFccC29V 5wFE3l/pJeufIxIK5l7jTns= X-Received: by 2002:a05:6402:44b:b0:4fa:eccd:9849 with SMTP id p11-20020a056402044b00b004faeccd9849mr2011896edw.9.1679037360872; Fri, 17 Mar 2023 00:16:00 -0700 (PDT) Received: from pc638.lan ([155.137.26.201]) by smtp.gmail.com with ESMTPSA id i23-20020a508717000000b004af6c5f1805sm642321edb.52.2023.03.17.00.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 00:16:00 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: Theodore Ts'o , Joel Fernandes Cc: RCU , "Paul E . McKenney" , LKML , Uladzislau Rezki , Oleksiy Avramchenko , Steven Rostedt , Frederic Weisbecker , linux-ext4@vger.kernel.org, Lukas Czerner , Andreas Dilger Subject: [PATCH 1/1] ext4: Replace ext4_kvfree_array_rcu() by kvfree_rcu_mightsleep() Date: Fri, 17 Mar 2023 08:15:58 +0100 Message-Id: <20230317071558.335645-1-urezki@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760599345126763075?= X-GMAIL-MSGID: =?utf-8?q?1760599345126763075?= The ext4_kvfree_array_rcu() function was introduced in order to release some memory after a grace period during resizing of a partition. An object that is freed does not contain any rcu_head filed. To do so, it requires to allocate some extra memory for a special structure that has an rcu_head filed and pointer one where a freed memory is attached. Finally call_rcu() API is invoked. Since we have a single argument of kvfree_rcu() API, we can easily replace all that tricky code by one single call that does the same but in more efficient way. Cc: linux-ext4@vger.kernel.org Cc: Lukas Czerner Cc: Andreas Dilger Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Paul E. McKenney --- fs/ext4/ext4.h | 1 - fs/ext4/mballoc.c | 2 +- fs/ext4/resize.c | 31 ++----------------------------- fs/ext4/super.c | 2 +- 4 files changed, 4 insertions(+), 32 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 140e1eb300d1..e43d1a2d175e 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3057,7 +3057,6 @@ extern int ext4_generic_delete_entry(struct inode *dir, extern bool ext4_empty_dir(struct inode *inode); /* resize.c */ -extern void ext4_kvfree_array_rcu(void *to_free); extern int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input); extern int ext4_group_extend(struct super_block *sb, diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 5b2ae37a8b80..96b4e3317640 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -3055,7 +3055,7 @@ int ext4_mb_alloc_groupinfo(struct super_block *sb, ext4_group_t ngroups) rcu_assign_pointer(sbi->s_group_info, new_groupinfo); sbi->s_group_info_size = size / sizeof(*sbi->s_group_info); if (old_groupinfo) - ext4_kvfree_array_rcu(old_groupinfo); + kvfree_rcu_mightsleep(old_groupinfo); ext4_debug("allocated s_groupinfo array for %d meta_bg's\n", sbi->s_group_info_size); return 0; diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index 6b91443d6bf3..330b81f36e10 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -18,33 +18,6 @@ #include "ext4_jbd2.h" -struct ext4_rcu_ptr { - struct rcu_head rcu; - void *ptr; -}; - -static void ext4_rcu_ptr_callback(struct rcu_head *head) -{ - struct ext4_rcu_ptr *ptr; - - ptr = container_of(head, struct ext4_rcu_ptr, rcu); - kvfree(ptr->ptr); - kfree(ptr); -} - -void ext4_kvfree_array_rcu(void *to_free) -{ - struct ext4_rcu_ptr *ptr = kzalloc(sizeof(*ptr), GFP_KERNEL); - - if (ptr) { - ptr->ptr = to_free; - call_rcu(&ptr->rcu, ext4_rcu_ptr_callback); - return; - } - synchronize_rcu(); - kvfree(to_free); -} - int ext4_resize_begin(struct super_block *sb) { struct ext4_sb_info *sbi = EXT4_SB(sb); @@ -931,7 +904,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode, n_group_desc[gdb_num] = gdb_bh; rcu_assign_pointer(EXT4_SB(sb)->s_group_desc, n_group_desc); EXT4_SB(sb)->s_gdb_count++; - ext4_kvfree_array_rcu(o_group_desc); + kvfree_rcu_mightsleep(o_group_desc); lock_buffer(EXT4_SB(sb)->s_sbh); le16_add_cpu(&es->s_reserved_gdt_blocks, -1); @@ -994,7 +967,7 @@ static int add_new_gdb_meta_bg(struct super_block *sb, rcu_assign_pointer(EXT4_SB(sb)->s_group_desc, n_group_desc); EXT4_SB(sb)->s_gdb_count++; - ext4_kvfree_array_rcu(o_group_desc); + kvfree_rcu_mightsleep(o_group_desc); return err; } diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 87aa23d047c9..34d802848d6d 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3108,7 +3108,7 @@ int ext4_alloc_flex_bg_array(struct super_block *sb, ext4_group_t ngroup) rcu_assign_pointer(sbi->s_flex_groups, new_groups); sbi->s_flex_groups_allocated = size; if (old_groups) - ext4_kvfree_array_rcu(old_groups); + kvfree_rcu_mightsleep(old_groups); return 0; }