From patchwork Mon Oct 17 18:13:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13009234 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 739D8C4167E for ; Mon, 17 Oct 2022 18:16:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D3FA8E0003; Mon, 17 Oct 2022 14:16:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 85CF66B007D; Mon, 17 Oct 2022 14:16:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34F988E0007; Mon, 17 Oct 2022 14:16:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0B0128E0003 for ; Mon, 17 Oct 2022 14:16:39 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D39691A0F0E for ; Mon, 17 Oct 2022 18:16:38 +0000 (UTC) X-FDA: 80031246876.30.D8AEC21 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf14.hostedemail.com (Postfix) with ESMTP id 717B8100014 for ; Mon, 17 Oct 2022 18:16:37 +0000 (UTC) Received: by dev1180.prn1.facebook.com (Postfix, from userid 425415) id 28DA239C99BC; Mon, 17 Oct 2022 11:13:56 -0700 (PDT) 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, willy@infradead.org, hch@infradead.org Subject: [RFC PATCH v2 05/14] mm: add bdi_get_max_bytes() function Date: Mon, 17 Oct 2022 11:13:28 -0700 Message-Id: <20221017181337.3884657-6-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221017181337.3884657-1-shr@devkernel.io> References: <20221017181337.3884657-1-shr@devkernel.io> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf14.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666030598; a=rsa-sha256; cv=none; b=2omwpY+0rplreqiqQhBq2Db6nJmKnmFXbBBBWsmMVXJ7ObrO0Yol+o331FX7o1joN97dLB /MXXW0425BUB+TS95df1ybiViDK9Gn77Q6ux83ZWpty3AFu8lSEaU+5lvgus9hJsRJvsMc RKmGix3kIsEtUCVot4uJpDXB3VptZYo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666030598; 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=t1aPZkjeB5Y6h6IJtUv4U9JkXNmAOOb0yMfCmHKUz0I=; b=QHdI3esOF6CuzpJl5fpnGlUi3GnEPmuyRqhzNT23j5rTZzwFK3ExfGnUW2Tgn1c1dXqqXq sW5ThaAkMfd0MFKee2TRxg8KrkJ7JjKq8Zrqqi+GwWiQrBqUHdyzbR3PozYxOO17GLJklZ Zhz7mRanZjNfkxjO50HTqd+7xvKXQGA= Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf14.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: 7ochhm7abi7y38csbndsfq1kcwsuiafr X-Rspamd-Queue-Id: 717B8100014 X-HE-Tag: 1666030597-435782 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 | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index 19fe0e605ed8..cb0e66564d4d 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 1000 for finer granularity. */ #define BDI_RATIO_SCALE 10 +unsigned long long 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 4d5383d4da45..0b9dcf5afda2 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 unsigned long long bdi_get_bytes(unsigned int ratio) +{ + unsigned long background_thresh; + unsigned long dirty_thresh; + unsigned long long 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,12 @@ int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned max_ratio) } EXPORT_SYMBOL(bdi_set_max_ratio); +unsigned long long bdi_get_max_bytes(struct backing_dev_info *bdi) +{ + return bdi_get_bytes(bdi->max_ratio); +} +EXPORT_SYMBOL_GPL(bdi_get_max_bytes); + int bdi_set_strict_limit(struct backing_dev_info *bdi, unsigned int strict_limit) { if (strict_limit > 1)