From patchwork Mon Oct 24 19:06:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13017995 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 2603EECAAA1 for ; Mon, 24 Oct 2022 19:06:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70294940014; Mon, 24 Oct 2022 15:06:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B28094000C; Mon, 24 Oct 2022 15:06:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E716940014; Mon, 24 Oct 2022 15:06:44 -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 0C4BA94000C for ; Mon, 24 Oct 2022 15:06:44 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D2169A524C for ; Mon, 24 Oct 2022 19:06:43 +0000 (UTC) X-FDA: 80056774686.25.EFAC31A Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf19.hostedemail.com (Postfix) with ESMTP id 6E7851A003C for ; Mon, 24 Oct 2022 19:06:43 +0000 (UTC) Received: by dev1180.prn1.facebook.com (Postfix, from userid 425415) id 932FB3ED5922; Mon, 24 Oct 2022 12:06:12 -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 v3 13/14] mm: add /sys/class/bdi//min_bytes knob Date: Mon, 24 Oct 2022 12:06:02 -0700 Message-Id: <20221024190603.3987969-14-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221024190603.3987969-1-shr@devkernel.io> References: <20221024190603.3987969-1-shr@devkernel.io> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666638403; a=rsa-sha256; cv=none; b=LnuluUG1VNOhT6JObrH8E0jeVL5x8QuryuWUWce6Q3p53/7V6e57uVMpTYS4BPxfy+3aWC 9vXVKVfscVLHwMOXpjI/zY1wJJFt2+pfHmgBpyDGpbs91rKiCEmshwJj8IbSG4EPkRMIcf mHpr+mnO5z+Rk7sNKXyuml0dMbKhso0= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf19.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=1666638403; 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=PQd6Jq4ND+jJMcRVkdVY6rBoLeMfYLdxqIFjJRet+M4=; b=1OGi2Ci7ImP6aOJLW6nxnpux+LLZFgwriVUzNKmTGbtWNsgJvPLLlvmjl2GqWcWjeBadVp GFjpyBmVLTHceQScej2AjvEP0fpa6SqES6vwR31QpnuFgiGBkock5/3FlMYhBbPKa8GNb/ hlxRjEM4+Uf8osbS8QPMbRt1stI2aH0= X-Rspamd-Queue-Id: 6E7851A003C Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf19.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: rspam12 X-Rspam-User: X-Stat-Signature: t85x4qjqs9b5des59uaxinwzum4kqu38 X-HE-Tag: 1666638403-376555 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: bdi has two existing knobs to limit the amount of dirty memory: min_ratio and max_ratio. However the granularity of the knobs is limited and often it is more convenient to specify limits in terms of bytes. This change adds the min_bytes knob. It does not store the min_bytes value, instead it converts the max_bytes value to a ratio. The value is therefore more an approximation than an absolute value. It also maintains the sum over all the bdi min_ratio values stored in the variable bdi_min_ratio. Signed-off-by: Stefan Roesch --- mm/backing-dev.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index d5f9a8a45550..53dc46ffdb9b 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -199,6 +199,34 @@ static ssize_t max_ratio_store(struct device *dev, } BDI_SHOW(max_ratio, bdi->max_ratio / BDI_RATIO_SCALE) +static ssize_t min_bytes_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct backing_dev_info *bdi = dev_get_drvdata(dev); + + return sysfs_emit(buf, "%llu\n", bdi_get_min_bytes(bdi)); +} + +static ssize_t min_bytes_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct backing_dev_info *bdi = dev_get_drvdata(dev); + unsigned long long bytes; + ssize_t ret; + + ret = kstrtoull(buf, 10, &bytes); + if (ret < 0) + return ret; + + ret = bdi_set_min_bytes(bdi, bytes); + if (!ret) + ret = count; + + return ret; +} +DEVICE_ATTR_RW(min_bytes); + static ssize_t max_bytes_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -269,6 +297,7 @@ static struct attribute *bdi_dev_attrs[] = { &dev_attr_read_ahead_kb.attr, &dev_attr_min_ratio.attr, &dev_attr_max_ratio.attr, + &dev_attr_min_bytes.attr, &dev_attr_max_bytes.attr, &dev_attr_stable_pages_required.attr, &dev_attr_strict_limit.attr,