Skip to content

Commit 74e2afc

Browse files
Qiujun Huangrostedt
authored andcommitted
ring-buffer: Add rb_check_bpage in __rb_allocate_pages
It may be better to check each page is aligned by 4 bytes. The 2 least significant bits of the address will be used as flags. Link: https://lkml.kernel.org/r/20201015113842.2921-1-hqjagain@gmail.com Signed-off-by: Qiujun Huang <hqjagain@gmail.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 82db909 commit 74e2afc

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎kernel/trace/ring_buffer.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,8 @@ static int rb_check_pages(struct ring_buffer_per_cpu *cpu_buffer)
14231423
return 0;
14241424
}
14251425

1426-
static int __rb_allocate_pages(long nr_pages, struct list_head *pages, int cpu)
1426+
static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
1427+
long nr_pages, struct list_head *pages)
14271428
{
14281429
struct buffer_page *bpage, *tmp;
14291430
bool user_thread = current->mm != NULL;
@@ -1463,13 +1464,15 @@ static int __rb_allocate_pages(long nr_pages, struct list_head *pages, int cpu)
14631464
struct page *page;
14641465

14651466
bpage = kzalloc_node(ALIGN(sizeof(*bpage), cache_line_size()),
1466-
mflags, cpu_to_node(cpu));
1467+
mflags, cpu_to_node(cpu_buffer->cpu));
14671468
if (!bpage)
14681469
goto free_pages;
14691470

1471+
rb_check_bpage(cpu_buffer, bpage);
1472+
14701473
list_add(&bpage->list, pages);
14711474

1472-
page = alloc_pages_node(cpu_to_node(cpu), mflags, 0);
1475+
page = alloc_pages_node(cpu_to_node(cpu_buffer->cpu), mflags, 0);
14731476
if (!page)
14741477
goto free_pages;
14751478
bpage->page = page_address(page);
@@ -1501,7 +1504,7 @@ static int rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
15011504

15021505
WARN_ON(!nr_pages);
15031506

1504-
if (__rb_allocate_pages(nr_pages, &pages, cpu_buffer->cpu))
1507+
if (__rb_allocate_pages(cpu_buffer, nr_pages, &pages))
15051508
return -ENOMEM;
15061509

15071510
/*
@@ -2008,8 +2011,8 @@ int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size,
20082011
* allocated without receiving ENOMEM
20092012
*/
20102013
INIT_LIST_HEAD(&cpu_buffer->new_pages);
2011-
if (__rb_allocate_pages(cpu_buffer->nr_pages_to_update,
2012-
&cpu_buffer->new_pages, cpu)) {
2014+
if (__rb_allocate_pages(cpu_buffer, cpu_buffer->nr_pages_to_update,
2015+
&cpu_buffer->new_pages)) {
20132016
/* not enough memory for new pages */
20142017
err = -ENOMEM;
20152018
goto out_err;
@@ -2074,8 +2077,8 @@ int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size,
20742077

20752078
INIT_LIST_HEAD(&cpu_buffer->new_pages);
20762079
if (cpu_buffer->nr_pages_to_update > 0 &&
2077-
__rb_allocate_pages(cpu_buffer->nr_pages_to_update,
2078-
&cpu_buffer->new_pages, cpu_id)) {
2080+
__rb_allocate_pages(cpu_buffer, cpu_buffer->nr_pages_to_update,
2081+
&cpu_buffer->new_pages)) {
20792082
err = -ENOMEM;
20802083
goto out_err;
20812084
}

0 commit comments

Comments
 (0)