From patchwork Wed Mar 13 17:02:45 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: 13591599 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 A705DC54E66 for ; Wed, 13 Mar 2024 17:03:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD2E280044; Wed, 13 Mar 2024 13:03:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5E2F940010; Wed, 13 Mar 2024 13:03:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD4A880044; Wed, 13 Mar 2024 13:03:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 97B3F940010 for ; Wed, 13 Mar 2024 13:03:14 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E952B1209CA for ; Wed, 13 Mar 2024 17:03:13 +0000 (UTC) X-FDA: 81892636266.13.EC779D7 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf24.hostedemail.com (Postfix) with ESMTP id 3D4FB18003C for ; Wed, 13 Mar 2024 17:03:11 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=CmOymcqE; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf24.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 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=1710349392; 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=Wszp5hbUcP6JMNVNZOwpP5JGK1SwphDd9Wp1MxuYftg=; b=MjIbVTsP2jiOVj3pXwxqA/G/UaEy2UxbZQufILOS+9IhDfVmCvXkmygRNp912RExtFcTUv clJsIxOIL6xTWpGurPpVu4pAPseJi8eqPcXQFdzGeQ5jqYcmHkqko0kciYB197P228SMqG c549Z6ymfwHAPD3/sU1Q1n+RUdmj9Sg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=CmOymcqE; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf24.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710349392; a=rsa-sha256; cv=none; b=aZIe/NiHCxFM31++mrYeFbOkXjs8BtfGwXLwrhy2fasvJd7jiLOBqtc2acJbxuwUUzWo+U EUaIcb19vXXTIDDZ23eC6w7DFaWakKApT1Q99b5UWloaR8Se3+uHzLGc0xX3P5mHZPjcFZ tLLkAmYpWL8+b4+KCVjSj8hrbvCMxYo= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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-201.mailbox.org (Postfix) with ESMTPS id 4TvxfN6wJZz9sZ1; Wed, 13 Mar 2024 18:03:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1710349389; 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=Wszp5hbUcP6JMNVNZOwpP5JGK1SwphDd9Wp1MxuYftg=; b=CmOymcqEA2k7F3fSEc2F0iZrVfdQjpS+vB/8mbuQc6OVEXK4IZaNdr26Mdt8g6AgFWGu+S /CcsBxKTvJT1TRyRh9A+aRMVGD1fy09gUUkNaLWdRLnQagNJEzLSuytM6bk+uf2+2uPZHR NozFQhS3e1i2r52JNALlZ8dxSL3OCSeTI8onadSfCy/V9uFlGUDynvxiSZ2ppEkNFvpUPE Re+YMOHOHJ8UaC/qsTcVZpYi69oAnc3A2wY4giR8dC7ieBM6FCviYzdlNCnz61gnqUlo01 v7XayFjgxuRzrlBX26Qau+MsdV8EI6YqAd1ZHFsgL4mfHVSEACXlboqLcp4Y9A== From: "Pankaj Raghav (Samsung)" To: willy@infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: gost.dev@samsung.com, chandan.babu@oracle.com, hare@suse.de, mcgrof@kernel.org, djwong@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@fromorbit.com, akpm@linux-foundation.org, Pankaj Raghav Subject: [PATCH v3 03/11] filemap: allocate mapping_min_order folios in the page cache Date: Wed, 13 Mar 2024 18:02:45 +0100 Message-ID: <20240313170253.2324812-4-kernel@pankajraghav.com> In-Reply-To: <20240313170253.2324812-1-kernel@pankajraghav.com> References: <20240313170253.2324812-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3D4FB18003C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: bnyko14m3t38q5f1utn9ac5tu36dqbof X-HE-Tag: 1710349391-491015 X-HE-Meta: U2FsdGVkX19jtb/F8CQ/AEN308Mjm+4icWVspG9aHI0ULA34kqK4cOiCCWEAYfO6pcGamoe0aRvORhYgUQw1yJ15hYS4eL51eU1ZNxkVyr9GIMxc8JlnA3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.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Luis Chamberlain filemap_create_folio() and do_read_cache_folio() were always allocating folio of order 0. __filemap_get_folio was trying to allocate higher order folios when fgp_flags had higher order hint set but it will default to order 0 folio if higher order memory allocation fails. Supporting mapping_min_order implies that we guarantee each folio in the page cache has at least an order of mapping_min_order. When adding new folios to the page cache we must also 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. Signed-off-by: Luis Chamberlain Co-developed-by: Pankaj Raghav Signed-off-by: Pankaj Raghav --- mm/filemap.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index a1cb3ea55fb6..57889f206829 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -849,6 +849,8 @@ noinline int __filemap_add_folio(struct address_space *mapping, VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(folio_test_swapbacked(folio), folio); + VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_folio_order(mapping), + folio); mapping_set_update(&xas, mapping); if (!huge) { @@ -1886,8 +1888,10 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, folio_wait_stable(folio); no_page: if (!folio && (fgp_flags & FGP_CREAT)) { - unsigned order = FGF_GET_ORDER(fgp_flags); + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int order = max(min_order, FGF_GET_ORDER(fgp_flags)); int err; + index = mapping_align_start_index(mapping, index); if ((fgp_flags & FGP_WRITE) && mapping_can_writeback(mapping)) gfp |= __GFP_WRITE; @@ -1927,7 +1931,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, break; folio_put(folio); folio = NULL; - } while (order-- > 0); + } while (order-- > min_order); if (err == -EEXIST) goto repeat; @@ -2416,13 +2420,16 @@ 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); + folio = filemap_alloc_folio(mapping_gfp_mask(mapping), + min_order); if (!folio) return -ENOMEM; @@ -2440,6 +2447,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 +2509,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; @@ -3662,9 +3670,11 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, repeat: folio = filemap_get_folio(mapping, index); if (IS_ERR(folio)) { - folio = filemap_alloc_folio(gfp, 0); + folio = filemap_alloc_folio(gfp, + mapping_min_folio_order(mapping)); if (!folio) return ERR_PTR(-ENOMEM); + index = mapping_align_start_index(mapping, index); err = filemap_add_folio(mapping, folio, index, gfp); if (unlikely(err)) { folio_put(folio);