From patchwork Fri Nov 18 07:30:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 22157 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp45887wrr; Thu, 17 Nov 2022 23:32:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf7hIOF71RU6SaPsZWLRA3mpnh4o5K/UhEDQuiKgEypeOaLL/hUHRhMRQV57IfrfRrx2ADR5 X-Received: by 2002:a63:d751:0:b0:46f:f87c:fb1a with SMTP id w17-20020a63d751000000b0046ff87cfb1amr5619391pgi.214.1668756720311; Thu, 17 Nov 2022 23:32:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668756720; cv=none; d=google.com; s=arc-20160816; b=ZMab/1J992B3r/y00GDyoI5hz6l08tXyz1KG4CHxc/aU48iOxnFkuHOhG85ysnZH+f DSPHqsbqlamG/fSAzuxIH+aQP7dlhO+D/O1dB+p6L82MPFuVg1h2Eh/Xv4+WGTOsRO8M X4GkSF7R95K1HgrXS+SvbbhWDDDMDF8Bhxdgu5lvY6Onx9SAOQa8HbNjKtKRlaAe52Lf 34esFN/cpNPcMfeiam3RL/3DqjBpVnS5dgK5R5+ZgV7YvcVytZ/P/IsXBYE60kShBuQW kN0pdp43cJFmmlBbfp+dZLWTJ0gGyQvyUs/lJORDXoUd0tHXCkEiKoCUvuh9fEuubEh3 0VCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Re0/IOxZf5Hx6BeFa9inJCF0a6cGKdlu1k/P2sxW8QU=; b=FGvFF8daiWn9v+B8SeW4UCWrwsmaUyN3i/2WTSQkvO44TugATKnkLWLNeS7pqZjNXN OF5eOupWij4+hi71bwraQPCb84Dg9c50dTnB8ffDpOxo3lYgEVbGlLL84y2RFclL6YRH Jm9c6IrhyT3oHDtD0lLj6D+woObP1n4EGb6oRurRi3Fffxl71SjlVXmWL1e5yGBmOmFQ htjKI+ZqI0Gy0hy2EHWn+UzYK9l7mq/CmLEYGVms3pHRPjfG1bvFZu01zDf3xnik7y7S bJAS3DEx804cM1J8G/8GpN0R98AZH9XRih50Kykaf11lecYPjDdR/65WOP+Alpw9IvJ9 57yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JbqHqUy5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id om14-20020a17090b3a8e00b0020bbfb294a1si7595560pjb.174.2022.11.17.23.31.47; Thu, 17 Nov 2022 23:32:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JbqHqUy5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241217AbiKRHbN (ORCPT + 99 others); Fri, 18 Nov 2022 02:31:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241118AbiKRHbC (ORCPT ); Fri, 18 Nov 2022 02:31:02 -0500 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA0BD205EF; Thu, 17 Nov 2022 23:31:00 -0800 (PST) Received: by mail-pg1-x52c.google.com with SMTP id 6so4298036pgm.6; Thu, 17 Nov 2022 23:31:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=Re0/IOxZf5Hx6BeFa9inJCF0a6cGKdlu1k/P2sxW8QU=; b=JbqHqUy5gwXZXXmeVcz1VjkFSML8VbgCJWNNoIeSydHy4Efkp/nj8IFLHy4/PRyQHV ZD3+lwCTNEDhNf9veaDSLhz7j3rTE4dSA4jeOiZEUCQyws3Y+MXRKm5Dx6naoty++WGj mgSMypdnxVTv66L8q6FElC2UoiRdmhg+l5LTbN2Cc3AqtbTaJnJbry0nqqNvt41WohIs ztjkEsGC3JY6Tb7yMLuQkZ4ruAJGVqCUBWYkGv/ejG/TxtUngfWOAkENVYlHfIHeipzE 4EaQZm6twldEsxve4TG9hLLt2BHQD5Wol13hE8LCOU9klaLw9axg+PJfCy1uLkMcLHnC TDyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Re0/IOxZf5Hx6BeFa9inJCF0a6cGKdlu1k/P2sxW8QU=; b=Ssipmmnta0bunipCbxktQBOE47EAyjYu+/r9/xdaWlKIeLIzCqiwiLisJUvIS0Xc8N 3hJ2RVDMDHtBR67pBuI7TMvShOSzqTViLxI2F7LbjGSzs+rctjvSb6UegdNB34cVVAF/ SUIqnku2xMDSj+s58iJZOXDQSoE/OWnCsHL0sDcTshnUupX1P0YqJ6zK7UYm7Dr8eHYP xptpf5/thfGXSy4+Pd9lUce5KQ1bRg0GKNzY8C5q1VoTXz3CyaeqetfN0ohA9f+HHabA HJHth5VXySsLH9pzpCV4g2cKZOhbjlQSwQb7s3PPA+1z0Skq5s94T89cLLRT9S+fEd/n qGIA== X-Gm-Message-State: ANoB5pm5zyiwE8LghfEr3TAiLyTUQoEFVL1+zQvckmQo6v4SKzqKKZMk Bb2SkXBKW0ZUj6PnInIBOagaK/EVj/QzBw== X-Received: by 2002:a63:2117:0:b0:474:f7bd:9462 with SMTP id h23-20020a632117000000b00474f7bd9462mr5417655pgh.189.1668756660244; Thu, 17 Nov 2022 23:31:00 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::2c6b]) by smtp.googlemail.com with ESMTPSA id f7-20020a625107000000b0056b818142a2sm2424325pfb.109.2022.11.17.23.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 23:30:59 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, akpm@linux-foundation.org, willy@infradead.org, naoya.horiguchi@nec.com, tytso@mit.edu, "Vishal Moola (Oracle)" Subject: [PATCH v3 1/4] ext4: Convert move_extent_per_page() to use folios Date: Thu, 17 Nov 2022 23:30:52 -0800 Message-Id: <20221118073055.55694-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221118073055.55694-1-vishal.moola@gmail.com> References: <20221118073055.55694-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749818246910298532?= X-GMAIL-MSGID: =?utf-8?q?1749818246910298532?= Converts move_extent_per_page() to use folios. This change removes 5 calls to compound_head() and is in preparation for the removal of the try_to_release_page() wrapper. Signed-off-by: Vishal Moola (Oracle) --- fs/ext4/move_extent.c | 52 ++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 044e34cd835c..8dbb87edf24c 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -253,6 +253,7 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, { struct inode *orig_inode = file_inode(o_filp); struct page *pagep[2] = {NULL, NULL}; + struct folio *folio[2] = {NULL, NULL}; handle_t *handle; ext4_lblk_t orig_blk_offset, donor_blk_offset; unsigned long blocksize = orig_inode->i_sb->s_blocksize; @@ -313,6 +314,13 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, * hold page's lock, if it is still the case data copy is not * necessary, just swap data blocks between orig and donor. */ + folio[0] = page_folio(pagep[0]); + folio[1] = page_folio(pagep[1]); + + VM_BUG_ON_FOLIO(folio_test_large(folio[0]), folio[0]); + VM_BUG_ON_FOLIO(folio_test_large(folio[1]), folio[1]); + VM_BUG_ON_FOLIO(folio_nr_pages(folio[0]) != folio_nr_pages(folio[1]), folio[1]); + if (unwritten) { ext4_double_down_write_data_sem(orig_inode, donor_inode); /* If any of extents in range became initialized we have to @@ -331,10 +339,10 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, ext4_double_up_write_data_sem(orig_inode, donor_inode); goto data_copy; } - if ((page_has_private(pagep[0]) && - !try_to_release_page(pagep[0], 0)) || - (page_has_private(pagep[1]) && - !try_to_release_page(pagep[1], 0))) { + if ((folio_has_private(folio[0]) && + !filemap_release_folio(folio[0], 0)) || + (folio_has_private(folio[1]) && + !filemap_release_folio(folio[1], 0))) { *err = -EBUSY; goto drop_data_sem; } @@ -344,19 +352,21 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, block_len_in_page, 1, err); drop_data_sem: ext4_double_up_write_data_sem(orig_inode, donor_inode); - goto unlock_pages; + goto unlock_folios; } data_copy: - *err = mext_page_mkuptodate(pagep[0], from, from + replaced_size); + *err = mext_page_mkuptodate(&folio[0]->page, from, from + replaced_size); if (*err) - goto unlock_pages; + goto unlock_folios; /* At this point all buffers in range are uptodate, old mapping layout * is no longer required, try to drop it now. */ - if ((page_has_private(pagep[0]) && !try_to_release_page(pagep[0], 0)) || - (page_has_private(pagep[1]) && !try_to_release_page(pagep[1], 0))) { + if ((folio_has_private(folio[0]) && + !filemap_release_folio(folio[0], 0)) || + (folio_has_private(folio[1]) && + !filemap_release_folio(folio[1], 0))) { *err = -EBUSY; - goto unlock_pages; + goto unlock_folios; } ext4_double_down_write_data_sem(orig_inode, donor_inode); replaced_count = ext4_swap_extents(handle, orig_inode, donor_inode, @@ -369,13 +379,13 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, replaced_size = block_len_in_page << orig_inode->i_blkbits; } else - goto unlock_pages; + goto unlock_folios; } /* Perform all necessary steps similar write_begin()/write_end() * but keeping in mind that i_size will not change */ - if (!page_has_buffers(pagep[0])) - create_empty_buffers(pagep[0], 1 << orig_inode->i_blkbits, 0); - bh = page_buffers(pagep[0]); + if (!folio_buffers(folio[0])) + create_empty_buffers(&folio[0]->page, 1 << orig_inode->i_blkbits, 0); + bh = folio_buffers(folio[0]); for (i = 0; i < data_offset_in_page; i++) bh = bh->b_this_page; for (i = 0; i < block_len_in_page; i++) { @@ -385,7 +395,7 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, bh = bh->b_this_page; } if (!*err) - *err = block_commit_write(pagep[0], from, from + replaced_size); + *err = block_commit_write(&folio[0]->page, from, from + replaced_size); if (unlikely(*err < 0)) goto repair_branches; @@ -395,11 +405,11 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, *err = ext4_jbd2_inode_add_write(handle, orig_inode, (loff_t)orig_page_offset << PAGE_SHIFT, replaced_size); -unlock_pages: - unlock_page(pagep[0]); - put_page(pagep[0]); - unlock_page(pagep[1]); - put_page(pagep[1]); +unlock_folios: + folio_unlock(folio[0]); + folio_put(folio[0]); + folio_unlock(folio[1]); + folio_put(folio[1]); stop_journal: ext4_journal_stop(handle); if (*err == -ENOSPC && @@ -430,7 +440,7 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, *err = -EIO; } replaced_count = 0; - goto unlock_pages; + goto unlock_folios; } /**