From patchwork Sat Nov 19 00:52:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13049513 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 224B0C433FE for ; Sat, 19 Nov 2022 02:03:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 944346B0075; Fri, 18 Nov 2022 21:03:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 808B36B0078; Fri, 18 Nov 2022 21:03:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60D888E0001; Fri, 18 Nov 2022 21:03:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4E9F16B0075 for ; Fri, 18 Nov 2022 21:03:44 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 218EC1A088B for ; Sat, 19 Nov 2022 02:03:44 +0000 (UTC) X-FDA: 80148545568.13.75D329F Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf24.hostedemail.com (Postfix) with ESMTP id AF89E18000B for ; Sat, 19 Nov 2022 02:03:43 +0000 (UTC) Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 80F9919380E2; 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 13/20] mm: add /sys/class/bdi//min_bytes knob Date: Fri, 18 Nov 2022 16:52:08 -0800 Message-Id: <20221119005215.3052436-14-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=1668823423; a=rsa-sha256; cv=none; b=yYx15ytOvGcVxxUKwj3Eqy2ndnM+cXaoY/uosdJ4l8Ss2P510gQmkfaAnZ6jtcKrqE/Zqu mHu+22Fb94FstujHxsr1YKukCpuQRPhno7fC6fp70n482M+K1oU+Ke6h5KEdUt00ejlaCQ bG1dnTnL3AYBFNCeRoRRxVLTuDiMyks= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf24.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=1668823423; 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=CpvPe/bxwEXdSY1z0mHR7c8X13zjnjPiwVJF99HBaCQ=; b=e1cVdbmTGdWAo0U410HxcNFf1rEP8PtHaLM0PuoCT+Af5h592tNyo32IOG3MXq3IIrv1i+ BhFw0KCgm8dky/FsaaQA5VjJOTrNxZa3NkXs8cptxbjgl5q1vguxjASu/oxpPjwCLeTl7v V15WnWWeXEfm4PPkoS5o2MjULGQvfbc= X-Stat-Signature: myk4bimutka3a9pdkzuxax6hbsrwj4du X-Rspamd-Queue-Id: AF89E18000B Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf24.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: 1668823423-426015 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 95d3229fc81f..3fab79061ade 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); + u64 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,