Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1064924lqt; Fri, 7 Jun 2024 07:11:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXrIxsMQ8RkWzDETg+meXdbMD7wq/i2Yq0Sf6GPsBLuv7SegGxNIGrjDL6S+wltObYNNHGy9A39vIDPE8EggB+HkZzBPrlVnYLsHXjbjQ== X-Google-Smtp-Source: AGHT+IG519XIa4JhK+tX30aSXk/EVeFmyDDLyAk4OANyqJ1bhLTP47Ux4bGx0lzkFGAQ+a9MI+qX X-Received: by 2002:a9d:6406:0:b0:6f9:5ba7:e64e with SMTP id 46e09a7af769-6f95ba7ef76mr1209107a34.35.1717769463140; Fri, 07 Jun 2024 07:11:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717769463; cv=pass; d=google.com; s=arc-20160816; b=CPZ/+YDnCjFWsfNRqweHTsHgpBgSfHD9KeZ9ij1UsdolVd6tv3UxX/CO0/BwqptyTj +Fu3QdhwB3GAHCnUdtebW5OE278rQprnFJn6dug3W1DmXUe+45HxLi84/HLNF8g5oemV +mkhaOnidLqWOO+2hGq4F04ed4iZxsrdUCFjXoyg6zGqL839ydPeV1YYmTA8QLlNGWVB 6qO2cwaTa7K3b66A1Tl+jdEQR3kGP6uftLJbCsJZDgG0KQ31pBKS+SfI0EiXYzOv04UB B+JEq8As4CQ184wY8wQl5LT8KJtwNUourUF0bhlktzdnDYXj2jC41Jy179A1+RRHrVr2 pmtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=3uKzkEEabbLkMFSctKI1rmghqi04TcrHrORhCCohS4U=; fh=aZxnGY6DDy9fpaQ8sgauFxrOLW1h/pe2SVmJPZJU9to=; b=i72Or1yzjhI/fCmh7f4Aztqlozl8jhgPAR7kIqtCjLb1VSdlxwYOd3mowhmpdyETwB eZnerh01JUD8fMy8GjtJZvnVkK7vn1c3kjjltO4norUubFRCET6RSQeih3NEQ1ycZqu6 AavWDI57qFQTLEr4pPBzeqHGNS8d05XSxuE4pxUIwg8I9qcCC7CMGkcIdrZFoa7RdAHq jSyvW4yEX0vsH2vAQV8MhxnPoAQE6bBLJBxaLVUEKUpt/7t3LkiXZyZ5CEkD1SG0jmlR hWX68g0v3NdnOLDKKDVqvLnI1CQSpHKDPat4O1MhkbnPix49snjtIWI3MEZ9kHq+GZ61 5YAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pvY2CVq8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-206219-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206219-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ada2fe7eead31-48c1a22fae5si969032137.612.2024.06.07.07.11.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 07:11:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206219-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pvY2CVq8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-206219-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206219-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B649E1C20DA4 for ; Fri, 7 Jun 2024 14:11:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E4BC195B2E; Fri, 7 Jun 2024 14:10:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pvY2CVq8" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99FE7192B89 for ; Fri, 7 Jun 2024 14:10:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717769455; cv=none; b=MnipIiBNDsnngQtIKv32OgtKCROYzxxNopXZXjP9DiofGY1q3QvTfFVhdBGAqmGUyMnjne6MT4RbNAhMSS+mP1h8D+dsV1vVnT02x5tqgjcz74DsYOf4ZbhCyS6YkS5fCQHsQvdFHOEdIbC3r/okKHM3RGrUf6jpnhR0akZANhE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717769455; c=relaxed/simple; bh=sciOujBFI9gvywDifAfAlIe7Qf9PZPeyUwNpz1jEwuY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Gsfi5cOI+8267uexweup6oMvvtA+lQQbrDWZhufNpTu2arrm8DTaTa4I15b6KCRJWTYc9zUdLGn0rwd8kjiezhVeMLf+g07HYb+TLy+KPuwRvL8NkM7qAj/UP5/YOvO1YpQuyMM7Px6Adox966k0J+5YUBNyHOYL/VNEH8e0WwI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pvY2CVq8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0159C32782; Fri, 7 Jun 2024 14:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717769455; bh=sciOujBFI9gvywDifAfAlIe7Qf9PZPeyUwNpz1jEwuY=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=pvY2CVq82lHS2IuDhm/tTt7LaBqa4lOD0C8bwAzVku489mHX+y2OC85cRr3L2Pph7 4mb+lgTl65sM9E++pv74B969fSm0Pt2Czp1IqR9G5PcNNHJdJBK5KIdsw8rnws+rJC Uo6v5NlFYxNpulwetYMqEb637dfuqyrbjIOvi82SA9g9OKn7+5IkSagf28rruqrGAL iq57r5eY66ppTyjE4SUObD83ZOZ1C2p+CZUsYUOU8tHR7pA+HizK00eg/ilRvR06D4 xxHCD+S8EjNKPa5vdR9sFQaewZdWWcTr9XXmfVvcHsxtOaCjCyonNZkXT4Eoy7b9/a i65rb4AsfWNvw== Message-ID: Date: Fri, 7 Jun 2024 22:10:52 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] f2fs: get rid of buffer_head use To: Matthew Wilcox Cc: jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <20240607101829.389015-1-chao@kernel.org> Content-Language: en-US From: Chao Yu Autocrypt: addr=chao@kernel.org; keydata= xsFNBFYs6bUBEADJuxYGZRMvAEySns+DKVtVQRKDYcHlmj+s9is35mtlhrLyjm35F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JE9eZSX7Rtdyt30MMHQARAQABwsFfBBgBCgAJBQJWLOm1AhsMAAoJ EKTPgB1/p52GPpoP/2LOn/5KSkGHGmdjzRoQHBTdm2YV1YwgADg52/mU68Wo6viStZqcVEnX 3ALsWeETod3qeBCJ/TR2C6hnsqsALkXMFFJTX8aRi/E4WgBqNvNgAkWGsg5XKB3JUoJmQLqe CGVCT1OSQA/gTEfB8tTZAGFwlw1D3W988CiGnnRb2EEqU4pEuBoQir0sixJzFWybf0jjEi7P pODxw/NCyIf9GNRNYByUTVKnC7C51a3b1gNs10aTUmRfQuu+iM5yST5qMp4ls/yYl5ybr7N1 zSq9iuL13I35csBOn13U5NE67zEb/pCFspZ6ByU4zxChSOTdIJSm4/DEKlqQZhh3FnVHh2Ld eG/Wbc1KVLZYX1NNbXTz7gBlVYe8aGpPNffsEsfNCGsFDGth0tC32zLT+5/r43awmxSJfx2P 5aGkpdszvvyZ4hvcDfZ7U5CBItP/tWXYV0DDl8rCFmhZZw570vlx8AnTiC1v1FzrNfvtuxm3 92Qh98hAj3cMFKtEVbLKJvrc2AO+mQlS7zl1qWblEhpZnXi05S1AoT0gDW2lwe54VfT3ySon 8Klpbp5W4eEoY21tLwuNzgUMxmycfM4GaJWNCncKuMT4qGVQO9SPFs0vgUrdBUC5Pn5ZJ46X mZA0DUz0S8BJtYGI0DUC/jAKhIgy1vAx39y7sAshwu2VILa71tXJ In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/6/7 21:33, Matthew Wilcox wrote: > On Fri, Jun 07, 2024 at 06:18:29PM +0800, Chao Yu wrote: >> @@ -1990,6 +1989,12 @@ static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) >> return (struct f2fs_super_block *)(sbi->raw_super); >> } >> >> +static inline struct f2fs_super_block *F2FS_SUPER_BLOCK(struct folio *folio) >> +{ >> + return (struct f2fs_super_block *)(page_address(folio_page(folio, 0)) + >> + F2FS_SUPER_OFFSET); >> +} > > This assumes that the superblock is in the first page of the folio. > That's not necessarily guaranteed; let's say you have a 64KiB folio > that covers the start of the bdev. Oh, I missed to add large folio support in this version. For the case: page size is 4KiB, and folio size is 64KiB, read_mapping_folio(mapping, 0, NULL) and read_mapping_folio(mapping, 1, NULL) will return the same #0 folio, right? > > I don't quite know how to write this because f2fs defines its block size > in terms of PAGE_SIZE, which just seems like nonsense to me. If you > format a filesystem on a 16KiB PAGE_SIZE machine and then try to mount > it on a machine with a 4KiB PAGE_SIZE, it's going to go horribly wrong. f2fs will check on-disk block size w/ PAGE_SIZE in sanity_check_raw_super() as below: /* only support block_size equals to PAGE_SIZE */ if (le32_to_cpu(raw_super->log_blocksize) != F2FS_BLKSIZE_BITS) { f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u", le32_to_cpu(raw_super->log_blocksize), F2FS_BLKSIZE_BITS); return -EFSCORRUPTED; } > > You'd need to pass in something that indicates whether you're trying to > access the first or second superblock; there's no way to tell from the > folio which one it is. > >> +static int __f2fs_commit_super(struct f2fs_sb_info *sbi, struct folio *folio, >> + bool update) >> { >> - lock_buffer(bh); >> - if (super) >> - memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super)); >> - set_buffer_dirty(bh); >> - unlock_buffer(bh); >> - >> + struct bio *bio; >> /* it's rare case, we can do fua all the time */ >> - return __sync_dirty_buffer(bh, REQ_SYNC | REQ_PREFLUSH | REQ_FUA); >> + blk_opf_t opf = REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH | REQ_FUA; >> + int ret; >> + >> + folio_lock(folio); >> + folio_wait_writeback(folio); >> + if (update) >> + memcpy(F2FS_SUPER_BLOCK(folio), F2FS_RAW_SUPER(sbi), >> + sizeof(struct f2fs_super_block)); >> + folio_mark_dirty(folio); >> + folio_clear_dirty_for_io(folio); >> + folio_start_writeback(folio); >> + folio_unlock(folio); >> + >> + bio = bio_alloc(sbi->sb->s_bdev, 1, opf, GFP_NOFS); >> + >> + /* it doesn't need to set crypto context for superblock update */ >> + bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(folio_index(folio)); >> + >> + if (!bio_add_folio(bio, folio, PAGE_SIZE, 0)) >> + f2fs_bug_on(sbi, 1); > > Better make that folio_size(folio) to support bs>PS. Looks better, will update. Thanks, >