From patchwork Tue Feb 6 04:57:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 13546633 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 E357DC48286 for ; Tue, 6 Feb 2024 04:57:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D74E6B006E; Mon, 5 Feb 2024 23:57:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2870D6B0071; Mon, 5 Feb 2024 23:57:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 175AE6B0072; Mon, 5 Feb 2024 23:57:45 -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 08BDB6B006E for ; Mon, 5 Feb 2024 23:57:45 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8F266A05B2 for ; Tue, 6 Feb 2024 04:57:44 +0000 (UTC) X-FDA: 81760171248.21.58BB955 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf26.hostedemail.com (Postfix) with ESMTP id AA24D140006 for ; Tue, 6 Feb 2024 04:57:41 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707195462; 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:references; bh=O5p0DyGpK5izSJ3vxKPceVkhkKyEVHltLVzQI48NOFQ=; b=S5BJZbR1pYAtmG4yCsIgB6r4E+dbXYu9PnpH6jvdEtokEEDdgUiNexiO7Af7Pb7ukqq6jg t/RGMYRdwgaN93QzJOeqSEt7+LmUMGfP5auBWIpT0xBRvlTWYXLmZedsbYUZJYgw+q5MDf aQK1pMgCB/qhUUiZWK/YJvfMhOmOloU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707195462; a=rsa-sha256; cv=none; b=vI5FKSoS/iYLrjzMmyjIldTETQmKW/mceer+w3HdqrxC8d96d067HmcmdZiCebibUIdeKG uFkgY1Wx472ZEN5C1T5VUCX10NJEzHH1srF7NSSUEOJkSSKlImuoREvZ4+Xdxlg9pYMjYs mdxjL/btxnLc5k9OeE7/Ujn5NOJ+6KM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3A5AE12FC; Mon, 5 Feb 2024 20:58:23 -0800 (PST) Received: from a077893.arm.com (unknown [10.163.42.38]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A26283F641; Mon, 5 Feb 2024 20:57:38 -0800 (PST) From: Anshuman Khandual To: linux-mm@kvack.org Cc: alexandru.elisei@arm.com, Anshuman Khandual , Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH] mm/cma: Add sysfs file 'release_pages_success' Date: Tue, 6 Feb 2024 10:27:31 +0530 Message-Id: <20240206045731.472759-1-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.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364H/SAt3sNs1H0lN2NCdvmWhpGXaNRdCaR1YK 7g/PFUTD ZOyYzVFw8FxW9O0lVizXJFzhaXqTm8v0YPkSsLtbjZl8Nu2z1Xluou+2lG5+y7BaYMyN3hXJVHifPV6nCE4plporcCid+qC/JylaPe/tHi4QRo1Z6NfABhcz5ncAo6c2s1eWusx80naNr49yDFoCnzandA56URjBK/K+QPRR6DdisnToX7dco/hIRQuH8TzJcWeke1RI40Hdz6kO75wznvule1KcjlE5k6ihz58vdN4Wgf27QGhl7mD2wNyEbyguMIc2w/7JozL4mmyx557xmSfJCOKlqw4JINs1q0Be23vtsG2+8A+U4gJqMVH0sTKnHeM7rc2qWXJsvT/6JkL+sHEGdk578ab9mKdNcWnrlJssVW3n844XhDSF44uOfmdU82EfLgI3sviQbRCAuUR/WYIfCHl5/UpBnXWV/xQdEOuFsBE4= 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: This adds the following new sysfs file tracking the number of successfully released pages from a given CMA heap area. Also like before - this will be available via CONFIG_CMA_SYSFS, and help in determining active CMA pages available on the system. /sys/kernel/mm/cma//release_pages_success It adds an element 'nr_pages_released' (with CONFIG_CMA_SYSFS config) into 'struct cma' which gets updated during cma_release(). Cc: Andrew Morton Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- This patch applies on v6.8-rc3 Some earlier relevant discussions regarding arm64 MTE dynamic tag storage in this regard can be found here. https://lore.kernel.org/all/ZbpKyNVHfhf1-AAv@raptor/ Documentation/ABI/testing/sysfs-kernel-mm-cma | 6 ++++++ mm/cma.c | 1 + mm/cma.h | 5 +++++ mm/cma_sysfs.c | 15 +++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-cma b/Documentation/ABI/testing/sysfs-kernel-mm-cma index 02b2bb60c296..dfd755201142 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-cma +++ b/Documentation/ABI/testing/sysfs-kernel-mm-cma @@ -23,3 +23,9 @@ Date: Feb 2021 Contact: Minchan Kim Description: the number of pages CMA API failed to allocate + +What: /sys/kernel/mm/cma//release_pages_success +Date: Feb 2024 +Contact: Anshuman Khandual +Description: + the number of pages CMA API succeeded to release diff --git a/mm/cma.c b/mm/cma.c index 2627f4ba481f..4f95266eba1d 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -559,6 +559,7 @@ bool cma_release(struct cma *cma, const struct page *pages, free_contig_range(pfn, count); cma_clear_bitmap(cma, pfn, count); + cma_sysfs_account_release_pages(cma, count); trace_cma_release(cma->name, pfn, pages, count); return true; diff --git a/mm/cma.h b/mm/cma.h index 88a0595670b7..ad61cc6dd439 100644 --- a/mm/cma.h +++ b/mm/cma.h @@ -27,6 +27,8 @@ struct cma { atomic64_t nr_pages_succeeded; /* the number of CMA page allocation failures */ atomic64_t nr_pages_failed; + /* the number of CMA page released */ + atomic64_t nr_pages_released; /* kobject requires dynamic object */ struct cma_kobject *cma_kobj; #endif @@ -44,10 +46,13 @@ static inline unsigned long cma_bitmap_maxno(struct cma *cma) #ifdef CONFIG_CMA_SYSFS void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages); void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages); +void cma_sysfs_account_release_pages(struct cma *cma, unsigned long nr_pages); #else static inline void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages) {}; static inline void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages) {}; +static inline void cma_sysfs_account_release_pages(struct cma *cma, + unsigned long nr_pages) {}; #endif #endif diff --git a/mm/cma_sysfs.c b/mm/cma_sysfs.c index 56347d15b7e8..f50db3973171 100644 --- a/mm/cma_sysfs.c +++ b/mm/cma_sysfs.c @@ -24,6 +24,11 @@ void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages) atomic64_add(nr_pages, &cma->nr_pages_failed); } +void cma_sysfs_account_release_pages(struct cma *cma, unsigned long nr_pages) +{ + atomic64_add(nr_pages, &cma->nr_pages_released); +} + static inline struct cma *cma_from_kobj(struct kobject *kobj) { return container_of(kobj, struct cma_kobject, kobj)->cma; @@ -48,6 +53,15 @@ static ssize_t alloc_pages_fail_show(struct kobject *kobj, } CMA_ATTR_RO(alloc_pages_fail); +static ssize_t release_pages_success_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct cma *cma = cma_from_kobj(kobj); + + return sysfs_emit(buf, "%llu\n", atomic64_read(&cma->nr_pages_released)); +} +CMA_ATTR_RO(release_pages_success); + static void cma_kobj_release(struct kobject *kobj) { struct cma *cma = cma_from_kobj(kobj); @@ -60,6 +74,7 @@ static void cma_kobj_release(struct kobject *kobj) static struct attribute *cma_attrs[] = { &alloc_pages_success_attr.attr, &alloc_pages_fail_attr.attr, + &release_pages_success_attr.attr, NULL, }; ATTRIBUTE_GROUPS(cma);