Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4845433rdb; Fri, 15 Sep 2023 14:16:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGP4/f5T48jHS/4rWqbWalMlB8eQP0SjJZB0ITu0lY6XG1Rsqz2rsKWscmhQKGEqKmiivqf X-Received: by 2002:a05:6a20:3d83:b0:13d:bf07:7444 with SMTP id s3-20020a056a203d8300b0013dbf077444mr3413027pzi.0.1694812593959; Fri, 15 Sep 2023 14:16:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694812593; cv=none; d=google.com; s=arc-20160816; b=mdpvSOVYGnRtRUHt7Cmg4juPCQ6Q303Ba4jGu/cWCMf9imhf3KkE8U5Ls1h2rj6Qid xCyZtcFx9Ct9U0TGMTJ8KJ+1dLLhsVTFd6Grq0IKyThfUr0wtLMaPwxVSymnGzWNITAD tLUVdc+Ybfjmugv4cFvGd44JJtql1WU3PLbx5hND2+JEwRQng4YcOqr+CUMxpy1+ac2Y 52oeVO5gAn3DoVk1/edunWIjE9Ju5n7yb1FkpmF1bJ92+mOzlAxcB/l3Udsji4Ku+8vu kIQuWmuEimDuxOQ9WnAFo0PmMMHjJ508Vf+djzLbIjcEC+tpvk9HdlJV08tA9/l3M0Tf W/wQ== 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=LywLEuPyM84LvnszU9bu3yYyFXSjfbQxmSaZo0Anuqo=; fh=kl+S4GAUWD1kOeoqBopscteh2mu3DZslcHc01dOJ6TI=; b=zfVm6YiKS7u9tOBoonkFvOtmjmmDxfCwt3xtas4s9Gz36/e2NgQEZPurweQ7OHrKOd rlnmEmUVH1nxZQcWhXEEW3Sx94gcw4SkYL//8hANRsVBcSGtZ1Y6K07sKjUF3PiqOpmQ ZUH+eiJLvjmN8fQZU2VVjcXx+Z+C4Xy3wLmUVUzBXP2KBnEhi/O8y1sG4TlPEhFslnu4 0qyOHMxHz+c3sdUv/8YuA+BZVRK747XCJyh2YLo3In7lnvtCZS8NsLKvlT17svgQ0yNf 0WsbN/kqqUrvR6DSD4TvCnCIPgYWSfjyXVltTt+dZpUCrXL0Oul+vCCahYhneQdQau+h jg6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=sPBj7+lP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id v64-20020a638943000000b00565e386ff40si3783225pgd.744.2023.09.15.14.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 14:16:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=sPBj7+lP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 830C780E6CBC; Fri, 15 Sep 2023 11:43:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236990AbjIOSmu (ORCPT + 99 others); Fri, 15 Sep 2023 14:42:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236981AbjIOSmS (ORCPT ); Fri, 15 Sep 2023 14:42:18 -0400 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52A324695; Fri, 15 Sep 2023 11:40:54 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4RnNJt60W1z9sTy; Fri, 15 Sep 2023 20:39:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1694803182; 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=LywLEuPyM84LvnszU9bu3yYyFXSjfbQxmSaZo0Anuqo=; b=sPBj7+lPJjN1O52TPN3bPIvCgfHWewlpa4lD2gPArpjJc42qjZjYB0ivxNzVoPtgWUV2X9 baXqoaVEy427TKtHRyh9CuvB1dGk4UoKPWdumhCVK/Zj7hjnyV/9B5lvcIJez7O/RYML7a 7BbpTXkSIEysivDSIn8uG2RYC8Ka8TO0B9P19XqbBg8Pj8JfaNqqdtPoeNMsD2lb4sD0eY cFRHPxdkrbiSJb37sUgM291kELuaAdt9gvlmR97ZVvHYeejas3FF4Zlhd05N2OYrwNWsrp 2xibhXY+ahHHlr/15+T/ltQEQlsnkfS5en8VhTucFA1GfYp0wjO7bbHAmSHM9Q== From: Pankaj Raghav To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: p.raghav@samsung.com, david@fromorbit.com, da.gomez@samsung.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, willy@infradead.org, djwong@kernel.org, linux-mm@kvack.org, chandan.babu@oracle.com, mcgrof@kernel.org, gost.dev@samsung.com Subject: [RFC 18/23] readahead: align ra start and size to mapping_min_order in ondemand_ra() Date: Fri, 15 Sep 2023 20:38:43 +0200 Message-Id: <20230915183848.1018717-19-kernel@pankajraghav.com> In-Reply-To: <20230915183848.1018717-1-kernel@pankajraghav.com> References: <20230915183848.1018717-1-kernel@pankajraghav.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4RnNJt60W1z9sTy X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 11:43:33 -0700 (PDT) From: Luis Chamberlain Align the ra->start and ra->size to mapping_min_order in ondemand_readahead(). This will ensure the folios added to the page_cache will be aligned to mapping_min_order number of pages. Signed-off-by: Luis Chamberlain --- mm/readahead.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 7c2660815a01..03fa6f6c8145 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -605,7 +605,11 @@ static void ondemand_readahead(struct readahead_control *ractl, unsigned long add_pages; pgoff_t index = readahead_index(ractl); pgoff_t expected, prev_index; - unsigned int order = folio ? folio_order(folio) : 0; + unsigned int min_order = mapping_min_folio_order(ractl->mapping); + unsigned int min_nrpages = 1UL << min_order; + unsigned int order = folio ? folio_order(folio) : min_order; + + VM_BUG_ON(ractl->_index & (min_nrpages - 1)); /* * If the request exceeds the readahead window, allow the read to @@ -627,9 +631,13 @@ static void ondemand_readahead(struct readahead_control *ractl, expected = round_up(ra->start + ra->size - ra->async_size, 1UL << order); if (index == expected || index == (ra->start + ra->size)) { - ra->start += ra->size; - ra->size = get_next_ra_size(ra, max_pages); + ra->start += round_down(ra->size, min_nrpages); + ra->size = get_next_ra_size(ra, min_order, max_pages); ra->async_size = ra->size; + + VM_BUG_ON(ra->size & ((1UL << min_order) - 1)); + VM_BUG_ON(ra->start & ((1UL << min_order) - 1)); + goto readit; } @@ -647,13 +655,19 @@ static void ondemand_readahead(struct readahead_control *ractl, max_pages); rcu_read_unlock(); + start = round_down(start, min_nrpages); + + VM_BUG_ON(start & (min_nrpages - 1)); + VM_BUG_ON(folio->index & (folio_nr_pages(folio) - 1)); + if (!start || start - index > max_pages) return; ra->start = start; ra->size = start - index; /* old async_size */ - ra->size += req_size; - ra->size = get_next_ra_size(ra, max_pages); + VM_BUG_ON(ra->size & (min_nrpages - 1)); + ra->size += round_up(req_size, min_nrpages); + ra->size = get_next_ra_size(ra, min_order, max_pages); ra->async_size = ra->size; goto readit; } @@ -690,7 +704,7 @@ static void ondemand_readahead(struct readahead_control *ractl, initial_readahead: ra->start = index; - ra->size = get_init_ra_size(req_size, max_pages); + ra->size = get_init_ra_size(req_size, min_order, max_pages); ra->async_size = ra->size > req_size ? ra->size - req_size : ra->size; readit: @@ -701,7 +715,7 @@ static void ondemand_readahead(struct readahead_control *ractl, * Take care of maximum IO pages as above. */ if (index == ra->start && ra->size == ra->async_size) { - add_pages = get_next_ra_size(ra, max_pages); + add_pages = get_next_ra_size(ra, min_order, max_pages); if (ra->size + add_pages <= max_pages) { ra->async_size = add_pages; ra->size += add_pages; @@ -712,6 +726,7 @@ static void ondemand_readahead(struct readahead_control *ractl, } ractl->_index = ra->start; + VM_BUG_ON(ractl->_index & (min_nrpages - 1)); page_cache_ra_order(ractl, ra, order); } -- 2.40.1