docs: ftrace: Clarify the RAM impact of buffer_size_kb
Subsystems (4)
cover docs: ftrace: Clarify the RAM impact of buffer_size_kb
Improves the documentation of buffer_size_kb by clarifying how is calculated the number of allocated pages for the ring buffer.
** Do not apply the second patch **. It's just for illustration purposes.
Frank A. Cancio Bello (2):
docs: ftrace: Clarify the RAM impact of buffer_size_kb ** do not apply this patch ** Just for illustration purposes
Documentation/trace/ftrace.rst | 13 +++++++++++-- kernel/trace/ring_buffer.c | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
RFC 1/2 docs: ftrace: Clarify the RAM impact of buffer_size_kb
The current text could mislead the user into believing that the number of pages allocated by each CPU ring buffer is calculated by the round up of the division: buffer_size_kb / PAGE_SIZE.
Clarify that the number of pages allocated is the round up of the
division: buffer_size_kb / (PAGE_SIZE - BUF_PAGE_HDR_SIZE). Add an example that shows how the number of pages allocated could be off by 5 pages more compared with how the current text suggests it should be.
--- Documentation/trace/ftrace.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
Documentation/trace/ftrace.rst +11 -2
@@ -188,8 +188,17 @@ of ftrace. Here is a list of some of the key files: If the last page allocated has room for more bytes than requested, the rest of the page will be used, making the actual allocation bigger than requested or shown. - ( Note, the size may not be a multiple of the page size - due to buffer management meta-data. ) + + The number of pages allocated for each CPU buffer may not + be the same than the round up of the division: + buffer_size_kb / PAGE_SIZE. This is because part of each page is + used to store a page header with metadata. E.g. with + buffer_size_kb=4096 (kilobytes), a PAGE_SIZE=4096 bytes and a + BUF_PAGE_HDR_SIZE=16 bytes (BUF_PAGE_HDR_SIZE is the size of the + page header with metadata) the number of pages allocated for each + CPU buffer is 1029, not 1024. The formula for calculating the + number of pages allocated for each CPU buffer is the round up of: + buffer_size_kb / (PAGE_SIZE - BUF_PAGE_HDR_SIZE). Buffer sizes for individual CPUs may vary (see "per_cpu/cpu0/buffer_size_kb" below), and if they do
Signature · 1 line
2.17.1
Steven Rostedt
maintainerQuoted 20 lines · On Wed, 13 Nov 2019 11:32:36 -0500 "Frank A. Cancio Bello"…
The current text could mislead the user into believing that the number of pages allocated by each CPU ring buffer is calculated by the round up of the division:
buffer_size_kb/PAGE_SIZE.Clarify that the number of pages allocated is the round up of the
division:buffer_size_kb/ (PAGE_SIZE-BUF_PAGE_HDR_SIZE). Add an example that shows how the number of pages allocated could be off by 5 pages more compared with how the current text suggests it should be.Suggested-by Joel Fernandes (Google) <[email protected]>Signed-off-by Frank A. Cancio Bello <[email protected]>--- Documentation/trace/ftrace.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)Documentation/trace/ftrace.rst +0
-0
Documentation/trace/ftrace.rst of ftrace. Here is a list of some of the key files: · line 192
Quoted 5 lines
Documentation/trace/ftrace.rst +0
-2@@ -188,8 +188,17 @@ of ftrace. Here is a list of some of the key files: If the last page allocated has room for more bytes than requested, the rest of the page will be used, making the actual allocation bigger than requested or shown. - ( Note, the size may not be a multiple of the page size - due to buffer management meta-data. )
The above is not untrue ;-)
Documentation/trace/ftrace.rst of ftrace. Here is a list of some of the key files: · line 201
Quoted 11 lines
Documentation/trace/ftrace.rst +11
-0+ + The number of pages allocated for each CPU buffer may not + be the same than the round up of the division: + buffer_size_kb / PAGE_SIZE. This is because part of each page is + used to store a page header with metadata. E.g. with + buffer_size_kb=4096 (kilobytes), a PAGE_SIZE=4096 bytes and a + BUF_PAGE_HDR_SIZE=16 bytes (BUF_PAGE_HDR_SIZE is the size of the + page header with metadata) the number of pages allocated for each + CPU buffer is 1029, not 1024. The formula for calculating the + number of pages allocated for each CPU buffer is the round up of: + buffer_size_kb / (PAGE_SIZE - BUF_PAGE_HDR_SIZE).
I have no problem with this patch, but the concern of documenting the implementation here, which will most likely not be updated if the implementation is ever changed, which is why I was vague to begin with.
But it may never be changed as that code has been like that for a decade now.
-- Steve
Quoted 3 lines
Documentation/trace/ftrace.rst +0
-0Buffer sizes for individual CPUs may vary (see "per_cpu/cpu0/buffer_size_kb" below), and if they do
Quoted 2 lines · Steven Rostedt
On Wed, 13 Nov 2019 11:32:36 -0500
"Frank A. Cancio Bello" <[email protected]> wrote:
[snip]
Quoted 12 lines
Documentation/trace/ftrace.rst of ftrace. Here is a list of some of the key files: · line 201
Quoted 11 lines
Documentation/trace/ftrace.rst +11
-0+ + The number of pages allocated for each CPU buffer may not + be the same than the round up of the division: + buffer_size_kb / PAGE_SIZE. This is because part of each page is + used to store a page header with metadata. E.g. with + buffer_size_kb=4096 (kilobytes), a PAGE_SIZE=4096 bytes and a + BUF_PAGE_HDR_SIZE=16 bytes (BUF_PAGE_HDR_SIZE is the size of the + page header with metadata) the number of pages allocated for each + CPU buffer is 1029, not 1024. The formula for calculating the + number of pages allocated for each CPU buffer is the round up of: + buffer_size_kb / (PAGE_SIZE - BUF_PAGE_HDR_SIZE).
Quoted 6 lines
I have no problem with this patch, but the concern of documenting the implementation here, which will most likely not be updated if the implementation is ever changed, which is why I was vague to begin with.
But it may never be changed as that code has been like that for a decade now.
Agreed. To give some context, Frank is an outreachy intern I am working with and one of his starter tasks was to understand the ring buffer's basics. I asked him to send a patch since I thought he mentioned there was an error in the documnentation. It looks like all that was missing is some explanation which the deleted text in brackets above should already cover.
Steve, your call if you want this patch. Looks like Frank understands the page header taking up some space, so one of the goals of the exercise is accomplished ;-)
thanks,
- Joel
Steven Rostedt
maintainerQuoted 29 lines · On Thu, 14 Nov 2019 15:20:59 -0500 Joel Fernandes <[email protected]>…
Quoted 2 lines · Steven Rostedt
On Wed, 13 Nov 2019 11:32:36 -0500
"Frank A. Cancio Bello" <[email protected]> wrote:[snip]
Quoted 12 lines
Documentation/trace/ftrace.rst of ftrace. Here is a list of some of the key files: · line 201
Quoted 11 lines
Documentation/trace/ftrace.rst +11
-0+ + The number of pages allocated for each CPU buffer may not + be the same than the round up of the division: + buffer_size_kb / PAGE_SIZE. This is because part of each page is + used to store a page header with metadata. E.g. with + buffer_size_kb=4096 (kilobytes), a PAGE_SIZE=4096 bytes and a + BUF_PAGE_HDR_SIZE=16 bytes (BUF_PAGE_HDR_SIZE is the size of the + page header with metadata) the number of pages allocated for each + CPU buffer is 1029, not 1024. The formula for calculating the + number of pages allocated for each CPU buffer is the round up of: + buffer_size_kb / (PAGE_SIZE - BUF_PAGE_HDR_SIZE).Quoted 6 lines
I have no problem with this patch, but the concern of documenting the implementation here, which will most likely not be updated if the implementation is ever changed, which is why I was vague to begin with.
But it may never be changed as that code has been like that for a decade now.
Agreed. To give some context, Frank is an outreachy intern I am working with and one of his starter tasks was to understand the ring buffer's basics. I asked him to send a patch since I thought he mentioned there was an error in the documnentation. It looks like all that was missing is some explanation which the deleted text in brackets above should already cover.
Quoted 3 lines
Steve, your call if you want this patch. Looks like Frank understands the page header taking up some space, so one of the goals of the exercise is accomplished ;-)
Yes agreed, what was written was not wrong (thus understood). But the more I think about this, the less I like the implementation details in the documentation directory. Now I am looking forward for some other patches from Frank, and perhaps he could add some comments in ring_buffer.c about this. ;-)
-- Steve
Quoted 26 lines · Steven Rostedt
Quoted 23 lines · On Thu, 14 Nov 2019 15:20:59 -0500 Joel Fernandes <[email protected]>…
Quoted 2 lines · Steven Rostedt
On Wed, 13 Nov 2019 11:32:36 -0500
"Frank A. Cancio Bello" <[email protected]> wrote:[snip]
Quoted 18 lines
Documentation/trace/ftrace.rst of ftrace. Here is a list of some of the key files: · line 201
Quoted 11 lines
Documentation/trace/ftrace.rst +11
-0+ + The number of pages allocated for each CPU buffer may not + be the same than the round up of the division: + buffer_size_kb / PAGE_SIZE. This is because part of each page is + used to store a page header with metadata. E.g. with + buffer_size_kb=4096 (kilobytes), a PAGE_SIZE=4096 bytes and a + BUF_PAGE_HDR_SIZE=16 bytes (BUF_PAGE_HDR_SIZE is the size of the + page header with metadata) the number of pages allocated for each + CPU buffer is 1029, not 1024. The formula for calculating the + number of pages allocated for each CPU buffer is the round up of: + buffer_size_kb / (PAGE_SIZE - BUF_PAGE_HDR_SIZE).I have no problem with this patch, but the concern of documenting the implementation here, which will most likely not be updated if the implementation is ever changed, which is why I was vague to begin with.
But it may never be changed as that code has been like that for a decade now.
Quoted 6 lines
Quoted 6 lines
Agreed. To give some context, Frank is an outreachy intern I am working with and one of his starter tasks was to understand the ring buffer's basics. I asked him to send a patch since I thought he mentioned there was an error in the documnentation. It looks like all that was missing is some explanation which the deleted text in brackets above should already cover.
Not exactly in my opinion ;) The deleted text was not the problem. I just deleted it because with the added text it turns to be redundant.
The issue that I found with the documentation (maybe just to my newbie's eyes) is in this part:
"The trace buffers are allocated in pages (blocks of memory that the kernel uses for allocation, usually 4 KB in size). If the last page allocated has room for more bytes than requested, the rest of the page will be used, making the actual allocation bigger than requested or shown."
For me that "suggests" the interpretation that the number of pages allocated in the current implementation correspond with the round integer division of buffer_size_kb / PAGE_SIZE, which is inaccurate (for 5 pages in the example that I mentioned).
Quoted 7 lines
Quoted 3 lines
Steve, your call if you want this patch. Looks like Frank understands the page header taking up some space, so one of the goals of the exercise is accomplished ;-)
Yes agreed, what was written was not wrong (thus understood). But the more I think about this, the less I like the implementation details in the documentation directory.
Understood and agreed. It is funny that what I spotted as "a problem" was precisely an incomplete description of the implementation (the sentences that I quoted above). What do you think about removing those two sentences?
Quoted 4 lines
Now I am looking forward for some other
patches from Frank, and perhaps he could add some comments inring_buffer.cabout this. ;-)
You can count on it. I'm just starting to learn. I'm very grateful that Joel took me under his wing ;) and with the time I hope to be able to give back more to the community with the help of experts like you Steve.
Thank you, Steve and Joel, for such quick feedback! frank a.
Steven Rostedt
maintainerQuoted 46 lines · On Thu, 14 Nov 2019 23:24:28 -0500 "Frank A. Cancio Bello"…
Quoted 26 lines · Steven Rostedt
Quoted 23 lines · On Thu, 14 Nov 2019 15:20:59 -0500 Joel Fernandes <[email protected]>…
Quoted 2 lines · Steven Rostedt
On Wed, 13 Nov 2019 11:32:36 -0500
"Frank A. Cancio Bello" <[email protected]> wrote:[snip]
Quoted 18 lines
Documentation/trace/ftrace.rst of ftrace. Here is a list of some of the key files: · line 201
Quoted 11 lines
Documentation/trace/ftrace.rst +11
-0+ + The number of pages allocated for each CPU buffer may not + be the same than the round up of the division: + buffer_size_kb / PAGE_SIZE. This is because part of each page is + used to store a page header with metadata. E.g. with + buffer_size_kb=4096 (kilobytes), a PAGE_SIZE=4096 bytes and a + BUF_PAGE_HDR_SIZE=16 bytes (BUF_PAGE_HDR_SIZE is the size of the + page header with metadata) the number of pages allocated for each + CPU buffer is 1029, not 1024. The formula for calculating the + number of pages allocated for each CPU buffer is the round up of: + buffer_size_kb / (PAGE_SIZE - BUF_PAGE_HDR_SIZE).I have no problem with this patch, but the concern of documenting the implementation here, which will most likely not be updated if the implementation is ever changed, which is why I was vague to begin with.
But it may never be changed as that code has been like that for a decade now.
Quoted 6 lines
Quoted 6 lines
Agreed. To give some context, Frank is an outreachy intern I am working with and one of his starter tasks was to understand the ring buffer's basics. I asked him to send a patch since I thought he mentioned there was an error in the documnentation. It looks like all that was missing is some explanation which the deleted text in brackets above should already cover.
Not exactly in my opinion ;) The deleted text was not the problem. I just deleted it because with the added text it turns to be redundant.
The issue that I found with the documentation (maybe just to my newbie's eyes) is in this part:
"The trace buffers are allocated in pages (blocks of memory that the kernel uses for allocation, usually 4 KB in size). If the last page allocated has room for more bytes than requested, the rest of the page will be used, making the actual allocation bigger than requested or shown."
Quoted 4 lines
For me that "suggests" the interpretation that the number of pages allocated in the current implementation correspond with the round integer division of
buffer_size_kb/PAGE_SIZE, which is inaccurate (for 5 pages in the example that I mentioned).
If you would like, you could reword that to something more accurate, but still not detailing the implementation.
Quoted 4 lines
Understood and agreed. It is funny that what I spotted as "a problem" was precisely an incomplete description of the implementation (the sentences that I quoted above). What do you think about removing those two sentences?
I wouldn't remove them, just reword them to something you find more accurate.
-- Steve
Quoted 57 lines · Steven Rostedt
Quoted 46 lines · On Thu, 14 Nov 2019 23:24:28 -0500 "Frank A. Cancio Bello"…
Quoted 26 lines · Steven Rostedt
Quoted 23 lines · On Thu, 14 Nov 2019 15:20:59 -0500 Joel Fernandes <[email protected]>…
Quoted 2 lines · Steven Rostedt
On Wed, 13 Nov 2019 11:32:36 -0500
"Frank A. Cancio Bello" <[email protected]> wrote:[snip]
Quoted 18 lines
Documentation/trace/ftrace.rst of ftrace. Here is a list of some of the key files: · line 201
Quoted 11 lines
Documentation/trace/ftrace.rst +11
-0+ + The number of pages allocated for each CPU buffer may not + be the same than the round up of the division: + buffer_size_kb / PAGE_SIZE. This is because part of each page is + used to store a page header with metadata. E.g. with + buffer_size_kb=4096 (kilobytes), a PAGE_SIZE=4096 bytes and a + BUF_PAGE_HDR_SIZE=16 bytes (BUF_PAGE_HDR_SIZE is the size of the + page header with metadata) the number of pages allocated for each + CPU buffer is 1029, not 1024. The formula for calculating the + number of pages allocated for each CPU buffer is the round up of: + buffer_size_kb / (PAGE_SIZE - BUF_PAGE_HDR_SIZE).I have no problem with this patch, but the concern of documenting the implementation here, which will most likely not be updated if the implementation is ever changed, which is why I was vague to begin with.
But it may never be changed as that code has been like that for a decade now.
Quoted 6 lines
Quoted 6 lines
Agreed. To give some context, Frank is an outreachy intern I am working with and one of his starter tasks was to understand the ring buffer's basics. I asked him to send a patch since I thought he mentioned there was an error in the documnentation. It looks like all that was missing is some explanation which the deleted text in brackets above should already cover.
Not exactly in my opinion ;) The deleted text was not the problem. I just deleted it because with the added text it turns to be redundant.
The issue that I found with the documentation (maybe just to my newbie's eyes) is in this part:
"The trace buffers are allocated in pages (blocks of memory that the kernel uses for allocation, usually 4 KB in size). If the last page allocated has room for more bytes than requested, the rest of the page will be used, making the actual allocation bigger than requested or shown."
Quoted 4 lines
For me that "suggests" the interpretation that the number of pages allocated in the current implementation correspond with the round integer division of
buffer_size_kb/PAGE_SIZE, which is inaccurate (for 5 pages in the example that I mentioned).If you would like, you could reword that to something more accurate, but still not detailing the implementation.
Quoted 8 lines
Quoted 4 lines
Understood and agreed. It is funny that what I spotted as "a problem" was precisely an incomplete description of the implementation (the sentences that I quoted above). What do you think about removing those two sentences?
I wouldn't remove them, just reword them to something you find more accurate.
I feel that adding:
"A few extra pages may be allocated to accommodate buffer management meta-data."
between the two sentences that I quoted will address the issue. If that is OK with you I will proceed to package this change in a new patchset along with a few fixes of typos that I spotted in other parts of the doc.
thanks one more time for your quick response.
frank a.
Steven Rostedt
maintainerQuoted 9 lines · On Fri, 15 Nov 2019 10:59:55 -0500 "Frank A. Cancio Bello"…
I feel that adding:
"A few extra pages may be allocated to accommodate buffer management meta-data."
between the two sentences that I quoted will address the issue. If that is OK with you I will proceed to package this change in a new patchset along with a few fixes of typos that I spotted in other parts of the doc.
Yep, I'm OK with that.
Thanks!
-- Steve
RFC 2/2 ** do not apply this patch ** Just for illustration purposes
In reply to Frank A. Cancio BelloPrints a message that will allow us to evaluate the number of pages allocated by each CPU buffer as well the main values that participate in its calculation.
$ echo 0 > /sys/kernel/debug/tracing/tracing_on $ echo 4096 > /sys/kernel/debug/tracing/buffer_size_kb .... e.g. of output: PAGE_SIZE: 4096, BUF_PAGE_HDR_SIZE: 16, size: 4194304, nr_pages: 1029
--- kernel/trace/ring_buffer.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/trace/ring_buffer.c +2 -0
@@ -1730,6 +1730,8 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,return size; nr_pages =DIV_ROUND_UP (size,BUF_PAGE_SIZE ); +printk (KERN_ALERT "PAGE_SIZE: %lu, BUF_PAGE_HDR_SIZE: %lu, size: %lu, nr_pages: %ld" , +PAGE_SIZE ,BUF_PAGE_HDR_SIZE , size, nr_pages);/* we need a minimum of two pages */ if (nr_pages <2 )
Signature · 1 line
2.17.1
kbuild test robot
build botRe: [RFC 2/2] ** do not apply this patch ** Just for illustration purposes
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…
Hi "Frank,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on tip/perf/core]
[cannot apply to v5.4-rc7 next-20191113]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Frank-A-Cancio-Bello/docs-ftrace-Clarify-the-RAM-impact-of-buffer_size_kb/20191114-040608 base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 295c52ee1485e4dee660fc1a0e6ceed6c803c9d3 config: i386-defconfig (attached as .config) compiler: gcc-7 (Debian 7.4.0-14) 7.4.0 reproduce: # save the attached .config to linux build tree make ARCH=i386
If you fix the issue, kindly add following tag
All warnings (new ones prefixed by >>):
In file included from include/linux/printk.h:7:0,
from include/linux/kernel.h:15,
from include/asm-generic/bug.h:19,
from arch/x86/include/asm/bug.h:83,
from include/linux/bug.h:5,
from include/linux/mmdebug.h:5,
from include/linux/mm.h:9,
from include/linux/ring_buffer.h:5,
from include/linux/trace_events.h:6,
from kernel/trace/ring_buffer.c:7:
kernel/trace/ring_buffer.c: In function 'ring_buffer_resize':
include/linux/kern_levels.h:5:18: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'unsigned int' [-Wformat=]
#define KERN_SOH "\001" /* ASCII Start Of Header */
^
include/linux/kern_levels.h:9:20: note: in expansion of macro 'KERN_SOH'
#define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
^~~~~~~~
>> kernel/trace/ring_buffer.c:1733:9: note: in expansion of macro 'KERN_ALERT'
printk(KERN_ALERT "PAGE_SIZE: %lu, BUF_PAGE_HDR_SIZE: %lu, size: %lu, nr_pages: %ld",
^~~~~~~~~~
kernel/trace/ring_buffer.c:1733:58: note: format string is defined here
printk(KERN_ALERT "PAGE_SIZE: %lu, BUF_PAGE_HDR_SIZE: %lu, size: %lu, nr_pages: %ld",
~~^
%uvim +/KERN_ALERT +1733 kernel/trace/ring_buffer.c
1703
1704 /**
1705 * ring_buffer_resize - resize the ring buffer
1706 * @buffer: the buffer to resize.
1707 * @size: the new size.
1708 * @cpu_id: the cpu buffer to resize
1709 *
1710 * Minimum size is 2 * BUF_PAGE_SIZE.
1711 *
1712 * Returns 0 on success and < 0 on failure.
1713 */
1714 int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
1715 int cpu_id)
1716 {
1717 struct ring_buffer_per_cpu *cpu_buffer;
1718 unsigned long nr_pages;
1719 int cpu, err = 0;
1720
1721 /*
1722 * Always succeed@resizing a non-existent buffer:
1723 */
1724 if (!buffer)
1725 return size;
1726
1727 /* Make sure the requested buffer exists */
1728 if (cpu_id != RING_BUFFER_ALL_CPUS &&
1729 !cpumask_test_cpu(cpu_id, buffer->cpumask))
1730 return size;
1731
1732 nr_pages = DIV_ROUND_UP(size, BUF_PAGE_SIZE);
> 1733 printk(KERN_ALERT "PAGE_SIZE: %lu, BUF_PAGE_HDR_SIZE: %lu, size: %lu, nr_pages: %ld",
1734 PAGE_SIZE, BUF_PAGE_HDR_SIZE, size, nr_pages);
1735
1736 /* we need a minimum of two pages */
1737 if (nr_pages < 2)
1738 nr_pages = 2;
1739
1740 size = nr_pages * BUF_PAGE_SIZE;
1741
1742 /*
1743 * Don't succeed if resizing is disabled, as a reader might be
1744 * manipulating the ring buffer and is expecting a sane state while
1745 * this is true.
1746 */
1747 if (atomic_read(&buffer->resize_disabled))
1748 return -EBUSY;
1749
1750 /* prevent another thread from changing buffer sizes */
1751 mutex_lock(&buffer->mutex);
1752
1753 if (cpu_id == RING_BUFFER_ALL_CPUS) {
1754 /* calculate the pages to update */
1755 for_each_buffer_cpu(buffer, cpu) {
1756 cpu_buffer = buffer->buffers[cpu];
1757
1758 cpu_buffer->nr_pages_to_update = nr_pages -
1759 cpu_buffer->nr_pages;
1760 /*
1761 * nothing more to do for removing pages or no update
1762 */
1763 if (cpu_buffer->nr_pages_to_update <= 0)
1764 continue;
1765 /*
1766 * to add pages, make sure all new pages can be
1767 * allocated without receiving ENOMEM
1768 */
1769 INIT_LIST_HEAD(&cpu_buffer->new_pages);
1770 if (__rb_allocate_pages(cpu_buffer->nr_pages_to_update,
1771 &cpu_buffer->new_pages, cpu)) {
1772 /* not enough memory for new pages */
1773 err = -ENOMEM;
1774 goto out_err;
1775 }
1776 }
1777
1778 get_online_cpus();
1779 /*
1780 * Fire off all the required work handlers
1781 * We can't schedule on offline CPUs, but it's not necessary
1782 * since we can change their buffer sizes without any race.
1783 */
1784 for_each_buffer_cpu(buffer, cpu) {
1785 cpu_buffer = buffer->buffers[cpu];
1786 if (!cpu_buffer->nr_pages_to_update)
1787 continue;
1788
1789 /* Can't run something on an offline CPU. */
1790 if (!cpu_online(cpu)) {
1791 rb_update_pages(cpu_buffer);
1792 cpu_buffer->nr_pages_to_update = 0;
1793 } else {
1794 schedule_work_on(cpu,
1795 &cpu_buffer->update_pages_work);
1796 }
1797 }
1798
1799 /* wait for all the updates to complete */
1800 for_each_buffer_cpu(buffer, cpu) {
1801 cpu_buffer = buffer->buffers[cpu];
1802 if (!cpu_buffer->nr_pages_to_update)
1803 continue;
1804
1805 if (cpu_online(cpu))
1806 wait_for_completion(&cpu_buffer->update_done);
1807 cpu_buffer->nr_pages_to_update = 0;
1808 }
1809
1810 put_online_cpus();
1811 } else {
1812 /* Make sure this CPU has been initialized */
1813 if (!cpumask_test_cpu(cpu_id, buffer->cpumask))
1814 goto out;
1815
1816 cpu_buffer = buffer->buffers[cpu_id];
1817
1818 if (nr_pages == cpu_buffer->nr_pages)
1819 goto out;
1820
1821 cpu_buffer->nr_pages_to_update = nr_pages -
1822 cpu_buffer->nr_pages;
1823
1824 INIT_LIST_HEAD(&cpu_buffer->new_pages);
1825 if (cpu_buffer->nr_pages_to_update > 0 &&
1826 __rb_allocate_pages(cpu_buffer->nr_pages_to_update,
1827 &cpu_buffer->new_pages, cpu_id)) {
1828 err = -ENOMEM;
1829 goto out_err;
1830 }
1831
1832 get_online_cpus();
1833
1834 /* Can't run something on an offline CPU. */
1835 if (!cpu_online(cpu_id))
1836 rb_update_pages(cpu_buffer);
1837 else {
1838 schedule_work_on(cpu_id,
1839 &cpu_buffer->update_pages_work);
1840 wait_for_completion(&cpu_buffer->update_done);
1841 }
1842
1843 cpu_buffer->nr_pages_to_update = 0;
1844 put_online_cpus();
1845 }
1846
1847 out:
1848 /*
1849 * The ring buffer resize can happen with the ring buffer
1850 * enabled, so that the update disturbs the tracing as little
1851 * as possible. But if the buffer is disabled, we do not need
1852 * to worry about that, and we can take the time to verify
1853 * that the buffer is not corrupt.
1854 */
1855 if (atomic_read(&buffer->record_disabled)) {
1856 atomic_inc(&buffer->record_disabled);
1857 /*
1858 * Even though the buffer was disabled, we must make sure
1859 * that it is truly disabled before calling rb_check_pages.
1860 * There could have been a race between checking
1861 * record_disable and incrementing it.
1862 */
1863 synchronize_rcu();
1864 for_each_buffer_cpu(buffer, cpu) {
1865 cpu_buffer = buffer->buffers[cpu];
1866 rb_check_pages(cpu_buffer);
1867 }
1868 atomic_dec(&buffer->record_disabled);
1869 }
1870
1871 mutex_unlock(&buffer->mutex);
1872 return size;
1873
1874 out_err:
1875 for_each_buffer_cpu(buffer, cpu) {
1876 struct buffer_page *bpage, *tmp;
1877
1878 cpu_buffer = buffer->buffers[cpu];
1879 cpu_buffer->nr_pages_to_update = 0;
1880
1881 if (list_empty(&cpu_buffer->new_pages))
1882 continue;
1883
1884 list_for_each_entry_safe(bpage, tmp, &cpu_buffer->new_pages,
1885 list) {
1886 list_del_init(&bpage->list);
1887 free_buffer_page(bpage);
1888 }
1889 }
1890 mutex_unlock(&buffer->mutex);
1891 return err;
1892 }
1893 EXPORT_SYMBOL_GPL(ring_buffer_resize);
1894
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation
kbuild test robot
build botRe: [RFC 2/2] ** do not apply this patch ** Just for illustration purposes
In reply to Frank A. Cancio Bello[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…
Hi "Frank,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on tip/perf/core]
[cannot apply to v5.4-rc7 next-20191114]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Frank-A-Cancio-Bello/docs-ftrace-Clarify-the-RAM-impact-of-buffer_size_kb/20191114-040608 base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 295c52ee1485e4dee660fc1a0e6ceed6c803c9d3 config: i386-randconfig-a002-20191115 (attached as .config) compiler: gcc-4.9 (Debian 4.9.2-10+deb8u1) 4.9.2 reproduce: # save the attached .config to linux build tree make ARCH=i386
If you fix the issue, kindly add following tag
All warnings (new ones prefixed by >>):
In file included from <command-line>:0:0:
kernel/trace/ring_buffer.c: In function 'ring_buffer_resize':
>> kernel/trace/ring_buffer.c:125:43: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'unsigned int' [-Wformat=]
#define BUF_PAGE_HDR_SIZE offsetof(struct buffer_data_page, data)
^
include/linux/compiler_types.h:129:54: note: in definition of macro '__compiler_offsetof'
#define __compiler_offsetof(a, b) __builtin_offsetof(a, b)
^
>> kernel/trace/ring_buffer.c:125:27: note: in expansion of macro 'offsetof'
#define BUF_PAGE_HDR_SIZE offsetof(struct buffer_data_page, data)
^
>> kernel/trace/ring_buffer.c:1734:20: note: in expansion of macro 'BUF_PAGE_HDR_SIZE'
PAGE_SIZE, BUF_PAGE_HDR_SIZE, size, nr_pages);
^vim +125 kernel/trace/ring_buffer.c
a358324466b171 Steven Rostedt 2008-11-11 124499e547057f5bb Steven Rostedt 2012-02-22 @125 #define BUF_PAGE_HDR_SIZE offsetof(struct buffer_data_page, data) 033601a32b2012 Steven Rostedt 2008-11-21 126
:::::: The code at line 125 was first introduced by commit
:::::: 499e547057f5bba5cd6f87ebe59b05d0c59da905 tracing/ring-buffer: Only have tracing_on disable tracing buffers
:::::: TO: Steven Rostedt <[email protected]>
:::::: CC: Steven Rostedt <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation