Re: [PATCH v5] mm: cma: support sysfs
From: Dmitry Osipenko <digetx@gmail.com>
Date: 2021-03-23 21:20:02
Also in:
lkml
23.03.2021 22:50, Minchan Kim пишет:
Since CMA is getting used more widely, it's more important to keep monitoring CMA statistics for system health since it's directly related to user experience. This patch introduces sysfs statistics for CMA, in order to provide some basic monitoring of the CMA allocator. * the number of CMA page successful allocations * the number of CMA page allocation failures These two values allow the user to calcuate the allocation
typo: calculate
quoted hunk ↗ jump to hunk
struct cma { unsigned long base_pfn;@@ -16,6 +22,14 @@ struct cma { struct debugfs_u32_array dfs_bitmap; #endif char name[CMA_MAX_NAME]; +#ifdef CONFIG_CMA_SYSFS + /* the number of CMA page successful allocations */ + atomic64_t nr_pages_succeeded; + /* the number of CMA page allocation failures */ + atomic64_t nr_pages_failed; + /* kobject requires dynamic objecjt */
typo: object ...
+static void cma_kobj_release(struct kobject *kobj)
+{
+ struct cma_kobject *cma_kobj =
+ container_of(kobj, struct cma_kobject, kobj);I'd add a to_cma_kobject() helper to improve readability.
+ struct cma *cma = cma_kobj->cma;
+
+ kfree(cma_kobj);
+ cma->kobj = NULL;
+}
+
+static struct attribute *cma_attrs[] = {
+ &alloc_pages_success_attr.attr,
+ &alloc_pages_fail_attr.attr,
+ NULL,
+};
+ATTRIBUTE_GROUPS(cma);
+
+static struct kobject *cma_kobj_root;
+
+static struct kobj_type cma_ktype = {
+ .release = cma_kobj_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = cma_groups
+};
+
+static int __init cma_sysfs_init(void)
+{
+ int i = 0;unsigned int, for consistency There is no need to initialize this variable.
+ struct cma *cma;
+
+ cma_kobj_root = kobject_create_and_add("cma", mm_kobj);
+ if (!cma_kobj_root)
+ return -ENOMEM;
+
+ for (i = 0; i < cma_area_count; i++) {
+ struct cma_kobject *kobj;
+
+ cma = &cma_areas[i];
+ kobj = kzalloc(sizeof(struct cma_kobject), GFP_KERNEL);Checkpatch should warn that kzalloc(*kobj, ..) is a better variant. I'd also rename kobj to cma_kobj everywhere, for clarity.
+ if (!kobj)
+ goto out;
+
+ kobj->cma = cma;
+ cma->kobj = kobj;
+ if (kobject_init_and_add(&cma->kobj->kobj, &cma_ktype,
+ cma_kobj_root, "%s", cma->name)) {
+ kobject_put(&cma->kobj->kobj);
+ goto out;
+ }
+ }
+
+ return 0;
+out:
+ kobject_put(cma_kobj_root);
+
+ return -ENOMEM;kobject_init_and_add returns a error code, it could be different from ENOMEM. Won't hurt to propagate the proper error code.