Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp88497lqb; Thu, 14 Mar 2024 06:18:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWbhZPSpe0hLYQ8kVFfrPu8Rgd4ULDenbF/96s/7mc3X8qnZCW6SJqAcaEN3Joe4+HsTsAZmF7jExyCNif779VUzdEr9NPhZcBS3a+ULA== X-Google-Smtp-Source: AGHT+IEIWJPCMTSQH4wyfaMtjpiXygmDsx1eJ0x18HDJrdjroHraJI1R3NEzMvxGFwuuTf6IY8lL X-Received: by 2002:a17:902:e74f:b0:1dd:8c28:8a8d with SMTP id p15-20020a170902e74f00b001dd8c288a8dmr1933284plf.68.1710422327966; Thu, 14 Mar 2024 06:18:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710422327; cv=pass; d=google.com; s=arc-20160816; b=BnZ6NYd03a9std1PvNqxo1pbHzSnbR2EQHKjraPsPHz0zwSfxdquNUzgRX8581g/tY 2+GSIuFxrA56MKqQUbKyYJHmvQnUg0Pse7EZ4wyJntLwiTgdk5p7QOmFHzAAVM48mcxv a4jpvD4eVQrkW89NX37eZdPDMOiXGWZ3vDAAZhCDXxR/2LAhsm+st1RTM2TKPGDFVfCe h+9VSTsWv5JhjGCPKxqAM7m1QXyT1dc0m9BxnreV1uSCcgGd913CWVmWY4TKq6Bqsr3S o6qK8Sxh+pAFM593DOlrJYENFXDnhIgZbW01QsMKYcoKSozIEzOlhXzJEyMkzZZnVUsh N6uw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Wszp5hbUcP6JMNVNZOwpP5JGK1SwphDd9Wp1MxuYftg=; fh=j3uz2NgZFfq57/Snoylk35aIHaL6SCDmmQDWQGY3sTA=; b=IFbv8lNOkSYFum08d5ybrXajo1MxccecFD8wzCwjRnzW5Pd2yaE1qvIqqd7enfmoxM FD/I7EJmyEPpUamofRXRVC71Eivcun+WSwkpvLDwdWwYVDiTRRgC10/TYXj3hb6/mBXz rIpiwwSSGoaKMOn+fghxZcrGBVaUq/+GNnj0F3k8j9Edp4zLtO4DSgX24sBK0bitDP4A QOiy/Z1XhTCWko/xjsGdWmbNqXmE4XPlZZKn0zdcEV1mRzmRSqOj8pu3z0evADrikNRZ UOqXqYrJ1fvMXqsx3v8dUU7iZn/+3IJFetJKpcrx1FqrR2c4w2Bld86EbEH/CLjcwSQ+ 42Kw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=CmOymcqE; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-102174-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s20-20020a17090330d400b001dda51ed78bsi1388043plc.422.2024.03.14.06.18.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 06:18:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102174-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=CmOymcqE; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-102174-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 26FA1285C77 for ; Wed, 13 Mar 2024 18:16:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B9EC197F1D; Wed, 13 Mar 2024 17:03:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="CmOymcqE" Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (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 7914B197F07; Wed, 13 Mar 2024 17:03:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710349400; cv=none; b=XHC2Cuv7yvlx9FHAv2K1KPr1hr6dIweatXAxdfO4l2s0SLg5ntoyXAl14jHbKRBUROjVJLUHangxNrkBVE4BAsft82u6p7W/xO4tFZg6Sk7vTuFtd7JFTOarLzzvTUqaiFDYd3gJm/g8jCyZyWyzZsVuTtIkksoppMXkDQOJfDk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710349400; c=relaxed/simple; bh=YxB/X/48cfwolL9OjGvtP+CkDHnRLIxkhXlYkn7ryjk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=td4dkZjb75rFHEGJHDN27WngYuLQm25KnlxbFHwMm0xLISZOKexpyeH+ykgJQz61lFFF2o8X9aogphvAD3gwb+Y8RifqhV1+zBJCIDfoC5IPvnr0F8FgkcP3hktK8r2VHG89xxzi5KBAIvhoWacWcI5WFvXLwQOhcwEh8U8jhLA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com; spf=pass smtp.mailfrom=pankajraghav.com; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b=CmOymcqE; arc=none smtp.client-ip=80.241.56.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pankajraghav.com 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4TvxfN6wJZz9sZ1 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); -- 2.43.0