]> Git Repo - linux.git/commitdiff
mm/cma: add sysfs file 'release_pages_success'
authorAnshuman Khandual <[email protected]>
Tue, 6 Feb 2024 04:57:31 +0000 (10:27 +0530)
committerAndrew Morton <[email protected]>
Thu, 22 Feb 2024 18:24:57 +0000 (10:24 -0800)
This adds the following new sysfs file tracking the number of successfully
released pages from a given CMA heap area.  This file will be available
via CONFIG_CMA_SYSFS and help in determining active CMA pages available on
the CMA heap area.  This adds a new 'nr_pages_released' (CONFIG_CMA_SYSFS)
into 'struct cma' which gets updated during cma_release().

/sys/kernel/mm/cma/<cma-heap-area>/release_pages_success

After this change, an user will be able to find active CMA pages available
in a given CMA heap area via the following method.

Active pages = alloc_pages_success - release_pages_success

That's valuable information for both software designers, and system admins
as it allows them to tune the number of CMA pages available in the system.
This increases user visibility for allocated CMA area and its
utilization.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Anshuman Khandual <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Documentation/ABI/testing/sysfs-kernel-mm-cma
mm/cma.c
mm/cma.h
mm/cma_sysfs.c

index 02b2bb60c2969c70ac47676d99847eac171d9ce0..dfd755201142f1c8f53416ed82010b316f75ee49 100644 (file)
@@ -23,3 +23,9 @@ Date:         Feb 2021
 Contact:       Minchan Kim <[email protected]>
 Description:
                the number of pages CMA API failed to allocate
+
+What:          /sys/kernel/mm/cma/<cma-heap-name>/release_pages_success
+Date:          Feb 2024
+Contact:       Anshuman Khandual <[email protected]>
+Description:
+               the number of pages CMA API succeeded to release
index 4902bbfe24f121df47636043931d3656b167444c..01f5a8f71ddfa7dc98ca3919f45ce61682d9bf11 100644 (file)
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -562,6 +562,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;
index 88a0595670b766cd9780476f7dacb71fd9979e34..ad61cc6dd4396f861553f5acf44a9d0b5bdd9576 100644 (file)
--- 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
index 56347d15b7e8b514dcd58928dc1fc16e3eddc3ea..f50db397317182f5ae4f230f0abe28c8cfbcf6eb 100644 (file)
@@ -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);
This page took 0.069267 seconds and 4 git commands to generate.