Re: [PATCH v4] mm: cma: support sysfs

From: Dmitry Osipenko
Date: Fri Mar 19 2021 - 15:00:01 EST


19.03.2021 21:18, Minchan Kim пишет:
>>> + if (ZERO_OR_NULL_PTR(cma_kobjs))
>>> + goto out;
>>> +
>>> + do {
>>> + cma = &cma_areas[i];
>>> + cma->kobj = &cma_kobjs[i];
>> Does cma really need are pointer to cma_kobj?
> Do you mean something like this?
>
> struct cma {
> ..
> ..
> struct kobject *kobj;
> };
>
> Then, how could we we make kobject dynamic model?
>
> We need to get struct cma from kboj like below.
>
> static ssize_t alloc_pages_success_show(struct kobject *kobj,
> struct kobj_attribute *attr, char *buf)
> {
> struct cma_kobject *cma_kobj = container_of(kobj,
> struct cma_kobject, kobj);
> struct cma *cma = cma_kobj->cma;
>
> return sysfs_emit(buf, "%llu\n",
> atomic64_read(&cma->nr_pages_succeeded));
> }
>
> So kobj should be not a pointer in the container struct.
> Am I missing your point? Otherwise, it would be great if you suggest
> better idea.

I meant that cma_kobj->cma is okay, but cma->kobj wasn't really used
anywhere since struct cma can't be released. I.e. we could write
kobject_put(&cma->kobj->kobj) as kobject_put(&cma_kobjs[i].kobj);

But since we won't use the array anymore and maybe will get back to use
the cma_stat, then it will be fine to add the pointer.