From nobody Mon Nov 25 21:24:27 2024 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8A741B3925; Thu, 24 Oct 2024 09:26:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761972; cv=none; b=WrffNi0Lt0H0KrexHpw2GJctMUbb1b23ALO21JjCsXl9X8TFHiXolvguIWhhVaOgab3MAXb+PsK3CWTjbeBvtXzFJa8/hGO8IpmXLO+NV1TJwe8zCVh9FmREsEeyQtRwrr7PILxSMY39iKab5u6MUikBcTLqrxTA5x3qmsBBF6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761972; c=relaxed/simple; bh=aR0BPAvWEJaq1IINO6JwAVrd0+FSpzvwkh3sGwILIkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LvOslGAmXT/1kCZlki7L93pq5dXmJveBB6ycE2HhxRWSMUSkBRatJ9szEhlDDTsK5058hVWdOCg8Cdwlyr1lR1VlZ1n8a4xc7LyoiaSldwyT7snmFOo5THsm6Ke5Ibp/vy4rxv+o44tY6RUmCHrL+7Dwq6aduhfzsmD1lAf50IU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hr6H9iJL; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hr6H9iJL" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-71e6d988ecfso539479b3a.0; Thu, 24 Oct 2024 02:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761970; x=1730366770; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=828W4pUclcW/X5PV9rIvmIQLFWKFsfY8rzBeoqJt6Uw=; b=hr6H9iJLFovqMef3XupYDwrf9aNS1S6KWUiBmoq32Ng8R5b8aYJRhYSJFmCa9xu/I8 1nM4r7VA/v9Cubn7dMQEI69vgqfl1rU2JUN0u1Cv5uEZLoTC5sgaf6YTiQV4CGxJHf2G xO5aBHa8oIpu4CPPB9JHpN5hWVw4eZGZHlxy2WFKxBkaW6dsKGl94UOBXLDb9RSwmgkO ffU0xXEb3hTQKoimy+HHKLXS07o6faHEggC4x1s7TbW14L/COQvPE6ZZKXTPHc3sq+A5 6nn6A4i/MiUxI6f5SKTSVL1jKOelqKlVcer2RqNByZ5yI6Pq+5YxsRK37xwm8veEK2Ez trbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761970; x=1730366770; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=828W4pUclcW/X5PV9rIvmIQLFWKFsfY8rzBeoqJt6Uw=; b=SgJsTwTmGfIhtcg74bcUV6FUAVysvUi35i4v/xLSupsUIZmGrlkBnD7biGJS/N49Io 9QxlK1YgLesZu/PGx5xkFdg6pp/mFId9F7iZH4nKrK2IpPBCgb+GoL/AO7pDV3tr6oN3 A9h/J+HboyP0CFazs4D5FMQsnfZmZ4C2px/AuduVrwPQcxOllTH7DzJgGPS2RA8STl2Y Edq4GdNV1V2WooaBT8ApRJVC/NIowYtZPB2Ba3RbkEI1F4FaP0w+jkGXTYcAecWaHyzY MeJ8qvF3Nd+106X546KKnKtRreDgbE4t2f1Vl2sKwfil4/TTwxiGZpB+cpEUzpgJEnmA 3mFg== X-Forwarded-Encrypted: i=1; AJvYcCVANO/YgizfteWy0U2e6+Ew5JcqdUXWgPPx3lXslN7vNn21AaVvuHPnkQmP9/M49YrIsCHzpzQ24LXzd8k=@vger.kernel.org, AJvYcCVLHPKywtMatL1EJqy5w+p2owbcwKUdROWgYGuRIIRkMZBr4elOT6Jh1O4ZqxZGpBf+vmJMem6JeHTq4/Zt@vger.kernel.org, AJvYcCWrBL9ckYRwlemCHku4CLjAyVLjnVD45dyVB9Bfv7Fw/K6BTiUIQQyC5rGIHvC5g5tfPkexzTkjxanmSJN8@vger.kernel.org X-Gm-Message-State: AOJu0Yx0UBiQn1CsubVxbxq9UhTL7fx42GiGohcS4AMXUq/kS8EVQBRR OMn9LrxnzFc9fwnVJImZ3M+jJvqGrkQe23q1lGwnpLYmO/gg2RDJ X-Google-Smtp-Source: AGHT+IHwNTDt2Km/E14JqnJAtswJDKwoRBooo1HUJXMdcLegLnogPBz/WFQtOLm6ihp8VMonfMZVcg== X-Received: by 2002:a05:6a00:22d3:b0:71e:4930:162c with SMTP id d2e1a72fcca58-72030a517f5mr7735804b3a.6.1729761969931; Thu, 24 Oct 2024 02:26:09 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:09 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 01/12] nilfs2: convert segment buffer to be folio-based Date: Thu, 24 Oct 2024 18:25:35 +0900 Message-ID: <20241024092602.13395-2-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the segment buffer (log buffer) implementation, two parts of the block buffer, CRC calculation and bio preparation, are still page-based, so convert them to folio-based. Signed-off-by: Ryusuke Konishi Cc: Matthew Wilcox (Oracle) --- fs/nilfs2/segbuf.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c index dc431b4c34c9..e08cab03366b 100644 --- a/fs/nilfs2/segbuf.c +++ b/fs/nilfs2/segbuf.c @@ -205,7 +205,6 @@ static void nilfs_segbuf_fill_in_data_crc(struct nilfs_= segment_buffer *segbuf, { struct buffer_head *bh; struct nilfs_segment_summary *raw_sum; - void *kaddr; u32 crc; =20 bh =3D list_entry(segbuf->sb_segsum_buffers.next, struct buffer_head, @@ -220,9 +219,13 @@ static void nilfs_segbuf_fill_in_data_crc(struct nilfs= _segment_buffer *segbuf, crc =3D crc32_le(crc, bh->b_data, bh->b_size); } list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) { - kaddr =3D kmap_local_page(bh->b_page); - crc =3D crc32_le(crc, kaddr + bh_offset(bh), bh->b_size); - kunmap_local(kaddr); + size_t offset =3D offset_in_folio(bh->b_folio, bh->b_data); + unsigned char *from; + + /* Do not support block sizes larger than PAGE_SIZE */ + from =3D kmap_local_folio(bh->b_folio, offset); + crc =3D crc32_le(crc, from, bh->b_size); + kunmap_local(from); } raw_sum->ss_datasum =3D cpu_to_le32(crc); } @@ -374,7 +377,7 @@ static int nilfs_segbuf_submit_bh(struct nilfs_segment_= buffer *segbuf, struct nilfs_write_info *wi, struct buffer_head *bh) { - int len, err; + int err; =20 BUG_ON(wi->nr_vecs <=3D 0); repeat: @@ -385,8 +388,8 @@ static int nilfs_segbuf_submit_bh(struct nilfs_segment_= buffer *segbuf, (wi->nilfs->ns_blocksize_bits - 9); } =20 - len =3D bio_add_page(wi->bio, bh->b_page, bh->b_size, bh_offset(bh)); - if (len =3D=3D bh->b_size) { + if (bio_add_folio(wi->bio, bh->b_folio, bh->b_size, + offset_in_folio(bh->b_folio, bh->b_data))) { wi->end++; return 0; } --=20 2.43.0 From nobody Mon Nov 25 21:24:27 2024 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AF351B6CE5; Thu, 24 Oct 2024 09:26:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761975; cv=none; b=pAeDHgwGYv+rJMrJdd6Bzvhs4UYiSgh0lFxKOM6vsBgd3QkKnCeH8rytrVZPW6Os2aQ5PgzFLAfVTK47XgFkJ1WiVoAxodtkAYRZeZx2AeYgjRf7zqhnU2QvaaINuiDEyHlRFRff1T9wrVH4f7gU6aQo2LOCQhUL4vK8PSzJnOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761975; c=relaxed/simple; bh=dAuAbitdK04/Qrt+mcN9ml8VLwPLnqkBs+pQeXLRJ70=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eACG/TzTVNY4Cu8OFBPCVFcCS8jUH0z2fUxjlzG+pLrBSES/iU301tDHyF88x0cD3kRTapb7BWmkLXxtPvRPsOCBsAUbCunj/EwFNXERbbE3MguOwED2iSbMGLivQfT0TxYSw9uEybG8+UYzS7IbCP/EqmA1qX3+C55WxoXX0J4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MmnzwDvl; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MmnzwDvl" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-7ed67cfc1fcso392667a12.1; Thu, 24 Oct 2024 02:26:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761972; x=1730366772; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PHfMBOD/PqNIJ26AHKOSrnJwh3FsZ7ICIL3IEGW9+OE=; b=MmnzwDvlNXQEzC7Hl0Q/UOlkiQnuN1Laa6+/nPDnZlk62LcmejUzGMrkHEmw10NWA0 hqtg54PZgUIjVNB9AYPiPsGZ2923jUvNIAbfLVVrLJvtjNpKf7q2FPVkiQADkyEJ4pez aLE2FMmLecZrFUPvU0wPTJT2my3qu5KHJ5x0K9O1WC0+zYXMS9ro1Etw/WKuHXBUKIWI bESH0pkhuUSZ8YHqxv9TOUHXHaAjrx98Xy86gxAGduqL8XqvPE0sr8EpzWlG+t34Sg0J N+MOrAS38KVqg0LzsMnUnJQKaA5o1wJSRr3OUP6OwmAHFZY5fhtyQGCAckfjE1A45mrf V4RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761972; x=1730366772; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PHfMBOD/PqNIJ26AHKOSrnJwh3FsZ7ICIL3IEGW9+OE=; b=nbgA0v9lU6C65ZoyKNNz6FpWy9ftFqttqKggdgM7EWqA0iiwzO+rOvIblJvg3dhJ5w KGx/U5WwYQjK83FXQigLfxewEbb3gwKrfLp5BnHFB3yiGW+QvJXnHs/FhIlCUoWG179D zKEDSaVYrfUyesXmrCxvHDGYmJwkr6Y0ln6RGKnT/BNXfPRR+MCwXReMpSvl5j7Ueq7K oSIFrnM6YGO8fhTk9b4V6uLz+Kf/zBhO7GOTy7cgnDPnQc74qitHjDECPHuXcOJTdIhT jZBusjz9rOt4UnM5yrNhUx6+2vJLjqhm5qJrep/2VZVNT0qH2Kf8A6GW6+n3/VSV5HiJ DQfw== X-Forwarded-Encrypted: i=1; AJvYcCV1jN84FR20D7Q7n8RUkJru1/3OKLVVVCX87E+mKCJwqbvFwrm7xQjWsVmW/wgFYCEis9+r/En6bGp/vlc=@vger.kernel.org, AJvYcCWCyBc9y3i8Tu70YmFw53vgVmwqxZK94YgwjHKK5stpmPAGnNR9NQEJBBK5nV1tGT9ps6uLAfWfFzQb/JjT@vger.kernel.org, AJvYcCWse6fv2Y9oQPdNZa2fATbxXKCNt5op383zyNHdVLlZ9jIpDmwn3KuvHu+tqp4y5iTI6L4OCOSTqQNL8nde@vger.kernel.org X-Gm-Message-State: AOJu0YyG3JDGRIz6Uqre++lAy0w1sPasnE7KPgPa0X5gcs4njvKW3NoX ar6RpFjKJJXgbXkZ/e8fX2EWmYMf6R+VWaWou/VRKXmv2rgptkNFm9R5zA== X-Google-Smtp-Source: AGHT+IGx0mmVGSkVPTW38b7zdZugzXCeoHUu/1sonYrx3QTIf8K0w3kKAen4zAsuZ6j2Spfj/dAPVQ== X-Received: by 2002:a05:6a20:e347:b0:1cf:573a:bb58 with SMTP id adf61e73a8af0-1d978bae140mr6510610637.40.1729761972469; Thu, 24 Oct 2024 02:26:12 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:11 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 02/12] nilfs2: convert common metadata file code to be folio-based Date: Thu, 24 Oct 2024 18:25:36 +0900 Message-ID: <20241024092602.13395-3-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the common routines for metadata files, nilfs_mdt_insert_new_block(), which inserts a new block buffer into the cache, is still page-based, and there are two places where bh_offset() is used. Convert these to page-based. Signed-off-by: Ryusuke Konishi Cc: Matthew Wilcox (Oracle) --- fs/nilfs2/alloc.c | 8 +++++--- fs/nilfs2/cpfile.c | 4 ++-- fs/nilfs2/mdt.c | 21 +++++++++++++-------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/fs/nilfs2/alloc.c b/fs/nilfs2/alloc.c index ba50388ee4bf..d30dfed707b6 100644 --- a/fs/nilfs2/alloc.c +++ b/fs/nilfs2/alloc.c @@ -177,12 +177,14 @@ nilfs_palloc_entry_blkoff(const struct inode *inode, = __u64 nr) * nilfs_palloc_desc_block_init - initialize buffer of a group descriptor = block * @inode: inode of metadata file * @bh: buffer head of the buffer to be initialized - * @kaddr: kernel address mapped for the page including the buffer + * @from: kernel address mapped for a chunk of the block + * + * This function does not yet support the case where block size > PAGE_SIZ= E. */ static void nilfs_palloc_desc_block_init(struct inode *inode, - struct buffer_head *bh, void *kaddr) + struct buffer_head *bh, void *from) { - struct nilfs_palloc_group_desc *desc =3D kaddr + bh_offset(bh); + struct nilfs_palloc_group_desc *desc =3D from; unsigned long n =3D nilfs_palloc_groups_per_desc_block(inode); __le32 nfrees; =20 diff --git a/fs/nilfs2/cpfile.c b/fs/nilfs2/cpfile.c index f0ce37552446..a8046cbf2753 100644 --- a/fs/nilfs2/cpfile.c +++ b/fs/nilfs2/cpfile.c @@ -113,9 +113,9 @@ nilfs_cpfile_block_get_checkpoint(const struct inode *c= pfile, __u64 cno, =20 static void nilfs_cpfile_block_init(struct inode *cpfile, struct buffer_head *bh, - void *kaddr) + void *from) { - struct nilfs_checkpoint *cp =3D kaddr + bh_offset(bh); + struct nilfs_checkpoint *cp =3D from; size_t cpsz =3D NILFS_MDT(cpfile)->mi_entry_size; int n =3D nilfs_cpfile_checkpoints_per_block(cpfile); =20 diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c index ceb7dc0b5bad..a4c1e00aaaac 100644 --- a/fs/nilfs2/mdt.c +++ b/fs/nilfs2/mdt.c @@ -33,7 +33,8 @@ nilfs_mdt_insert_new_block(struct inode *inode, unsigned = long block, struct buffer_head *, void *)) { struct nilfs_inode_info *ii =3D NILFS_I(inode); - void *kaddr; + struct folio *folio =3D bh->b_folio; + void *from; int ret; =20 /* Caller exclude read accesses using page lock */ @@ -47,12 +48,14 @@ nilfs_mdt_insert_new_block(struct inode *inode, unsigne= d long block, =20 set_buffer_mapped(bh); =20 - kaddr =3D kmap_local_page(bh->b_page); - memset(kaddr + bh_offset(bh), 0, i_blocksize(inode)); + /* Initialize block (block size > PAGE_SIZE not yet supported) */ + from =3D kmap_local_folio(folio, offset_in_folio(folio, bh->b_data)); + memset(from, 0, bh->b_size); if (init_block) - init_block(inode, bh, kaddr); - flush_dcache_page(bh->b_page); - kunmap_local(kaddr); + init_block(inode, bh, from); + kunmap_local(from); + + flush_dcache_folio(folio); =20 set_buffer_uptodate(bh); mark_buffer_dirty(bh); @@ -571,7 +574,8 @@ int nilfs_mdt_freeze_buffer(struct inode *inode, struct= buffer_head *bh) if (!bh_frozen) bh_frozen =3D create_empty_buffers(folio, 1 << blkbits, 0); =20 - bh_frozen =3D get_nth_bh(bh_frozen, bh_offset(bh) >> blkbits); + bh_frozen =3D get_nth_bh(bh_frozen, + offset_in_folio(folio, bh->b_data) >> blkbits); =20 if (!buffer_uptodate(bh_frozen)) nilfs_copy_buffer(bh_frozen, bh); @@ -601,7 +605,8 @@ nilfs_mdt_get_frozen_buffer(struct inode *inode, struct= buffer_head *bh) if (!IS_ERR(folio)) { bh_frozen =3D folio_buffers(folio); if (bh_frozen) { - n =3D bh_offset(bh) >> inode->i_blkbits; + n =3D offset_in_folio(folio, bh->b_data) >> + inode->i_blkbits; bh_frozen =3D get_nth_bh(bh_frozen, n); } folio_unlock(folio); --=20 2.43.0 From nobody Mon Nov 25 21:24:27 2024 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9C991B6D01; Thu, 24 Oct 2024 09:26:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761982; cv=none; b=j8voYXEfBsfviNIbWHBFBNlA5Vmll+wEAEqYE/V5ZI75EPgg5Roarq3lBHxfO9TUO55pKdugfIhpNE5GE4EVBu7HdxY4wz6guhRfOmnvhthG2jT5TWoJSr4E1dgMVlsN6T6ePsFV4i4lzBMrkCp1zSPMMzmuFUMttPpye95DGmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761982; c=relaxed/simple; bh=vtTvtsQdkz4/yTiq4OQsJy7KWz0L86eeowaYLNlKGu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rXOwmUmeTZ7ofiTQNuq8gSASd3BO782kZV4tpFNpQqkJg8tWFzXrBLlkrim1hMSvpTwqKPfW7dTZyPUPO/8nd/2UQTJjyUlwheTp+7kxpEGdUOxIC0OFl3yZJy+qHCNWeiEMzQIMmPHqkNLNmRP+OvHuPWqhQtT+fsz1m8vYaPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RbGbVGbV; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RbGbVGbV" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-71e49ef3b2bso500129b3a.2; Thu, 24 Oct 2024 02:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761975; x=1730366775; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2nXrQmW+YVo2eeU8/p6IXqjviSMZctE3yKb4AwwJMu4=; b=RbGbVGbVYG3LzoWKgPdhUP29/Vb+xnu5KSGNYw4ef9E0LHjU+h8SvamlzNeqpiiLiB XGtks2phgbutLJVYzaLXwM/SA1envNG1cZuWU+X003fCX+23g7Y3fv2UbuqJsDcnLkDV qsiw92lyVp7bDCNFxlQ0+/YRgNd+2Nv2i3A0poMcwiLg7P6nI5/FS3Ony/EBmGCqUGL+ VIxSLht8hHUV4q8QQoade9m0Gs6LStDj7ozx5BZ4hP7yycDebdZhHeLM4TP7vXE5dGI3 t7FgOtect0Jq/J5OiZXYV9DSlLbGfGfoKFA05L2AiDo6Z3bO3AFgd9FrnVQuWQBXuEyh meTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761975; x=1730366775; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2nXrQmW+YVo2eeU8/p6IXqjviSMZctE3yKb4AwwJMu4=; b=ohzdHmSnsbpDVHhQt0IKVs2E+NSmVssDsdeg0yz9s2/gOSASpbf6KD9VQiqMXGO6lb CSha54TbWVtLQNWJHxPLewRYm71WWmorYPkoSmwDTKpsKbIrAHs/IhkzyS3ZohKYfNKC C0R72pZix+0pYhW3lLepRvmgqs2GUfxUqMr+vjLYp86fimRwme3iqsrNvtY+r9oTMswr hVODYqAMhvbTNcc8yTjMRigITIEgulvySa0Ihcrg2Ujq3V+hWYc+zvMtV9v14kgnhuyf K0Vd+XH13hVo6X//AmPIaxktuXNEnB+3DSu6EmcFhqNzxAUAePvxDzS05IS8ZlhkjWON 0lmA== X-Forwarded-Encrypted: i=1; AJvYcCU7+fgSajOfWiIWVIj/koD0/z9p5g/CBOr3ZfO+lwwELq4gYK5qUTtreyalGirtiupfUTRHvT1+DEWFZyyr@vger.kernel.org, AJvYcCVsSJHLuVijRnvZz61v7RqG3DyQvA3ptVWte0XVRtUv8lTEHIyGsQAzDW38KsPZ7VFe7pThugbPx2nNDqE=@vger.kernel.org, AJvYcCWdjg3TqfZ9tqwb8Ty+wHlJBGa7Hux3e3rGAOlo3ebB0gAh6ce3iJ6JS986OsvtrmvTWofaZKX3a9wBFmnC@vger.kernel.org X-Gm-Message-State: AOJu0YzG6SvKZYLrWXPfRI+0e+UYbCUoGU0+omgzPDxcOGRoFB27BbSZ TI30Z6Xr9Srl+je817p00wDHm1OmE9TmMrPIMs/ZDSPy+YbnqfNR X-Google-Smtp-Source: AGHT+IH3NVvtkTpiokiRrac5UJHIZYDOd2D8G4giZv/Qtpvm5ZmwrA4DZjZweJ1Bt5ia1E6C+TkQ0A== X-Received: by 2002:aa7:88ce:0:b0:71e:44f6:6900 with SMTP id d2e1a72fcca58-72030a8a42bmr7581102b3a.16.1729761974975; Thu, 24 Oct 2024 02:26:14 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:14 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 03/12] nilfs2: convert segment usage file to be folio-based Date: Thu, 24 Oct 2024 18:25:37 +0900 Message-ID: <20241024092602.13395-4-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For the sufile, which is a metadata file that holds information about managing segments, convert the page-based implementation to a folio-based implementation. kmap_local_page() is changed to use kmap_local_folio(), and where offsets within a page are calculated using bh_offset(), are replaced with calculations using offset_in_folio() with an additional helper function nilfs_sufile_segment_usage_offset(). Signed-off-by: Ryusuke Konishi Cc: Matthew Wilcox (Oracle) --- fs/nilfs2/sufile.c | 160 +++++++++++++++++++++++---------------------- 1 file changed, 82 insertions(+), 78 deletions(-) diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c index eea5a6a12f7b..d3ecc813d633 100644 --- a/fs/nilfs2/sufile.c +++ b/fs/nilfs2/sufile.c @@ -70,11 +70,20 @@ nilfs_sufile_segment_usages_in_block(const struct inode= *sufile, __u64 curr, max - curr + 1); } =20 -static struct nilfs_segment_usage * -nilfs_sufile_block_get_segment_usage(const struct inode *sufile, __u64 seg= num, - struct buffer_head *bh, void *kaddr) +/** + * nilfs_sufile_segment_usage_offset - calculate the byte offset of a segm= ent + * usage entry in the folio containing= it + * @sufile: segment usage file inode + * @segnum: number of segment usage + * @bh: buffer head of block containing segment usage indexed by @segn= um + * + * Return: Byte offset in the folio of the segment usage entry. + */ +static size_t nilfs_sufile_segment_usage_offset(const struct inode *sufile, + __u64 segnum, + struct buffer_head *bh) { - return kaddr + bh_offset(bh) + + return offset_in_folio(bh->b_folio, bh->b_data) + nilfs_sufile_get_offset(sufile, segnum) * NILFS_MDT(sufile)->mi_entry_size; } @@ -112,13 +121,11 @@ static void nilfs_sufile_mod_counter(struct buffer_he= ad *header_bh, u64 ncleanadd, u64 ndirtyadd) { struct nilfs_sufile_header *header; - void *kaddr; =20 - kaddr =3D kmap_local_page(header_bh->b_page); - header =3D kaddr + bh_offset(header_bh); + header =3D kmap_local_folio(header_bh->b_folio, 0); le64_add_cpu(&header->sh_ncleansegs, ncleanadd); le64_add_cpu(&header->sh_ndirtysegs, ndirtyadd); - kunmap_local(kaddr); + kunmap_local(header); =20 mark_buffer_dirty(header_bh); } @@ -313,6 +320,7 @@ int nilfs_sufile_alloc(struct inode *sufile, __u64 *seg= nump) struct nilfs_sufile_info *sui =3D NILFS_SUI(sufile); size_t susz =3D NILFS_MDT(sufile)->mi_entry_size; __u64 segnum, maxsegnum, last_alloc; + size_t offset; void *kaddr; unsigned long nsegments, nsus, cnt; int ret, j; @@ -322,10 +330,9 @@ int nilfs_sufile_alloc(struct inode *sufile, __u64 *se= gnump) ret =3D nilfs_sufile_get_header_block(sufile, &header_bh); if (ret < 0) goto out_sem; - kaddr =3D kmap_local_page(header_bh->b_page); - header =3D kaddr + bh_offset(header_bh); + header =3D kmap_local_folio(header_bh->b_folio, 0); last_alloc =3D le64_to_cpu(header->sh_last_alloc); - kunmap_local(kaddr); + kunmap_local(header); =20 nsegments =3D nilfs_sufile_get_nsegments(sufile); maxsegnum =3D sui->allocmax; @@ -359,9 +366,10 @@ int nilfs_sufile_alloc(struct inode *sufile, __u64 *se= gnump) &su_bh); if (ret < 0) goto out_header; - kaddr =3D kmap_local_page(su_bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage( - sufile, segnum, su_bh, kaddr); + + offset =3D nilfs_sufile_segment_usage_offset(sufile, segnum, + su_bh); + su =3D kaddr =3D kmap_local_folio(su_bh->b_folio, offset); =20 nsus =3D nilfs_sufile_segment_usages_in_block( sufile, segnum, maxsegnum); @@ -372,12 +380,11 @@ int nilfs_sufile_alloc(struct inode *sufile, __u64 *s= egnump) nilfs_segment_usage_set_dirty(su); kunmap_local(kaddr); =20 - kaddr =3D kmap_local_page(header_bh->b_page); - header =3D kaddr + bh_offset(header_bh); + header =3D kmap_local_folio(header_bh->b_folio, 0); le64_add_cpu(&header->sh_ncleansegs, -1); le64_add_cpu(&header->sh_ndirtysegs, 1); header->sh_last_alloc =3D cpu_to_le64(segnum); - kunmap_local(kaddr); + kunmap_local(header); =20 sui->ncleansegs--; mark_buffer_dirty(header_bh); @@ -411,18 +418,18 @@ void nilfs_sufile_do_cancel_free(struct inode *sufile= , __u64 segnum, struct buffer_head *su_bh) { struct nilfs_segment_usage *su; - void *kaddr; + size_t offset; =20 - kaddr =3D kmap_local_page(su_bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage(sufile, segnum, su_bh, kaddr); + offset =3D nilfs_sufile_segment_usage_offset(sufile, segnum, su_bh); + su =3D kmap_local_folio(su_bh->b_folio, offset); if (unlikely(!nilfs_segment_usage_clean(su))) { nilfs_warn(sufile->i_sb, "%s: segment %llu must be clean", __func__, (unsigned long long)segnum); - kunmap_local(kaddr); + kunmap_local(su); return; } nilfs_segment_usage_set_dirty(su); - kunmap_local(kaddr); + kunmap_local(su); =20 nilfs_sufile_mod_counter(header_bh, -1, 1); NILFS_SUI(sufile)->ncleansegs--; @@ -436,14 +443,14 @@ void nilfs_sufile_do_scrap(struct inode *sufile, __u6= 4 segnum, struct buffer_head *su_bh) { struct nilfs_segment_usage *su; - void *kaddr; + size_t offset; int clean, dirty; =20 - kaddr =3D kmap_local_page(su_bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage(sufile, segnum, su_bh, kaddr); + offset =3D nilfs_sufile_segment_usage_offset(sufile, segnum, su_bh); + su =3D kmap_local_folio(su_bh->b_folio, offset); if (su->su_flags =3D=3D cpu_to_le32(BIT(NILFS_SEGMENT_USAGE_DIRTY)) && su->su_nblocks =3D=3D cpu_to_le32(0)) { - kunmap_local(kaddr); + kunmap_local(su); return; } clean =3D nilfs_segment_usage_clean(su); @@ -453,7 +460,7 @@ void nilfs_sufile_do_scrap(struct inode *sufile, __u64 = segnum, su->su_lastmod =3D cpu_to_le64(0); su->su_nblocks =3D cpu_to_le32(0); su->su_flags =3D cpu_to_le32(BIT(NILFS_SEGMENT_USAGE_DIRTY)); - kunmap_local(kaddr); + kunmap_local(su); =20 nilfs_sufile_mod_counter(header_bh, clean ? (u64)-1 : 0, dirty ? 0 : 1); NILFS_SUI(sufile)->ncleansegs -=3D clean; @@ -467,15 +474,15 @@ void nilfs_sufile_do_free(struct inode *sufile, __u64= segnum, struct buffer_head *su_bh) { struct nilfs_segment_usage *su; - void *kaddr; + size_t offset; int sudirty; =20 - kaddr =3D kmap_local_page(su_bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage(sufile, segnum, su_bh, kaddr); + offset =3D nilfs_sufile_segment_usage_offset(sufile, segnum, su_bh); + su =3D kmap_local_folio(su_bh->b_folio, offset); if (nilfs_segment_usage_clean(su)) { nilfs_warn(sufile->i_sb, "%s: segment %llu is already clean", __func__, (unsigned long long)segnum); - kunmap_local(kaddr); + kunmap_local(su); return; } if (unlikely(nilfs_segment_usage_error(su))) @@ -488,7 +495,7 @@ void nilfs_sufile_do_free(struct inode *sufile, __u64 s= egnum, (unsigned long long)segnum); =20 nilfs_segment_usage_set_clean(su); - kunmap_local(kaddr); + kunmap_local(su); mark_buffer_dirty(su_bh); =20 nilfs_sufile_mod_counter(header_bh, 1, sudirty ? (u64)-1 : 0); @@ -507,7 +514,7 @@ void nilfs_sufile_do_free(struct inode *sufile, __u64 s= egnum, int nilfs_sufile_mark_dirty(struct inode *sufile, __u64 segnum) { struct buffer_head *bh; - void *kaddr; + size_t offset; struct nilfs_segment_usage *su; int ret; =20 @@ -523,12 +530,12 @@ int nilfs_sufile_mark_dirty(struct inode *sufile, __u= 64 segnum) goto out_sem; } =20 - kaddr =3D kmap_local_page(bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage(sufile, segnum, bh, kaddr); + offset =3D nilfs_sufile_segment_usage_offset(sufile, segnum, bh); + su =3D kmap_local_folio(bh->b_folio, offset); if (unlikely(nilfs_segment_usage_error(su))) { struct the_nilfs *nilfs =3D sufile->i_sb->s_fs_info; =20 - kunmap_local(kaddr); + kunmap_local(su); brelse(bh); if (nilfs_segment_is_active(nilfs, segnum)) { nilfs_error(sufile->i_sb, @@ -546,7 +553,7 @@ int nilfs_sufile_mark_dirty(struct inode *sufile, __u64= segnum) ret =3D -EIO; } else { nilfs_segment_usage_set_dirty(su); - kunmap_local(kaddr); + kunmap_local(su); mark_buffer_dirty(bh); nilfs_mdt_mark_dirty(sufile); brelse(bh); @@ -568,7 +575,7 @@ int nilfs_sufile_set_segment_usage(struct inode *sufile= , __u64 segnum, { struct buffer_head *bh; struct nilfs_segment_usage *su; - void *kaddr; + size_t offset; int ret; =20 down_write(&NILFS_MDT(sufile)->mi_sem); @@ -576,8 +583,8 @@ int nilfs_sufile_set_segment_usage(struct inode *sufile= , __u64 segnum, if (ret < 0) goto out_sem; =20 - kaddr =3D kmap_local_page(bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage(sufile, segnum, bh, kaddr); + offset =3D nilfs_sufile_segment_usage_offset(sufile, segnum, bh); + su =3D kmap_local_folio(bh->b_folio, offset); if (modtime) { /* * Check segusage error and set su_lastmod only when updating @@ -587,7 +594,7 @@ int nilfs_sufile_set_segment_usage(struct inode *sufile= , __u64 segnum, su->su_lastmod =3D cpu_to_le64(modtime); } su->su_nblocks =3D cpu_to_le32(nblocks); - kunmap_local(kaddr); + kunmap_local(su); =20 mark_buffer_dirty(bh); nilfs_mdt_mark_dirty(sufile); @@ -619,7 +626,6 @@ int nilfs_sufile_get_stat(struct inode *sufile, struct = nilfs_sustat *sustat) struct buffer_head *header_bh; struct nilfs_sufile_header *header; struct the_nilfs *nilfs =3D sufile->i_sb->s_fs_info; - void *kaddr; int ret; =20 down_read(&NILFS_MDT(sufile)->mi_sem); @@ -628,8 +634,7 @@ int nilfs_sufile_get_stat(struct inode *sufile, struct = nilfs_sustat *sustat) if (ret < 0) goto out_sem; =20 - kaddr =3D kmap_local_page(header_bh->b_page); - header =3D kaddr + bh_offset(header_bh); + header =3D kmap_local_folio(header_bh->b_folio, 0); sustat->ss_nsegs =3D nilfs_sufile_get_nsegments(sufile); sustat->ss_ncleansegs =3D le64_to_cpu(header->sh_ncleansegs); sustat->ss_ndirtysegs =3D le64_to_cpu(header->sh_ndirtysegs); @@ -638,7 +643,7 @@ int nilfs_sufile_get_stat(struct inode *sufile, struct = nilfs_sustat *sustat) spin_lock(&nilfs->ns_last_segment_lock); sustat->ss_prot_seq =3D nilfs->ns_prot_seq; spin_unlock(&nilfs->ns_last_segment_lock); - kunmap_local(kaddr); + kunmap_local(header); brelse(header_bh); =20 out_sem: @@ -651,18 +656,18 @@ void nilfs_sufile_do_set_error(struct inode *sufile, = __u64 segnum, struct buffer_head *su_bh) { struct nilfs_segment_usage *su; - void *kaddr; + size_t offset; int suclean; =20 - kaddr =3D kmap_local_page(su_bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage(sufile, segnum, su_bh, kaddr); + offset =3D nilfs_sufile_segment_usage_offset(sufile, segnum, su_bh); + su =3D kmap_local_folio(su_bh->b_folio, offset); if (nilfs_segment_usage_error(su)) { - kunmap_local(kaddr); + kunmap_local(su); return; } suclean =3D nilfs_segment_usage_clean(su); nilfs_segment_usage_set_error(su); - kunmap_local(kaddr); + kunmap_local(su); =20 if (suclean) { nilfs_sufile_mod_counter(header_bh, -1, 0); @@ -700,7 +705,7 @@ static int nilfs_sufile_truncate_range(struct inode *su= file, unsigned long segusages_per_block; unsigned long nsegs, ncleaned; __u64 segnum; - void *kaddr; + size_t offset; ssize_t n, nc; int ret; int j; @@ -731,16 +736,16 @@ static int nilfs_sufile_truncate_range(struct inode *= sufile, /* hole */ continue; } - kaddr =3D kmap_local_page(su_bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage( - sufile, segnum, su_bh, kaddr); + offset =3D nilfs_sufile_segment_usage_offset(sufile, segnum, + su_bh); + su =3D kmap_local_folio(su_bh->b_folio, offset); su2 =3D su; for (j =3D 0; j < n; j++, su =3D (void *)su + susz) { if ((le32_to_cpu(su->su_flags) & ~BIT(NILFS_SEGMENT_USAGE_ERROR)) || nilfs_segment_is_active(nilfs, segnum + j)) { ret =3D -EBUSY; - kunmap_local(kaddr); + kunmap_local(su2); brelse(su_bh); goto out_header; } @@ -752,7 +757,7 @@ static int nilfs_sufile_truncate_range(struct inode *su= file, nc++; } } - kunmap_local(kaddr); + kunmap_local(su2); if (nc > 0) { mark_buffer_dirty(su_bh); ncleaned +=3D nc; @@ -799,7 +804,6 @@ int nilfs_sufile_resize(struct inode *sufile, __u64 new= nsegs) struct buffer_head *header_bh; struct nilfs_sufile_header *header; struct nilfs_sufile_info *sui =3D NILFS_SUI(sufile); - void *kaddr; unsigned long nsegs, nrsvsegs; int ret =3D 0; =20 @@ -837,10 +841,9 @@ int nilfs_sufile_resize(struct inode *sufile, __u64 ne= wnsegs) sui->allocmin =3D 0; } =20 - kaddr =3D kmap_local_page(header_bh->b_page); - header =3D kaddr + bh_offset(header_bh); + header =3D kmap_local_folio(header_bh->b_folio, 0); header->sh_ncleansegs =3D cpu_to_le64(sui->ncleansegs); - kunmap_local(kaddr); + kunmap_local(header); =20 mark_buffer_dirty(header_bh); nilfs_mdt_mark_dirty(sufile); @@ -874,6 +877,7 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, _= _u64 segnum, void *buf, struct nilfs_suinfo *si =3D buf; size_t susz =3D NILFS_MDT(sufile)->mi_entry_size; struct the_nilfs *nilfs =3D sufile->i_sb->s_fs_info; + size_t offset; void *kaddr; unsigned long nsegs, segusages_per_block; ssize_t n; @@ -901,9 +905,9 @@ ssize_t nilfs_sufile_get_suinfo(struct inode *sufile, _= _u64 segnum, void *buf, continue; } =20 - kaddr =3D kmap_local_page(su_bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage( - sufile, segnum, su_bh, kaddr); + offset =3D nilfs_sufile_segment_usage_offset(sufile, segnum, + su_bh); + su =3D kaddr =3D kmap_local_folio(su_bh->b_folio, offset); for (j =3D 0; j < n; j++, su =3D (void *)su + susz, si =3D (void *)si + sisz) { si->sui_lastmod =3D le64_to_cpu(su->su_lastmod); @@ -951,7 +955,7 @@ ssize_t nilfs_sufile_set_suinfo(struct inode *sufile, v= oid *buf, struct buffer_head *header_bh, *bh; struct nilfs_suinfo_update *sup, *supend =3D buf + supsz * nsup; struct nilfs_segment_usage *su; - void *kaddr; + size_t offset; unsigned long blkoff, prev_blkoff; int cleansi, cleansu, dirtysi, dirtysu; long ncleaned =3D 0, ndirtied =3D 0; @@ -983,9 +987,9 @@ ssize_t nilfs_sufile_set_suinfo(struct inode *sufile, v= oid *buf, goto out_header; =20 for (;;) { - kaddr =3D kmap_local_page(bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage( - sufile, sup->sup_segnum, bh, kaddr); + offset =3D nilfs_sufile_segment_usage_offset( + sufile, sup->sup_segnum, bh); + su =3D kmap_local_folio(bh->b_folio, offset); =20 if (nilfs_suinfo_update_lastmod(sup)) su->su_lastmod =3D cpu_to_le64(sup->sup_sui.sui_lastmod); @@ -1020,7 +1024,7 @@ ssize_t nilfs_sufile_set_suinfo(struct inode *sufile,= void *buf, su->su_flags =3D cpu_to_le32(sup->sup_sui.sui_flags); } =20 - kunmap_local(kaddr); + kunmap_local(su); =20 sup =3D (void *)sup + supsz; if (sup >=3D supend) @@ -1076,6 +1080,7 @@ int nilfs_sufile_trim_fs(struct inode *sufile, struct= fstrim_range *range) struct the_nilfs *nilfs =3D sufile->i_sb->s_fs_info; struct buffer_head *su_bh; struct nilfs_segment_usage *su; + size_t offset; void *kaddr; size_t n, i, susz =3D NILFS_MDT(sufile)->mi_entry_size; sector_t seg_start, seg_end, start_block, end_block; @@ -1125,9 +1130,9 @@ int nilfs_sufile_trim_fs(struct inode *sufile, struct= fstrim_range *range) continue; } =20 - kaddr =3D kmap_local_page(su_bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage(sufile, segnum, - su_bh, kaddr); + offset =3D nilfs_sufile_segment_usage_offset(sufile, segnum, + su_bh); + su =3D kaddr =3D kmap_local_folio(su_bh->b_folio, offset); for (i =3D 0; i < n; ++i, ++segnum, su =3D (void *)su + susz) { if (!nilfs_segment_usage_clean(su)) continue; @@ -1167,9 +1172,10 @@ int nilfs_sufile_trim_fs(struct inode *sufile, struc= t fstrim_range *range) } =20 ndiscarded +=3D nblocks; - kaddr =3D kmap_local_page(su_bh->b_page); - su =3D nilfs_sufile_block_get_segment_usage( - sufile, segnum, su_bh, kaddr); + offset =3D nilfs_sufile_segment_usage_offset( + sufile, segnum, su_bh); + su =3D kaddr =3D kmap_local_folio(su_bh->b_folio, + offset); } =20 /* start new extent */ @@ -1221,7 +1227,6 @@ int nilfs_sufile_read(struct super_block *sb, size_t = susize, struct nilfs_sufile_info *sui; struct buffer_head *header_bh; struct nilfs_sufile_header *header; - void *kaddr; int err; =20 if (susize > sb->s_blocksize) { @@ -1262,10 +1267,9 @@ int nilfs_sufile_read(struct super_block *sb, size_t= susize, } =20 sui =3D NILFS_SUI(sufile); - kaddr =3D kmap_local_page(header_bh->b_page); - header =3D kaddr + bh_offset(header_bh); + header =3D kmap_local_folio(header_bh->b_folio, 0); sui->ncleansegs =3D le64_to_cpu(header->sh_ncleansegs); - kunmap_local(kaddr); + kunmap_local(header); brelse(header_bh); =20 sui->allocmax =3D nilfs_sufile_get_nsegments(sufile) - 1; --=20 2.43.0 From nobody Mon Nov 25 21:24:27 2024 Received: from mail-oa1-f48.google.com (mail-oa1-f48.google.com [209.85.160.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B85E61BDAB9; Thu, 24 Oct 2024 09:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761981; cv=none; b=JPacv6yeXmUf+ngSkjVUj2UrIzeZjSlW0Lw7ZGzKi4PmglvRB9UYoJkS4bcxiiGMjVnZI5JHO3WUNwn1OkS9WOyj6KjkYRsKFieYhWqcORdmT2VyfV3+6yCp+qoQnMivTWpjnOh/oxlAIfYclDROAfIEP2UbKC71HoZIHfcLaSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761981; c=relaxed/simple; bh=YBGa1W/R574ExgUu1Xmj/WNRWG9AEhdKLc/mvsWGYM0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FpQ26V1imuCCjzRMBXPRNGkjd9+489uiPXh4r2AB1YDxAhQZA/tb9U7ZoFJDVkMUf5LwrjVUC8Aq3CoOA6o86z3PDbDiW0idm9sAncrlHOQNycKer8Tw0PC31jY221mqtuQ2mt8qZWtdekgiIzpxaIiq2zEljIcSfHCUPWKIqHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=e6UTHWQy; arc=none smtp.client-ip=209.85.160.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e6UTHWQy" Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-2884e7fadb8so423788fac.2; Thu, 24 Oct 2024 02:26:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761977; x=1730366777; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IoCQQE9idr8Ibh7QiNSt322nKVFTvmt/BLT3jNLBlk8=; b=e6UTHWQyDrJpfZNIQn8n4E34iTQgLfgFDsrMfYMryFz9jWyWTULHySAi8nMB4wa2MR cabC7qERsAgG0gvneQeUcFCPWUpCpWM3BKpBeuwZS7fZnPTVMTpAOmpyUPIZcU4PDfkg gHokE/WczwNmHR6wBCw4I8Dn5SzvmatGF8DLMROYgZQRMane4qLrj4tqrLNwLTWJWOg1 Im8FX0qXoRZV59D7KpaCQmmXNRWcQcmL4wLRW8XmCUIIOAYwWFXGmG5uAtmjqYk7e3Wm LtlckRuez/Chvm1oikT10J8goSHrTbozGXnaib8XAb9O91Tk9v/yQX7HwLvwbb0g2F7l s8ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761977; x=1730366777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IoCQQE9idr8Ibh7QiNSt322nKVFTvmt/BLT3jNLBlk8=; b=ho5omkJwOnr/mdp00frFXNx7GkIh6pE32m8TAwmolha3zhALpm+XkbtnKzzkG58DjY 7EjzWQeVNOLafOa20hlBp95tnp9G655Er3r0e+9wlddX1dJcKBRivbLA06QZdXq8DsBx ka76xC0FXFYnBiPxxsUdG6WKe6/MnX4OVUgjS1BIfGLwPX+3ECJIbvBmBYXUqexLdbFi gu2GUIfYaucZyVTEO04CgTGKtS5jjkuE+4j5XCN9a434DkEFhtDuYub+cyRTykFXX/OA veilWTD1wrPHEUS/T4OM8O+1jTNpoZzCHf4uxwXbwgW/Gi3d9vRkugjWYXETgsxKugRs rIgQ== X-Forwarded-Encrypted: i=1; AJvYcCUIJqUYvUc3AQn+n3GsOMDcuKBSToliC0SQDnAl4s5RxqOW7gqBR9BylNcB4rjOuVdA2MUs0jCean3NMgJq@vger.kernel.org, AJvYcCVPEbUIiDumHic54JvQ4IninRGu1jgyoPsxdHy0iqxBolVijKAbwcpjLq3sdpW8Gfi36trlWttYf6QiFJk=@vger.kernel.org, AJvYcCXkw1EtjAWaZL7jdLQnViLliP54Nx+dnYXgmtuBzsfsGsgN9I/P/S/WoybBSVuJgDq9J6O2oYPRtjVHwKIO@vger.kernel.org X-Gm-Message-State: AOJu0Yz8kGNhR1bX769z3Ok5TuNCCEp5xnUXixsscFXykXSnBbu/KirY E1gZSaSXaQEjvXVJdnMSClGx5eZ8UPaQETfSS3REMx6nL4LqZOXr X-Google-Smtp-Source: AGHT+IFDqD5NT+w/YCScMbz0etsmr/tPYi6Fhrdj9JvpJvKYC6RUwxM/wq2kNwbIVhhKmgn31rsXug== X-Received: by 2002:a05:6871:3a14:b0:288:6365:d7a2 with SMTP id 586e51a60fabf-28ccba5169amr6011474fac.44.1729761977392; Thu, 24 Oct 2024 02:26:17 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:16 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 04/12] nilfs2: convert persistent object allocator to be folio-based Date: Thu, 24 Oct 2024 18:25:38 +0900 Message-ID: <20241024092602.13395-5-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Regarding the persistent oject allocator, a common mechanism for allocating objects in metadata files such as inodes and DAT entries, convert the page-based implementation to a folio-based implementation. In this conversion, helper functions nilfs_palloc_group_desc_offset() and nilfs_palloc_bitmap_offset() are added and used to calculate the byte offset within a folio of a group descriptor structure and bitmap, respectively, to replace kmap_local_page with kmap_local_folio. In addition, a helper function called nilfs_palloc_entry_offset() is provided to facilitate common calculation of the byte offset within a folio of metadata file entries managed in the persistent object allocator format. Signed-off-by: Ryusuke Konishi Cc: Matthew Wilcox (Oracle) --- fs/nilfs2/alloc.c | 137 +++++++++++++++++++++++++++++----------------- fs/nilfs2/alloc.h | 2 + 2 files changed, 89 insertions(+), 50 deletions(-) diff --git a/fs/nilfs2/alloc.c b/fs/nilfs2/alloc.c index d30dfed707b6..5e0a6bd3e015 100644 --- a/fs/nilfs2/alloc.c +++ b/fs/nilfs2/alloc.c @@ -339,19 +339,55 @@ static int nilfs_palloc_delete_entry_block(struct ino= de *inode, __u64 nr) } =20 /** - * nilfs_palloc_block_get_group_desc - get kernel address of a group descr= iptor + * nilfs_palloc_group_desc_offset - calculate the byte offset of a group + * descriptor in the folio containing it * @inode: inode of metadata file using this allocator * @group: group number - * @bh: buffer head of the buffer storing the group descriptor block - * @kaddr: kernel address mapped for the page including the buffer + * @bh: buffer head of the group descriptor block + * + * Return: Byte offset in the folio of the group descriptor for @group. */ -static struct nilfs_palloc_group_desc * -nilfs_palloc_block_get_group_desc(const struct inode *inode, - unsigned long group, - const struct buffer_head *bh, void *kaddr) +static size_t nilfs_palloc_group_desc_offset(const struct inode *inode, + unsigned long group, + const struct buffer_head *bh) { - return (struct nilfs_palloc_group_desc *)(kaddr + bh_offset(bh)) + - group % nilfs_palloc_groups_per_desc_block(inode); + return offset_in_folio(bh->b_folio, bh->b_data) + + sizeof(struct nilfs_palloc_group_desc) * + (group % nilfs_palloc_groups_per_desc_block(inode)); +} + +/** + * nilfs_palloc_bitmap_offset - calculate the byte offset of a bitmap block + * in the folio containing it + * @bh: buffer head of the bitmap block + * + * Return: Byte offset in the folio of the bitmap block for @bh. + */ +static size_t nilfs_palloc_bitmap_offset(const struct buffer_head *bh) +{ + return offset_in_folio(bh->b_folio, bh->b_data); +} + +/** + * nilfs_palloc_entry_offset - calculate the byte offset of an entry in the + * folio containing it + * @inode: inode of metadata file using this allocator + * @nr: serial number of the entry (e.g. inode number) + * @bh: buffer head of the entry block + * + * Return: Byte offset in the folio of the entry @nr. + */ +size_t nilfs_palloc_entry_offset(const struct inode *inode, __u64 nr, + const struct buffer_head *bh) +{ + unsigned long entry_index_in_group, entry_index_in_block; + + nilfs_palloc_group(inode, nr, &entry_index_in_group); + entry_index_in_block =3D entry_index_in_group % + NILFS_MDT(inode)->mi_entries_per_block; + + return offset_in_folio(bh->b_folio, bh->b_data) + + entry_index_in_block * NILFS_MDT(inode)->mi_entry_size; } =20 /** @@ -508,7 +544,7 @@ int nilfs_palloc_prepare_alloc_entry(struct inode *inod= e, struct buffer_head *desc_bh, *bitmap_bh; struct nilfs_palloc_group_desc *desc; unsigned char *bitmap; - void *desc_kaddr, *bitmap_kaddr; + size_t doff, boff; unsigned long group, maxgroup, ngroups; unsigned long group_offset, maxgroup_offset; unsigned long n, entries_per_group; @@ -531,17 +567,17 @@ int nilfs_palloc_prepare_alloc_entry(struct inode *in= ode, ret =3D nilfs_palloc_get_desc_block(inode, group, 1, &desc_bh); if (ret < 0) return ret; - desc_kaddr =3D kmap_local_page(desc_bh->b_page); - desc =3D nilfs_palloc_block_get_group_desc( - inode, group, desc_bh, desc_kaddr); + + doff =3D nilfs_palloc_group_desc_offset(inode, group, desc_bh); + desc =3D kmap_local_folio(desc_bh->b_folio, doff); n =3D nilfs_palloc_rest_groups_in_desc_block(inode, group, maxgroup); - for (j =3D 0; j < n; j++, desc++, group++, group_offset =3D 0) { + for (j =3D 0; j < n; j++, group++, group_offset =3D 0) { lock =3D nilfs_mdt_bgl_lock(inode, group); - if (nilfs_palloc_group_desc_nfrees(desc, lock) =3D=3D 0) + if (nilfs_palloc_group_desc_nfrees(&desc[j], lock) =3D=3D 0) continue; =20 - kunmap_local(desc_kaddr); + kunmap_local(desc); ret =3D nilfs_palloc_get_bitmap_block(inode, group, 1, &bitmap_bh); if (unlikely(ret < 0)) { @@ -549,12 +585,14 @@ int nilfs_palloc_prepare_alloc_entry(struct inode *in= ode, return ret; } =20 - desc_kaddr =3D kmap_local_page(desc_bh->b_page); - desc =3D nilfs_palloc_block_get_group_desc( - inode, group, desc_bh, desc_kaddr); + /* + * Re-kmap the folio containing the first (and + * subsequent) group descriptors. + */ + desc =3D kmap_local_folio(desc_bh->b_folio, doff); =20 - bitmap_kaddr =3D kmap_local_page(bitmap_bh->b_page); - bitmap =3D bitmap_kaddr + bh_offset(bitmap_bh); + boff =3D nilfs_palloc_bitmap_offset(bitmap_bh); + bitmap =3D kmap_local_folio(bitmap_bh->b_folio, boff); pos =3D nilfs_palloc_find_available_slot( bitmap, group_offset, entries_per_group, lock, wrap); @@ -564,14 +602,14 @@ int nilfs_palloc_prepare_alloc_entry(struct inode *in= ode, * beginning, the wrap flag only has an effect on the * first search. */ - kunmap_local(bitmap_kaddr); + kunmap_local(bitmap); if (pos >=3D 0) goto found; =20 brelse(bitmap_bh); } =20 - kunmap_local(desc_kaddr); + kunmap_local(desc); brelse(desc_bh); } =20 @@ -580,9 +618,9 @@ int nilfs_palloc_prepare_alloc_entry(struct inode *inod= e, =20 found: /* found a free entry */ - nilfs_palloc_group_desc_add_entries(desc, lock, -1); + nilfs_palloc_group_desc_add_entries(&desc[j], lock, -1); req->pr_entry_nr =3D entries_per_group * group + pos; - kunmap_local(desc_kaddr); + kunmap_local(desc); =20 req->pr_desc_bh =3D desc_bh; req->pr_bitmap_bh =3D bitmap_bh; @@ -613,18 +651,18 @@ void nilfs_palloc_commit_alloc_entry(struct inode *in= ode, void nilfs_palloc_commit_free_entry(struct inode *inode, struct nilfs_palloc_req *req) { - struct nilfs_palloc_group_desc *desc; unsigned long group, group_offset; + size_t doff, boff; + struct nilfs_palloc_group_desc *desc; unsigned char *bitmap; - void *desc_kaddr, *bitmap_kaddr; spinlock_t *lock; =20 group =3D nilfs_palloc_group(inode, req->pr_entry_nr, &group_offset); - desc_kaddr =3D kmap_local_page(req->pr_desc_bh->b_page); - desc =3D nilfs_palloc_block_get_group_desc(inode, group, - req->pr_desc_bh, desc_kaddr); - bitmap_kaddr =3D kmap_local_page(req->pr_bitmap_bh->b_page); - bitmap =3D bitmap_kaddr + bh_offset(req->pr_bitmap_bh); + doff =3D nilfs_palloc_group_desc_offset(inode, group, req->pr_desc_bh); + desc =3D kmap_local_folio(req->pr_desc_bh->b_folio, doff); + + boff =3D nilfs_palloc_bitmap_offset(req->pr_bitmap_bh); + bitmap =3D kmap_local_folio(req->pr_bitmap_bh->b_folio, boff); lock =3D nilfs_mdt_bgl_lock(inode, group); =20 if (!nilfs_clear_bit_atomic(lock, group_offset, bitmap)) @@ -635,8 +673,8 @@ void nilfs_palloc_commit_free_entry(struct inode *inode, else nilfs_palloc_group_desc_add_entries(desc, lock, 1); =20 - kunmap_local(bitmap_kaddr); - kunmap_local(desc_kaddr); + kunmap_local(bitmap); + kunmap_local(desc); =20 mark_buffer_dirty(req->pr_desc_bh); mark_buffer_dirty(req->pr_bitmap_bh); @@ -655,17 +693,17 @@ void nilfs_palloc_abort_alloc_entry(struct inode *ino= de, struct nilfs_palloc_req *req) { struct nilfs_palloc_group_desc *desc; - void *desc_kaddr, *bitmap_kaddr; + size_t doff, boff; unsigned char *bitmap; unsigned long group, group_offset; spinlock_t *lock; =20 group =3D nilfs_palloc_group(inode, req->pr_entry_nr, &group_offset); - desc_kaddr =3D kmap_local_page(req->pr_desc_bh->b_page); - desc =3D nilfs_palloc_block_get_group_desc(inode, group, - req->pr_desc_bh, desc_kaddr); - bitmap_kaddr =3D kmap_local_page(req->pr_bitmap_bh->b_page); - bitmap =3D bitmap_kaddr + bh_offset(req->pr_bitmap_bh); + doff =3D nilfs_palloc_group_desc_offset(inode, group, req->pr_desc_bh); + desc =3D kmap_local_folio(req->pr_desc_bh->b_folio, doff); + + boff =3D nilfs_palloc_bitmap_offset(req->pr_bitmap_bh); + bitmap =3D kmap_local_folio(req->pr_bitmap_bh->b_folio, boff); lock =3D nilfs_mdt_bgl_lock(inode, group); =20 if (!nilfs_clear_bit_atomic(lock, group_offset, bitmap)) @@ -676,8 +714,8 @@ void nilfs_palloc_abort_alloc_entry(struct inode *inode, else nilfs_palloc_group_desc_add_entries(desc, lock, 1); =20 - kunmap_local(bitmap_kaddr); - kunmap_local(desc_kaddr); + kunmap_local(bitmap); + kunmap_local(desc); =20 brelse(req->pr_bitmap_bh); brelse(req->pr_desc_bh); @@ -741,7 +779,7 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entr= y_nrs, size_t nitems) struct buffer_head *desc_bh, *bitmap_bh; struct nilfs_palloc_group_desc *desc; unsigned char *bitmap; - void *desc_kaddr, *bitmap_kaddr; + size_t doff, boff; unsigned long group, group_offset; __u64 group_min_nr, last_nrs[8]; const unsigned long epg =3D nilfs_palloc_entries_per_group(inode); @@ -769,8 +807,8 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entr= y_nrs, size_t nitems) /* Get the first entry number of the group */ group_min_nr =3D (__u64)group * epg; =20 - bitmap_kaddr =3D kmap_local_page(bitmap_bh->b_page); - bitmap =3D bitmap_kaddr + bh_offset(bitmap_bh); + boff =3D nilfs_palloc_bitmap_offset(bitmap_bh); + bitmap =3D kmap_local_folio(bitmap_bh->b_folio, boff); lock =3D nilfs_mdt_bgl_lock(inode, group); =20 j =3D i; @@ -815,7 +853,7 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *entr= y_nrs, size_t nitems) entry_start =3D rounddown(group_offset, epb); } while (true); =20 - kunmap_local(bitmap_kaddr); + kunmap_local(bitmap); mark_buffer_dirty(bitmap_bh); brelse(bitmap_bh); =20 @@ -829,11 +867,10 @@ int nilfs_palloc_freev(struct inode *inode, __u64 *en= try_nrs, size_t nitems) inode->i_ino); } =20 - desc_kaddr =3D kmap_local_page(desc_bh->b_page); - desc =3D nilfs_palloc_block_get_group_desc( - inode, group, desc_bh, desc_kaddr); + doff =3D nilfs_palloc_group_desc_offset(inode, group, desc_bh); + desc =3D kmap_local_folio(desc_bh->b_folio, doff); nfree =3D nilfs_palloc_group_desc_add_entries(desc, lock, n); - kunmap_local(desc_kaddr); + kunmap_local(desc); mark_buffer_dirty(desc_bh); nilfs_mdt_mark_dirty(inode); brelse(desc_bh); diff --git a/fs/nilfs2/alloc.h b/fs/nilfs2/alloc.h index e19d7eb10084..af8f882619d4 100644 --- a/fs/nilfs2/alloc.h +++ b/fs/nilfs2/alloc.h @@ -33,6 +33,8 @@ int nilfs_palloc_get_entry_block(struct inode *, __u64, i= nt, struct buffer_head **); void *nilfs_palloc_block_get_entry(const struct inode *, __u64, const struct buffer_head *, void *); +size_t nilfs_palloc_entry_offset(const struct inode *inode, __u64 nr, + const struct buffer_head *bh); =20 int nilfs_palloc_count_max_entries(struct inode *, u64, u64 *); =20 --=20 2.43.0 From nobody Mon Nov 25 21:24:27 2024 Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAF1C1B392C; Thu, 24 Oct 2024 09:26:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761982; cv=none; b=d8SHuF+UMMSE//sTg6WWyJIaHo3voTNp7jalIjgiLX9pSuVoDer/PYo+5ICpdFgptTyCUTS7qRLcxeTwbX5s2YEEj1xQTnWCnKf0h2GnPD2VfnG1TmnYlgcCwBwV8qXhW98hFuf0XB9tjM0l7e8qZWtUisooIwKzlBAqzkhNEx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761982; c=relaxed/simple; bh=ApXolRjbW7uPTaPug2xagYT5GraWeA47lhyoOlE59ZU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BV+PGQwia7szxguJr+YO/TIiqZxeMeyV5SNfz5RDj64+GlWOn4JomFy0bAamhyLvBCkBnBARjkJ7w06qfRS0+XpSB7LJOhPPlBqm5CDeem2taJe87Hj5FYLfWV0p45Nx2I0ty43AikrBXtCa3R/neVIVTfEiqTSF+bT/snOt240= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BnCnjP0h; arc=none smtp.client-ip=209.85.219.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BnCnjP0h" Received: by mail-yb1-f171.google.com with SMTP id 3f1490d57ef6-e29687f4cc6so760322276.2; Thu, 24 Oct 2024 02:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761980; x=1730366780; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kbcwrjGS6D/wxYkZ0FTx8Zm+DfXe52iNpdOWPXiGeb8=; b=BnCnjP0hxHdq15qS25E/+fCngmBNLN0b7M/yqwGNpPkHknxWhJUDAELsmyldbMBsLV DJoYOunGkvFggT2B6KIlOnj6LPJ5TE3pHdcjeQ0a7l8g7DZvo/7ituhMb7Fg3H5vACfJ g5ghA8aMaN3OsAHgTz+VymXbY3iaFLEhtIyvDHFTX+QMtQzoBimVHwD7tkQqfjzhfs20 ODPmkjvdOeTpQhMRqGHCGt34WvK9pNinGqPOJ4by9Vb/r9f6fF0ahfefS26ebLRVH56V 3jtVMH2I/E39Q+WJTn5j99xpHyxKZJyhWfxllCb3odlpB3TxmSmgUDv+EiC24aVLAZB7 wFtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761980; x=1730366780; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kbcwrjGS6D/wxYkZ0FTx8Zm+DfXe52iNpdOWPXiGeb8=; b=bZrrEL2Qx9vTXAkrxxxbsTQSV0Q6icL8PiGRBrCV1VlxRASOtpsLyuaiYMzNT1MtAE zCqArs748GOTk3uYDpcxZ2hDNs7NjaMK1IA71T4Ee3R7P3uXUPvOXTjAfPYevce3vmNG tKEFbBxbKbwtuURXLs+B7WY+DnYS7eVKkGxJZHTShqoOvbvWQxGpblZBMfprAWjBG25H IwFxKdyhWbiDEot4MMdFurJC5asoQQJWZSPxHDJipykbylBoxRch28sUX0BmIMdz4/r8 5hcrM57WD5epr33iYWa4hnJLh27PknIMUBOcuzHo3qtLdnSL9JM1ALAMjTmrwbRnJVV7 sE+A== X-Forwarded-Encrypted: i=1; AJvYcCWT472z3Gy001sOfX8vTaf7RKqhHREfdbWtylNmbXhZc5HdP8DZFdQiGFo8VTrCEsDiPhZD/uoIzxTengU=@vger.kernel.org, AJvYcCWlZKmeL3oxQUA3sXZsK+Yg09a2EvLj2P4h25HnnweMkdymZQNr2jfRk+5sV04DFoUmKOvKWXmPhiU2zuTy@vger.kernel.org, AJvYcCXF6VsjLHMg075wgft8DumnyPmpFX8Szioc1T3wN64OhsbgXB77cGF8dk5Nxh0YuYSVt4I0AhCGYXgsAuzo@vger.kernel.org X-Gm-Message-State: AOJu0YxaeHXcemuSEa9342LgMMCJlqUVdaPPxWFk+I4RSrMvYe9hqKJ8 xx+Z6Qn7sUbV80+jS857lm131u0NMOr2OraME+eWjQ4KhRF9/hcP X-Google-Smtp-Source: AGHT+IH1X684ycjGALsbCCbZeWy+0hqSVcdj1UUI/CHecNEAZasCF34CQe4RPljVk4H0QDHz6QLoKg== X-Received: by 2002:a05:6902:c06:b0:e2b:e286:b60e with SMTP id 3f1490d57ef6-e2e3a6c7cd7mr5322784276.42.1729761979744; Thu, 24 Oct 2024 02:26:19 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:19 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 05/12] nilfs2: convert inode file to be folio-based Date: Thu, 24 Oct 2024 18:25:39 +0900 Message-ID: <20241024092602.13395-6-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert the page-based implementation of ifile, a metadata file that manages inodes, to folio-based. Signed-off-by: Ryusuke Konishi Cc: Matthew Wilcox (Oracle) --- fs/nilfs2/ifile.c | 10 +++++----- fs/nilfs2/ifile.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/nilfs2/ifile.c b/fs/nilfs2/ifile.c index 1e86b9303b7c..e7339eb3c08a 100644 --- a/fs/nilfs2/ifile.c +++ b/fs/nilfs2/ifile.c @@ -98,7 +98,7 @@ int nilfs_ifile_delete_inode(struct inode *ifile, ino_t i= no) .pr_entry_nr =3D ino, .pr_entry_bh =3D NULL }; struct nilfs_inode *raw_inode; - void *kaddr; + size_t offset; int ret; =20 ret =3D nilfs_palloc_prepare_free_entry(ifile, &req); @@ -113,11 +113,11 @@ int nilfs_ifile_delete_inode(struct inode *ifile, ino= _t ino) return ret; } =20 - kaddr =3D kmap_local_page(req.pr_entry_bh->b_page); - raw_inode =3D nilfs_palloc_block_get_entry(ifile, req.pr_entry_nr, - req.pr_entry_bh, kaddr); + offset =3D nilfs_palloc_entry_offset(ifile, req.pr_entry_nr, + req.pr_entry_bh); + raw_inode =3D kmap_local_folio(req.pr_entry_bh->b_folio, offset); raw_inode->i_flags =3D 0; - kunmap_local(kaddr); + kunmap_local(raw_inode); =20 mark_buffer_dirty(req.pr_entry_bh); brelse(req.pr_entry_bh); diff --git a/fs/nilfs2/ifile.h b/fs/nilfs2/ifile.h index 625545cc2a98..5d116a566d9e 100644 --- a/fs/nilfs2/ifile.h +++ b/fs/nilfs2/ifile.h @@ -21,9 +21,9 @@ static inline struct nilfs_inode * nilfs_ifile_map_inode(struct inode *ifile, ino_t ino, struct buffer_head *= ibh) { - void *kaddr =3D kmap_local_page(ibh->b_page); + size_t __offset_in_folio =3D nilfs_palloc_entry_offset(ifile, ino, ibh); =20 - return nilfs_palloc_block_get_entry(ifile, ino, ibh, kaddr); + return kmap_local_folio(ibh->b_folio, __offset_in_folio); } =20 static inline void nilfs_ifile_unmap_inode(struct nilfs_inode *raw_inode) --=20 2.43.0 From nobody Mon Nov 25 21:24:27 2024 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5E481B394F; Thu, 24 Oct 2024 09:26:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761985; cv=none; b=S/nl2HBjovT8VhoAYudxAnTO9DrL7ytQsw+a10Juc7xCEK/dMXBjJvBYBK9GdgKRSBx3K27KHmLIB2DMIigSWf9kwas/EhNHw/dBUIBODGS6/NNDHthyVXKf0D5hFzYCEo+1w8+OCsNv9habtoxXl5rYk8gz9QgxqIL6WbHWko8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761985; c=relaxed/simple; bh=lnlSpSRuEWC2+V1fFBVKSi7pR/S2wsUDYeUHRvfZDsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pnSpOJlaAhPR606X6vBzl3Ioyg2jz/eNIaFPe4ACEYs7NNquToinrTpffg99yl5W/yS0iksRCqnVCdPh/VExsrZhHGryBJVkIRagsGz4UbGsTJSEIYwW8+Lkdv+JngfqT93PtAuYgKI9Cm7axWMt59UROTg+2JcwhThLKMHALNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QdxfDyoY; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QdxfDyoY" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so451991a12.3; Thu, 24 Oct 2024 02:26:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761982; x=1730366782; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PjC2ZyAS0c5+ZNkIKeA4HqrorWpfWyuyhr+EB27pGMQ=; b=QdxfDyoYwc1CHmV05/A5dTslomfCVbcNQZSOgku6+cu5o76b/kuUBFeL+qzDezfodV fe2tXN5iCAqwScPervHRwhQQf1ebN2ETlMNlgD/67an6BTPuYLF4qLntD3m7qAA/4LKI x6U/K+UBIz7egEQ81ZhKMbPzMuPpGKDW0nPKAPxgel4116FrV5FkYstypMwHnKsg9iHn C5nONERpFL9rFOyG+7ys1k4WSAihw0AH/gJScpcK9BSJtdbe7h9sxNKRFvHHs0Fnli5k F3iS9UWYPcUDWBxzrCQ7dKLRw6ZX24ULq2qcQp8pC9iUflmYjaESXrDUlpjfXzctBJO/ EBWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761982; x=1730366782; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PjC2ZyAS0c5+ZNkIKeA4HqrorWpfWyuyhr+EB27pGMQ=; b=f3if7J6I+IBz9hb1MCEktP57Ik+feX857+sUiaAPaZSZAblo+94u+pDl9WLFr1mnen rfZM82aJx1lY6ogIGy97/Mteeywxgv7VC+BWxmaWeRvg8rKY0J/aDSXlKC1/3EV/lg8G sxxuh17KTqr3ufmc687EAlHeWRKnyU1nyejyV8ieWLO6wtf/rEF+j7fSkoybLWqv+Ivg dSWnXk3V3adLNreu3lTSuasYaxSVHjIcRlQKDJiG37MI0xUg86PYkq8RYfvfOkhKa6rD 7Pp+MgD2dBAA7eduQ52Q4mVjgOgGapFG1Ii7ICuSZsUMBwD62oV2lYV8jqjqq01EF+YH Dv8A== X-Forwarded-Encrypted: i=1; AJvYcCVZwcH8DaOcic8xXDKGZB26+SGQCm3RD++k6Vp+A8VzbLyfxU/jFLicb5gPSilo/mswuISWToOrMjYlk4hH@vger.kernel.org, AJvYcCWWluRZjEKBpua+F/ElXC0k71A3/IvK6Gb5Pf2IzCN/1LAuMK8Xy9c0AqnhswaNC34tuK+0hcPRACp6Xq18@vger.kernel.org, AJvYcCWqScYFMqduqSQLzZPmm73mFSCujaP0OeKkgV9kzny1987Gjv6nn4P2lzms8U6anN95umyPKf8zy+KgwYM=@vger.kernel.org X-Gm-Message-State: AOJu0YxtXxjo/2ywH23CgOPhkDan38vHs1kcZCbb0vFCj2PmAIrkcer5 MWnrCTkYmd1mATF4QcOtGX7cdTsqTvgWdl3JdR3BWZ/RV8tA0AfyB1U2lQ== X-Google-Smtp-Source: AGHT+IEue/HkDpnTRSPvjF+GeHCL0FWVWHhW8thqswbSVQ0jhYwBfAj5Boirue/y+UqaVN4yA5a+pQ== X-Received: by 2002:a05:6a21:3984:b0:1d9:275b:4ee9 with SMTP id adf61e73a8af0-1d978af6913mr6299775637.15.1729761982081; Thu, 24 Oct 2024 02:26:22 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:21 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 06/12] nilfs2: convert DAT file to be folio-based Date: Thu, 24 Oct 2024 18:25:40 +0900 Message-ID: <20241024092602.13395-7-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Regarding the DAT, a metadata file that manages virtual block addresses, convert the page-based implementation to a folio-based implementation. Signed-off-by: Ryusuke Konishi Cc: Matthew Wilcox (Oracle) --- fs/nilfs2/dat.c | 98 ++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 46 deletions(-) diff --git a/fs/nilfs2/dat.c b/fs/nilfs2/dat.c index 0bef662176a4..e220dcb08aa6 100644 --- a/fs/nilfs2/dat.c +++ b/fs/nilfs2/dat.c @@ -89,15 +89,15 @@ int nilfs_dat_prepare_alloc(struct inode *dat, struct n= ilfs_palloc_req *req) void nilfs_dat_commit_alloc(struct inode *dat, struct nilfs_palloc_req *re= q) { struct nilfs_dat_entry *entry; - void *kaddr; + size_t offset; =20 - kaddr =3D kmap_local_page(req->pr_entry_bh->b_page); - entry =3D nilfs_palloc_block_get_entry(dat, req->pr_entry_nr, - req->pr_entry_bh, kaddr); + offset =3D nilfs_palloc_entry_offset(dat, req->pr_entry_nr, + req->pr_entry_bh); + entry =3D kmap_local_folio(req->pr_entry_bh->b_folio, offset); entry->de_start =3D cpu_to_le64(NILFS_CNO_MIN); entry->de_end =3D cpu_to_le64(NILFS_CNO_MAX); entry->de_blocknr =3D cpu_to_le64(0); - kunmap_local(kaddr); + kunmap_local(entry); =20 nilfs_palloc_commit_alloc_entry(dat, req); nilfs_dat_commit_entry(dat, req); @@ -113,15 +113,15 @@ static void nilfs_dat_commit_free(struct inode *dat, struct nilfs_palloc_req *req) { struct nilfs_dat_entry *entry; - void *kaddr; + size_t offset; =20 - kaddr =3D kmap_local_page(req->pr_entry_bh->b_page); - entry =3D nilfs_palloc_block_get_entry(dat, req->pr_entry_nr, - req->pr_entry_bh, kaddr); + offset =3D nilfs_palloc_entry_offset(dat, req->pr_entry_nr, + req->pr_entry_bh); + entry =3D kmap_local_folio(req->pr_entry_bh->b_folio, offset); entry->de_start =3D cpu_to_le64(NILFS_CNO_MIN); entry->de_end =3D cpu_to_le64(NILFS_CNO_MIN); entry->de_blocknr =3D cpu_to_le64(0); - kunmap_local(kaddr); + kunmap_local(entry); =20 nilfs_dat_commit_entry(dat, req); =20 @@ -143,14 +143,14 @@ void nilfs_dat_commit_start(struct inode *dat, struct= nilfs_palloc_req *req, sector_t blocknr) { struct nilfs_dat_entry *entry; - void *kaddr; + size_t offset; =20 - kaddr =3D kmap_local_page(req->pr_entry_bh->b_page); - entry =3D nilfs_palloc_block_get_entry(dat, req->pr_entry_nr, - req->pr_entry_bh, kaddr); + offset =3D nilfs_palloc_entry_offset(dat, req->pr_entry_nr, + req->pr_entry_bh); + entry =3D kmap_local_folio(req->pr_entry_bh->b_folio, offset); entry->de_start =3D cpu_to_le64(nilfs_mdt_cno(dat)); entry->de_blocknr =3D cpu_to_le64(blocknr); - kunmap_local(kaddr); + kunmap_local(entry); =20 nilfs_dat_commit_entry(dat, req); } @@ -160,19 +160,19 @@ int nilfs_dat_prepare_end(struct inode *dat, struct n= ilfs_palloc_req *req) struct nilfs_dat_entry *entry; __u64 start; sector_t blocknr; - void *kaddr; + size_t offset; int ret; =20 ret =3D nilfs_dat_prepare_entry(dat, req, 0); if (ret < 0) return ret; =20 - kaddr =3D kmap_local_page(req->pr_entry_bh->b_page); - entry =3D nilfs_palloc_block_get_entry(dat, req->pr_entry_nr, - req->pr_entry_bh, kaddr); + offset =3D nilfs_palloc_entry_offset(dat, req->pr_entry_nr, + req->pr_entry_bh); + entry =3D kmap_local_folio(req->pr_entry_bh->b_folio, offset); start =3D le64_to_cpu(entry->de_start); blocknr =3D le64_to_cpu(entry->de_blocknr); - kunmap_local(kaddr); + kunmap_local(entry); =20 if (blocknr =3D=3D 0) { ret =3D nilfs_palloc_prepare_free_entry(dat, req); @@ -200,11 +200,11 @@ void nilfs_dat_commit_end(struct inode *dat, struct n= ilfs_palloc_req *req, struct nilfs_dat_entry *entry; __u64 start, end; sector_t blocknr; - void *kaddr; + size_t offset; =20 - kaddr =3D kmap_local_page(req->pr_entry_bh->b_page); - entry =3D nilfs_palloc_block_get_entry(dat, req->pr_entry_nr, - req->pr_entry_bh, kaddr); + offset =3D nilfs_palloc_entry_offset(dat, req->pr_entry_nr, + req->pr_entry_bh); + entry =3D kmap_local_folio(req->pr_entry_bh->b_folio, offset); end =3D start =3D le64_to_cpu(entry->de_start); if (!dead) { end =3D nilfs_mdt_cno(dat); @@ -212,7 +212,7 @@ void nilfs_dat_commit_end(struct inode *dat, struct nil= fs_palloc_req *req, } entry->de_end =3D cpu_to_le64(end); blocknr =3D le64_to_cpu(entry->de_blocknr); - kunmap_local(kaddr); + kunmap_local(entry); =20 if (blocknr =3D=3D 0) nilfs_dat_commit_free(dat, req); @@ -225,14 +225,14 @@ void nilfs_dat_abort_end(struct inode *dat, struct ni= lfs_palloc_req *req) struct nilfs_dat_entry *entry; __u64 start; sector_t blocknr; - void *kaddr; + size_t offset; =20 - kaddr =3D kmap_local_page(req->pr_entry_bh->b_page); - entry =3D nilfs_palloc_block_get_entry(dat, req->pr_entry_nr, - req->pr_entry_bh, kaddr); + offset =3D nilfs_palloc_entry_offset(dat, req->pr_entry_nr, + req->pr_entry_bh); + entry =3D kmap_local_folio(req->pr_entry_bh->b_folio, offset); start =3D le64_to_cpu(entry->de_start); blocknr =3D le64_to_cpu(entry->de_blocknr); - kunmap_local(kaddr); + kunmap_local(entry); =20 if (start =3D=3D nilfs_mdt_cno(dat) && blocknr =3D=3D 0) nilfs_palloc_abort_free_entry(dat, req); @@ -336,7 +336,7 @@ int nilfs_dat_move(struct inode *dat, __u64 vblocknr, s= ector_t blocknr) { struct buffer_head *entry_bh; struct nilfs_dat_entry *entry; - void *kaddr; + size_t offset; int ret; =20 ret =3D nilfs_palloc_get_entry_block(dat, vblocknr, 0, &entry_bh); @@ -359,21 +359,21 @@ int nilfs_dat_move(struct inode *dat, __u64 vblocknr,= sector_t blocknr) } } =20 - kaddr =3D kmap_local_page(entry_bh->b_page); - entry =3D nilfs_palloc_block_get_entry(dat, vblocknr, entry_bh, kaddr); + offset =3D nilfs_palloc_entry_offset(dat, vblocknr, entry_bh); + entry =3D kmap_local_folio(entry_bh->b_folio, offset); if (unlikely(entry->de_blocknr =3D=3D cpu_to_le64(0))) { nilfs_crit(dat->i_sb, "%s: invalid vblocknr =3D %llu, [%llu, %llu)", __func__, (unsigned long long)vblocknr, (unsigned long long)le64_to_cpu(entry->de_start), (unsigned long long)le64_to_cpu(entry->de_end)); - kunmap_local(kaddr); + kunmap_local(entry); brelse(entry_bh); return -EINVAL; } WARN_ON(blocknr =3D=3D 0); entry->de_blocknr =3D cpu_to_le64(blocknr); - kunmap_local(kaddr); + kunmap_local(entry); =20 mark_buffer_dirty(entry_bh); nilfs_mdt_mark_dirty(dat); @@ -407,7 +407,7 @@ int nilfs_dat_translate(struct inode *dat, __u64 vblock= nr, sector_t *blocknrp) struct buffer_head *entry_bh, *bh; struct nilfs_dat_entry *entry; sector_t blocknr; - void *kaddr; + size_t offset; int ret; =20 ret =3D nilfs_palloc_get_entry_block(dat, vblocknr, 0, &entry_bh); @@ -423,8 +423,8 @@ int nilfs_dat_translate(struct inode *dat, __u64 vblock= nr, sector_t *blocknrp) } } =20 - kaddr =3D kmap_local_page(entry_bh->b_page); - entry =3D nilfs_palloc_block_get_entry(dat, vblocknr, entry_bh, kaddr); + offset =3D nilfs_palloc_entry_offset(dat, vblocknr, entry_bh); + entry =3D kmap_local_folio(entry_bh->b_folio, offset); blocknr =3D le64_to_cpu(entry->de_blocknr); if (blocknr =3D=3D 0) { ret =3D -ENOENT; @@ -433,7 +433,7 @@ int nilfs_dat_translate(struct inode *dat, __u64 vblock= nr, sector_t *blocknrp) *blocknrp =3D blocknr; =20 out: - kunmap_local(kaddr); + kunmap_local(entry); brelse(entry_bh); return ret; } @@ -442,11 +442,12 @@ ssize_t nilfs_dat_get_vinfo(struct inode *dat, void *= buf, unsigned int visz, size_t nvi) { struct buffer_head *entry_bh; - struct nilfs_dat_entry *entry; + struct nilfs_dat_entry *entry, *first_entry; struct nilfs_vinfo *vinfo =3D buf; __u64 first, last; - void *kaddr; + size_t offset; unsigned long entries_per_block =3D NILFS_MDT(dat)->mi_entries_per_block; + unsigned int entry_size =3D NILFS_MDT(dat)->mi_entry_size; int i, j, n, ret; =20 for (i =3D 0; i < nvi; i +=3D n) { @@ -454,23 +455,28 @@ ssize_t nilfs_dat_get_vinfo(struct inode *dat, void *= buf, unsigned int visz, 0, &entry_bh); if (ret < 0) return ret; - kaddr =3D kmap_local_page(entry_bh->b_page); - /* last virtual block number in this block */ + first =3D vinfo->vi_vblocknr; first =3D div64_ul(first, entries_per_block); first *=3D entries_per_block; + /* first virtual block number in this block */ + last =3D first + entries_per_block - 1; + /* last virtual block number in this block */ + + offset =3D nilfs_palloc_entry_offset(dat, first, entry_bh); + first_entry =3D kmap_local_folio(entry_bh->b_folio, offset); for (j =3D i, n =3D 0; j < nvi && vinfo->vi_vblocknr >=3D first && vinfo->vi_vblocknr <=3D last; j++, n++, vinfo =3D (void *)vinfo + visz) { - entry =3D nilfs_palloc_block_get_entry( - dat, vinfo->vi_vblocknr, entry_bh, kaddr); + entry =3D (void *)first_entry + + (vinfo->vi_vblocknr - first) * entry_size; vinfo->vi_start =3D le64_to_cpu(entry->de_start); vinfo->vi_end =3D le64_to_cpu(entry->de_end); vinfo->vi_blocknr =3D le64_to_cpu(entry->de_blocknr); } - kunmap_local(kaddr); + kunmap_local(first_entry); brelse(entry_bh); } =20 --=20 2.43.0 From nobody Mon Nov 25 21:24:27 2024 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B50C1C32EC; Thu, 24 Oct 2024 09:26:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761987; cv=none; b=lNtxDwMlb8VIY4gALUpCoLWNwVD+bwb0FBArB1nsNG54nJEO5tz46+Urp0EO0IbpcDLuYAE022rRtTXuq14gbq03qZuYPl4NQsWW070bOkS1xt8laGSDLFZj7bPP7GOxGZcx39R4LZ4zOZPN7+6BHWBSm46brE6zlwl4o9UH1AU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761987; c=relaxed/simple; bh=C3/JXOy6pyXEnet2ZU3cquvkOzRp30347+gzWGD6VE4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Upaj1aZStH0c6CPGzcwmPc3/WzrPUgGD7t/vZGzEZNEh6utjuNkM3xyQgrJ1dNjqM3lfDvzASmUB5hHr5j1DKzM/S0Vcx1QbZfP7pNjarzN7Ic5RIeWqi/I4cV0KCtB5cXILkQLBhuG4BDMGMFSeJ5iijzFnhMkn/QarhBGysuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=U0DIYaCL; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U0DIYaCL" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-71e625b00bcso515795b3a.3; Thu, 24 Oct 2024 02:26:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761984; x=1730366784; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d+VrIqKKYOtO3M0mpfjgZhM5oDURd/5X3mD5U8C7QOQ=; b=U0DIYaCLPFEhekvfMQzsiQZtKSRTp7om8lpbO+KBDWHbDnmqQtaENtajxd9RnyHLtH jr+jipUBz07AN0Scis3tTqyQoF/DAvTfVz7DVuC0pXqGlecXi1OrhN78/bvI74uuE1Dr Jz0ybHI1zgd/clVLhB373zx8wXQJ3oN24/GC81zChPB/DSV3Jfksjet2xQATaKCnow/e IijRYFLufNp7VUbcaTKn9O3mE9/UbgR/hNL8jeCz+QhVnXHno8EgOfpXMJtj+u/Pb9OH OzP9NxHDDqWMTVAfKzg74gRKgdcptUm3kXXC/S9bp4k793pnl7R0LNXeTRl13T5N0ig+ E0Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761984; x=1730366784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d+VrIqKKYOtO3M0mpfjgZhM5oDURd/5X3mD5U8C7QOQ=; b=AH1oTj02raLoQhT5IjCsPfIsT2sdNneFmZZyeHB5EUYdX5VRG7vzMauM1OSVTmWZBx UFTHxKBfyngmrdJ3IUUJOTIDrLEgpXd2Pte3p1RS7uj+BeE4nzToCzDlJGmTqMv833sl HK1/LV+MY4+r4oQ4bJSg86obiJKARvB042CLLwCKWLsOP0ua21HNDHqgYjtAAYx27mE7 vUF0gqE6S8wQTUYI4iusecCqAfSu+drEsg9V3LJGGyWM+tBZAbyfYam9jXbPe55Vnzgr ptIgIOK69vJG3KBd3YnSGQOPmxU29KJYhnNqGFqa1TW0Z4bOkPb9N4kwMnq3zGgTubtF tewA== X-Forwarded-Encrypted: i=1; AJvYcCVanf3GRNxNAcdF6oEpShoTa5Y5xaibETIzSIQyBoyKfDmIIWwficEstm7GjDjTPFiGiHy2VPp/z6oquoY=@vger.kernel.org, AJvYcCXPwcb6nMDqMwuhxNHGyaDX8F+WoKBBQF5BRdbxq1RUSQ9m8nGeph+Xl/sEQv80l9Gvnqo//c8EmPMZ9OBd@vger.kernel.org, AJvYcCXbf9QNhoarZqdyO4jOc5+SVTP7VvF86bAxjoMOEuhPPWJD6wO+DdZnvirvAzxxJ2SMcJIbNeAlBke0gaVO@vger.kernel.org X-Gm-Message-State: AOJu0YywRwbp3ZGwRy4oElEdTbvNDAqefaVga8Aug1kl0w+3KcSS7ovI cGcweovvZchx6ENNBz7QXU+7kJycaYgmC6XyllhjDRIBzRwZFhr0KXMKRQ== X-Google-Smtp-Source: AGHT+IEAdfW6BQA61M8dhRfZrI4T8nteE8I7s4nNrFfOocP9QK13oGguSg5R20rcPru5VGaXIc2VRg== X-Received: by 2002:a05:6a00:1390:b0:71e:6f4d:1fa4 with SMTP id d2e1a72fcca58-72030a4b659mr7850810b3a.10.1729761984387; Thu, 24 Oct 2024 02:26:24 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:23 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 07/12] nilfs2: remove nilfs_palloc_block_get_entry() Date: Thu, 24 Oct 2024 18:25:41 +0900 Message-ID: <20241024092602.13395-8-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" All calls to nilfs_palloc_block_get_entry() are now gone, so remove it. Signed-off-by: Ryusuke Konishi Cc: Matthew Wilcox (Oracle) --- fs/nilfs2/alloc.c | 19 ------------------- fs/nilfs2/alloc.h | 2 -- 2 files changed, 21 deletions(-) diff --git a/fs/nilfs2/alloc.c b/fs/nilfs2/alloc.c index 5e0a6bd3e015..ba3e1f591f36 100644 --- a/fs/nilfs2/alloc.c +++ b/fs/nilfs2/alloc.c @@ -390,25 +390,6 @@ size_t nilfs_palloc_entry_offset(const struct inode *i= node, __u64 nr, entry_index_in_block * NILFS_MDT(inode)->mi_entry_size; } =20 -/** - * nilfs_palloc_block_get_entry - get kernel address of an entry - * @inode: inode of metadata file using this allocator - * @nr: serial number of the entry (e.g. inode number) - * @bh: buffer head of the buffer storing the entry block - * @kaddr: kernel address mapped for the page including the buffer - */ -void *nilfs_palloc_block_get_entry(const struct inode *inode, __u64 nr, - const struct buffer_head *bh, void *kaddr) -{ - unsigned long entry_offset, group_offset; - - nilfs_palloc_group(inode, nr, &group_offset); - entry_offset =3D group_offset % NILFS_MDT(inode)->mi_entries_per_block; - - return kaddr + bh_offset(bh) + - entry_offset * NILFS_MDT(inode)->mi_entry_size; -} - /** * nilfs_palloc_find_available_slot - find available slot in a group * @bitmap: bitmap of the group diff --git a/fs/nilfs2/alloc.h b/fs/nilfs2/alloc.h index af8f882619d4..3f115ab7e9a7 100644 --- a/fs/nilfs2/alloc.h +++ b/fs/nilfs2/alloc.h @@ -31,8 +31,6 @@ nilfs_palloc_entries_per_group(const struct inode *inode) int nilfs_palloc_init_blockgroup(struct inode *, unsigned int); int nilfs_palloc_get_entry_block(struct inode *, __u64, int, struct buffer_head **); -void *nilfs_palloc_block_get_entry(const struct inode *, __u64, - const struct buffer_head *, void *); size_t nilfs_palloc_entry_offset(const struct inode *inode, __u64 nr, const struct buffer_head *bh); =20 --=20 2.43.0 From nobody Mon Nov 25 21:24:27 2024 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE0EB1C75F9; Thu, 24 Oct 2024 09:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761991; cv=none; b=rkGjUZFbM58dfgKkF0Ws1vvS5qRlxLJbXNKNrXq2ROk/Bh9IiAtaa5gwppzxGXLSha/5XzeKfVAviPQIjCRJPOSMvySWdtiIEyC3virr3gEPlszRIyZ8340juTzokKFeEBTh8CmoW1lpgRYG0fyE+Xcgfidry9T2FxF5/1WPPfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761991; c=relaxed/simple; bh=Syw4GyotNgDMewrm2WfebnZtMBQ5lp2jvq84CsU4/qk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WuFRAI85MVt1+vU3+yo2OADnGOrYwUfy9Uu57rC4CgH4GtHHrjtr+0DR18cTHrXyn8n62cbfv5jWTQiTinBiHviYbLRjyguwk24jNc1Jg+An045xLwi++AYffP6EiJDDqMBt7vGzJ9+7bmN5nTrmzudObU93ZE9ALKMkRZQAif8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gxoFnObn; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gxoFnObn" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-71e4244fdc6so517860b3a.0; Thu, 24 Oct 2024 02:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761987; x=1730366787; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6HCAS6C7GITEkTSee22mjEQINZktMD4P7+akevVqk6c=; b=gxoFnObnp3hI5ukRTJcvBEmglgv59f3qKLZWjF5twGI2k2hyp4BegYNCWPUcMdNyjo 4viXVa4qlai/fO+aCsMEEb2n3KwjM7rj8INia3dqPRkGnshJESx6yZtLQnjVU6ZJcdZ5 21s6epkA+B8tnK+JAp6+6YxfK0rnRmahCIfYWOSznkMpfsmQf3OTbUEXv1hZ7RTtZUQo +5jkNsYMBtN97OsNwVSMpasln9nLRVUymSQ8bxn4Dd70uTt8rpU/heB5klmT+yFktgUr 6gGrQ8bYKx0pFGQ9oF8UqkVxjAiOqyRrfYnXpf3RtZVupEgWCpZi1/+HjrKsf5Qnp9V2 /2Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761987; x=1730366787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6HCAS6C7GITEkTSee22mjEQINZktMD4P7+akevVqk6c=; b=cMRgn/0sy3RTvcvQ8Vt2vPq2JtuAhkT3Y8oZn3aGLyHosL85Hyr2CWoVrb+5Cl1bY1 BCFdkhbNYCg2ONgUrEtcRd8kVq8Z5hjOfHvLHBhi4EMKPW6TneR1VFQZiv6bMyDlaWBi d4FkNvdO0OxgjfsJmIVhMEyOZvSTpNDvEpMi1J1G5DWzbxl8Kcw3hdUlY2n3eKC9l4Ta G7rxfGaAymeqSP+RDUYi9PnWj5fP249JSXs74d9ptGEbv281xc5+eYrrjKyaRXER5MBL AoxeyA5PrVUJvLJgeVGfR9byxYY/j1tRFkyUYbnvf1u5CD6uEJXWB/PER1DbDEL62cV2 zhwA== X-Forwarded-Encrypted: i=1; AJvYcCUqZYJNziuwBNvg6WkicOZ8Fg7asTFnrKclAdXmzN9FRc2clANA1GChOPTWE4TmgTNXfIBg4vPXqK4vljtO@vger.kernel.org, AJvYcCVzi4FeyIuydQ+Xv2e1w8yWNJz9RbeTBxp0EobmAWpOPiyfGdxqDVVFuk4xtt46QDToa0FszD/VqX2ohe3L@vger.kernel.org, AJvYcCXgwroUMFrjB/itSWA8Fgob/Y4CpWCipvq9D+PGPIBC/zLTuqcYrm3hswtjd2ZyN8LphdAsZJVIYuYMZa4=@vger.kernel.org X-Gm-Message-State: AOJu0YxDnzJP7hsRaMN8Fw5bo37KsYFVjoUSmkdBufMHB07jcyKoaYW7 bSphXT16Hae7X4u7wloHZNVSijxvWrujQo4LadvvALyUbirsb1wSIejnog== X-Google-Smtp-Source: AGHT+IFeIypfH8v9Nrynkx/2/y18iRnMBFTkFgBHuG0MiTYRxM6iB+YHmF68Bk2y2ckF8hq6/EwtUA== X-Received: by 2002:a05:6a00:22d3:b0:71e:3b51:e850 with SMTP id d2e1a72fcca58-72030b62bffmr7918748b3a.2.1729761986935; Thu, 24 Oct 2024 02:26:26 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:26 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 08/12] nilfs2: convert checkpoint file to be folio-based Date: Thu, 24 Oct 2024 18:25:42 +0900 Message-ID: <20241024092602.13395-9-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Regarding the cpfile, a metadata file that manages checkpoints, convert the page-based implementation to a folio-based implementation. This change involves some helper functions to calculate byte offsets on folios and removing a few helper functions that are no longer needed. Signed-off-by: Ryusuke Konishi Cc: Matthew Wilcox (Oracle) --- fs/nilfs2/cpfile.c | 379 ++++++++++++++++++++++++--------------------- 1 file changed, 204 insertions(+), 175 deletions(-) diff --git a/fs/nilfs2/cpfile.c b/fs/nilfs2/cpfile.c index a8046cbf2753..c20207d7a989 100644 --- a/fs/nilfs2/cpfile.c +++ b/fs/nilfs2/cpfile.c @@ -68,49 +68,36 @@ static inline int nilfs_cpfile_is_in_first(const struct= inode *cpfile, static unsigned int nilfs_cpfile_block_add_valid_checkpoints(const struct inode *cpfile, struct buffer_head *bh, - void *kaddr, unsigned int n) { - struct nilfs_checkpoint *cp =3D kaddr + bh_offset(bh); + struct nilfs_checkpoint *cp; unsigned int count; =20 + cp =3D kmap_local_folio(bh->b_folio, + offset_in_folio(bh->b_folio, bh->b_data)); count =3D le32_to_cpu(cp->cp_checkpoints_count) + n; cp->cp_checkpoints_count =3D cpu_to_le32(count); + kunmap_local(cp); return count; } =20 static unsigned int nilfs_cpfile_block_sub_valid_checkpoints(const struct inode *cpfile, struct buffer_head *bh, - void *kaddr, unsigned int n) { - struct nilfs_checkpoint *cp =3D kaddr + bh_offset(bh); + struct nilfs_checkpoint *cp; unsigned int count; =20 + cp =3D kmap_local_folio(bh->b_folio, + offset_in_folio(bh->b_folio, bh->b_data)); WARN_ON(le32_to_cpu(cp->cp_checkpoints_count) < n); count =3D le32_to_cpu(cp->cp_checkpoints_count) - n; cp->cp_checkpoints_count =3D cpu_to_le32(count); + kunmap_local(cp); return count; } =20 -static inline struct nilfs_cpfile_header * -nilfs_cpfile_block_get_header(const struct inode *cpfile, - struct buffer_head *bh, - void *kaddr) -{ - return kaddr + bh_offset(bh); -} - -static struct nilfs_checkpoint * -nilfs_cpfile_block_get_checkpoint(const struct inode *cpfile, __u64 cno, - struct buffer_head *bh, - void *kaddr) -{ - return kaddr + bh_offset(bh) + nilfs_cpfile_get_offset(cpfile, cno) * - NILFS_MDT(cpfile)->mi_entry_size; -} - static void nilfs_cpfile_block_init(struct inode *cpfile, struct buffer_head *bh, void *from) @@ -125,6 +112,54 @@ static void nilfs_cpfile_block_init(struct inode *cpfi= le, } } =20 +/** + * nilfs_cpfile_checkpoint_offset - calculate the byte offset of a checkpo= int + * entry in the folio containing it + * @cpfile: checkpoint file inode + * @cno: checkpoint number + * @bh: buffer head of block containing checkpoint indexed by @cno + * + * Return: Byte offset in the folio of the checkpoint specified by @cno. + */ +static size_t nilfs_cpfile_checkpoint_offset(const struct inode *cpfile, + __u64 cno, + struct buffer_head *bh) +{ + return offset_in_folio(bh->b_folio, bh->b_data) + + nilfs_cpfile_get_offset(cpfile, cno) * + NILFS_MDT(cpfile)->mi_entry_size; +} + +/** + * nilfs_cpfile_cp_snapshot_list_offset - calculate the byte offset of a + * checkpoint snapshot list in the = folio + * containing it + * @cpfile: checkpoint file inode + * @cno: checkpoint number + * @bh: buffer head of block containing checkpoint indexed by @cno + * + * Return: Byte offset in the folio of the checkpoint snapshot list specif= ied + * by @cno. + */ +static size_t nilfs_cpfile_cp_snapshot_list_offset(const struct inode *cpf= ile, + __u64 cno, + struct buffer_head *bh) +{ + return nilfs_cpfile_checkpoint_offset(cpfile, cno, bh) + + offsetof(struct nilfs_checkpoint, cp_snapshot_list); +} + +/** + * nilfs_cpfile_ch_snapshot_list_offset - calculate the byte offset of the + * snapshot list in the header + * + * Return: Byte offset in the folio of the checkpoint snapshot list + */ +static size_t nilfs_cpfile_ch_snapshot_list_offset(void) +{ + return offsetof(struct nilfs_cpfile_header, ch_snapshot_list); +} + static int nilfs_cpfile_get_header_block(struct inode *cpfile, struct buffer_head **bhp) { @@ -214,7 +249,7 @@ int nilfs_cpfile_read_checkpoint(struct inode *cpfile, = __u64 cno, { struct buffer_head *cp_bh; struct nilfs_checkpoint *cp; - void *kaddr; + size_t offset; int ret; =20 if (cno < 1 || cno > nilfs_mdt_cno(cpfile)) @@ -228,8 +263,8 @@ int nilfs_cpfile_read_checkpoint(struct inode *cpfile, = __u64 cno, goto out_sem; } =20 - kaddr =3D kmap_local_page(cp_bh->b_page); - cp =3D nilfs_cpfile_block_get_checkpoint(cpfile, cno, cp_bh, kaddr); + offset =3D nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh); + cp =3D kmap_local_folio(cp_bh->b_folio, offset); if (nilfs_checkpoint_invalid(cp)) { ret =3D -EINVAL; goto put_cp; @@ -254,7 +289,7 @@ int nilfs_cpfile_read_checkpoint(struct inode *cpfile, = __u64 cno, root->ifile =3D ifile; =20 put_cp: - kunmap_local(kaddr); + kunmap_local(cp); brelse(cp_bh); out_sem: up_read(&NILFS_MDT(cpfile)->mi_sem); @@ -282,7 +317,7 @@ int nilfs_cpfile_create_checkpoint(struct inode *cpfile= , __u64 cno) struct buffer_head *header_bh, *cp_bh; struct nilfs_cpfile_header *header; struct nilfs_checkpoint *cp; - void *kaddr; + size_t offset; int ret; =20 if (WARN_ON_ONCE(cno < 1)) @@ -297,24 +332,22 @@ int nilfs_cpfile_create_checkpoint(struct inode *cpfi= le, __u64 cno) if (unlikely(ret < 0)) goto out_header; =20 - kaddr =3D kmap_local_page(cp_bh->b_page); - cp =3D nilfs_cpfile_block_get_checkpoint(cpfile, cno, cp_bh, kaddr); + offset =3D nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh); + cp =3D kmap_local_folio(cp_bh->b_folio, offset); if (nilfs_checkpoint_invalid(cp)) { /* a newly-created checkpoint */ nilfs_checkpoint_clear_invalid(cp); + kunmap_local(cp); if (!nilfs_cpfile_is_in_first(cpfile, cno)) nilfs_cpfile_block_add_valid_checkpoints(cpfile, cp_bh, - kaddr, 1); - kunmap_local(kaddr); + 1); =20 - kaddr =3D kmap_local_page(header_bh->b_page); - header =3D nilfs_cpfile_block_get_header(cpfile, header_bh, - kaddr); + header =3D kmap_local_folio(header_bh->b_folio, 0); le64_add_cpu(&header->ch_ncheckpoints, 1); - kunmap_local(kaddr); + kunmap_local(header); mark_buffer_dirty(header_bh); } else { - kunmap_local(kaddr); + kunmap_local(cp); } =20 /* Force the buffer and the inode to become dirty */ @@ -353,7 +386,7 @@ int nilfs_cpfile_finalize_checkpoint(struct inode *cpfi= le, __u64 cno, { struct buffer_head *cp_bh; struct nilfs_checkpoint *cp; - void *kaddr; + size_t offset; int ret; =20 if (WARN_ON_ONCE(cno < 1)) @@ -367,10 +400,10 @@ int nilfs_cpfile_finalize_checkpoint(struct inode *cp= file, __u64 cno, goto out_sem; } =20 - kaddr =3D kmap_local_page(cp_bh->b_page); - cp =3D nilfs_cpfile_block_get_checkpoint(cpfile, cno, cp_bh, kaddr); + offset =3D nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh); + cp =3D kmap_local_folio(cp_bh->b_folio, offset); if (unlikely(nilfs_checkpoint_invalid(cp))) { - kunmap_local(kaddr); + kunmap_local(cp); brelse(cp_bh); goto error; } @@ -391,7 +424,7 @@ int nilfs_cpfile_finalize_checkpoint(struct inode *cpfi= le, __u64 cno, nilfs_write_inode_common(root->ifile, &cp->cp_ifile_inode); nilfs_bmap_write(NILFS_I(root->ifile)->i_bmap, &cp->cp_ifile_inode); =20 - kunmap_local(kaddr); + kunmap_local(cp); brelse(cp_bh); out_sem: up_write(&NILFS_MDT(cpfile)->mi_sem); @@ -432,6 +465,7 @@ int nilfs_cpfile_delete_checkpoints(struct inode *cpfil= e, struct nilfs_checkpoint *cp; size_t cpsz =3D NILFS_MDT(cpfile)->mi_entry_size; __u64 cno; + size_t offset; void *kaddr; unsigned long tnicps; int ret, ncps, nicps, nss, count, i; @@ -462,9 +496,8 @@ int nilfs_cpfile_delete_checkpoints(struct inode *cpfil= e, continue; } =20 - kaddr =3D kmap_local_page(cp_bh->b_page); - cp =3D nilfs_cpfile_block_get_checkpoint( - cpfile, cno, cp_bh, kaddr); + offset =3D nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh); + cp =3D kaddr =3D kmap_local_folio(cp_bh->b_folio, offset); nicps =3D 0; for (i =3D 0; i < ncps; i++, cp =3D (void *)cp + cpsz) { if (nilfs_checkpoint_snapshot(cp)) { @@ -474,43 +507,42 @@ int nilfs_cpfile_delete_checkpoints(struct inode *cpf= ile, nicps++; } } - if (nicps > 0) { - tnicps +=3D nicps; - mark_buffer_dirty(cp_bh); - nilfs_mdt_mark_dirty(cpfile); - if (!nilfs_cpfile_is_in_first(cpfile, cno)) { - count =3D - nilfs_cpfile_block_sub_valid_checkpoints( - cpfile, cp_bh, kaddr, nicps); - if (count =3D=3D 0) { - /* make hole */ - kunmap_local(kaddr); - brelse(cp_bh); - ret =3D - nilfs_cpfile_delete_checkpoint_block( - cpfile, cno); - if (ret =3D=3D 0) - continue; - nilfs_err(cpfile->i_sb, - "error %d deleting checkpoint block", - ret); - break; - } - } + kunmap_local(kaddr); + + if (nicps <=3D 0) { + brelse(cp_bh); + continue; } =20 - kunmap_local(kaddr); + tnicps +=3D nicps; + mark_buffer_dirty(cp_bh); + nilfs_mdt_mark_dirty(cpfile); + if (nilfs_cpfile_is_in_first(cpfile, cno)) { + brelse(cp_bh); + continue; + } + + count =3D nilfs_cpfile_block_sub_valid_checkpoints(cpfile, cp_bh, + nicps); brelse(cp_bh); + if (count) + continue; + + /* Delete the block if there are no more valid checkpoints */ + ret =3D nilfs_cpfile_delete_checkpoint_block(cpfile, cno); + if (unlikely(ret)) { + nilfs_err(cpfile->i_sb, + "error %d deleting checkpoint block", ret); + break; + } } =20 if (tnicps > 0) { - kaddr =3D kmap_local_page(header_bh->b_page); - header =3D nilfs_cpfile_block_get_header(cpfile, header_bh, - kaddr); + header =3D kmap_local_folio(header_bh->b_folio, 0); le64_add_cpu(&header->ch_ncheckpoints, -(u64)tnicps); mark_buffer_dirty(header_bh); nilfs_mdt_mark_dirty(cpfile); - kunmap_local(kaddr); + kunmap_local(header); } =20 brelse(header_bh); @@ -544,6 +576,7 @@ static ssize_t nilfs_cpfile_do_get_cpinfo(struct inode = *cpfile, __u64 *cnop, struct buffer_head *bh; size_t cpsz =3D NILFS_MDT(cpfile)->mi_entry_size; __u64 cur_cno =3D nilfs_mdt_cno(cpfile), cno =3D *cnop; + size_t offset; void *kaddr; int n, ret; int ncps, i; @@ -562,8 +595,8 @@ static ssize_t nilfs_cpfile_do_get_cpinfo(struct inode = *cpfile, __u64 *cnop, } ncps =3D nilfs_cpfile_checkpoints_in_block(cpfile, cno, cur_cno); =20 - kaddr =3D kmap_local_page(bh->b_page); - cp =3D nilfs_cpfile_block_get_checkpoint(cpfile, cno, bh, kaddr); + offset =3D nilfs_cpfile_checkpoint_offset(cpfile, cno, bh); + cp =3D kaddr =3D kmap_local_folio(bh->b_folio, offset); for (i =3D 0; i < ncps && n < nci; i++, cp =3D (void *)cp + cpsz) { if (!nilfs_checkpoint_invalid(cp)) { nilfs_cpfile_checkpoint_to_cpinfo(cpfile, cp, @@ -597,7 +630,7 @@ static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode = *cpfile, __u64 *cnop, struct nilfs_cpinfo *ci =3D buf; __u64 curr =3D *cnop, next; unsigned long curr_blkoff, next_blkoff; - void *kaddr; + size_t offset; int n =3D 0, ret; =20 down_read(&NILFS_MDT(cpfile)->mi_sem); @@ -606,10 +639,9 @@ static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode= *cpfile, __u64 *cnop, ret =3D nilfs_cpfile_get_header_block(cpfile, &bh); if (ret < 0) goto out; - kaddr =3D kmap_local_page(bh->b_page); - header =3D nilfs_cpfile_block_get_header(cpfile, bh, kaddr); + header =3D kmap_local_folio(bh->b_folio, 0); curr =3D le64_to_cpu(header->ch_snapshot_list.ssl_next); - kunmap_local(kaddr); + kunmap_local(header); brelse(bh); if (curr =3D=3D 0) { ret =3D 0; @@ -627,9 +659,9 @@ static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode = *cpfile, __u64 *cnop, ret =3D 0; /* No snapshots (started from a hole block) */ goto out; } - kaddr =3D kmap_local_page(bh->b_page); + offset =3D nilfs_cpfile_checkpoint_offset(cpfile, curr, bh); + cp =3D kmap_local_folio(bh->b_folio, offset); while (n < nci) { - cp =3D nilfs_cpfile_block_get_checkpoint(cpfile, curr, bh, kaddr); curr =3D ~(__u64)0; /* Terminator */ if (unlikely(nilfs_checkpoint_invalid(cp) || !nilfs_checkpoint_snapshot(cp))) @@ -641,9 +673,9 @@ static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode = *cpfile, __u64 *cnop, if (next =3D=3D 0) break; /* reach end of the snapshot list */ =20 + kunmap_local(cp); next_blkoff =3D nilfs_cpfile_get_blkoff(cpfile, next); if (curr_blkoff !=3D next_blkoff) { - kunmap_local(kaddr); brelse(bh); ret =3D nilfs_cpfile_get_checkpoint_block(cpfile, next, 0, &bh); @@ -651,12 +683,13 @@ static ssize_t nilfs_cpfile_do_get_ssinfo(struct inod= e *cpfile, __u64 *cnop, WARN_ON(ret =3D=3D -ENOENT); goto out; } - kaddr =3D kmap_local_page(bh->b_page); } + offset =3D nilfs_cpfile_checkpoint_offset(cpfile, next, bh); + cp =3D kmap_local_folio(bh->b_folio, offset); curr =3D next; curr_blkoff =3D next_blkoff; } - kunmap_local(kaddr); + kunmap_local(cp); brelse(bh); *cnop =3D curr; ret =3D n; @@ -733,26 +766,6 @@ int nilfs_cpfile_delete_checkpoint(struct inode *cpfil= e, __u64 cno) return nilfs_cpfile_delete_checkpoints(cpfile, cno, cno + 1); } =20 -static struct nilfs_snapshot_list * -nilfs_cpfile_block_get_snapshot_list(const struct inode *cpfile, - __u64 cno, - struct buffer_head *bh, - void *kaddr) -{ - struct nilfs_cpfile_header *header; - struct nilfs_checkpoint *cp; - struct nilfs_snapshot_list *list; - - if (cno !=3D 0) { - cp =3D nilfs_cpfile_block_get_checkpoint(cpfile, cno, bh, kaddr); - list =3D &cp->cp_snapshot_list; - } else { - header =3D nilfs_cpfile_block_get_header(cpfile, bh, kaddr); - list =3D &header->ch_snapshot_list; - } - return list; -} - static int nilfs_cpfile_set_snapshot(struct inode *cpfile, __u64 cno) { struct buffer_head *header_bh, *curr_bh, *prev_bh, *cp_bh; @@ -761,94 +774,103 @@ static int nilfs_cpfile_set_snapshot(struct inode *c= pfile, __u64 cno) struct nilfs_snapshot_list *list; __u64 curr, prev; unsigned long curr_blkoff, prev_blkoff; - void *kaddr; + size_t offset, curr_list_offset, prev_list_offset; int ret; =20 if (cno =3D=3D 0) return -ENOENT; /* checkpoint number 0 is invalid */ down_write(&NILFS_MDT(cpfile)->mi_sem); =20 + ret =3D nilfs_cpfile_get_header_block(cpfile, &header_bh); + if (unlikely(ret < 0)) + goto out_sem; + ret =3D nilfs_cpfile_get_checkpoint_block(cpfile, cno, 0, &cp_bh); if (ret < 0) - goto out_sem; - kaddr =3D kmap_local_page(cp_bh->b_page); - cp =3D nilfs_cpfile_block_get_checkpoint(cpfile, cno, cp_bh, kaddr); + goto out_header; + + offset =3D nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh); + cp =3D kmap_local_folio(cp_bh->b_folio, offset); if (nilfs_checkpoint_invalid(cp)) { ret =3D -ENOENT; - kunmap_local(kaddr); + kunmap_local(cp); goto out_cp; } if (nilfs_checkpoint_snapshot(cp)) { ret =3D 0; - kunmap_local(kaddr); + kunmap_local(cp); goto out_cp; } - kunmap_local(kaddr); + kunmap_local(cp); =20 - ret =3D nilfs_cpfile_get_header_block(cpfile, &header_bh); - if (ret < 0) - goto out_cp; - kaddr =3D kmap_local_page(header_bh->b_page); - header =3D nilfs_cpfile_block_get_header(cpfile, header_bh, kaddr); + /* + * Find the last snapshot before the checkpoint being changed to + * snapshot mode by going backwards through the snapshot list. + * Set "prev" to its checkpoint number, or 0 if not found. + */ + header =3D kmap_local_folio(header_bh->b_folio, 0); list =3D &header->ch_snapshot_list; curr_bh =3D header_bh; get_bh(curr_bh); curr =3D 0; curr_blkoff =3D 0; + curr_list_offset =3D nilfs_cpfile_ch_snapshot_list_offset(); prev =3D le64_to_cpu(list->ssl_prev); while (prev > cno) { prev_blkoff =3D nilfs_cpfile_get_blkoff(cpfile, prev); curr =3D prev; + kunmap_local(list); if (curr_blkoff !=3D prev_blkoff) { - kunmap_local(kaddr); brelse(curr_bh); ret =3D nilfs_cpfile_get_checkpoint_block(cpfile, curr, 0, &curr_bh); - if (ret < 0) - goto out_header; - kaddr =3D kmap_local_page(curr_bh->b_page); + if (unlikely(ret < 0)) + goto out_cp; } + curr_list_offset =3D nilfs_cpfile_cp_snapshot_list_offset( + cpfile, curr, curr_bh); + list =3D kmap_local_folio(curr_bh->b_folio, curr_list_offset); curr_blkoff =3D prev_blkoff; - cp =3D nilfs_cpfile_block_get_checkpoint( - cpfile, curr, curr_bh, kaddr); - list =3D &cp->cp_snapshot_list; prev =3D le64_to_cpu(list->ssl_prev); } - kunmap_local(kaddr); + kunmap_local(list); =20 if (prev !=3D 0) { ret =3D nilfs_cpfile_get_checkpoint_block(cpfile, prev, 0, &prev_bh); if (ret < 0) goto out_curr; + + prev_list_offset =3D nilfs_cpfile_cp_snapshot_list_offset( + cpfile, prev, prev_bh); } else { prev_bh =3D header_bh; get_bh(prev_bh); + prev_list_offset =3D nilfs_cpfile_ch_snapshot_list_offset(); } =20 - kaddr =3D kmap_local_page(curr_bh->b_page); - list =3D nilfs_cpfile_block_get_snapshot_list( - cpfile, curr, curr_bh, kaddr); + /* Update the list entry for the next snapshot */ + list =3D kmap_local_folio(curr_bh->b_folio, curr_list_offset); list->ssl_prev =3D cpu_to_le64(cno); - kunmap_local(kaddr); + kunmap_local(list); =20 - kaddr =3D kmap_local_page(cp_bh->b_page); - cp =3D nilfs_cpfile_block_get_checkpoint(cpfile, cno, cp_bh, kaddr); + /* Update the checkpoint being changed to a snapshot */ + offset =3D nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh); + cp =3D kmap_local_folio(cp_bh->b_folio, offset); cp->cp_snapshot_list.ssl_next =3D cpu_to_le64(curr); cp->cp_snapshot_list.ssl_prev =3D cpu_to_le64(prev); nilfs_checkpoint_set_snapshot(cp); - kunmap_local(kaddr); + kunmap_local(cp); =20 - kaddr =3D kmap_local_page(prev_bh->b_page); - list =3D nilfs_cpfile_block_get_snapshot_list( - cpfile, prev, prev_bh, kaddr); + /* Update the list entry for the previous snapshot */ + list =3D kmap_local_folio(prev_bh->b_folio, prev_list_offset); list->ssl_next =3D cpu_to_le64(cno); - kunmap_local(kaddr); + kunmap_local(list); =20 - kaddr =3D kmap_local_page(header_bh->b_page); - header =3D nilfs_cpfile_block_get_header(cpfile, header_bh, kaddr); + /* Update the statistics in the header */ + header =3D kmap_local_folio(header_bh->b_folio, 0); le64_add_cpu(&header->ch_nsnapshots, 1); - kunmap_local(kaddr); + kunmap_local(header); =20 mark_buffer_dirty(prev_bh); mark_buffer_dirty(curr_bh); @@ -861,12 +883,12 @@ static int nilfs_cpfile_set_snapshot(struct inode *cp= file, __u64 cno) out_curr: brelse(curr_bh); =20 - out_header: - brelse(header_bh); - out_cp: brelse(cp_bh); =20 + out_header: + brelse(header_bh); + out_sem: up_write(&NILFS_MDT(cpfile)->mi_sem); return ret; @@ -879,79 +901,87 @@ static int nilfs_cpfile_clear_snapshot(struct inode *= cpfile, __u64 cno) struct nilfs_checkpoint *cp; struct nilfs_snapshot_list *list; __u64 next, prev; - void *kaddr; + size_t offset, next_list_offset, prev_list_offset; int ret; =20 if (cno =3D=3D 0) return -ENOENT; /* checkpoint number 0 is invalid */ down_write(&NILFS_MDT(cpfile)->mi_sem); =20 + ret =3D nilfs_cpfile_get_header_block(cpfile, &header_bh); + if (unlikely(ret < 0)) + goto out_sem; + ret =3D nilfs_cpfile_get_checkpoint_block(cpfile, cno, 0, &cp_bh); if (ret < 0) - goto out_sem; - kaddr =3D kmap_local_page(cp_bh->b_page); - cp =3D nilfs_cpfile_block_get_checkpoint(cpfile, cno, cp_bh, kaddr); + goto out_header; + + offset =3D nilfs_cpfile_checkpoint_offset(cpfile, cno, cp_bh); + cp =3D kmap_local_folio(cp_bh->b_folio, offset); if (nilfs_checkpoint_invalid(cp)) { ret =3D -ENOENT; - kunmap_local(kaddr); + kunmap_local(cp); goto out_cp; } if (!nilfs_checkpoint_snapshot(cp)) { ret =3D 0; - kunmap_local(kaddr); + kunmap_local(cp); goto out_cp; } =20 list =3D &cp->cp_snapshot_list; next =3D le64_to_cpu(list->ssl_next); prev =3D le64_to_cpu(list->ssl_prev); - kunmap_local(kaddr); + kunmap_local(cp); =20 - ret =3D nilfs_cpfile_get_header_block(cpfile, &header_bh); - if (ret < 0) - goto out_cp; if (next !=3D 0) { ret =3D nilfs_cpfile_get_checkpoint_block(cpfile, next, 0, &next_bh); if (ret < 0) - goto out_header; + goto out_cp; + + next_list_offset =3D nilfs_cpfile_cp_snapshot_list_offset( + cpfile, next, next_bh); } else { next_bh =3D header_bh; get_bh(next_bh); + next_list_offset =3D nilfs_cpfile_ch_snapshot_list_offset(); } if (prev !=3D 0) { ret =3D nilfs_cpfile_get_checkpoint_block(cpfile, prev, 0, &prev_bh); if (ret < 0) goto out_next; + + prev_list_offset =3D nilfs_cpfile_cp_snapshot_list_offset( + cpfile, prev, prev_bh); } else { prev_bh =3D header_bh; get_bh(prev_bh); + prev_list_offset =3D nilfs_cpfile_ch_snapshot_list_offset(); } =20 - kaddr =3D kmap_local_page(next_bh->b_page); - list =3D nilfs_cpfile_block_get_snapshot_list( - cpfile, next, next_bh, kaddr); + /* Update the list entry for the next snapshot */ + list =3D kmap_local_folio(next_bh->b_folio, next_list_offset); list->ssl_prev =3D cpu_to_le64(prev); - kunmap_local(kaddr); + kunmap_local(list); =20 - kaddr =3D kmap_local_page(prev_bh->b_page); - list =3D nilfs_cpfile_block_get_snapshot_list( - cpfile, prev, prev_bh, kaddr); + /* Update the list entry for the previous snapshot */ + list =3D kmap_local_folio(prev_bh->b_folio, prev_list_offset); list->ssl_next =3D cpu_to_le64(next); - kunmap_local(kaddr); + kunmap_local(list); =20 - kaddr =3D kmap_local_page(cp_bh->b_page); - cp =3D nilfs_cpfile_block_get_checkpoint(cpfile, cno, cp_bh, kaddr); + /* Update the snapshot being changed back to a plain checkpoint */ + cp =3D kmap_local_folio(cp_bh->b_folio, offset); cp->cp_snapshot_list.ssl_next =3D cpu_to_le64(0); cp->cp_snapshot_list.ssl_prev =3D cpu_to_le64(0); nilfs_checkpoint_clear_snapshot(cp); - kunmap_local(kaddr); + kunmap_local(cp); =20 - kaddr =3D kmap_local_page(header_bh->b_page); - header =3D nilfs_cpfile_block_get_header(cpfile, header_bh, kaddr); + /* Update the statistics in the header */ + header =3D kmap_local_folio(header_bh->b_folio, 0); le64_add_cpu(&header->ch_nsnapshots, -1); - kunmap_local(kaddr); + kunmap_local(header); =20 mark_buffer_dirty(next_bh); mark_buffer_dirty(prev_bh); @@ -964,12 +994,12 @@ static int nilfs_cpfile_clear_snapshot(struct inode *= cpfile, __u64 cno) out_next: brelse(next_bh); =20 - out_header: - brelse(header_bh); - out_cp: brelse(cp_bh); =20 + out_header: + brelse(header_bh); + out_sem: up_write(&NILFS_MDT(cpfile)->mi_sem); return ret; @@ -990,7 +1020,7 @@ int nilfs_cpfile_is_snapshot(struct inode *cpfile, __u= 64 cno) { struct buffer_head *bh; struct nilfs_checkpoint *cp; - void *kaddr; + size_t offset; int ret; =20 /* @@ -1004,13 +1034,14 @@ int nilfs_cpfile_is_snapshot(struct inode *cpfile, = __u64 cno) ret =3D nilfs_cpfile_get_checkpoint_block(cpfile, cno, 0, &bh); if (ret < 0) goto out; - kaddr =3D kmap_local_page(bh->b_page); - cp =3D nilfs_cpfile_block_get_checkpoint(cpfile, cno, bh, kaddr); + + offset =3D nilfs_cpfile_checkpoint_offset(cpfile, cno, bh); + cp =3D kmap_local_folio(bh->b_folio, offset); if (nilfs_checkpoint_invalid(cp)) ret =3D -ENOENT; else ret =3D nilfs_checkpoint_snapshot(cp); - kunmap_local(kaddr); + kunmap_local(cp); brelse(bh); =20 out: @@ -1079,7 +1110,6 @@ int nilfs_cpfile_get_stat(struct inode *cpfile, struc= t nilfs_cpstat *cpstat) { struct buffer_head *bh; struct nilfs_cpfile_header *header; - void *kaddr; int ret; =20 down_read(&NILFS_MDT(cpfile)->mi_sem); @@ -1087,12 +1117,11 @@ int nilfs_cpfile_get_stat(struct inode *cpfile, str= uct nilfs_cpstat *cpstat) ret =3D nilfs_cpfile_get_header_block(cpfile, &bh); if (ret < 0) goto out_sem; - kaddr =3D kmap_local_page(bh->b_page); - header =3D nilfs_cpfile_block_get_header(cpfile, bh, kaddr); + header =3D kmap_local_folio(bh->b_folio, 0); cpstat->cs_cno =3D nilfs_mdt_cno(cpfile); cpstat->cs_ncps =3D le64_to_cpu(header->ch_ncheckpoints); cpstat->cs_nsss =3D le64_to_cpu(header->ch_nsnapshots); - kunmap_local(kaddr); + kunmap_local(header); brelse(bh); =20 out_sem: --=20 2.43.0 From nobody Mon Nov 25 21:24:27 2024 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E3D31CACEE; Thu, 24 Oct 2024 09:26:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761996; cv=none; b=GpV//6DP5MhphVA81Meq5HGum94JVeOf9dBb9aL+CvUYgpR6CvC24PYjVwF8BKE3RLw8UOs8f64JNzJLChlvi83DdQnoIa3Y3exUpD0vquOS+ZpXAanMgdCm2uQ6jubi5cYTeEA87TkAZxre1aoLDg4P+2YaKHRP4jLUtxASa0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761996; c=relaxed/simple; bh=gI5r6WxghRNbaB4222Ow6J8HwbUxosES6vp+uQE8wT4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MN05RX94isV25BYWYqeDpaIVWMMM96DVKqoRcnR8oEqEaW4lNWZi/LlWgEdivSGQqU8CB8cRulp+yEmzyapgHf/Cbpic3EBGO37qJtrjR0SoUpCmdrXxG1ZRT78gna5QqOFTPOwMDe5kYYwpSS+ZYxKz3wRVOmRkSvqL6vpofKM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cenCSqyO; arc=none smtp.client-ip=209.85.161.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cenCSqyO" Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5e7e1320cabso283057eaf.0; Thu, 24 Oct 2024 02:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761989; x=1730366789; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uByvF+p9sfUcjbc3juszjPemeC33hYqCK/m9ejh7ku8=; b=cenCSqyO3S6BVIjZ5cPyVfngnhDvL/d9Z8ECythjpXdb1d0Ge3f5hYswUgv/rYyzsM YKJhFJ3cRY/P7lMKdjVRNR9r0zyNGCAQjweUY1FlkNMJ9yCcFd3pJVL+25WLiVoV2XjZ FKWxRtG1ZFG0IoRAbLtNCLPYoR9v5jB5NJs+HydfUoG+2JmOpVP5PBphvEBNzUpDmXyy sdDJcK+sEhEO3UkkpUjFHWdALeo12nhQ+ZLUkJ44ZrEl29+dq/yQisbgabaXGP7ljMq1 dnPaCQ8DpFsGt6AH9ZwheJ9nkt0/Wil/Z43IaROOmAu30pD4t0D13pzi4QgYtkWKR20P 9ZSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761989; x=1730366789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uByvF+p9sfUcjbc3juszjPemeC33hYqCK/m9ejh7ku8=; b=dpgNgX3ACEfzv8pO4ZCqmReMzhpJh5GQLUWJo0rSFD8jH+lUPD+GTTN3V1ZEKTzT+W EHVTGUOHMyw0ult1Y1uWEcDaVsbasuBjOv4WyuP2/+5ujUfAqYsjdRwFTQwE9IrymS5X kJoTDOwvHys4kUA9s/O6bxTjx1ni2YX5nJpsBBbju+FGyYEQO7MPkXhttSZ2QgsA+/mi 8Kjp77Y67JZ3IX76E/EEHfpwm2w1kovH/iDbfJNf+ivg/ubeF0BI28b/pxl/vd92tvrF +rne85eUndTBnuZ/zl/LDpMFcRlOwwGoejwOMtsPcaTUO9zGkzZriMYJBQG5JJXbBD87 ULuQ== X-Forwarded-Encrypted: i=1; AJvYcCU5fv1oTne9LP8icDTx7gMdrWOWtSOk7JeSsOzrhIUqWPUMrM41Mt3p2pVBDqmLEAQSCvsbs7ce3a+GTsY=@vger.kernel.org, AJvYcCVt17rtgCVHMXhkL0D2fUalkLAnZwNRfuZTCdU1JMVZKKsK8bBQBXC+zXeOBXpb830B24NL7cyT4TQoe0TR@vger.kernel.org, AJvYcCXe6zKdrvyXV2RP65TX7qYAFwCf/RmblhBylF3K8O6kkEDwMP86XJ+shwIpf3QtAgg3/9Yz+n5002bBEd83@vger.kernel.org X-Gm-Message-State: AOJu0Yzz+0OJhiGsmoO0excgqb474azKkS191+7zaF8pbsQ3Sx2lG0N2 amc9lTOswAWDeW2T49ktUvNYsvWZ8+LVGJRguzsAhGsAd8vqCHuX X-Google-Smtp-Source: AGHT+IEfzOe49P4Bt14+CWfuNgq3/ZfrLUbVLpMvO1IY7qyylHG+wsjwmkiTLExkIbZBLS1JIQGgiw== X-Received: by 2002:a05:6870:392b:b0:27b:b2e0:6a5 with SMTP id 586e51a60fabf-28ccb774520mr6181526fac.3.1729761989369; Thu, 24 Oct 2024 02:26:29 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:28 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 09/12] nilfs2: Remove nilfs_writepage Date: Thu, 24 Oct 2024 18:25:43 +0900 Message-ID: <20241024092602.13395-10-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Matthew Wilcox (Oracle)" Since nilfs2 has a ->writepages operation already, ->writepage is only called by the migration code. If we add a ->migrate_folio operation, it won't even be used for that and so it can be deleted. [ konishi.ryusuke: fixed panic by using buffer_migrate_folio_norefs ] Link: https://lkml.kernel.org/r/20241002150036.1339475-2-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Ryusuke Konishi --- fs/nilfs2/inode.c | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index be6acf6e2bfc..c24f06268010 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c @@ -170,37 +170,6 @@ static int nilfs_writepages(struct address_space *mapp= ing, return err; } =20 -static int nilfs_writepage(struct page *page, struct writeback_control *wb= c) -{ - struct folio *folio =3D page_folio(page); - struct inode *inode =3D folio->mapping->host; - int err; - - if (sb_rdonly(inode->i_sb)) { - /* - * It means that filesystem was remounted in read-only - * mode because of error or metadata corruption. But we - * have dirty pages that try to be flushed in background. - * So, here we simply discard this dirty page. - */ - nilfs_clear_folio_dirty(folio); - folio_unlock(folio); - return -EROFS; - } - - folio_redirty_for_writepage(wbc, folio); - folio_unlock(folio); - - if (wbc->sync_mode =3D=3D WB_SYNC_ALL) { - err =3D nilfs_construct_segment(inode->i_sb); - if (unlikely(err)) - return err; - } else if (wbc->for_reclaim) - nilfs_flush_segment(inode->i_sb, inode->i_ino); - - return 0; -} - static bool nilfs_dirty_folio(struct address_space *mapping, struct folio *folio) { @@ -295,7 +264,6 @@ nilfs_direct_IO(struct kiocb *iocb, struct iov_iter *it= er) } =20 const struct address_space_operations nilfs_aops =3D { - .writepage =3D nilfs_writepage, .read_folio =3D nilfs_read_folio, .writepages =3D nilfs_writepages, .dirty_folio =3D nilfs_dirty_folio, @@ -304,6 +272,7 @@ const struct address_space_operations nilfs_aops =3D { .write_end =3D nilfs_write_end, .invalidate_folio =3D block_invalidate_folio, .direct_IO =3D nilfs_direct_IO, + .migrate_folio =3D buffer_migrate_folio_norefs, .is_partially_uptodate =3D block_is_partially_uptodate, }; =20 --=20 2.43.0 From nobody Mon Nov 25 21:24:27 2024 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEC2A1CACD0; Thu, 24 Oct 2024 09:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761994; cv=none; b=ElUrD4IuiTr0B6FXP6wselxpSA4EVuqBz0eX5yn5FGDaaiACdHwGCXcXg7/mMDFHpoIEpQott1pXrbTErz4LFL7sV8tbgQC4xcCbJuQqWhxp64xX80hOkwDteCsbsb+IrwUwOWftJI11YTx7hwYXLmAaeCCWP95xAaXRG3SB45Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761994; c=relaxed/simple; bh=83oWICUaM1pez/cllfdiTPn+JZHb5MaKCRkNi0TEwEs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TeyfbB4zFOr+ME+LrlyyVSt2t2faIEW613QJ63STZelab/RW/5LqhvVHz26ZeswpOLTFnf+UPRQsqzwM1wjs2Zssa0vNOoUmq9LcF2LfM085BTEZ/tSk6+8hNf6FzJ7AOb5vPejSAI/ZnLsju+v+hDX1qOZQ6N8gAsykSGhYnYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KUj+Avcb; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KUj+Avcb" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-20caea61132so4784405ad.2; Thu, 24 Oct 2024 02:26:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761992; x=1730366792; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lE3hzGmrsBlUG0nTaJ74q6XkM5Ijqikn5DY/sHHFnWE=; b=KUj+AvcbRBtKlMDHMTTU10K6rUBxw/Ruk5JSQ+RYUrj1cwaumcUcHPY6ef+AM+9Ehp gQi6ijejS/X8W+N+SPtKdcC6YUgiv/pchk+xcvY5uSsc5JypznURkBCiSaTmlAF9uJ7w gkS+pzOnI6TE1nAKSZ7wsk+HwAXlb/XSdl06Iqa9yGgjIjpGlYrVByibEqQc4zK38NKg dtvZcu+Du8RM2pnILUGW4sm3RS2UDIz7I5pWjHhs36YgulW4Gssd2vfc7oEEygO0Cz+T DC/LLetRen9/cqvAiA/Kk/VXyL+biib9TCja+o9PcCXchDlCRLl2AqQNJmS0n09C3a8K vcSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761992; x=1730366792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lE3hzGmrsBlUG0nTaJ74q6XkM5Ijqikn5DY/sHHFnWE=; b=YNMmyrxZy9tmEoKzilIvKq47zfUfyERyt4q4r9uJ0v/VxSKAsZZzLDOeFIMkBKkCqn Hesu74fPB7frfTysfxajb1tYOqF8aG9lC4vS6Lpph6DZ5dn7ic61LsviFplg1MjEScfM S/SQjUBPXalYsPjPErx6j2yyVDJ/fIDQLiXCrJV0H0wVjL64AEd44snsvNhFcuqRISpx TJCvkBcfh3Cp5zdGo1PuU6nAiVEd+sku6vtOjcyt/I/Jl95UnSLkRC1s0djtycpxpI7k wmLVp6YiQYRNDSMDbt1XtOdtxLPoNDsmZ2tWWQ9hrkkQzAXmEJ0+JS9vMPvXGsF+qti0 C9tA== X-Forwarded-Encrypted: i=1; AJvYcCUOa8t8snmHoc46GLmZoEGMlvR7D/KnWK9pvpZ4VZG1VWVaNLa46Q6r50nu6u7LZm7TKV5EvKEFBAfoTgd2@vger.kernel.org, AJvYcCUPZrIZU8ZBbYJ4jpg5duVZxYP9dwuXTbXRdDZo0FPXjOi0B4HMq5wU3IPEL3XUsTEjdkR893ypp2uZLeo=@vger.kernel.org, AJvYcCVWgjJanCUuny7+Ngo7x9bQ3p86W8LgBzSErL43+eJRb3XK/ntEPrm1Qom6fThHz7QuNXOOD/q6Ldurp7Xk@vger.kernel.org X-Gm-Message-State: AOJu0YwEkqmqfw77CYXSiO6myI6uRN4xXb8GKgOgLO2eKO4C3TehV3O7 e6ADDlvNd+/jl1CHFM+Sc405WMfKQksvKUv53HkIrvrmMj8/jyMX X-Google-Smtp-Source: AGHT+IHUtg0SMbnTv0FXcuMGx8pIxWDFjcw3z5vfuJKLY/LncWPph7w+1vBPd735uJW9h3UyjuGdEw== X-Received: by 2002:a05:6a20:d98:b0:1d9:1af6:94ba with SMTP id adf61e73a8af0-1d978b0b693mr6788947637.14.1729761991838; Thu, 24 Oct 2024 02:26:31 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:31 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 10/12] nilfs2: Convert nilfs_page_count_clean_buffers() to take a folio Date: Thu, 24 Oct 2024 18:25:44 +0900 Message-ID: <20241024092602.13395-11-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Matthew Wilcox (Oracle)" Both callers have a folio, so pass it in and use it directly. [ konishi.ryusuke: fixed a checkpatch warning about function declaration ] Link: https://lkml.kernel.org/r/20241002150036.1339475-3-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Ryusuke Konishi --- fs/nilfs2/dir.c | 2 +- fs/nilfs2/inode.c | 2 +- fs/nilfs2/page.c | 4 ++-- fs/nilfs2/page.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c index a8602729586a..14e8d82f8629 100644 --- a/fs/nilfs2/dir.c +++ b/fs/nilfs2/dir.c @@ -95,7 +95,7 @@ static void nilfs_commit_chunk(struct folio *folio, unsigned int nr_dirty; int err; =20 - nr_dirty =3D nilfs_page_count_clean_buffers(&folio->page, from, to); + nr_dirty =3D nilfs_page_count_clean_buffers(folio, from, to); copied =3D block_write_end(NULL, mapping, pos, len, len, folio, NULL); if (pos + copied > dir->i_size) i_size_write(dir, pos + copied); diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index c24f06268010..cf9ba481ae37 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c @@ -242,7 +242,7 @@ static int nilfs_write_end(struct file *file, struct ad= dress_space *mapping, unsigned int nr_dirty; int err; =20 - nr_dirty =3D nilfs_page_count_clean_buffers(&folio->page, start, + nr_dirty =3D nilfs_page_count_clean_buffers(folio, start, start + copied); copied =3D generic_write_end(file, mapping, pos, len, copied, folio, fsdata); diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c index 10def4b55995..e48079ebe939 100644 --- a/fs/nilfs2/page.c +++ b/fs/nilfs2/page.c @@ -422,14 +422,14 @@ void nilfs_clear_folio_dirty(struct folio *folio) __nilfs_clear_folio_dirty(folio); } =20 -unsigned int nilfs_page_count_clean_buffers(struct page *page, +unsigned int nilfs_page_count_clean_buffers(struct folio *folio, unsigned int from, unsigned int to) { unsigned int block_start, block_end; struct buffer_head *bh, *head; unsigned int nc =3D 0; =20 - for (bh =3D head =3D page_buffers(page), block_start =3D 0; + for (bh =3D head =3D folio_buffers(folio), block_start =3D 0; bh !=3D head || !block_start; block_start =3D block_end, bh =3D bh->b_this_page) { block_end =3D block_start + bh->b_size; diff --git a/fs/nilfs2/page.h b/fs/nilfs2/page.h index 64521a03a19e..136cd1c143c9 100644 --- a/fs/nilfs2/page.h +++ b/fs/nilfs2/page.h @@ -43,8 +43,8 @@ int nilfs_copy_dirty_pages(struct address_space *, struct= address_space *); void nilfs_copy_back_pages(struct address_space *, struct address_space *); void nilfs_clear_folio_dirty(struct folio *folio); void nilfs_clear_dirty_pages(struct address_space *mapping); -unsigned int nilfs_page_count_clean_buffers(struct page *, unsigned int, - unsigned int); +unsigned int nilfs_page_count_clean_buffers(struct folio *folio, + unsigned int from, unsigned int to); unsigned long nilfs_find_uncommitted_extent(struct inode *inode, sector_t start_blk, sector_t *blkoff); --=20 2.43.0 From nobody Mon Nov 25 21:24:27 2024 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 194BA1CB9E6; Thu, 24 Oct 2024 09:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761997; cv=none; b=syWXVaIuno2rTOD6YK8r4ONaiTciiBjHPCsrlCTN+YxJXtok6doOa8+z3IFYolKY8MWspzBxSPvsHdksQSskwevuO2euqXE0gsNSAloUKLULzsEX5hQxeJeego/kTYr7mye6f6W95MiILlcpRdwUJTWsFfEROytQ10p8a8UEr+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761997; c=relaxed/simple; bh=FFT2XXK09KhKi7sc/MPEDIljixwaNgFnEqinLBMTJS4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PKPSPZUK+BHyYlpr9WXrxlUEK0U0MRnCs77Teniq3QpZadztj3P9kFaEsTxsRidH39MoeAoSdbkMyJI/EFu88lkrJxeIvBZAq1MFnTOTs1i90MUuJ6M5KXvXJqTBCyWNqtE8qKG3YlQhR9CpjVeMAy3DP91D9DtAK3I62PS/8RI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Xj6FDRhi; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xj6FDRhi" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-7db54269325so418383a12.2; Thu, 24 Oct 2024 02:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761994; x=1730366794; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rRl7nYlKQVTtZPOf3bc0DgwCB2RgytmZgZRN7PTGqn8=; b=Xj6FDRhiGP+mnqByzW7pJ0asmO4K9+amHZ6b70jo8XByIedo5AZkBXO2AVRhCIVEJ1 QcUg6Zg0sGMAutHGMko+iL3vzWuF/xx4x4Qf1gJmrO9K1ghtI+V4PJMGuAsUbK/SdzYP 0UEy7twm1u7IGCIeBnxeYAs9ZpFj62PazDsce0R6Qa1oUAr18OaXfnsx+dEco5T4IH/0 GTeBPDBPDJTr3MngsKkeMSJ0SsT9TDxiPNjN8BDP+51I0yXp6Iwhe4Gv+RxRbObj+VTc uTeMpD7i53HU3K8CQaDBjCYZC/ki3JWTQWon354H56cIoBP2NksjAMY4NO8txD1AkFun ESaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761994; x=1730366794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rRl7nYlKQVTtZPOf3bc0DgwCB2RgytmZgZRN7PTGqn8=; b=stWgXDaldEaSLmOC/qqOxzbkSORz+ZSfG1PZ3QOvNKCRZshFq1eybNpCTU/9gkNPYv kidwZle9MKtcz2VTisCWt8UBvSdsqd+hbTUShJ+1Va2WJXhQSpNzm+J+hrlVKeSgZ+6a AYwM8r4hkUV3e0djT4VlPnBZbfBuQ+EoC8EGANciqxfkwuWIVnlBfkTkcoiEw656u2Qb EBOtj706XcCIVe3VP2rgU1Veb7gGYSwqPrFlUgt/i3/k0Af2kKiuhlhjXXHo/49KXScK gu99FUpb8I+oZoWfBMrNdiAZvr9sZSX6tBxykq2q64QYuq8pocgBpSktZnnC4BODalA1 qHiQ== X-Forwarded-Encrypted: i=1; AJvYcCUvXNqpFw11113fYvlHUO0nM4i5XUL0g5+7AxiFWoQcZFEUTIb50aA5zZOGfL1zWMCu9MQolz52+kPhaLqW@vger.kernel.org, AJvYcCWXzwYiGDroLVpRboEwKkFNCuT+9FRB1qQCYDs4jDQDcDRp2FxKTaq8vLpDGR0r7KRcHcLbZm7+pMV6t/g=@vger.kernel.org, AJvYcCWkMfW+YWX0YeZGWn9Vn/8Xo32v/hzqrjQljpfatbJwmVMWZReJJ+aZljCqxfzVC4HP7c/+rkzUiJ7c+U99@vger.kernel.org X-Gm-Message-State: AOJu0YxgS3kZpJ1ipGROt1bE8dCm8s8mbOOhOw6P+mVcnCaLd3esc205 szIhcaIqv2xqrmsRKDdkcqEPXuIsI7LI6Iky/aTQJijEMwLNYC5EU5pggQ== X-Google-Smtp-Source: AGHT+IHeGa1Aq2n+f8LUC5Q289Qpqye10iLPUl7E6EQKyPtmyMJKXcM+BBLXwoHkgLyq6xdnBsiGFw== X-Received: by 2002:a05:6a20:b40a:b0:1d9:261c:5937 with SMTP id adf61e73a8af0-1d978ba06eemr6078349637.33.1729761994202; Thu, 24 Oct 2024 02:26:34 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:33 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 11/12] nilfs2: Convert nilfs_recovery_copy_block() to take a folio Date: Thu, 24 Oct 2024 18:25:45 +0900 Message-ID: <20241024092602.13395-12-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Matthew Wilcox (Oracle)" Use memcpy_to_folio() instead of open-coding it, and use offset_in_folio() in case anybody wants to use nilfs2 on a device with large blocks. [ konishi.ryusuke: added label name change ] Link: https://lkml.kernel.org/r/20241002150036.1339475-4-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Ryusuke Konishi --- fs/nilfs2/recovery.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fs/nilfs2/recovery.c b/fs/nilfs2/recovery.c index 21d81097a89f..e43405bf521e 100644 --- a/fs/nilfs2/recovery.c +++ b/fs/nilfs2/recovery.c @@ -481,19 +481,16 @@ static int nilfs_prepare_segment_for_recovery(struct = the_nilfs *nilfs, =20 static int nilfs_recovery_copy_block(struct the_nilfs *nilfs, struct nilfs_recovery_block *rb, - loff_t pos, struct page *page) + loff_t pos, struct folio *folio) { struct buffer_head *bh_org; - size_t from =3D pos & ~PAGE_MASK; - void *kaddr; + size_t from =3D offset_in_folio(folio, pos); =20 bh_org =3D __bread(nilfs->ns_bdev, rb->blocknr, nilfs->ns_blocksize); if (unlikely(!bh_org)) return -EIO; =20 - kaddr =3D kmap_local_page(page); - memcpy(kaddr + from, bh_org->b_data, bh_org->b_size); - kunmap_local(kaddr); + memcpy_to_folio(folio, from, bh_org->b_data, bh_org->b_size); brelse(bh_org); return 0; } @@ -531,13 +528,13 @@ static int nilfs_recover_dsync_blocks(struct the_nilf= s *nilfs, goto failed_inode; } =20 - err =3D nilfs_recovery_copy_block(nilfs, rb, pos, &folio->page); + err =3D nilfs_recovery_copy_block(nilfs, rb, pos, folio); if (unlikely(err)) - goto failed_page; + goto failed_folio; =20 err =3D nilfs_set_file_dirty(inode, 1); if (unlikely(err)) - goto failed_page; + goto failed_folio; =20 block_write_end(NULL, inode->i_mapping, pos, blocksize, blocksize, folio, NULL); @@ -548,7 +545,7 @@ static int nilfs_recover_dsync_blocks(struct the_nilfs = *nilfs, (*nr_salvaged_blocks)++; goto next; =20 - failed_page: + failed_folio: folio_unlock(folio); folio_put(folio); =20 --=20 2.43.0 From nobody Mon Nov 25 21:24:27 2024 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47EA71CBEA6; Thu, 24 Oct 2024 09:26:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761999; cv=none; b=IhjC86FHEP4B9LpAYLsOnaDBkC4xnWpceitFYMyocuRhZmAMVFTixGS7vtOKBiMFewc3Z+pp+sSoxQMtUsH2BPsGmoDfhXANdhgIAbqQM9P3r9l5nobsXNlnRfwDf363/m6BRxnwuMEtfdUGOUNxu8ajkZYur6uqacd4cAbou/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729761999; c=relaxed/simple; bh=iqLZMe0dYkUhRF/FOyCNKd9pUIGhJjxvLcvo8+B/lHg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GaeJHZRo/lVNdeSADk6LixE+pWvaXxcs+fUmecos8TM6kupLOl0aZFzv+4A6mb6eOF4JdSalrP0fGAEKS6Yn2CCbfHZbdFgwfl0uNi2xOhEyfHQzwX+6TqRP5RgAxu2AFqMwWpysCTZ88pi6Hs6iuIsrQ9dGGn96YuVoEC9dV/s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CGJ4+A3t; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CGJ4+A3t" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-7ea7e250c54so461854a12.0; Thu, 24 Oct 2024 02:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729761996; x=1730366796; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UbLFzgd79wLmsOWzFDrD0P/iHQtZq8xD1Eu63hITF5I=; b=CGJ4+A3t8b+LJuYRIVz4XVqiumx8jOpSoYNQsrEvYV+3zDqDbrpG6GTh7yl56ppjqt /fD44IfNhAai3sBnJAnS1RAfFcb3wsrqG6Qri9yYZK+4L/BN86LIfjlT5SVsGQCHeYqN EoRZyOfDBE+aX0cduDsACipwwOxDheKHH2uMB9Na6GMqjYY+hu6i2T40tEiq7L4CSSTT kEqe/nt6rCJq9H1vHd0FT3GyQ8kAZkwsC6PhR3Cl1uECkKV5TroS3tmdLvlcO6owBPw4 RmWfP7wYwKZRlP4yf2ureAHU4SYhtemy62hzxz4Wvfz/2Jpa2aa+2UgeLFUgp0VeC5Gl c+6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729761996; x=1730366796; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UbLFzgd79wLmsOWzFDrD0P/iHQtZq8xD1Eu63hITF5I=; b=CeNcktCLXwkoDRfPw8dx4zahKXmi1TIF4z4/xeYdN1dz4fwOLxvR+RM3//BnGb7Ih7 pYC8PRV2ehMT1VUM6MkI/qaKYX+e0yUUMPjfiG7rFoC/MZWqzF8dBP6IYaPqlZ5h+oDI xC7ghzhdLO/7QSkOYdP/06dmRqOzgHtRo6qZ/Z0DSX+40kfNXJ/TvNi5ayG2zX4IccHR zODVYEtY19Eb3qtot2D2P/gTI/lHrobgBHhUespdEvpXsJlb+J9mrSoaVvv0Eu6NXh6S gnCubIJ6CNE1iJDGBGHk04M0OEZGvVdlu8lVn+3cBpYv+7VSyiu5RH4SSEF82BE/Pu28 KAgg== X-Forwarded-Encrypted: i=1; AJvYcCXETJsGP6doBfI0tLIiEafer93dMD3u1eepfqHY5oINdEzqenN/ecbHlAMUy4+1XJx0bRKK3PwvVRxZKs0=@vger.kernel.org, AJvYcCXOatWZTMeseyQpILKlzzUoeipuw4HyfcyYQjtGuCiBVoQtHhzkaeeJ0tzLdUcWgQCt2uO/8rTZZMRJCURi@vger.kernel.org, AJvYcCXqPLw0PHL2bZX/1LjV8vo0fN7SME2mlhrGr+U5gZYBlV6b+o2ZAQOaZmYDdFLoVcqjovoWVbccO2Zn5ku0@vger.kernel.org X-Gm-Message-State: AOJu0YwAUOwX37r25CKj0vyDwcRJo7NQS8rtSge78AQ2C73C8dR8wxDi 2sl1DI7dSw118tL0/0/4uvmCFaPMHK46/6mAmeX20ewL6iCny5dS/zECdg== X-Google-Smtp-Source: AGHT+IG9WDMVc5A+ppB9wz7eToYUHfrWnIYbecQ+buyieTbsZGooXmbDfQaX18EnNHR/Lh6wIq96hA== X-Received: by 2002:a05:6a20:d491:b0:1d2:bb49:63ac with SMTP id adf61e73a8af0-1d978b98fd9mr6293914637.40.1729761996595; Thu, 24 Oct 2024 02:26:36 -0700 (PDT) Received: from carrot.. (i118-19-49-33.s41.a014.ap.plala.or.jp. [118.19.49.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec13d774fsm7608906b3a.106.2024.10.24.02.26.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 02:26:35 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: Matthew Wilcox , linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 12/12] nilfs2: Convert metadata aops from writepage to writepages Date: Thu, 24 Oct 2024 18:25:46 +0900 Message-ID: <20241024092602.13395-13-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241024092602.13395-1-konishi.ryusuke@gmail.com> References: <20241024092602.13395-1-konishi.ryusuke@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Matthew Wilcox (Oracle)" By implementing ->writepages instead of ->writepage, we remove a layer of indirect function calls from the writeback path and the last use of struct page in nilfs2. [ konishi.ryusuke: fixed panic by using buffer_migrate_folio_norefs ] Link: https://lkml.kernel.org/r/20241002150036.1339475-5-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Ryusuke Konishi --- fs/nilfs2/mdt.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c index a4c1e00aaaac..432181cfb0b5 100644 --- a/fs/nilfs2/mdt.c +++ b/fs/nilfs2/mdt.c @@ -399,10 +399,9 @@ int nilfs_mdt_fetch_dirty(struct inode *inode) return test_bit(NILFS_I_DIRTY, &ii->i_state); } =20 -static int -nilfs_mdt_write_page(struct page *page, struct writeback_control *wbc) +static int nilfs_mdt_write_folio(struct folio *folio, + struct writeback_control *wbc) { - struct folio *folio =3D page_folio(page); struct inode *inode =3D folio->mapping->host; struct super_block *sb; int err =3D 0; @@ -435,11 +434,23 @@ nilfs_mdt_write_page(struct page *page, struct writeb= ack_control *wbc) return err; } =20 +static int nilfs_mdt_writeback(struct address_space *mapping, + struct writeback_control *wbc) +{ + struct folio *folio =3D NULL; + int error; + + while ((folio =3D writeback_iter(mapping, wbc, folio, &error))) + error =3D nilfs_mdt_write_folio(folio, wbc); + + return error; +} =20 static const struct address_space_operations def_mdt_aops =3D { .dirty_folio =3D block_dirty_folio, .invalidate_folio =3D block_invalidate_folio, - .writepage =3D nilfs_mdt_write_page, + .writepages =3D nilfs_mdt_writeback, + .migrate_folio =3D buffer_migrate_folio_norefs, }; =20 static const struct inode_operations def_mdt_iops; --=20 2.43.0