Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp881459lqo; Wed, 8 May 2024 19:41:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU8nWvwC9SPyyUTUGWQCPXQIHuQVlMuL6di7ob8Ln26oVi8SsZt4UEynV/eUDi2V007JFoeyUOAprAQypU2oVAqW31vk25wmQiTet/8Zg== X-Google-Smtp-Source: AGHT+IFIQtGCa8ScKYRaspzFDnu4tPaSB8eEXLsJ6nKkXnTA6nfApbBm2ZfZZHDoKSzFXMUjJBEG X-Received: by 2002:a05:6218:2612:b0:192:5cfd:8c7 with SMTP id e5c5f4694b2df-192d39730d5mr466881355d.30.1715222500049; Wed, 08 May 2024 19:41:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715222500; cv=pass; d=google.com; s=arc-20160816; b=yV01uikcx+Or53VlDZGCV1ZuR2ZCylu5lENLC/WYBH2eKVX6tPKDOSBBgnUhPoPnJ+ icmibEvdS085tHCqerVPlBPUMW8KD7OmR/x6HjHnl9vN29gAPMT96mEG+h/YfnBIosys LNCutWeLxpk5naDnqLjdW2kwitXDuJsGm2TTM/sNIaYzYt0tsPITWSXMN3h/SFpSAVu5 6OTzGEIR+/9fCOfw9sIpmr3PrePlBK7czFJd/yk0VFLxH41lrq68XaXjXW8Ea6TbQvf6 cX8l9/4N/X00QAGt/FBY8km6zsSYajzXlw9pooHUDTyQNFM3tZCIu0cMeTQTk0RLdLBw FH6w== 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:to:from; bh=byEvaHsYWbx9jsAJ3lZFFRsCWbGZ8O9IdN+pwgQo25o=; fh=aLp6JX2nQZchPp4bZbB1BXrBVzPzKjcTx+fC0wO/zBE=; b=fa3YF8zNtXctjhIAK1vys2Zek5VKLpCJtN9EemINxhw5ARZg8HbkMmWonShJ9deBI8 EFoqi4STC8I002p+ZyoK+xYzjFWjq7VN4hfEzVqrrCGUfhtx8Yg3PGBRGBva8nzj1uSS kW4GfDronfF30oXoo8vnTJN0UoJ+tX1mav612wbpvEB2zYkYeMFgmVUejYj1IrjjhJTk M2T8tWu4eD4AKOlFxuFUO9u6r3BE6vwGziABOT4Q/DAXuh1aLgPjPm5qEgYKjOHbd600 /vBNMo8fdoWTHh9KKZTDDb+FvACwtaIStICiP1bmk6nfVmOf6lAsoWS7hixQbz2auvED W1gg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-174063-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174063-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-634103f681bsi409759a12.315.2024.05.08.19.41.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 19:41:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174063-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; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-174063-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174063-linux.lists.archive=gmail.com@vger.kernel.org" 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 61171283E49 for ; Thu, 9 May 2024 02:41:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CFAA8146D50; Thu, 9 May 2024 02:41:29 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (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 BDB7614601F; Thu, 9 May 2024 02:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715222489; cv=none; b=fvnXqJAgQfbas+wayOm+oLQz6kemIGwc51iYGdTObawT/AF8WkPxvKpJ9rVFUPBm6k6uHGNpGYY7gDcxgmgwVZ2sSblhjGbYneo2feUArHmpJSoHhYnOkkBT31/zt6tXf+QSOX7Guk77ZYbD43CbSsfrASSKPlFWbmzi9myKw+o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715222489; c=relaxed/simple; bh=yMMIUz7DubXFQXYpZ3HCVv1OQrz7GVWdZJEPrbTdrZU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kmJNBouEQqkZaZ/Uyz5xIwVdqbccj6bkukFaiWbB0NVZLddlaM0/rCPvrcuCsVIKplktL+HLmuV1Ec/ie5YRq5fMO3ctgCtXarv1xhIUCUHtVtqyIgI8AP8+GB66ApudH7sBesyXpRxwxL55S0RpRE4W8uLvVPLP9/w/de9vksk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 4492dpDj051905; Thu, 9 May 2024 10:39:51 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4VZbkN3NW5z2PGl6X; Thu, 9 May 2024 10:36:44 +0800 (CST) Received: from bj03382pcu01.spreadtrum.com (10.0.73.40) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 9 May 2024 10:39:48 +0800 From: "zhaoyang.huang" To: Andrew Morton , Matthew Wilcox , Jens Axboe , Tejun Heo , Josef Bacik , Baolin Wang , , , , , Zhaoyang Huang , Subject: [RFC PATCH 2/2] mm: introduce budgt control in readahead Date: Thu, 9 May 2024 10:39:37 +0800 Message-ID: <20240509023937.1090421-3-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240509023937.1090421-1-zhaoyang.huang@unisoc.com> References: <20240509023937.1090421-1-zhaoyang.huang@unisoc.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 Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL:SHSQR01.spreadtrum.com 4492dpDj051905 From: Zhaoyang Huang Currently, readahead's size is decided mainly by page cache's status like hit/miss or hole size which could lead to suspension of following bio which is over the size of blk-throttle allowed size when BLK_THROTTLING is on. Introduce the budgt value here to have the bio's size be within the legal size. Signed-off-by: Zhaoyang Huang --- mm/readahead.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 130c0e7df99f..2b6120ced6f9 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -128,6 +128,7 @@ #include #include #include +#include #include "internal.h" @@ -358,16 +359,23 @@ static unsigned long get_init_ra_size(unsigned long size, unsigned long max) * Get the previous window size, ramp it up, and * return it as the new window size. */ -static unsigned long get_next_ra_size(struct file_ra_state *ra, +static unsigned long get_next_ra_size(struct readahead_control *ractl, unsigned long max) { - unsigned long cur = ra->size; + unsigned long cur = ractl->ra->size; + struct inode *inode = ractl->mapping->host; + unsigned long budgt = inode->i_sb->s_bdev ? + blk_throttle_budgt(inode->i_sb->s_bdev) : 0; + unsigned long val = max; if (cur < max / 16) - return 4 * cur; + val = 4 * cur; if (cur <= max / 2) - return 2 * cur; - return max; + val = 2 * cur; + + val = budgt ? min(budgt / PAGE_SIZE, val) : val; + + return val; } /* @@ -437,6 +445,8 @@ static int try_context_readahead(struct address_space *mapping, unsigned long max) { pgoff_t size; + unsigned long budgt = mapping->host->i_sb->s_bdev ? + blk_throttle_budgt(mapping->host->i_sb->s_bdev) : 0; size = count_history_pages(mapping, index, max); @@ -455,7 +465,7 @@ static int try_context_readahead(struct address_space *mapping, size *= 2; ra->start = index; - ra->size = min(size + req_size, max); + ra->size = min3(budgt / PAGE_SIZE, size + req_size, max); ra->async_size = 1; return 1; @@ -552,6 +562,8 @@ static void ondemand_readahead(struct readahead_control *ractl, pgoff_t index = readahead_index(ractl); pgoff_t expected, prev_index; unsigned int order = folio ? folio_order(folio) : 0; + unsigned long budgt = ractl->mapping->host->i_sb->s_bdev ? + blk_throttle_budgt(ractl->mapping->host->i_sb->s_bdev) : 0; /* * If the request exceeds the readahead window, allow the read to @@ -574,7 +586,7 @@ static void ondemand_readahead(struct readahead_control *ractl, 1UL << order); if (index == expected || index == (ra->start + ra->size)) { ra->start += ra->size; - ra->size = get_next_ra_size(ra, max_pages); + ra->size = get_next_ra_size(ractl, max_pages); ra->async_size = ra->size; goto readit; } @@ -599,7 +611,7 @@ static void ondemand_readahead(struct readahead_control *ractl, ra->start = start; ra->size = start - index; /* old async_size */ ra->size += req_size; - ra->size = get_next_ra_size(ra, max_pages); + ra->size = get_next_ra_size(ractl, max_pages); ra->async_size = ra->size; goto readit; } @@ -631,6 +643,9 @@ static void ondemand_readahead(struct readahead_control *ractl, * standalone, small random read * Read as is, and do not pollute the readahead state. */ + if (budgt) + req_size = min(budgt / PAGE_SIZE, req_size); + do_page_cache_ra(ractl, req_size, 0); return; @@ -647,7 +662,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(ractl, max_pages); if (ra->size + add_pages <= max_pages) { ra->async_size = add_pages; ra->size += add_pages; -- 2.25.1