From patchwork Fri Mar 1 16:44:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13578741 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 5B59AC5475B for ; Fri, 1 Mar 2024 16:45:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5F3A6B0087; Fri, 1 Mar 2024 11:45:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C0F736B0088; Fri, 1 Mar 2024 11:45:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A61626B0089; Fri, 1 Mar 2024 11:45:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 93FA06B0087 for ; Fri, 1 Mar 2024 11:45:04 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5DF7F1606E5 for ; Fri, 1 Mar 2024 16:45:04 +0000 (UTC) X-FDA: 81849044928.06.A459559 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf23.hostedemail.com (Postfix) with ESMTP id 9D27B140023 for ; Fri, 1 Mar 2024 16:45:02 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="HN/hGMWj"; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf23.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311502; 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:in-reply-to:references:references:dkim-signature; bh=BCQodYVgPvK7zJztO22OSwzZBWMPBsGjwa0dIcNZkr8=; b=jeWH444rmJ1FWsF7nMg1avRoFtKH3efwbvHHaNI0gkI1JAFSAcYOXlNAs+YZbbGO7XD4be 2otpKkVDrGKPfp7A+9Nr//LbR46TsA4Gb/a/kOLfHEE9jXRUxsMBmDDfTQFUQgIuRmFYXw plvjm7U3iBTxDocNIszC/AzCE3cV0Lg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="HN/hGMWj"; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf23.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311502; a=rsa-sha256; cv=none; b=6eoks9q59vXtoHl2oEz49yei0WP0pxKbxYDcG3UxNbtqoe/l6KxPuM/rPlEtc67hQZj0va /O2YXv1iZ5E6mjnANeTksx15EHxp6pbsYp6z+SawHGWGZos23+E8VOnTxF726mULhyzKZk ylEfPmNa+ZfnyFBd/GLQqwgW1BPgXRU= Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4TmYpz35Y1z9t7Z; Fri, 1 Mar 2024 17:44:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BCQodYVgPvK7zJztO22OSwzZBWMPBsGjwa0dIcNZkr8=; b=HN/hGMWj2gC5ZojLre62sCdhsS18t89JR0BD9LJzX7iJ/Hqx9zmSsQtDrhYImhyoAxGAO/ ruoKmN06+/h7LtqfkBwARYmoZ0+J8PfLGGkOmqyqs2wo8Ib04XGqutAvFrw9JWq1uMImwZ 5J4jlTrgdOVujUjaWDNOgaDR6C9KMlCIw/5oCv6ERInUn8FOInxxcRlA0aZecyczCv1d9D MkEyl3pqTJHM2TU2ErxfE3hE5dV3hL3yj/GVot+TyNb6m9tcmVWrVLRdLf/Pd3C7qUD5UW 3Dv2OCudXJiZqfb5sxfmf6tQheb+gjipAbANPdwH71pSHy4a3Jgu/Ikv8G8i+g== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 03/13] filemap: align the index to mapping_min_order in the page cache Date: Fri, 1 Mar 2024 17:44:34 +0100 Message-ID: <20240301164444.3799288-4-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9D27B140023 X-Stat-Signature: 3akrqewquqydr7ck8kaog5agsppkq66x X-Rspam-User: X-HE-Tag: 1709311502-847331 X-HE-Meta: U2FsdGVkX1/rYTo9MyxzL7h9lZpCM3F3yQIgv0BSzHL5ijF6FetcnBUpytOu24ukBgO6LNw95eFdxSKIo0wh4bbIEp9FvNRErin7TqoklyFDKOwfnykp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org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Luis Chamberlain Supporting mapping_min_order implies that we guarantee each folio in the page cache has at least an order of mapping_min_order. So when adding new folios to the page cache we must ensure the index used is aligned to the mapping_min_order as the page cache requires the index to be aligned to the order of the folio. A higher order folio than min_order by definition is a multiple of the min_order. If an index is aligned to an order higher than a min_order, it will also be aligned to the min order. This effectively introduces no new functional changes when min order is not set other than a few rounding computations that should result in the same value. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- include/linux/pagemap.h | 10 +++++++++- mm/filemap.c | 16 ++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index fc8eb9c94e9c..b3cf8ef89826 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1328,6 +1328,14 @@ struct readahead_control { ._index = i, \ } +#define DEFINE_READAHEAD_ALIGNED(ractl, f, r, m, i) \ + struct readahead_control ractl = { \ + .file = f, \ + .mapping = m, \ + .ra = r, \ + ._index = mapping_align_start_index(m, i), \ + } + #define VM_READAHEAD_PAGES (SZ_128K / PAGE_SIZE) void page_cache_ra_unbounded(struct readahead_control *, @@ -1356,7 +1364,7 @@ void page_cache_sync_readahead(struct address_space *mapping, struct file_ra_state *ra, struct file *file, pgoff_t index, unsigned long req_count) { - DEFINE_READAHEAD(ractl, file, ra, mapping, index); + DEFINE_READAHEAD_ALIGNED(ractl, file, ra, mapping, index); page_cache_sync_ra(&ractl, req_count); } diff --git a/mm/filemap.c b/mm/filemap.c index 2b00442b9d19..96fe5c7fe094 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2416,11 +2416,13 @@ static int filemap_update_page(struct kiocb *iocb, } static int filemap_create_folio(struct file *file, - struct address_space *mapping, pgoff_t index, + struct address_space *mapping, loff_t pos, struct folio_batch *fbatch) { struct folio *folio; int error; + unsigned int min_order = mapping_min_folio_order(mapping); + pgoff_t index; folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0); if (!folio) @@ -2440,6 +2442,8 @@ static int filemap_create_folio(struct file *file, * well to keep locking rules simple. */ filemap_invalidate_lock_shared(mapping); + /* index in PAGE units but aligned to min_order number of pages. */ + index = (pos >> (PAGE_SHIFT + min_order)) << min_order; error = filemap_add_folio(mapping, folio, index, mapping_gfp_constraint(mapping, GFP_KERNEL)); if (error == -EEXIST) @@ -2500,8 +2504,7 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, if (!folio_batch_count(fbatch)) { if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ)) return -EAGAIN; - err = filemap_create_folio(filp, mapping, - iocb->ki_pos >> PAGE_SHIFT, fbatch); + err = filemap_create_folio(filp, mapping, iocb->ki_pos, fbatch); if (err == AOP_TRUNCATED_PAGE) goto retry; return err; @@ -3093,7 +3096,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) struct file *file = vmf->vma->vm_file; struct file_ra_state *ra = &file->f_ra; struct address_space *mapping = file->f_mapping; - DEFINE_READAHEAD(ractl, file, ra, mapping, vmf->pgoff); + DEFINE_READAHEAD_ALIGNED(ractl, file, ra, mapping, vmf->pgoff); struct file *fpin = NULL; unsigned long vm_flags = vmf->vma->vm_flags; unsigned int mmap_miss; @@ -3147,7 +3150,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) ra->start = max_t(long, 0, vmf->pgoff - ra->ra_pages / 2); ra->size = ra->ra_pages; ra->async_size = ra->ra_pages / 4; - ractl._index = ra->start; + ractl._index = mapping_align_start_index(mapping, ra->start); page_cache_ra_order(&ractl, ra, 0); return fpin; } @@ -3162,7 +3165,7 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf, { struct file *file = vmf->vma->vm_file; struct file_ra_state *ra = &file->f_ra; - DEFINE_READAHEAD(ractl, file, ra, file->f_mapping, vmf->pgoff); + DEFINE_READAHEAD_ALIGNED(ractl, file, ra, file->f_mapping, vmf->pgoff); struct file *fpin = NULL; unsigned int mmap_miss; @@ -3657,6 +3660,7 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, struct folio *folio; int err; + index = mapping_align_start_index(mapping, index); if (!filler) filler = mapping->a_ops->read_folio; repeat: