From patchwork Sat Nov 19 00:52:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13049439 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 1BA7EC433FE for ; Sat, 19 Nov 2022 00:57:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7ED3D6B0072; Fri, 18 Nov 2022 19:57:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 79D7C6B0073; Fri, 18 Nov 2022 19:57:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 665F68E0001; Fri, 18 Nov 2022 19:57:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 534276B0072 for ; Fri, 18 Nov 2022 19:57:38 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2CE30A075C for ; Sat, 19 Nov 2022 00:57:38 +0000 (UTC) X-FDA: 80148378996.03.C27A4EC Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf18.hostedemail.com (Postfix) with ESMTP id C31BB1C000B for ; Sat, 19 Nov 2022 00:57:37 +0000 (UTC) Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 5DF8C19380D0; Fri, 18 Nov 2022 16:52:18 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com, linux-block@vger.kernel.org, linux-mm@kvack.org Cc: shr@devkernel.io, axboe@kernel.dk, clm@meta.com, akpm@linux-foundation.org Subject: [RFC PATCH v4 05/20] mm: add bdi_get_max_bytes() function Date: Fri, 18 Nov 2022 16:52:00 -0800 Message-Id: <20221119005215.3052436-6-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221119005215.3052436-1-shr@devkernel.io> References: <20221119005215.3052436-1-shr@devkernel.io> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668819457; a=rsa-sha256; cv=none; b=NBrU2BGudLbB7JmRpZguxZSdHnAOUD5RPPaq+8ZEs4Thz+wTx6ULfL3usA1ZaBAAkuA7Y+ 6e/66OArbmq9YSGs3ns/FXATyYpMRo/aVQ9e/s0L1C1KfH+q8V0Ciaq68DwYnQWRGRRH8k jq8z8kXVYvgMpK0SfyVsEpGK1SvIHBE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf18.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668819457; 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; bh=aXsnCLS53W8cxzDoMdNwuSaFrrJ0VnEpsYBQ38HuW6o=; b=Fr16hMgMfnlrlxEa9N2V9APx/ZSfLzWn7WUfZTAItI/Kvrgk11iGuVDYokKTIH1e2tgBM7 p6d7h+cfmpgOHgwJEF/ZnFwEsJu+xcmaI9B57MBO0TRr9AEeRm6kaf0LX+5hF/RZcng8Zw gX1deTu8vI9cs14CydpsBIh/0GiK/Ks= X-Stat-Signature: 79nrmobh54dgi3enntgbrfhx5sjoqm6a X-Rspamd-Queue-Id: C31BB1C000B Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf18.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1668819457-761878 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: This adds a function to return the specified value for max_bytes. It converts the stored max_ratio of the bdi to the corresponding bytes value. It introduces the bdi_get_bytes helper function to do the conversion. This is an approximation as it is based on the value that is returned by global_dirty_limits(), which can change. The helper function will also be used by the min_bytes bdi knob. Signed-off-by: Stefan Roesch --- include/linux/backing-dev.h | 1 + mm/page-writeback.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index 1b50c028e5ad..473686c32775 100644 --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h @@ -105,6 +105,7 @@ static inline unsigned long wb_stat_error(void) /* BDI ratio is expressed as part per 1000000 for finer granularity. */ #define BDI_RATIO_SCALE 10000 +u64 bdi_get_max_bytes(struct backing_dev_info *bdi); int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio); int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio); int bdi_set_strict_limit(struct backing_dev_info *bdi, unsigned int strict_limit); diff --git a/mm/page-writeback.c b/mm/page-writeback.c index dd98b2654302..719404e0d03d 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -650,6 +650,18 @@ void wb_domain_exit(struct wb_domain *dom) */ static unsigned int bdi_min_ratio; +static u64 bdi_get_bytes(unsigned int ratio) +{ + unsigned long background_thresh; + unsigned long dirty_thresh; + u64 bytes; + + global_dirty_limits(&background_thresh, &dirty_thresh); + bytes = (dirty_thresh * PAGE_SIZE * ratio) / BDI_RATIO_SCALE / 100; + + return bytes; +} + int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio) { unsigned int delta; @@ -701,6 +713,11 @@ int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned max_ratio) } EXPORT_SYMBOL(bdi_set_max_ratio); +u64 bdi_get_max_bytes(struct backing_dev_info *bdi) +{ + return bdi_get_bytes(bdi->max_ratio); +} + int bdi_set_strict_limit(struct backing_dev_info *bdi, unsigned int strict_limit) { if (strict_limit > 1)