From patchwork Wed May 15 01:23:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13664515 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 A1B35C41513 for ; Wed, 15 May 2024 01:25:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2898C8D005B; Tue, 14 May 2024 21:25:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 26D458D005A; Tue, 14 May 2024 21:25:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 101AE8D005A; Tue, 14 May 2024 21:25:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E90968D004F for ; Tue, 14 May 2024 21:25:10 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 77CE88028F for ; Wed, 15 May 2024 01:25:09 +0000 (UTC) X-FDA: 82118886738.06.A521A7A Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by imf26.hostedemail.com (Postfix) with ESMTP id A5494140008 for ; Wed, 15 May 2024 01:25:06 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715736307; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=byEvaHsYWbx9jsAJ3lZFFRsCWbGZ8O9IdN+pwgQo25o=; b=i0frCZkHyxBSvVEB3QGg2MTVk2XMs7reX9ZL2vTBL8ZsKGBVrtxVhwWlG8zUfWAv6duj06 Wtgs+UvmnCLR+pBmG74/ixrIt9OARJRElDMIzNp3o+rr95JY+m37L0w8zu0Vyr5OJJm8z0 pdGwDQAk5BvKtGaXMlpa8SfVh+6IGik= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715736307; a=rsa-sha256; cv=none; b=L+xnUTDRau1PtSLfa+CS3oSpElGZ10Au3EXjDRp2YkTyOQZ1a7MamoAG2HmFvf32F/WOXg F/KvC4FaEyGEiqwLOv6g9vt5bbEgs0ajKJP9SrgB+rJ8fFZWs7pSemvYYua2/cNlXN6gEd myVVsr/r70JTZpfQfA3dNDQ3DCnjl7Q= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 44F1O7LZ051706; Wed, 15 May 2024 09:24:07 +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 4VfFm04QmWz2PDtZH; Wed, 15 May 2024 09:20:48 +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; Wed, 15 May 2024 09:24:05 +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: Wed, 15 May 2024 09:23:50 +0800 Message-ID: <20240515012350.1166350-3-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240515012350.1166350-1-zhaoyang.huang@unisoc.com> References: <20240515012350.1166350-1-zhaoyang.huang@unisoc.com> MIME-Version: 1.0 X-Originating-IP: [10.0.73.40] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 44F1O7LZ051706 X-Stat-Signature: zrbwr3ugmtbsx7p64oo5k139yxf754eh X-Rspamd-Queue-Id: A5494140008 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1715736306-417092 X-HE-Meta: U2FsdGVkX19fcdzqj9LbX7ZPO1L9upkpY8lHfZcs3pUOSp7LaG4zTqJxXkQHFrbvim5Khe+oYsC2Nzu2mew3tH0844dQRra3ZPCXwAlSFMJBd5tSF/v5Dtb4AVoj2R9yuXtv2yv0D16BJnsLl+qL9dzVpRo2QSeg2VskKlw3F7snaltwUCMhhIvhDU69nWwintXfjgSWqjtEa5oKCEiUbiLfx7usP/ojAXuslZQ+KaeOew5Ad2JJJ5Buw9OEvzYphITD6KkAoiGtwircyBK9kICgTsalm6knInUG9tQj+PVh/ljcwEt9WuhHYvEJ/kbxXMFZw+LuhjP2N5W5unKWjIqThqfeL5wrsqmUDqOMQes2wv0xsoWujK+fvKgxufWwjsxVNa/HfoGW20KtyWjQTPIrkWfNMtYqpnPLg9sfUhZPe/8rWEq+u8ni5avJFrfeJ7g9+RufU2paKf5iKb6aXwfLLz9PlYEOAZSOc4nnlJEn+agTeJ1BDzvUcoyhQ6s44/XJIAIYuT1kPYBzgXzhJWvgRxlWWq/PxaGD51+C8AdEWFadiL1Dxpd4iyxV5cDF4N1ZKoc04PYPAB1CMxRyDu667nardAjglHQGPXJa7/V0VvMuFzTlOL0uPsIk9tmZn6ndQIYNISnvoxo8xRhfHnj1Ct88yaVLMcssEC+tShuzsiaTDQq6BsfqNDGqI2SXX03b3x+75ZPcZoHZqr12LmzjCoocqPrF06qRActo6IY8UHBDpu8rFZ+P2GeQcm//xoLjECElYMslNIIv+999DnHLUHXOUokcVD3NpDF13alqgeqiOvbwYYtubvWX0rf4y8lMIdXOcyIl2Nr3eGWDv7tb8o8ahQ5ucYCf7lRpsdLzkM5vBHQLU1GJMdbgDT4RUAZv8CpF2c6XNtJTlvd31/FEFQPCqhMoAVkZD/eJNzKnlqrgbVpMimCXlpjRA1GZtNewUoY7yQQ5yIZ/95P tp3bOsNZ sGynN2eHUCKR8hZTgd9rJh2rcLIMs0ccLZXYV7oB3N+W1yCWmvgkamMJ2GHwzXBl+NMlqlLds7VAfpT1Q74dcJhtStVT9qLlkUC0LLGYszYVsqw1CyXu5VDS1inZD0wkkHb9AmCgPrztYzs76Z4FRkqGCbhDsU+EZeib1fKf/UPtFcK9kaaUafgPJW+WzFJ0JE38dnvSqBSs7Gos= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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;