Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2820468rdb; Mon, 5 Feb 2024 20:57:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IG2NxIU0lGf+T9IRwA8RrwQz/C9JqYNxSTX2v0zqfxBxI6i4xMq2+xLSIWkH/OGG+gpMeS3 X-Received: by 2002:a05:622a:287:b0:42c:30fb:d78e with SMTP id z7-20020a05622a028700b0042c30fbd78emr1611785qtw.48.1707195470864; Mon, 05 Feb 2024 20:57:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707195470; cv=pass; d=google.com; s=arc-20160816; b=WG74KtbVTuvpTx1q1PjTUH1419QBrlE5JogHc/TWhFJNPMaudHM0VwBtis8WktWHI+ TNRrkH6bOZw7sClTgkHG9QcPxU8k0AiZu+jsnMmHUVgEcJj8C6EpLkqVJtyOo13BqRuP mVlzNt0ANm+LPG5+uAc81y0bhTboYpSriE2e8Vklw0EXFHmQ/zH1ombvBEmAOUBzkagO yP1DN0G2gF7pyksUkchO/lrjITsUsyCuuQA35+lAy6I25GMQee2Np5KvkzpD/HCJfz+s GLWCSQE/eahRRBeR1VWgqVje9hJ5UBRsmy3QMIK9pXKzpMiwv/rjjQxWYBEE/dW2/j0f L68w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=O5p0DyGpK5izSJ3vxKPceVkhkKyEVHltLVzQI48NOFQ=; fh=FH8vLIi4SR5gkJM269+p9cob10R7lYUT9KUnALxCyiY=; b=BrdaJL03xrXf3haRjSClwm0ltdUZGe81dySvmSdaCO9rNiGnRUI0ENt23ztCIWBgGP 42664nXYeO9UbJf983ebtRW34e1Otzjc80X3iqU974bUSwdImqAtOz1O0nce9nvMv8SB jii0wHVWnpLSsVREVWwCXK+uga0QG2O30mOsyehf4MsSx8wkdDVoAIL1l6sRBCAma8ck +gUGRCqz4G46QuePO8kTjlxdAM/P5au5OgyzVBNUKMOEoHEYgRjykfXedy1SNvIPcSlX 4YMCx2xBnVgoWcFyKVAgqkxP55YnjFNgsPR021gGMVvEjmFjL8xR/uc+YTqs5/O5FJFx IDGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-54331-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54331-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCVefG19CYMJHUUwXdBCCjZ6HZoaLC5y7gGSNVYTc2CyrKA/cWsLeLHlCubsyrKAqeD/92UOHYI76vg5yLI3eUYIZZgT+h6hTImiqke2rw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s14-20020a05622a178e00b0042c0d77ad95si1543988qtk.214.2024.02.05.20.57.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 20:57:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54331-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-54331-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54331-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 387BD1C225CF for ; Tue, 6 Feb 2024 04:57:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1F0E77F37; Tue, 6 Feb 2024 04:57:44 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A9F877F19 for ; Tue, 6 Feb 2024 04:57:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707195464; cv=none; b=d/ODRF7Ral9Zwe2xx4e4pKRay8ep/lyiK09Oiv3tILjuGRCG8fzc9iW3l3+zHgnUzTGyzdICQzuraOufMUfBSzS6qmF+ZItnvmd1EGCG2YaFvDB8aRMYNwItvKQgf6/oRtmxWF/Kp0h4yCxScTXcjV4LclYhj5Nee67iewC94Gk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707195464; c=relaxed/simple; bh=C7dEciQXByHTE3Dmv/L9UCYEwE6MR5xRJb9k0LLOyYw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=d9CHyX+Z6burNoBrYAA0RQBuKM+k19RJazXMVpQCO3wSlVIfStbVbz/VqB9PqeO2L6x7XpElKN6X4OWltHKILPszaMqCGXJqfTdvWfzoflLyA1brUxKg8znGwx2f7kjnZrgklaDuv2zOsMV2D5FgoQLlpCmjAjKV40TEpNtXOI0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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); -- 2.25.1