From patchwork Thu Jan 19 06:36:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107454 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7EC13C6379F for ; Thu, 19 Jan 2023 06:36:51 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pIOXa-0001Sh-QT; Thu, 19 Jan 2023 06:36:49 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pIOXY-0001SS-4a for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=3Q1xLjahu5r3Hpi8KZaN6erKrrcckUykkiJeIuFGVEE=; b=IlUErF5i3b7jZi3XAcRuZ47I3B 42g12CLaQqhqwHGO8uChh8UOzdiNj82T+OikL3ZHqL/E08eJh74Qqvbl4y2+Lvp9wbTpR4LBbT7Wn PWsnvAkPGH6m8EjEo5Rf6zN2AKfu/Gr/+BMJ4+ISE0cjC2JmZpsLABzn10acGEfACGlQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=3Q1xLjahu5r3Hpi8KZaN6erKrrcckUykkiJeIuFGVEE=; b=OTLiXq4nvPxNTLlP1xV5mAQxqv heIgOB3ruDEjvIMjMVppWStsoUOKrCeTqvetqe2UZkFvzKkVKlqes7vrSOViQ7wNNeYUWoBygFw1F Kehp3P5t3kG+6fOolSZjVTRTQaRCvqN/gXlkErPIBWln+R2AFL/9/8+8T1mcxF9rFStQ=; Received: from bombadil.infradead.org ([198.137.202.133]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pIOXT-0001dS-40 for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=3Q1xLjahu5r3Hpi8KZaN6erKrrcckUykkiJeIuFGVEE=; b=d3DP1HJYKUhjmxH2khsCX1lzSb nYglgL/Luow7+mlgv4t+ID3WyUjWW9WIam85f66YeL15OSsO+J0ymB+slQIbcyGc/3LmvY/aYRZRd aH33+vPELLR9WQ/fNMYoAzLixuxhgN6DQqTmZb00SOWavugxADcDu/T8zmnBuK/cAF0AbVKJ7js3N gYXpRYnWEcfZh32rhGj4+WiRcQk1W+PcroHK6uclkU+1BzPrhAgLSR0GSpRhG20calAetf2vxQXLe aF1of7K1s+92MjOIKVvRtJ1NSXMqX7Qge+/iUw95vdn/jVnMJJezaR6Bs6dNXfUPNHZCJEiB7MhJf 5tSq7T2g==; Received: from [2001:4bb8:19a:2039:96fe:c1ec:dda2:41a3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIOXH-003kak-D6; Thu, 19 Jan 2023 06:36:32 +0000 From: Christoph Hellwig To: Jaegeuk Kim , Chao Yu Date: Thu, 19 Jan 2023 07:36:18 +0100 Message-Id: <20230119063625.466485-2-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119063625.466485-1-hch@lst.de> References: <20230119063625.466485-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Headers-End: 1pIOXT-0001dS-40 Subject: [f2fs-dev] [PATCH 1/8] f2fs: remove __add_sum_entry X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net This function just assigns a summary entry. This can be done entirely typesafe with an open code struct assignment that relies on array indexing. Signed-off-by: Christoph Hellwig Reviewed-by: Chao Yu --- fs/f2fs/segment.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 311243dda4cefa..ec6880213e8fa9 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2323,19 +2323,6 @@ bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr) return is_cp; } -/* - * This function should be resided under the curseg_mutex lock - */ -static void __add_sum_entry(struct f2fs_sb_info *sbi, int type, - struct f2fs_summary *sum) -{ - struct curseg_info *curseg = CURSEG_I(sbi, type); - void *addr = curseg->sum_blk; - - addr += curseg->next_blkoff * sizeof(struct f2fs_summary); - memcpy(addr, sum, sizeof(struct f2fs_summary)); -} - /* * Calculate the number of current summary pages for writing */ @@ -3262,13 +3249,7 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, f2fs_wait_discard_bio(sbi, *new_blkaddr); - /* - * __add_sum_entry should be resided under the curseg_mutex - * because, this function updates a summary entry in the - * current summary block. - */ - __add_sum_entry(sbi, type, sum); - + curseg->sum_blk->entries[curseg->next_blkoff] = *sum; __refresh_next_blkoff(sbi, curseg); stat_inc_block_count(sbi, curseg); @@ -3571,7 +3552,7 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, } curseg->next_blkoff = GET_BLKOFF_FROM_SEG0(sbi, new_blkaddr); - __add_sum_entry(sbi, type, sum); + curseg->sum_blk->entries[curseg->next_blkoff] = *sum; if (!recover_curseg || recover_newaddr) { if (!from_gc) From patchwork Thu Jan 19 06:36:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107451 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE02AC00A5A for ; Thu, 19 Jan 2023 06:36:50 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pIOXa-0001Sa-8U; Thu, 19 Jan 2023 06:36:48 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pIOXY-0001SN-0s for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=wI3Vffj/Y5/w+tGLiOXfNC6bTn/YLU1DHa2oGPTIuIQ=; b=WxVHh5/CfIv8zJv/j3PEoooibG bobyle4jOLg2f+HgNvEJjUTzoZLRYoViHm3gDjcQ4KCQVBjQwcALUnKn10RZiaOA2l/4F4RI/MQHL YTP69bVr09xhpTGD4c97qnlpzVJYPGl0EJtSbW4dP67AgqhaMFFHnzRIZ52PehLjMxkM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=wI3Vffj/Y5/w+tGLiOXfNC6bTn/YLU1DHa2oGPTIuIQ=; b=KDzaAAkMxRFwnY4uF45ykGpydn ckog4af0Hj0/mVuKiN1OgoqI+P4jX7hXVCbSGSkDhsCOOS7hPGhogl38F8FkFP43Qv/VRJ7yVJe9N xyB4tCecNm6q37F6UqfB6oV0q+h1oDLBi7MWmghBmXh59AKttsPwV5hQ9gVYJr+tiW6A=; Received: from bombadil.infradead.org ([198.137.202.133]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pIOXW-008fSH-0P for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=wI3Vffj/Y5/w+tGLiOXfNC6bTn/YLU1DHa2oGPTIuIQ=; b=1KyRE5AhwCYkbKr83BICy8/GOT KhN8x8857MD1XgWYJpfVavUrxnHBkIOaffuw13sCDl8VUBx4pv7ZDMf6ptflhn8dOV+4IBRnGEPJl 8VlUcHTQ7nrNcbXCcf15DIs04qWO4Gzch8PYMNrxO+sLwWi62oBYxcsbSdWIKHhQ4qhM4uqY0wkvA iTDXECiS6uOZLO6pcLrBw5wYpNxuHRysjG93U+RnS0m971nIxioIFRwcFB58UubAhE8h9eXlDWKij m2CAAsUo7DO3HJqJz+qqkYu4LBHNYJ8CaFp2aZ2xNJ3RIrpXaZItZA7V6WsyQ7CG1+7BiUPnpKngU vMjrthSg==; Received: from [2001:4bb8:19a:2039:96fe:c1ec:dda2:41a3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIOXL-003kb4-6L; Thu, 19 Jan 2023 06:36:35 +0000 From: Christoph Hellwig To: Jaegeuk Kim , Chao Yu Date: Thu, 19 Jan 2023 07:36:19 +0100 Message-Id: <20230119063625.466485-3-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119063625.466485-1-hch@lst.de> References: <20230119063625.466485-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Headers-End: 1pIOXW-008fSH-0P Subject: [f2fs-dev] [PATCH 2/8] f2fs: simplify do_checkpoint X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net For each loop add a local curseg_info pointer insted of looking it up for each of the three fields. Signed-off-by: Christoph Hellwig Reviewed-by: Chao Yu --- fs/f2fs/checkpoint.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index d68b3c991888df..641165c8299231 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1470,20 +1470,18 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi, true)); ckpt->free_segment_count = cpu_to_le32(free_segments(sbi)); for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { - ckpt->cur_node_segno[i] = - cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE)); - ckpt->cur_node_blkoff[i] = - cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_NODE)); - ckpt->alloc_type[i + CURSEG_HOT_NODE] = - curseg_alloc_type(sbi, i + CURSEG_HOT_NODE); + struct curseg_info *curseg = CURSEG_I(sbi, i + CURSEG_HOT_NODE); + + ckpt->cur_node_segno[i] = cpu_to_le32(curseg->segno); + ckpt->cur_node_blkoff[i] = cpu_to_le16(curseg->next_blkoff); + ckpt->alloc_type[i + CURSEG_HOT_NODE] = curseg->alloc_type; } for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { - ckpt->cur_data_segno[i] = - cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA)); - ckpt->cur_data_blkoff[i] = - cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_DATA)); - ckpt->alloc_type[i + CURSEG_HOT_DATA] = - curseg_alloc_type(sbi, i + CURSEG_HOT_DATA); + struct curseg_info *curseg = CURSEG_I(sbi, i + CURSEG_HOT_DATA); + + ckpt->cur_data_segno[i] = cpu_to_le32(curseg->segno);; + ckpt->cur_data_blkoff[i] = cpu_to_le16(curseg->next_blkoff); + ckpt->alloc_type[i + CURSEG_HOT_DATA] = curseg->alloc_type; } /* 2 cp + n data seg summary + orphan inode blocks */ From patchwork Thu Jan 19 06:36:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107455 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4AC1C678DC for ; Thu, 19 Jan 2023 06:36:52 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pIOXd-0000z4-7u; Thu, 19 Jan 2023 06:36:52 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pIOXX-0000yr-E5 for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=i98/N1jTMU5BFfsuB5WaRbW8ztdFj6EVQJfgX6qMD04=; b=GOdis+lxbjhu+qGphaZFn49r8w DC2s1uPCovyxvKMahfgp7lmJ33qP1IvvnDBzevm3idK/zvHjfCj3dZ9AzqKTrqc674oq7fSFr0rF0 mHh1MBksZu7uhVs5aExsbPun8zY9PqgEh9/a9uPXzgHbvizRKYUQYPwXCQzOda8ngBkQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=i98/N1jTMU5BFfsuB5WaRbW8ztdFj6EVQJfgX6qMD04=; b=RQxpuitvN6/62+VmWmgG34Q54+ UaJ5zmq18tAbEOvmwcIt0/f0Mcn7cUyIYL8at0Htb7yIFLPn+Z2hsV8eHynL28XBlxqUmYrA6obTU Nv5DPhPlfv5Mziuav+g+aFI9NivvpNlF1YdEyTiBj1Y75cpOkHOM6DEOBl6mRHu+kSfY=; Received: from bombadil.infradead.org ([198.137.202.133]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pIOXW-008fSJ-0O for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=i98/N1jTMU5BFfsuB5WaRbW8ztdFj6EVQJfgX6qMD04=; b=vSRe5crZIFOdBLzlPen2t7HXXL M5HIjZkDID1izOD5c3F52h3rhFDR3HOn08Lhtl2Lb1n60gs25Wm3ai/gMOj8Ubo4og5wEMwsYJfia oKdwV70gIBIgoTKG/XgFJu4t4hUp55EjaVtSzRkXNEQ6binpXi0vSzDtMh330V8+T9CBfO2W+S3Id wOZxNfOkutwUypANhwmzQmk6hCsBitD7ub+pdYViu8YbyC8Ezp5LeLEBjwfRumcUv/eCqriQJX3ug OaRMNHGllfJXCYcHbXqP5XLnsNr8g4VwvN0tj7uDoM3L9xybsb2RuQX+rOMIWZ1im/YEU7bhLX6Gc HCzDfx6w==; Received: from [2001:4bb8:19a:2039:96fe:c1ec:dda2:41a3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIOXO-003kbY-F3; Thu, 19 Jan 2023 06:36:38 +0000 From: Christoph Hellwig To: Jaegeuk Kim , Chao Yu Date: Thu, 19 Jan 2023 07:36:20 +0100 Message-Id: <20230119063625.466485-4-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119063625.466485-1-hch@lst.de> References: <20230119063625.466485-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Headers-End: 1pIOXW-008fSJ-0O Subject: [f2fs-dev] [PATCH 3/8] f2fs: add a f2fs_curseg_valid_blocks helper X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Add a helper to return the valid blocks on log and SSR segments, and replace the last two uses of curseg_blkoff with it. Signed-off-by: Christoph Hellwig Reviewed-by: Chao Yu --- fs/f2fs/segment.c | 32 +++++++++++++++----------------- fs/f2fs/segment.h | 6 ------ 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index ec6880213e8fa9..ad323b6e8609cd 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2323,6 +2323,15 @@ bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr) return is_cp; } +static unsigned short f2fs_curseg_valid_blocks(struct f2fs_sb_info *sbi, int type) +{ + struct curseg_info *curseg = CURSEG_I(sbi, type); + + if (sbi->ckpt->alloc_type[type] == SSR) + return sbi->blocks_per_seg; + return curseg->next_blkoff; +} + /* * Calculate the number of current summary pages for writing */ @@ -2332,15 +2341,11 @@ int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra) int i, sum_in_page; for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) { - if (sbi->ckpt->alloc_type[i] == SSR) - valid_sum_count += sbi->blocks_per_seg; - else { - if (for_ra) - valid_sum_count += le16_to_cpu( - F2FS_CKPT(sbi)->cur_data_blkoff[i]); - else - valid_sum_count += curseg_blkoff(sbi, i); - } + if (sbi->ckpt->alloc_type[i] != SSR && for_ra) + valid_sum_count += + le16_to_cpu(F2FS_CKPT(sbi)->cur_data_blkoff[i]); + else + valid_sum_count += f2fs_curseg_valid_blocks(sbi, i); } sum_in_page = (PAGE_SIZE - 2 * SUM_JOURNAL_SIZE - @@ -3861,15 +3866,8 @@ static void write_compacted_summaries(struct f2fs_sb_info *sbi, block_t blkaddr) /* Step 3: write summary entries */ for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) { - unsigned short blkoff; - seg_i = CURSEG_I(sbi, i); - if (sbi->ckpt->alloc_type[i] == SSR) - blkoff = sbi->blocks_per_seg; - else - blkoff = curseg_blkoff(sbi, i); - - for (j = 0; j < blkoff; j++) { + for (j = 0; j < f2fs_curseg_valid_blocks(sbi, i); j++) { if (!page) { page = f2fs_grab_meta_page(sbi, blkaddr++); kaddr = (unsigned char *)page_address(page); diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index ad6a9c19f46a48..0f3f05cb8c29f5 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -710,12 +710,6 @@ static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi, return curseg->alloc_type; } -static inline unsigned short curseg_blkoff(struct f2fs_sb_info *sbi, int type) -{ - struct curseg_info *curseg = CURSEG_I(sbi, type); - return curseg->next_blkoff; -} - static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno) { f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1); From patchwork Thu Jan 19 06:36:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107453 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8FCA4C38142 for ; Thu, 19 Jan 2023 06:36:53 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pIOXd-0000zF-JX; Thu, 19 Jan 2023 06:36:52 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pIOXa-0000yx-2g for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=RaIJOL3tZjwnjJLMQegT6UdG+T8F6w/K41EghEUnqso=; b=AJqqWO7hzw3+M7RytedaRavnov iE17VmnHqMiTv3S46X6/Jk7Xi9ByHpzUiKT/1/FF65oMBUir3zpYwhrUmfLlyMiLtJsCmar6sE+XL YFgfwIX+LNiWK0W+W2vkzoRzmlg2glRg8j6QmITwow8WaLWXt2Cuufh2+ybDZHYOPuCQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=RaIJOL3tZjwnjJLMQegT6UdG+T8F6w/K41EghEUnqso=; b=CHIApXBcojvpNFqNDMo2BaGkLv KbLhLW5177Qd6AFYTp5UjVg3M7XoQrePZgJCBfYLIB8zT3T2IoJamXRclUknhD0oQdror1FPYA5i2 yFlFt8bDeLhO1+wpz9qu/StkKY0bzFxTRCrPOEveCULKWJCuOaQcHtGJlHjtHrivJpPk=; Received: from bombadil.infradead.org ([198.137.202.133]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pIOXW-0001dc-Sm for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=RaIJOL3tZjwnjJLMQegT6UdG+T8F6w/K41EghEUnqso=; b=WDsWKycwyhzt1i8Vd8nRRyYus+ xiOjr2vznU6YWtjn9QomlxDUeKaavEPBfNd8BwLv8rFs8Hv3/Zh2XDHfdlOibkdu3N0Y9IAQBZ6eR HGhXQfG4kHT+VdWLenhr6nTizMABcwJnjA0OiuBUO+hNqqfCnUzhPWsIKPzZoEQE6Hp7n9wn7camf c0yU8kt6HUvGmoFXob3VoEQLo7W2KAZkfN7p59kWvp2+aztNISzG40OR1wm/gbri7VWFm0JN0iSny 0kXs5F9F9Lr3dzkFx/zU9nFHWCaQfjRh6tategyvDsELMcBkndTWKkBxpxWDvjXDXGH90tMWykzgN e7IMXg2w==; Received: from [2001:4bb8:19a:2039:96fe:c1ec:dda2:41a3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIOXR-003kbz-1S; Thu, 19 Jan 2023 06:36:41 +0000 From: Christoph Hellwig To: Jaegeuk Kim , Chao Yu Date: Thu, 19 Jan 2023 07:36:21 +0100 Message-Id: <20230119063625.466485-5-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119063625.466485-1-hch@lst.de> References: <20230119063625.466485-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Headers-End: 1pIOXW-0001dc-Sm Subject: [f2fs-dev] [PATCH 4/8] f2fs: factor the read/write tracing logic into a helper X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Factor the logic to log a path for reads and writs into a helper shared between the read_iter and write_iter methods. Signed-off-by: Christoph Hellwig --- fs/f2fs/file.c | 60 +++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index f5c1b78149540c..305be6ac024196 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4340,6 +4340,27 @@ static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +static void f2fs_trace_rw_file_path(struct kiocb *iocb, size_t count, int rw) +{ + struct inode *inode = file_inode(iocb->ki_filp); + char *buf, *path; + + buf = f2fs_kmalloc(F2FS_I_SB(inode), PATH_MAX, GFP_KERNEL); + if (!buf) + return; + path = dentry_path_raw(file_dentry(iocb->ki_filp), buf, PATH_MAX); + if (IS_ERR(path)) + goto free_buf; + if (rw == WRITE) + trace_f2fs_datawrite_start(inode, iocb->ki_pos, count, + current->pid, path, current->comm); + else + trace_f2fs_dataread_start(inode, iocb->ki_pos, count, + current->pid, path, current->comm); +free_buf: + kfree(buf); +} + static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) { struct inode *inode = file_inode(iocb->ki_filp); @@ -4349,24 +4370,9 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) if (!f2fs_is_compress_backend_ready(inode)) return -EOPNOTSUPP; - if (trace_f2fs_dataread_start_enabled()) { - char *p = f2fs_kmalloc(F2FS_I_SB(inode), PATH_MAX, GFP_KERNEL); - char *path; - - if (!p) - goto skip_read_trace; + if (trace_f2fs_dataread_start_enabled()) + f2fs_trace_rw_file_path(iocb, iov_iter_count(to), READ); - path = dentry_path_raw(file_dentry(iocb->ki_filp), p, PATH_MAX); - if (IS_ERR(path)) { - kfree(p); - goto skip_read_trace; - } - - trace_f2fs_dataread_start(inode, pos, iov_iter_count(to), - current->pid, path, current->comm); - kfree(p); - } -skip_read_trace: if (f2fs_should_use_dio(inode, iocb, to)) { ret = f2fs_dio_read_iter(iocb, to); } else { @@ -4672,24 +4678,8 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) if (preallocated < 0) { ret = preallocated; } else { - if (trace_f2fs_datawrite_start_enabled()) { - char *p = f2fs_kmalloc(F2FS_I_SB(inode), - PATH_MAX, GFP_KERNEL); - char *path; - - if (!p) - goto skip_write_trace; - path = dentry_path_raw(file_dentry(iocb->ki_filp), - p, PATH_MAX); - if (IS_ERR(path)) { - kfree(p); - goto skip_write_trace; - } - trace_f2fs_datawrite_start(inode, orig_pos, orig_count, - current->pid, path, current->comm); - kfree(p); - } -skip_write_trace: + f2fs_trace_rw_file_path(iocb, orig_count, WRITE); + /* Do the actual write. */ ret = dio ? f2fs_dio_write_iter(iocb, from, &may_need_sync) : From patchwork Thu Jan 19 06:36:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107452 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97F89C678DB for ; Thu, 19 Jan 2023 06:36:52 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pIOXc-0005fc-Sj; Thu, 19 Jan 2023 06:36:52 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pIOXb-0005fK-C5 for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8IcUKwSAmXzOWW15XJQNwueQJY6OPm3Il580HF26m9M=; b=YRMGOBigXQZP0UXM0alUn7wKe8 CcVTwzXPuhUZ9JwsuwDGhxEMAnbmMKn/KbTAwST1fwlc5Dx1Ka27o7iKZWLlax8oYqtD0D8wRPrwm N+eFd5FpW+iwC5uC7UKb3JgrnQiv8OlgGuA0IJ0o/GX7N9fawfuDXi7Npvzvdqa+wHD4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=8IcUKwSAmXzOWW15XJQNwueQJY6OPm3Il580HF26m9M=; b=gyDvjfZ6UCqVYPY6B6ejtAk9R1 4jIjLvEEr2UkBnB5ROVN45Qd06fQps2IG6Vyo4i/gWY5Sv5cocS4whBZhqTfTgoLUPz1jFPCuF//j GD3y3nnnh0WWCAObNoUox1O6yLVo7vxML9pN9FGuf8qiYe6SwfEsiUskkOl0vEQ6PGTQ=; Received: from bombadil.infradead.org ([198.137.202.133]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pIOXa-0001dh-6q for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=8IcUKwSAmXzOWW15XJQNwueQJY6OPm3Il580HF26m9M=; b=f0NWAUj34w/UgYENRZfRE6I508 BLQvFK0FrtNWuzEk9pEpXUPR4Z+6S8HkVp73u09NIqZsr/+iMGGRslBq6zEEVyKvDF57IDM0NsSq+ E0uN+QIaMgnP12L96r86ytaUeK0UVmbF7n6/WGirbdIHLWvO1Sj2WYDn2u1lkpzEI0En1Md5xf0Yk vepSiRNOvYhP3RIjv2L7qKWq0oAqb+4HqSNDH4d3flN9lIy5D93c8/x74cw2cbDgGf1e0OPK8wRhf cPtZrK9gVQtlErPcGfx46aSeNCe2RJA+jBRWxaHHwN4iLsGOP8aLoZ5uqICll99ZcYg0JrzZWerxX rJ+pt36Q==; Received: from [2001:4bb8:19a:2039:96fe:c1ec:dda2:41a3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIOXU-003kcF-6f; Thu, 19 Jan 2023 06:36:44 +0000 From: Christoph Hellwig To: Jaegeuk Kim , Chao Yu Date: Thu, 19 Jan 2023 07:36:22 +0100 Message-Id: <20230119063625.466485-6-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119063625.466485-1-hch@lst.de> References: <20230119063625.466485-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Headers-End: 1pIOXa-0001dh-6q Subject: [f2fs-dev] [PATCH 5/8] f2fs: refactor __allocate_new_segment X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Simplify the check whether to allocate a new segment or reuse an open one. Signed-off-by: Christoph Hellwig Reviewed-by: Chao Yu --- fs/f2fs/segment.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index ad323b6e8609cd..b25ee37d0375e2 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2897,16 +2897,12 @@ static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type, struct curseg_info *curseg = CURSEG_I(sbi, type); unsigned int old_segno; - if (!curseg->inited) - goto alloc; - - if (force || curseg->next_blkoff || - get_valid_blocks(sbi, curseg->segno, new_sec)) - goto alloc; - - if (!get_ckpt_valid_blocks(sbi, curseg->segno, new_sec)) + if (!force && curseg->inited && + !curseg->next_blkoff && + !get_valid_blocks(sbi, curseg->segno, new_sec) && + !get_ckpt_valid_blocks(sbi, curseg->segno, new_sec)) return; -alloc: + old_segno = curseg->segno; new_curseg(sbi, type, true); stat_inc_seg_type(sbi, curseg); From patchwork Thu Jan 19 06:36:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107456 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5C284C00A5A for ; Thu, 19 Jan 2023 06:36:56 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pIOXh-0001TQ-3B; Thu, 19 Jan 2023 06:36:55 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pIOXg-0001TJ-DN for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=FU9XPk1Xy4Y2DchoDdUH6tbkVbpUG46KvCMnzRlLK94=; b=cUXY+STvbVZMVtG1efw4SolMCI Zhnt9kLU+xNW9yfPLBvmmw6ZcSPsUpbHM2FC/xXrj4r6UWo0JdrLQtrjRE+JPbGY0385PL7Dw2Ej7 idHjSKpoKoVwXfo2v1ACSSfMFJxPNjHdrNbJ5R6CFpUIAG+VNOrX/MPbsUE0bL38bU8U=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=FU9XPk1Xy4Y2DchoDdUH6tbkVbpUG46KvCMnzRlLK94=; b=JKG7DKIOtGjlujVv6BDEfOA1a5 niOlJCQIxwpG2/4o5+iDKBB+fbUvv7V3Pjc2p0p5a8RoV1CjlkZovsOh1gteRr/Hhvw7HkqogAHMV 8PV1qPoxkNBxK9zRKtX6eIWE/C4NaB+/H73H5BqRAzAm/A1JTzcF1yk62cxtR1vOwXZo=; Received: from bombadil.infradead.org ([198.137.202.133]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pIOXd-008fSY-7Y for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=FU9XPk1Xy4Y2DchoDdUH6tbkVbpUG46KvCMnzRlLK94=; b=Lo47Kj4DaOA1rl4k1yX8SI/FKx QAQyrk6YK3B8t6oN5f9zpb++rOCTLEZZBkxWHVeHB7uYKbL8cG9MFDEnrRWKXDkd4yRW/S29X79dP sQy7iJRNs8x9FOlJiw/P7vSV28+m2IhyKPFGHgQrcwdCVpdOIi7UC3WhjenIQXPIk3Sm0V4cYbQve aodF5aw75aPlgTzSQdXNTMWPupH8eTMlRPOaYCE5HlhOUAnjYuCBDeMQOZN+z84kCoyasMT7fMiWB kY1K5CX1pZxCKeVZ+j/4mOMncmkScUhL9qw29VX8MKi3H53l+i465NbxUF2It4sVkeWF4AiGCXsEh aaPJcQlA==; Received: from [2001:4bb8:19a:2039:96fe:c1ec:dda2:41a3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIOXX-003kcj-C6; Thu, 19 Jan 2023 06:36:47 +0000 From: Christoph Hellwig To: Jaegeuk Kim , Chao Yu Date: Thu, 19 Jan 2023 07:36:23 +0100 Message-Id: <20230119063625.466485-7-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119063625.466485-1-hch@lst.de> References: <20230119063625.466485-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Headers-End: 1pIOXd-008fSY-7Y Subject: [f2fs-dev] [PATCH 6/8] f2fs: remove __allocate_new_section X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Just fold this trivial wrapper into the only caller. Signed-off-by: Christoph Hellwig Reviewed-by: Chao Yu --- fs/f2fs/segment.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index b25ee37d0375e2..f889f623a59fd6 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2909,17 +2909,11 @@ static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type, locate_dirty_segment(sbi, old_segno); } -static void __allocate_new_section(struct f2fs_sb_info *sbi, - int type, bool force) -{ - __allocate_new_segment(sbi, type, true, force); -} - void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force) { f2fs_down_read(&SM_I(sbi)->curseg_lock); down_write(&SIT_I(sbi)->sentry_lock); - __allocate_new_section(sbi, type, force); + __allocate_new_segment(sbi, type, true, force); up_write(&SIT_I(sbi)->sentry_lock); f2fs_up_read(&SM_I(sbi)->curseg_lock); } From patchwork Thu Jan 19 06:36:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107457 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B4641C00A5A for ; Thu, 19 Jan 2023 06:36:58 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pIOXj-0000zy-5A; Thu, 19 Jan 2023 06:36:58 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pIOXi-0000zq-08 for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=DKCT1WdWWcozfWmEkEsG0Gw3gxiMmitAN1Tyuop0nBM=; b=N/E4t8B4z6qVkjjR0od/97IbuJ 9V6xrZZmZJABu4qrrSkGdSL6IgG1g0IlPCr7VUrjwMLbWMQrIxo+h0dg0kLPkdDrBNMzKPbYdc2bd eYujNbHmyjLPNomJM5m/pt4QaC/A21FHI1UqBJ5pOvT+dSYL42OT0zd0kpBkZ5umpW/E=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=DKCT1WdWWcozfWmEkEsG0Gw3gxiMmitAN1Tyuop0nBM=; b=IMZmbOC0fl6IH7ystG1rx2Gjvz BEh3svc3YT1BfCPod3l/Yo2BDeOKI/NvYqvCKdgm0XMzn9YGPCdxbhAjSE/hdeByQKHxfXmLOmV90 8hZ7ORnJZ1u2jWXpjzRZghqQ90N4xiK0afy052vnmtelA/dWiyhCTqvz5Jap/Z+cjMZo=; Received: from bombadil.infradead.org ([198.137.202.133]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pIOXg-008fSc-KB for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:36:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=DKCT1WdWWcozfWmEkEsG0Gw3gxiMmitAN1Tyuop0nBM=; b=CZoIsrBNPFOjRJAaG43j9Ta7m2 3HgMax3vv/u0oOn/yLAFxxAzHOIAE/Y24zlmVmAJlLO7ZON3+57qIFNs83DSoh+VkLP3Yb9U+IBGB +TCcy9xpll3jFu8qCrqDKiQ0gO1weRgMR5++RrnFonzqB4AlQidU4dZgEijoG1r7em0JbrthFBiFC FnqhLylMrvIgKMESOBctnQvVo933Lvc1jsxg3KL/E6kWyCqwM403B6FzTP1OyBidP5LJlEvTiKekN skKJ7R+ruzMBEJSS1/MIV9MWLBV4IYKpll3ICCPbTQz9KkEAPN37CmcUZOafdVykaE3YfwgFQCiNq Q7CNI9Xg==; Received: from [2001:4bb8:19a:2039:96fe:c1ec:dda2:41a3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIOXa-003kdF-LB; Thu, 19 Jan 2023 06:36:51 +0000 From: Christoph Hellwig To: Jaegeuk Kim , Chao Yu Date: Thu, 19 Jan 2023 07:36:24 +0100 Message-Id: <20230119063625.466485-8-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119063625.466485-1-hch@lst.de> References: <20230119063625.466485-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Headers-End: 1pIOXg-008fSc-KB Subject: [f2fs-dev] [PATCH 7/8] f2fs: refactor next blk selection X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Remove __refresh_next_blkoff by opencoding the SSR vs LFS segment check in the only caller, and then add helpers for SSR block selection and blkoff randomization instead. Signed-off-by: Christoph Hellwig Reviewed-by: Chao Yu --- fs/f2fs/segment.c | 48 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index f889f623a59fd6..6f588e440c7575 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2616,30 +2616,10 @@ static int __next_free_blkoff(struct f2fs_sb_info *sbi, return __find_rev_next_zero_bit(target_map, sbi->blocks_per_seg, start); } -/* - * If a segment is written by LFS manner, next block offset is just obtained - * by increasing the current block offset. However, if a segment is written by - * SSR manner, next block offset obtained by calling __next_free_blkoff - */ -static void __refresh_next_blkoff(struct f2fs_sb_info *sbi, - struct curseg_info *seg) +static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi, + struct curseg_info *seg) { - if (seg->alloc_type == SSR) { - seg->next_blkoff = - __next_free_blkoff(sbi, seg->segno, - seg->next_blkoff + 1); - } else { - seg->next_blkoff++; - if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) { - /* To allocate block chunks in different sizes, use random number */ - if (--seg->fragment_remained_chunk <= 0) { - seg->fragment_remained_chunk = - get_random_u32_inclusive(1, sbi->max_fragment_chunk); - seg->next_blkoff += - get_random_u32_inclusive(1, sbi->max_fragment_hole); - } - } - } + return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1); } bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno) @@ -3216,6 +3196,19 @@ static int __get_segment_type(struct f2fs_io_info *fio) return type; } +static void f2fs_randomize_chunk(struct f2fs_sb_info *sbi, + struct curseg_info *seg) +{ + /* To allocate block chunks in different sizes, use random number */ + if (--seg->fragment_remained_chunk > 0) + return; + + seg->fragment_remained_chunk = + get_random_u32_inclusive(1, sbi->max_fragment_chunk); + seg->next_blkoff += + get_random_u32_inclusive(1, sbi->max_fragment_hole); +} + void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, block_t old_blkaddr, block_t *new_blkaddr, struct f2fs_summary *sum, int type, @@ -3245,8 +3238,13 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, f2fs_wait_discard_bio(sbi, *new_blkaddr); curseg->sum_blk->entries[curseg->next_blkoff] = *sum; - __refresh_next_blkoff(sbi, curseg); - + if (curseg->alloc_type == SSR) { + curseg->next_blkoff = f2fs_find_next_ssr_block(sbi, curseg); + } else { + curseg->next_blkoff++; + if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) + f2fs_randomize_chunk(sbi, curseg); + } stat_inc_block_count(sbi, curseg); if (from_gc) { From patchwork Thu Jan 19 06:36:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13107458 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13067C00A5A for ; Thu, 19 Jan 2023 06:37:02 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1pIOXm-0005gi-9I; Thu, 19 Jan 2023 06:37:01 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pIOXl-0005gQ-4O for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:37:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Q90SBhhzV2/wQOli658ZOhCekhuARCeHpkXve95IZF8=; b=DMYdIOvkPRF58ov1y2+61v7gix Oxe1VcEqyDWk9xdGCRyboJO/hbBjl0i6PY3P68x5CzDYjTp63NVSi/L6OC2In5UCIxTyl0bTLLh2X 5YTjA4KIPyeRDg/fmFIha3gfqp2d5HrXrhPMXQQaQaeqC2mUVnJDJinIFj0OqW6wTfqY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Q90SBhhzV2/wQOli658ZOhCekhuARCeHpkXve95IZF8=; b=Rs3t1VNnraDbtSbcl8Ac7AClxZ 15wi6XHOuN7ai2GPN7G7fXgjlZ44+IF2JWRwOCwo/mccvv+cifpqz7won0GU/Aifd3o+u1rdwV3Be xl9x6D7MOpP11Ey5/pUKEngHLzi73Bh1RABWtwIunt+niJrFeB/P+Vr+rIf/RVHysFDA=; Received: from bombadil.infradead.org ([198.137.202.133]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pIOXj-008fSe-TY for linux-f2fs-devel@lists.sourceforge.net; Thu, 19 Jan 2023 06:37:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Q90SBhhzV2/wQOli658ZOhCekhuARCeHpkXve95IZF8=; b=c4tJ0kYNTyZTmOv6CwFucf107c ESUH4mM9IYf5bUteUUaaV3i01GnVRcjuPBe+1J41wuHiszLnPYd4mhf/FTNvqHs8exGlb1d9C7P7C ELjHROHq/CQnluKRm9mOJ7Xwuzo9ZyequrQVbc2OeN2g1H2LtY775sDVP2K8Ppmh/kUnE1j9mSXE6 DbXslzcOBZwWogC6L0GalzJBRMe+X60OVsLJ8o/ILR6fyQib9cV+f8MB/ThUx30FITgMeXrWJtsnd tXd/UMbN0LPye7ure/0J8swcJ/ClhbdIzmiFm0jv0X2BVvFbXMYJlF4kyCsGumEkovG8hsX0DjFfv 0dugKAxw==; Received: from [2001:4bb8:19a:2039:96fe:c1ec:dda2:41a3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIOXd-003kdk-U9; Thu, 19 Jan 2023 06:36:54 +0000 From: Christoph Hellwig To: Jaegeuk Kim , Chao Yu Date: Thu, 19 Jan 2023 07:36:25 +0100 Message-Id: <20230119063625.466485-9-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119063625.466485-1-hch@lst.de> References: <20230119063625.466485-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Headers-End: 1pIOXj-008fSe-TY Subject: [f2fs-dev] [PATCH 8/8] f2fs: remove __has_curseg_space X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Just open code the logic in the only caller, where it is more obvious. Signed-off-by: Christoph Hellwig Reviewed-by: Chao Yu --- fs/f2fs/segment.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 6f588e440c7575..4646c2ca2d55c2 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3071,13 +3071,6 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) return err; } -static bool __has_curseg_space(struct f2fs_sb_info *sbi, - struct curseg_info *curseg) -{ - return curseg->next_blkoff < f2fs_usable_blks_in_seg(sbi, - curseg->segno); -} - int f2fs_rw_hint_to_seg_type(enum rw_hint hint) { switch (hint) { @@ -3219,6 +3212,7 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, unsigned long long old_mtime; bool from_gc = (type == CURSEG_ALL_DATA_ATGC); struct seg_entry *se = NULL; + bool segment_full = false; f2fs_down_read(&SM_I(sbi)->curseg_lock); @@ -3245,6 +3239,8 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) f2fs_randomize_chunk(sbi, curseg); } + if (curseg->next_blkoff >= f2fs_usable_blks_in_seg(sbi, curseg->segno)) + segment_full = true; stat_inc_block_count(sbi, curseg); if (from_gc) { @@ -3263,10 +3259,11 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) update_sit_entry(sbi, old_blkaddr, -1); - if (!__has_curseg_space(sbi, curseg)) { - /* - * Flush out current segment and replace it with new segment. - */ + /* + * If the current segment is full, flush it out and replace it with a + * new segment. + */ + if (segment_full) { if (from_gc) { get_atssr_segment(sbi, type, se->type, AT_SSR, se->mtime);