From: Beau Belgrave <beaub@linux.microsoft.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: mhiramat@kernel.org, anders.roxell@linaro.org,
linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-next@vger.kernel.org
Subject: Re: [PATCH] user_events: Use alloc_pages instead of kzalloc for register pages
Date: Fri, 11 Mar 2022 15:55:30 -0800 [thread overview]
Message-ID: <20220311235530.GB2101@kbox> (raw)
In-Reply-To: <20220311184440.537e9f83@gandalf.local.home>
On Fri, Mar 11, 2022 at 06:44:40PM -0500, Steven Rostedt wrote:
> On Fri, 11 Mar 2022 18:33:43 -0500
> Steven Rostedt <rostedt@goodmis.org> wrote:
>
> > I tried it slightly differently. Why waist bits if MAX_EVENTS is greater
> > than the order. That is, make MAX_EVENTS depend on the order, not the other
> > way around.
>
> Here's a version that keeps the reserving part as well as some bug fixes (I
> didn't even compile the previous version ;-)
>
> -- Steve
>
> diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
> index 4febc1d6ae72..e10ad057e797 100644
> --- a/kernel/trace/trace_events_user.c
> +++ b/kernel/trace/trace_events_user.c
> @@ -30,9 +30,10 @@
>
> /*
> * Limits how many trace_event calls user processes can create:
> - * Must be multiple of PAGE_SIZE.
> + * Must be a power of two of PAGE_SIZE.
> */
> -#define MAX_PAGES 1
> +#define MAX_PAGE_ORDER 0
> +#define MAX_PAGES (1 << MAX_PAGE_ORDER)
> #define MAX_EVENTS (MAX_PAGES * PAGE_SIZE)
>
> /* Limit how long of an event name plus args within the subsystem. */
> @@ -1622,16 +1623,17 @@ static void set_page_reservations(bool set)
>
> static int __init trace_events_user_init(void)
> {
> + struct page *pages;
> int ret;
>
> /* Zero all bits beside 0 (which is reserved for failures) */
> bitmap_zero(page_bitmap, MAX_EVENTS);
> set_bit(0, page_bitmap);
>
> - register_page_data = kzalloc(MAX_EVENTS, GFP_KERNEL);
> -
> - if (!register_page_data)
> + pages = alloc_pages(GFP_KERNEL | __GFP_ZERO, MAX_PAGE_ORDER);
> + if (!pages)
> return -ENOMEM;
> + register_page_data = page_address(pages);
>
> set_page_reservations(true);
>
> @@ -1640,7 +1642,7 @@ static int __init trace_events_user_init(void)
> if (ret) {
> pr_warn("user_events could not register with tracefs\n");
> set_page_reservations(false);
> - kfree(register_page_data);
> + __free_pages(pages, MAX_PAGE_ORDER);
> return ret;
> }
>
This looks good to me, I agree having the max events aligning to page
order makes more sense going forward.
Thanks,
-Beau
prev parent reply other threads:[~2022-03-11 23:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-11 22:30 [PATCH] user_events: Use alloc_pages instead of kzalloc for register pages Beau Belgrave
2022-03-11 23:33 ` Steven Rostedt
2022-03-11 23:44 ` Steven Rostedt
2022-03-11 23:55 ` Beau Belgrave [this message]
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=20220311235530.GB2101@kbox \
--to=beaub@linux.microsoft.com \
--cc=anders.roxell@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).