All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx@gmail.com>
To: Minchan Kim <minchan@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	gregkh@linuxfoundation.org, surenb@google.com,
	joaodias@google.com, jhubbard@nvidia.com, willy@infradead.org
Subject: Re: [PATCH v5] mm: cma: support sysfs
Date: Wed, 24 Mar 2021 00:19:02 +0300	[thread overview]
Message-ID: <bff2b424-91f7-5748-fa27-54cc75667548@gmail.com> (raw)
In-Reply-To: <20210323195050.2577017-1-minchan@kernel.org>

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

>  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.


  reply	other threads:[~2021-03-23 21:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 19:50 [PATCH v5] mm: cma: support sysfs Minchan Kim
2021-03-23 21:19 ` Dmitry Osipenko [this message]
2021-03-23 21:29   ` Dmitry Osipenko
2021-03-23 21:44 ` Dmitry Osipenko
2021-03-24  0:54   ` Minchan Kim
2021-03-24  3:02 ` Matthew Wilcox
2021-03-24  3:31   ` Minchan Kim
2021-03-24  4:34     ` Matthew Wilcox
2021-03-24  5:45       ` Minchan Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bff2b424-91f7-5748-fa27-54cc75667548@gmail.com \
    --to=digetx@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jhubbard@nvidia.com \
    --cc=joaodias@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=surenb@google.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.