From patchwork Wed Dec 7 18:10:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13067492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87CDCC4708D for ; Wed, 7 Dec 2022 18:10:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD0C58E0003; Wed, 7 Dec 2022 13:10:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B80F58E0001; Wed, 7 Dec 2022 13:10:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A489C8E0003; Wed, 7 Dec 2022 13:10:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 94EDB8E0001 for ; Wed, 7 Dec 2022 13:10:16 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 64EAA401A1 for ; Wed, 7 Dec 2022 18:10:16 +0000 (UTC) X-FDA: 80216299632.28.4AEA670 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf05.hostedemail.com (Postfix) with ESMTP id 1AB0A100018 for ; Wed, 7 Dec 2022 18:10:14 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=V1arU17e; spf=pass (imf05.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670436615; a=rsa-sha256; cv=none; b=PKFIouzXLpZ078a2soZkA1UsQoGKtu1uBt9iedUmaz7Mtz3WsMuLf/Mpd1WM0bAEdIlsST kIYHvNIDb84JG5NM20nxvz5nLHt+2jlYx6AImCrmbIyDnrc6nBg8U+GLxC89EW2q+6FSOm PHNeHsJ/QXF71TjHJ+iL6DC07npM3Ig= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=V1arU17e; spf=pass (imf05.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670436615; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=xAXo1CC+DgLv8rsBENeTWCQSP6gxhN9/sRtHellAmI4=; b=iO8FhGu1tUH6MgyYFoeHJtl9iTFhyhIKq7JmfQqiKe0Lq8E+G/JcHVZAv856AvyTMiOlx8 pqB2LvO/WhQorHMRlhcVD/oCo/0dMaS0lPVQ8dr00RnHc/i9CqMBjwX7YU33kYJ0w1BsSL /OHHVviMXu5npp5KsKu4ky2K12wlQf0= Received: by mail-pf1-f174.google.com with SMTP id 65so5514146pfx.9 for ; Wed, 07 Dec 2022 10:10:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xAXo1CC+DgLv8rsBENeTWCQSP6gxhN9/sRtHellAmI4=; b=V1arU17eo0dro0cMkfZPYd0YHgGtjRfIQwEbUUHPwbn8exlXaQdYGMQYrzdSqb+2hx 3kkrZL685pmQA3r0JkmR+ri5O91x3EMDHlIS545Yyh8dfOUNkHEYnMS3Y9m/CeKF8ESo /XBAGOqVRRyxlVsBYnlruFYc/scVRL+VVjrgwO0gPBRXUEsViKzxZ1U8DMHLfzeLiGke 5CuHJAF4PSOxoxSfrIiUe8PbJT2DO287MAkU7QVPYtmEFhxViRSNY86iSCc+807w7FMJ iBqNmdrZ7Idc4pzUjL8ZGTLjr0IOLuyOiFVCMBTkrtqCCZ9iIyAZOsBWA6LCZmOmFvGX ieTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xAXo1CC+DgLv8rsBENeTWCQSP6gxhN9/sRtHellAmI4=; b=Re7zHlz61IxYJjgEHSpV4Uko/qvXcCJfCaYEWLzOSeAhLxBfMFXwF2MPMdBtZ2U0Gd SDWZA+mXWqHl6/TsDkGMzBYMAsoqpMsJWF3xeePQby5u3mhKIzVTAvBCwiU9bONy7zVo gDcmwaCUTEMk3e4WdZru502X7XNrBfTGpr5kBPsH4U2t8WayXUnVEV86Ksj8yAbBVToM f8MdMVAFRa9eYP82u79Bn47Esu/Qzq4k+nnhNldTGHu/CtGnpsx//zZxJv3KNe2DmBJ5 +oHUAxlgF27tqTJOno+A8k8d+Qq4vH9gb3QUEYVnrnOUrHrl5eBgM7wzIO5ZCTEYfcxN KQLw== X-Gm-Message-State: ANoB5pmijZ+oOaCD5HnHyqwLPvX5d3NxT5DSLnSoIbud3n4i4a9HvT2R tbhwyB62QciS0ADVq4RpPdJpA2yS/pphDw== X-Google-Smtp-Source: AA0mqf7m7wuh4m5rf8Cez3jfVm/OWprGMUX0IVr1hFeuMnIv9fTJVVEUyET0IGPR7pbrif2/9j4saA== X-Received: by 2002:a63:1e44:0:b0:478:91e1:ff60 with SMTP id p4-20020a631e44000000b0047891e1ff60mr20669074pgm.206.1670436613596; Wed, 07 Dec 2022 10:10:13 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::2c6b]) by smtp.googlemail.com with ESMTPSA id w2-20020a17090abc0200b00218f9bd50c7sm1468735pjr.50.2022.12.07.10.10.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 10:10:13 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: tytso@mit.edu, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, "Vishal Moola (Oracle)" , Matthew Wilcox Subject: [PATCH mm-unstable v2] ext4: Convert mext_page_double_lock() to mext_folio_double_lock() Date: Wed, 7 Dec 2022 10:10:09 -0800 Message-Id: <20221207181009.4016-1-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spamd-Result: default: False [2.16 / 9.00]; BAYES_HAM(-5.94)[99.88%]; SORBS_IRL_BL(3.00)[209.85.210.174:from]; R_MISSING_CHARSET(2.50)[]; SUSPICIOUS_RECIPS(1.50)[]; SUBJECT_HAS_UNDERSCORES(1.00)[]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; RCVD_NO_TLS_LAST(0.10)[]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; MID_RHS_MATCH_FROM(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; R_DKIM_ALLOW(0.00)[gmail.com:s=20210112]; TAGGED_RCPT(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; ARC_NA(0.00)[]; TAGGED_FROM(0.00)[]; DMARC_POLICY_ALLOW(0.00)[gmail.com,none]; DKIM_TRACE(0.00)[gmail.com:+]; RCVD_COUNT_THREE(0.00)[3]; R_SPF_ALLOW(0.00)[+ip4:209.85.128.0/17:c]; RCPT_COUNT_SEVEN(0.00)[7]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 1AB0A100018 X-Stat-Signature: ezn1nmj3qd79basi98i9mkbrk6nj1aom X-HE-Tag: 1670436614-496269 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Converts mext_page_double_lock() to use folios. This change saves 146 bytes of kernel text. It also removes 6 calls to compound_head() and 2 calls to folio_file_page(). Signed-off-by: Vishal Moola (Oracle) Reviewed-by: Matthew Wilcox (Oracle) --- fs/ext4/move_extent.c | 46 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 8dbb87edf24c..2de9829aed63 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -110,22 +110,23 @@ mext_check_coverage(struct inode *inode, ext4_lblk_t from, ext4_lblk_t count, } /** - * mext_page_double_lock - Grab and lock pages on both @inode1 and @inode2 + * mext_folio_double_lock - Grab and lock folio on both @inode1 and @inode2 * * @inode1: the inode structure * @inode2: the inode structure - * @index1: page index - * @index2: page index - * @page: result page vector + * @index1: folio index + * @index2: folio index + * @folio: result folio vector * - * Grab two locked pages for inode's by inode order + * Grab two locked folio for inode's by inode order */ static int -mext_page_double_lock(struct inode *inode1, struct inode *inode2, - pgoff_t index1, pgoff_t index2, struct page *page[2]) +mext_folio_double_lock(struct inode *inode1, struct inode *inode2, + pgoff_t index1, pgoff_t index2, struct folio *folio[2]) { struct address_space *mapping[2]; unsigned int flags; + unsigned fgp_flags = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE; BUG_ON(!inode1 || !inode2); if (inode1 < inode2) { @@ -138,28 +139,30 @@ mext_page_double_lock(struct inode *inode1, struct inode *inode2, } flags = memalloc_nofs_save(); - page[0] = grab_cache_page_write_begin(mapping[0], index1); - if (!page[0]) { + folio[0] = __filemap_get_folio(mapping[0], index1, fgp_flags, + mapping_gfp_mask(mapping[0])); + if (!folio[0]) { memalloc_nofs_restore(flags); return -ENOMEM; } - page[1] = grab_cache_page_write_begin(mapping[1], index2); + folio[1] = __filemap_get_folio(mapping[1], index2, fgp_flags, + mapping_gfp_mask(mapping[1])); memalloc_nofs_restore(flags); - if (!page[1]) { - unlock_page(page[0]); - put_page(page[0]); + if (!folio[1]) { + folio_unlock(folio[0]); + folio_put(folio[0]); return -ENOMEM; } /* - * grab_cache_page_write_begin() may not wait on page's writeback if + * __filemap_get_folio() may not wait on folio's writeback if * BDI not demand that. But it is reasonable to be very conservative - * here and explicitly wait on page's writeback + * here and explicitly wait on folio's writeback */ - wait_on_page_writeback(page[0]); - wait_on_page_writeback(page[1]); + folio_wait_writeback(folio[0]); + folio_wait_writeback(folio[1]); if (inode1 > inode2) - swap(page[0], page[1]); + swap(folio[0], folio[1]); return 0; } @@ -252,7 +255,6 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, int block_len_in_page, int unwritten, int *err) { 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; @@ -303,8 +305,8 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, replaced_size = data_size; - *err = mext_page_double_lock(orig_inode, donor_inode, orig_page_offset, - donor_page_offset, pagep); + *err = mext_folio_double_lock(orig_inode, donor_inode, orig_page_offset, + donor_page_offset, folio); if (unlikely(*err < 0)) goto stop_journal; /* @@ -314,8 +316,6 @@ 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]);