Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp22114488rwd; Fri, 30 Jun 2023 04:11:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlEX1y6CUiA04YIU4ZujvfmsznZrYSQSEfpDasnpdA6YdT7V8jmh5p44HtG9/oylp+QfFIyv X-Received: by 2002:a17:90a:ea93:b0:262:fc8a:ecf with SMTP id h19-20020a17090aea9300b00262fc8a0ecfmr1778681pjz.27.1688123505889; Fri, 30 Jun 2023 04:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688123505; cv=none; d=google.com; s=arc-20160816; b=FxWxdDKrGh5ndWSl93kwJYRLdJsLauEH4UwzMGNIe0JdH+SL9s/JgmCHJ1/eyHPnyh 3twY86Wz3P24NgrHbT7D9eNzZ07JIx6iDTRdf0pnSMhzsbgqAaIBoYy4dyLx1cwdL7LS OroQrtGrgOULpl0c3Glp5nvgyzaSJnG50HN62eIpCVKOXxqKsJboqZGWhVeHuQ6kpZZx NFZ+M+3l+HoqJnRE4DIF48ezDk7i5Y44wd4dlBarLVAofJZobpbZh+aqmTpjmTlWgh7p 4PdP5wZnJi+TjezIozOIvGrTrsVFBWIqkkyY6gswjDo7A/ycnkjjOhWox+2/aSzLqP5U rvwQ== 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; bh=BQW1k4Z4xnbzql03yUHk5me5VvHoARrfMxfYfwbr6tw=; fh=fHzCyx2lgDg5rzxkd+fn4L1zIOfYfCj3lN8BN24cVWY=; b=FujwZJ1Ye+2AarYIEjX+W+iZWLYuntmYG3r7C41yQ0vj+eafufE7wUXWoUGJ1Mtb/+ RQJuO5p+g8nedy1EX9UZ9/d+1Rv+9Wqoo7LHM1D1tH0d3AyD5/fc4xIYpJqVb+m16KIS H1Pk6EksiIUpbd1O53MGZf0CCufuDvfnt1IeU8sWegnpQhv2uT2ahXBwOIc7EJsJaAvm Dx22Qe7cmAKpfhMl48ByTGzdWH//LpfvWO97BHz3r0rWfERks2/+o1ZtjZOOkkXfnagy zBtkLU08XULDZOBM4z2E/WsfMGMyPfUMNdJKUnSXn3O/BR741qrDznz/hoWYunYYmloq +Xaw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a17090ad34d00b0025ea380f868si14936299pjx.2.2023.06.30.04.11.09; Fri, 30 Jun 2023 04:11:45 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232613AbjF3LKx (ORCPT + 99 others); Fri, 30 Jun 2023 07:10:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232361AbjF3LKv (ORCPT ); Fri, 30 Jun 2023 07:10:51 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 693D8198E; Fri, 30 Jun 2023 04:10:50 -0700 (PDT) Received: from dggpeml500021.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Qst050Q3SzqV8f; Fri, 30 Jun 2023 19:10:29 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpeml500021.china.huawei.com (7.185.36.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 30 Jun 2023 19:10:48 +0800 From: Baokun Li To: CC: , , , , , , , Subject: [PATCH v3 5/5] quota: simplify drop_dquot_ref() Date: Fri, 30 Jun 2023 19:08:22 +0800 Message-ID: <20230630110822.3881712-6-libaokun1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230630110822.3881712-1-libaokun1@huawei.com> References: <20230630110822.3881712-1-libaokun1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500021.china.huawei.com (7.185.36.21) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 As Honza said, remove_inode_dquot_ref() currently does not release the last dquot reference but instead adds the dquot to tofree_head list. This is because dqput() can sleep while dropping of the last dquot reference (writing back the dquot and calling ->release_dquot()) and that must not happen under dq_list_lock. Now that dqput() queues the final dquot cleanup into a workqueue, remove_inode_dquot_ref() can call dqput() unconditionally and we can significantly simplify it. Here we open code the simplified code of remove_inode_dquot_ref() into remove_dquot_ref() and remove the function put_dquot_list() which is no longer used. Signed-off-by: Baokun Li --- V2->V3: Added changelog provided by Jan Kara (thanks Jan). Merge the patch that removed put_dquot_list() to the current patch. Open code Simplified remove_inode_dquot_ref() code to remove_dquot_ref(). fs/quota/dquot.c | 70 +++++++----------------------------------------- 1 file changed, 9 insertions(+), 61 deletions(-) diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index c7afe433d991..e8232242dd34 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -1072,59 +1072,7 @@ static int add_dquot_ref(struct super_block *sb, int type) return err; } -/* - * Remove references to dquots from inode and add dquot to list for freeing - * if we have the last reference to dquot - */ -static void remove_inode_dquot_ref(struct inode *inode, int type, - struct list_head *tofree_head) -{ - struct dquot **dquots = i_dquot(inode); - struct dquot *dquot = dquots[type]; - - if (!dquot) - return; - - dquots[type] = NULL; - if (list_empty(&dquot->dq_free)) { - /* - * The inode still has reference to dquot so it can't be in the - * free list - */ - spin_lock(&dq_list_lock); - list_add(&dquot->dq_free, tofree_head); - spin_unlock(&dq_list_lock); - } else { - /* - * Dquot is already in a list to put so we won't drop the last - * reference here. - */ - dqput(dquot); - } -} - -/* - * Free list of dquots - * Dquots are removed from inodes and no new references can be got so we are - * the only ones holding reference - */ -static void put_dquot_list(struct list_head *tofree_head) -{ - struct list_head *act_head; - struct dquot *dquot; - - act_head = tofree_head->next; - while (act_head != tofree_head) { - dquot = list_entry(act_head, struct dquot, dq_free); - act_head = act_head->next; - /* Remove dquot from the list so we won't have problems... */ - list_del_init(&dquot->dq_free); - dqput(dquot); - } -} - -static void remove_dquot_ref(struct super_block *sb, int type, - struct list_head *tofree_head) +static void remove_dquot_ref(struct super_block *sb, int type) { struct inode *inode; #ifdef CONFIG_QUOTA_DEBUG @@ -1141,11 +1089,16 @@ static void remove_dquot_ref(struct super_block *sb, int type, */ spin_lock(&dq_data_lock); if (!IS_NOQUOTA(inode)) { + struct dquot **dquots = i_dquot(inode); + struct dquot *dquot = dquots[type]; + #ifdef CONFIG_QUOTA_DEBUG if (unlikely(inode_get_rsv_space(inode) > 0)) reserved = 1; #endif - remove_inode_dquot_ref(inode, type, tofree_head); + dquots[type] = NULL; + if (dquot) + dqput(dquot); } spin_unlock(&dq_data_lock); } @@ -1162,13 +1115,8 @@ static void remove_dquot_ref(struct super_block *sb, int type, /* Gather all references from inodes and drop them */ static void drop_dquot_ref(struct super_block *sb, int type) { - LIST_HEAD(tofree_head); - - if (sb->dq_op) { - remove_dquot_ref(sb, type, &tofree_head); - synchronize_srcu(&dquot_srcu); - put_dquot_list(&tofree_head); - } + if (sb->dq_op) + remove_dquot_ref(sb, type); } static inline -- 2.31.1