mm: cma: add some debug information for CMA
Subsystems (4)
v4 cover mm: cma: add some debug information for CMA
Hi all.
Here is the fourth version of a patch set that adds some debugging facility for CMA.
This patch set is based on next-20150316. It is also available on git:git://github.com/stefanstrogin/linux -b cmainfo-v4
We want an interface to see a list of currently allocated CMA buffers and some useful information about them (like /proc/vmallocinfo but for physically contiguous buffers allocated with CMA).
For example. We want a big (megabytes) CMA buffer to be allocated in runtime in default CMA region. If someone already uses CMA then the big allocation could fail. If it happened then with such an interface we could find who used CMA at the moment of failure, who caused fragmentation and so on. Ftrace also would be helpful here, but with ftrace we can see the whole history of allocations and releases, whereas with this patch set we can see a snapshot of CMA region with actual information about its allocations.
These patches add some files to debugfs when CONFIG_CMA_DEBUGFS is enbled.
/sys/kernel/debug/cma/cma-<N>/used and cma/cma-<N>/maxchunk are added to show used size in pages and the biggest free chunk in each CMA region.
When CONFIG_CMA_BUFFER_LIST is enabled (depended on CONFIG_CMA_DEBUGFS) /sys/kernel/debug/cma/cma-<N>/buffers is added. It contains a list of currently allocated contiguous buffers for each CMA region (N stands for region number). Format is:
<base_phys_addr> - <end_phys_addr> (<size> kB), allocated by <PID> (<comm>)
Another added option is CONFIG_CMA_ALLOC_STACKTRACE. When it's enabled then stack traces are also saved when the allocations are made. The stack traces are added to each entry in cma/cma-<N>/buffers (see an example [3]). This can be used to see who and whence allocated each buffer.
Also added trace events for cma_alloc() and cma_release().
Changes from v3 (https://lkml.org/lkml/2015/2/24/555):
- Rebased on next-20150316 (includes Sasha Levin's patch set).
- Use seq_file for cma/cma-<N>/buffers.
- Trace allocation failures in cma_alloc() as well as successful allocations.
- Added acks by Michal Nazarewicz and a review by SeongJae Park.
Changes from v2 (https://lkml.org/lkml/2015/2/12/647):
- Rebased on v4.0-rc1 and Sasha Levin's patch set v5 [1].
- Changed kmalloc() to vmalloc() in cma_buffer_list_read().
- Added CONFIG_CMA_BUFFER_LIST and CONFIG_CMA_ALLOC_STACKTRACE.
- Considered order_per_bit for returning page number in cma_get_used() and cma_get_maxchunk().
- Reordered the patches to make the one with trace events indepentent of others.
- Moved the prototypes of cma_buffer_list_add() and cma_buffer_list_del() from include/linux/cma.h to mm/cma.h.
- Various small changes.
Changes from v1 (aka "mm: cma: add /proc/cmainfo")
(https://lkml.org/lkml/2014/12/26/95):
- Rebased on v3.19 and Sasha Levin's patch set v4 [2].
- Moved debug code from cma.c to cma_debug.c.
- Moved cmainfo to debugfs and splited it by CMA region.
- Splited 'cmainfo' into 'buffers', 'used' and 'maxchunk'.
- Used CONFIG_CMA_DEBUGFS instead of CONFIG_CMA_DEBUG.
- Added trace events for cma_alloc() and cma_release().
- Don't use seq_files.
- A small change of debug output in cma_release().
- cma_buffer_list_del() now supports releasing chunks which ranges don't match allocations. E.g. we have buffer1: [0x0, 0x1], buffer2: [0x2, 0x3], then cma_buffer_list_del(cma, 0x1 /*or 0x0*/, 1 /*(or 2 or 3)*/) should work.
- Various small changes.
[1] https://lkml.org/lkml/2015/2/12/657
[2] https://lkml.org/lkml/2015/1/28/755
[3] root@debian:/sys/kernel/debug/cma# cat cma-0/buffers 0x2f400000 - 0x2f417000 (92 kB), allocated by pid 1 (swapper/0)
[<c1142c4b>] cma_alloc+0x1bb/0x200 [<c143d28a>] dma_alloc_from_contiguous+0x3a/0x40 [<c10079d9>] dma_generic_alloc_coherent+0x89/0x160 [<c14456ce>] dmam_alloc_coherent+0xbe/0x100 [<c1487312>] ahci_port_start+0xe2/0x210 [<c146e0e0>] ata_host_start.part.28+0xc0/0x1a0 [<c1473650>] ata_host_activate+0xd0/0x110 [<c14881bf>] ahci_host_activate+0x3f/0x170 [<c14854e4>] ahci_init_one+0x764/0xab0 [<c12e415f>] pci_device_probe+0x6f/0xd0 [<c14378a8>] driver_probe_device+0x68/0x210 [<c1437b09>] __driver_attach+0x79/0x80 [<c1435eef>] bus_for_each_dev+0x4f/0x80 [<c143749e>] driver_attach+0x1e/0x20 [<c1437197>] bus_add_driver+0x157/0x200 [<c14381bd>] driver_register+0x5d/0xf0 <...> 0x2f41b000 - 0x2f41c000 (4 kB), allocated by pid 1264 (NetworkManager) [<c1142c4b>] cma_alloc+0x1bb/0x200 [<c143d28a>] dma_alloc_from_contiguous+0x3a/0x40 [<c10079d9>] dma_generic_alloc_coherent+0x89/0x160 [<c14c5d13>] e1000_setup_all_tx_resources+0x93/0x540 [<c14c8021>] e1000_open+0x31/0x120 [<c16264cf>] __dev_open+0x9f/0x130 [<c16267ce>] __dev_change_flags+0x8e/0x150 [<c16268b8>] dev_change_flags+0x28/0x60 [<c1633ee0>] do_setlink+0x2a0/0x760 [<c1634acb>] rtnl_newlink+0x60b/0x7b0 [<c16314f4>] rtnetlink_rcv_msg+0x84/0x1f0 [<c164b58e>] netlink_rcv_skb+0x8e/0xb0 [<c1631461>] rtnetlink_rcv+0x21/0x30 [<c164af7a>] netlink_unicast+0x13a/0x1d0 [<c164b250>] netlink_sendmsg+0x240/0x3e0 [<c160cbfd>] do_sock_sendmsg+0xbd/0xe0
<...>
Dmitry Safonov (1):
mm: cma: add functions to get region pages counters
Stefan Strogin (4):
mm: cma: add trace events to debug physically-contiguous memory
allocations
mm: cma: add number of pages to debug message in cma_release()
stacktrace: add seq_print_stack_trace()
mm: cma: add list of currently allocated CMA buffers to debugfs
include/linux/cma.h | 2 + include/linux/stacktrace.h | 4 + include/trace/events/cma.h | 57 +++++++++++ kernel/stacktrace.c | 17 ++++ mm/Kconfig | 17 ++++ mm/cma.c | 44 ++++++++- mm/cma.h | 14 +++ mm/cma_debug.c | 230 ++++++++++++++++++++++++++++++++++++++++++++- 8 files changed, 383 insertions(+), 2 deletions(-) create mode 100644 include/trace/events/cma.h
Signature · 1 line
2.1.0
PATCH v4 1/5 mm: cma: add trace events to debug physically-contiguous memory allocations
Add trace events for cma_alloc() and cma_release().
--- include/trace/events/cma.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++ mm/cma.c | 5 ++++ 2 files changed, 62 insertions(+) create mode 100644 include/trace/events/cma.h
include/trace/events/cma.h new file +57 -0
@@ -0,0 +1,57 @@ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM cma + +#if !defined(_TRACE_CMA_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _TRACE_CMA_H + +#include <linux/types.h> +#include <linux/tracepoint.h> + +TRACE_EVENT (cma_alloc, + + TP_PROTO(struct cma *cma, struct page *page, int count), + +TP_ARGS (cma, page, count), + +TP_STRUCT__entry ( + __field(struct page *, page) + __field(unsigned long, count) + ), + +TP_fast_assign ( + __entry->page = page; + __entry->count = count; + ), + +TP_printk ("page=%p pfn=%lu count=%lu" , + __entry->page, + __entry->page ?page_to_pfn (__entry->page) :0 , + __entry->count) +); + +TRACE_EVENT (cma_release, + + TP_PROTO(struct cma *cma, unsigned long pfn, int count), + +TP_ARGS (cma, pfn, count), + +TP_STRUCT__entry ( + __field(unsigned long, pfn) + __field(unsigned long, count) + ), + +TP_fast_assign ( + __entry->pfn = pfn; + __entry->count = count; + ), + +TP_printk ("pfn=%lu page=%p count=%lu" , + __entry->pfn, +pfn_to_page (__entry->pfn), + __entry->count) +); + +#endif /* _TRACE_CMA_H */ + +/* This part must be outside protection */ +#include <trace/define_trace.h>
mm/cma.c +5 -0
@@ -23,6 +23,7 @@# define DEBUG #endif #endif +#define CREATE_TRACE_POINTS #include <linux/memblock.h> #include <linux/err.h>
@@ -34,6 +35,7 @@#include <linux/cma.h> #include <linux/highmem.h> #include <linux/io.h> +#include <trace/events/cma.h> #include "cma.h"
@@ -414,6 +416,8 @@ struct page *cma_alloc(struct cma *cma, unsigned int count, unsigned int align) start = bitmap_no + mask +1 ; } +trace_cma_alloc (cma, page, count); +pr_debug ("%s(): returned %p\n" , __func__, page);return page; }
@@ -446,6 +450,7 @@ bool cma_release(struct cma *cma, const struct page *pages, unsigned int count)free_contig_range (pfn, count);cma_clear_bitmap (cma, pfn, count); +trace_cma_release (cma, pfn, count);return true; }
Signature · 7 lines
2.1.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 1/5] mm: cma: add trace events to debug physically-contiguous memory allocations
Oops... forgot to cc tracing maintainers. Sorry!
Quoted 103 lines · Stefan Strogin
Add trace events for
cma_alloc()andcma_release().Signed-off-by Stefan Strogin <[email protected]>--- include/trace/events/cma.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++ mm/cma.c | 5 ++++ 2 files changed, 62 insertions(+) create mode 100644 include/trace/events/cma.hinclude/trace/events/cma.h new file +57
-0@@ -0,0 +1,57 @@ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM cma + +#if !defined(_TRACE_CMA_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _TRACE_CMA_H + +#include <linux/types.h> +#include <linux/tracepoint.h> + +TRACE_EVENT (cma_alloc, + + TP_PROTO(struct cma *cma, struct page *page, int count), + +TP_ARGS (cma, page, count), + +TP_STRUCT__entry ( + __field(struct page *, page) + __field(unsigned long, count) + ), + +TP_fast_assign ( + __entry->page = page; + __entry->count = count; + ), + +TP_printk ("page=%p pfn=%lu count=%lu" , + __entry->page, + __entry->page ?page_to_pfn (__entry->page) :0 , + __entry->count) +); + +TRACE_EVENT (cma_release, + + TP_PROTO(struct cma *cma, unsigned long pfn, int count), + +TP_ARGS (cma, pfn, count), + +TP_STRUCT__entry ( + __field(unsigned long, pfn) + __field(unsigned long, count) + ), + +TP_fast_assign ( + __entry->pfn = pfn; + __entry->count = count; + ), + +TP_printk ("pfn=%lu page=%p count=%lu" , + __entry->pfn, +pfn_to_page (__entry->pfn), + __entry->count) +); + +#endif /* _TRACE_CMA_H */ + +/* This part must be outside protection */ +#include <trace/define_trace.h> mm/cma.c +4
-0@@ -23,6 +23,7 @@# define DEBUG #endif #endif +#define CREATE_TRACE_POINTS #include <linux/memblock.h> #include <linux/err.h> @@ -34,6 +35,7 @@#include <linux/cma.h> #include <linux/highmem.h> #include <linux/io.h> +#include <trace/events/cma.h> #include "cma.h" @@ -414,6 +416,8 @@ struct page *cma_alloc(struct cma *cma, unsigned int count, unsigned int align) start = bitmap_no + mask +1 ; } +trace_cma_alloc (cma, page, count); +pr_debug ("%s(): returned %p\n" , __func__, page);return page; }
mm/cma.c bool cma_release(struct cma *cma, const struct page *pages, unsigned int count) · line 456
Quoted 7 lines
mm/cma.c +1
-0@@ -446,6 +450,7 @@ bool cma_release(struct cma *cma, const struct page *pages, unsigned int count)free_contig_range (pfn, count);cma_clear_bitmap (cma, pfn, count); +trace_cma_release (cma, pfn, count);return true; }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v4 1/5] mm: cma: add trace events to debug physically-contiguous memory allocations
Quoted 1 line · On Mon, 16 Mar 2015 23:49:01 +0300 Stefan Strogin…
Oops... forgot to cc tracing maintainers. Sorry!
Thanks,
Quoted 37 lines · Stefan Strogin
Quoted 35 lines
Add trace events for
cma_alloc()andcma_release().Signed-off-by Stefan Strogin <[email protected]>--- include/trace/events/cma.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++ mm/cma.c | 5 ++++ 2 files changed, 62 insertions(+) create mode 100644 include/trace/events/cma.hinclude/trace/events/cma.h new file +20
-0@@ -0,0 +1,57 @@ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM cma + +#if !defined(_TRACE_CMA_H) || defined(TRACE_HEADER_MULTI_READ ) +#define _TRACE_CMA_H + +#include <linux/types.h> +#include <linux/tracepoint.h> + +TRACE_EVENT(cma_alloc, + + TP_PROTO(struct cma *cma, struct page *page, int count), + + TP_ARGS(cma, page, count), + + TP_STRUCT__entry( + __field(struct page *, page) + __field(unsigned long, count) + ), +
Quoted 8 lines
include/trace/events/cma.h line 28
Quoted 8 lines
include/trace/events/cma.h new file +8
-0+TP_fast_assign ( + __entry->page = page; + __entry->count = count; + ), + + TP_printk("page=%p pfn=%lu count=%lu", + __entry->page, + __entry->page ? page_to_pfn(__entry->page) : 0,
Can page_to_pfn(value) ever be different throughout the life of the boot? That is, can it return a different result given the same value (vmalloc area comes to mind).
Quoted 14 lines
Quoted 14 lines
include/trace/events/cma.h new file +14
-0+ __entry->count) +); + +TRACE_EVENT(cma_release, + + TP_PROTO(struct cma *cma, unsigned long pfn, int count), + + TP_ARGS(cma, pfn, count), + + TP_STRUCT__entry( + __field(unsigned long, pfn) + __field(unsigned long, count) + ), +
Quoted 8 lines
include/trace/events/cma.h line 50
Quoted 8 lines
include/trace/events/cma.h new file +8
-0+TP_fast_assign ( + __entry->pfn = pfn; + __entry->count = count; + ), + + TP_printk("pfn=%lu page=%p count=%lu", + __entry->pfn, + pfn_to_page(__entry->pfn),
Same here. Can pfn_to_page(value) ever return a different result with the same value in a single boot?
-- Steve
Quoted 38 lines
Quoted 38 lines
include/trace/events/cma.h new file +7
-0+ __entry->count) +); + +#endif /* _TRACE_CMA_H */ + +/* This part must be outside protection */ +#include <trace/define_trace.h> mm/cma.c +4
-0@@ -23,6 +23,7 @@# define DEBUG #endif #endif +#define CREATE_TRACE_POINTS #include <linux/memblock.h> #include <linux/err.h> @@ -34,6 +35,7 @@#include <linux/cma.h> #include <linux/highmem.h> #include <linux/io.h> +#include <trace/events/cma.h> #include "cma.h" @@ -414,6 +416,8 @@ struct page *cma_alloc(struct cma *cma, unsigned int count, unsigned int align) start = bitmap_no + mask +1 ; } +trace_cma_alloc (cma, page, count); +pr_debug ("%s(): returned %p\n" , __func__, page);return page; }@@ -446,6 +450,7 @@ bool cma_release(struct cma *cma, const struct page *pages, unsigned int count)
Quoted 7 lines
mm/cma.c bool cma_release(struct cma *cma, const struct page *pages, unsigned int count) · line 456
Quoted 7 lines
mm/cma.c +1
-0free_contig_range (pfn, count);cma_clear_bitmap (cma, pfn, count); +trace_cma_release (cma, pfn, count);return true; }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 1/5] mm: cma: add trace events to debug physically-contiguous memory allocations
Quoted 24 lines · Steven Rostedt
Quoted 11 lines
Quoted 11 lines
include/trace/events/cma.h new file +11
-0+TRACE_EVENT(cma_alloc, + + TP_PROTO(struct cma *cma, struct page *page, int count), + + TP_ARGS(cma, page, count), + + TP_STRUCT__entry( + __field(struct page *, page) + __field(unsigned long, count) + ), +Quoted 8 lines
include/trace/events/cma.h line 28
Quoted 8 lines
include/trace/events/cma.h new file +8
-0+TP_fast_assign ( + __entry->page = page; + __entry->count = count; + ), + + TP_printk("page=%p pfn=%lu count=%lu", + __entry->page, + __entry->page ? page_to_pfn(__entry->page) : 0,Can
page_to_pfn(value)ever be different throughout the life of the boot? That is, can it return a different result given the same value (vmalloc area comes to mind).
Quoted 7 lines
Quoted 3 lines
include/trace/events/cma.h line 50
Quoted 3 lines
include/trace/events/cma.h new file +3
-0+ TP_printk("pfn=%lu page=%p count=%lu", + __entry->pfn, + pfn_to_page(__entry->pfn),Same here. Can
pfn_to_page(value)ever return a different result with the same value in a single boot?
Thank you for the reply, Steven.
I supposed that page_to_pfn() cannot change after mem_map initialization, can it? I'm not sure about such things as memory hotplug though...
Also cma_alloc() calls alloc_contig_range() which returns pfn, then it's converted to struct page * and cma_alloc() returns struct page *, and vice versa in cma_release() (receives struct page * and passes pfn to free_contig_rage()).
Do you mean that printing pfn (or struct page *) in trace event is redundant?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Steven Rostedt
maintainerRe: [PATCH v4 1/5] mm: cma: add trace events to debug physically-contiguous memory allocations
Quoted 10 lines · On Thu, 19 Mar 2015 23:18:18 +0300 Stefan Strogin…
Thank you for the reply, Steven.
I supposed thatpage_to_pfn()cannot change aftermem_mapinitialization, can it? I'm not sure about such things as memory hotplug though...
Alsocma_alloc()callsalloc_contig_range()which returns pfn, then it's converted to struct page * andcma_alloc()returns struct page *, and vice versa incma_release()(receives struct page * and passes pfn tofree_contig_rage()).
Do you mean that printing pfn (or struct page *) in trace event is redundant?
I'm concerned about the time TP_printk() is executed and when TP_fast_assign() is. That is, when the tracepoint is called, TP_fast_assign() is executed, but TP_printk() is called when someone reads the trace files, which can happen seconds, hours, days, weeks, months later.
As long as the result of page_to_pfn() and pfn_to_page() stay the same throughout the life of the boot, things will be fine. But if they could ever change, due to hotplug memory or whatever. The data in the trace buffer will become stale, and report the wrong information.
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 1/5] mm: cma: add trace events to debug physically-contiguous memory allocations
Quoted 20 lines · Steven Rostedt
Quoted 10 lines · On Thu, 19 Mar 2015 23:18:18 +0300 Stefan Strogin…
Thank you for the reply, Steven.
I supposed thatpage_to_pfn()cannot change aftermem_mapinitialization, can it? I'm not sure about such things as memory hotplug though...
Alsocma_alloc()callsalloc_contig_range()which returns pfn, then it's converted to struct page * andcma_alloc()returns struct page *, and vice versa incma_release()(receives struct page * and passes pfn tofree_contig_rage()).
Do you mean that printing pfn (or struct page *) in trace event is redundant?I'm concerned about the time
TP_printk()is executed and whenTP_fast_assign()is. That is, when the tracepoint is called,TP_fast_assign()is executed, butTP_printk()is called when someone reads the trace files, which can happen seconds, hours, days, weeks, months later.
Quoted 7 lines
As long as the result of
page_to_pfn()andpfn_to_page()stay the same throughout the life of the boot, things will be fine. But if they could ever change, due to hotplug memory or whatever. The data in the trace buffer will become stale, and report the wrong information.-- Steve
Ah, thanks, I see. So will this solve the described issue?
+ TP_fast_assign(
+ __entry->page = page;
+ __entry->pfn = page_to_pfn(__entry->page) : 0;
/* or -1 as Ingo suggested */
+ __entry->count = count;
+ ),
+
+ TP_printk("page=%p pfn=%lu count=%u",
+ __entry->page, + __entry->pfn, + __entry->count)
Should we do the same in trace/events/kmem.h then?
But really I'm not sure why page_to_pfn()/pfn_to_page() can return different results... I thought that there can appear new 'struct page' entries arrays throughout one boot due to memory hotplug or smth. But how can existing 'struct page' entries associated with the same physical pages change their physical addresses? Or how can one physical address correspond to different physical page throughout one boot?
Steven Rostedt
maintainerRe: [PATCH v4 1/5] mm: cma: add trace events to debug physically-contiguous memory allocations
Quoted 13 lines · On Fri, 20 Mar 2015 13:46:39 +0300 Stefan Strogin…
Ah, thanks, I see. So will this solve the described issue?
include/trace/events/cma.h new file +3
-0+TP_fast_assign ( + __entry->page = page; + __entry->pfn = page_to_pfn(__entry->page) : 0;/* or -1 as Ingo suggested */
include/trace/events/cma.h new file +7
-0+ __entry->count = count; + ), + +TP_printk ("page=%p pfn=%lu count=%u" , + __entry->page, + __entry->pfn, + __entry->count)
Quoted 8 lines
Should we do the same in
trace/events/kmem.hthen?But really I'm not sure why page_to_pfn()/pfn_to_page() can return different results... I thought that there can appear new 'struct page' entries arrays throughout one boot due to memory hotplug or smth. But how can existing 'struct page' entries associated with the same physical pages change their physical addresses? Or how can one physical address correspond to different physical page throughout one boot?
I don't know if those mappings can change. I'm just warning you that if they can, then you can have an issue with it. If that's the case, then it would be best to do the work in the tracepoint instead of the print.
One benefit for making this change is that it will let userspace tools such as perf and trace-cmd parse it better.
-- Steve
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 1/5] mm: cma: add trace events to debug physically-contiguous memory allocations
In reply to Stefan StroginQuoted 12 lines · Stefan Strogin
Quoted 12 lines
include/trace/events/cma.h new file +12
-0+TRACE_EVENT(cma_alloc, + + TP_PROTO(struct cma *cma, struct page *page, int count), + + TP_ARGS(cma, page, count), + + TP_STRUCT__entry( + __field(struct page *, page) + __field(unsigned long, count) + ), + + TP_fast_assign(
Quoted 8 lines
include/trace/events/cma.h line 29
Quoted 8 lines
include/trace/events/cma.h new file +8
-0+ __entry->page = page; + __entry->count = count; + ), + +TP_printk ("page=%p pfn=%lu count=%lu" , + __entry->page, + __entry->page ?page_to_pfn (__entry->page) :0 , + __entry->count)
So I'm wondering, the fast-assign side is not equivalent to the TP_printk() side:
Quoted 2 lines
include/trace/events/cma.h line 28
Quoted 2 lines
include/trace/events/cma.h new file +2
-0+ __entry->page = page; + __entry->page ? page_to_pfn(__entry->page) : 0,
to me it seems it would be useful if MM tracing standardized on pfn printing. Just like you did for trace_cma_release().
Also:
Quoted 1 line
include/trace/events/cma.h line 28
Quoted 1 line
include/trace/events/cma.h new file +1
-0+ __entry->page ? page_to_pfn(__entry->page) : 0,
pfn 0 should probably be reserved for the true 0th pfn - those exist in some machines. Returning -1ll could be the 'no such pfn' condition?
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ TP_STRUCT__entry( + __field(unsigned long, pfn)
Btw., does pfn always fit into 32 bits on 32-bit platforms?
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +1
-0+ __field(unsigned long, count)
Does this have to be 64-bit on 64-bit platforms?
Quoted 11 lines
include/trace/events/cma.h line 51
Quoted 11 lines
include/trace/events/cma.h new file +11
-0+ ), + + TP_fast_assign( + __entry->pfn = pfn; + __entry->count = count; + ), + +TP_printk ("pfn=%lu page=%p count=%lu" , + __entry->pfn, +pfn_to_page (__entry->pfn), + __entry->count)
So here you print more in the TP_printk() line than in the fast-assign side.
Again I'd double check the various boundary conditions.
Thanks,
Ingo
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 1/5] mm: cma: add trace events to debug physically-contiguous memory allocations
Quoted 27 lines · Ingo Molnar
Quoted 12 lines · Stefan Strogin
Quoted 12 lines
include/trace/events/cma.h new file +12
-0+TRACE_EVENT(cma_alloc, + + TP_PROTO(struct cma *cma, struct page *page, int count), + + TP_ARGS(cma, page, count), + + TP_STRUCT__entry( + __field(struct page *, page) + __field(unsigned long, count) + ), + + TP_fast_assign(Quoted 8 lines
include/trace/events/cma.h line 29
Quoted 8 lines
include/trace/events/cma.h new file +8
-0+ __entry->page = page; + __entry->count = count; + ), + +TP_printk ("page=%p pfn=%lu count=%lu" , + __entry->page, + __entry->page ?page_to_pfn (__entry->page) :0 , + __entry->count)So I'm wondering, the fast-assign side is not equivalent to the
TP_printk()side:
Quoted 6 lines
Quoted 2 lines
include/trace/events/cma.h line 28
Quoted 2 lines
include/trace/events/cma.h new file +2
-0+ __entry->page = page; + __entry->page ? page_to_pfn(__entry->page) : 0,to me it seems it would be useful if MM tracing standardized on pfn printing. Just like you did for
trace_cma_release().
Hello Ingo, thank you for the reply.
I afraid there is no special sense in printing both struct page * and pfn. But cma_alloc() returns struct page *, cma_release receives struct page *, and pr_debugs in these functions print struct page *. Maybe it would be better to print the same here too?
Quoted 7 lines
Also:
Quoted 1 line
include/trace/events/cma.h line 28
Quoted 1 line
include/trace/events/cma.h new file +1
-0+ __entry->page ? page_to_pfn(__entry->page) : 0,pfn 0 should probably be reserved for the true 0th pfn - those exist in some machines. Returning -1ll could be the 'no such pfn' condition?
I took this from trace_mm_page_alloc() and other trace events from trace/events/kmem.h. If we return -1 here to indicate "no such pfn", should we change do this in kmem.h too?
Quoted 5 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ TP_STRUCT__entry( + __field(unsigned long, pfn)Btw., does pfn always fit into 32 bits on 32-bit platforms?
Well, I think it does. cma_release() uses 'unsigned long' on all platforms.
Quoted 4 lines
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +1
-0+ __field(unsigned long, count)Does this have to be 64-bit on 64-bit platforms?
Oops! I'm terribly wrong.
+ __field(unsigned int, count)
I guess it shouldn't be 64-bit on 64-bit platforms. It's the number of pages being freed, and in cma_release() 'unsigned int' is used for it.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/trace/events/cma.h new file +6
-0+ ), + + TP_fast_assign( + __entry->pfn = pfn; + __entry->count = count; + ),
Quoted 9 lines
Quoted 5 lines
include/trace/events/cma.h line 51
Quoted 5 lines
include/trace/events/cma.h new file +5
-0+ +TP_printk ("pfn=%lu page=%p count=%lu" , + __entry->pfn, +pfn_to_page (__entry->pfn), + __entry->count)So here you print more in the
TP_printk()line than in the fast-assign side.
See above, I think it's the same case as in trace_cma_alloc() TP_printk().
Quoted 2 lines
Again I'd double check the various boundary conditions.
Sorry, I don't quite understand. Boundary conditions are already [should be] checked in cma_alloc()/cma_release, we should only pass to a trace event the information we want to be known, isn't it so?
I again terribly sorry, I also completely forgot about struct cma * being passed to trace event. I think either it should be used somehow (e.g. to print the number of CMA region) or shouldn't be passed...
Re: [PATCH v4 1/5] mm: cma: add trace events to debug physically-contiguous memory allocations
Quoted 36 lines · Stefan Strogin
Quoted 27 lines · Ingo Molnar
Quoted 12 lines · Stefan Strogin
Quoted 12 lines
include/trace/events/cma.h new file +12
-0+TRACE_EVENT(cma_alloc, + + TP_PROTO(struct cma *cma, struct page *page, int count), + + TP_ARGS(cma, page, count), + + TP_STRUCT__entry( + __field(struct page *, page) + __field(unsigned long, count) + ), + + TP_fast_assign(Quoted 8 lines
include/trace/events/cma.h line 29
Quoted 8 lines
include/trace/events/cma.h new file +8
-0+ __entry->page = page; + __entry->count = count; + ), + +TP_printk ("page=%p pfn=%lu count=%lu" , + __entry->page, + __entry->page ?page_to_pfn (__entry->page) :0 , + __entry->count)So I'm wondering, the fast-assign side is not equivalent to the
TP_printk()side:Quoted 6 lines
Quoted 2 lines
include/trace/events/cma.h line 28
Quoted 2 lines
include/trace/events/cma.h new file +2
-0+ __entry->page = page; + __entry->page ? page_to_pfn(__entry->page) : 0,to me it seems it would be useful if MM tracing standardized on pfn printing. Just like you did for
trace_cma_release().
Quoted 5 lines
Hello Ingo, thank you for the reply.
I afraid there is no special sense in printing both struct page * and pfn. Butcma_alloc()returns struct page *,cma_releasereceives struct page *, andpr_debugsin these functions print struct page *. Maybe it would be better to print the same here too?
So will the tracepoints primarily log 'struct page *'?
If yes, my question is: why not log pfn? pfn is much more informative (it's a hardware property of the page, not a kernel-internal descriptor like 'struct page *') , and it tells us (without knowing the layout of the kernel) which NUMA node a given area lies on, etc.
Or do other mm tracepoints already (mistakenly) use 'struct page *'?
Quoted 6 lines
Quoted 2 lines
Again I'd double check the various boundary conditions.
Sorry, I don't quite understand. Boundary conditions are already [should be] checked in cma_alloc()/cma_release, we should only pass to a trace event the information we want to be known, isn't it so?
No, I mean tracing info boundary conditions: what is returned when no such page is allocated, what is returned when pfn #0 is allocated, etc.
Thanks,
Ingo
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v4 2/5 mm: cma: add number of pages to debug message in cma_release()
In reply to Stefan StroginIt's more useful to print address and number of pages which are being released, not only address.
--- mm/cma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/cma.c +1 -1
@@ -439,7 +439,7 @@ bool cma_release(struct cma *cma, const struct page *pages, unsigned int count)if (!cma || !pages)return false; -pr_debug ("%s(page %p)\n" , __func__, (void *)pages); +pr_debug ("%s(page %p, count %d)\n" , __func__, (void *)pages, count); pfn =page_to_pfn (pages);
Signature · 7 lines
2.1.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v4 3/5 stacktrace: add seq_print_stack_trace()
In reply to Stefan StroginAdd a function seq_print_stack_trace() which prints stacktraces to seq_files.
--- include/linux/stacktrace.h | 4 ++++ kernel/stacktrace.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+)
include/linux/stacktrace.h +4 -0
@@ -2,6 +2,7 @@#define __LINUX_STACKTRACE_H#include <linux/types.h> +#include <linux/seq_file.h> struct task_struct ;struct pt_regs ;
@@ -22,6 +23,8 @@ extern void save_stack_trace_tsk(struct task_struct *tsk,extern void print_stack_trace (struct stack_trace *trace,int spaces);extern int snprint_stack_trace (char *buf,size_t size,struct stack_trace *trace,int spaces); +extern void seq_print_stack_trace (struct seq_file *m, +struct stack_trace *trace,int spaces);#ifdef CONFIG_USER_STACKTRACE_SUPPORT extern void save_stack_trace_user (struct stack_trace *trace);
@@ -35,6 +38,7 @@ extern void save_stack_trace_user(struct stack_trace *trace);# define save_stack_trace_user (trace) do { } while (0)# define print_stack_trace (trace, spaces) do { } while (0)# define snprint_stack_trace (buf, size, trace, spaces) do { } while (0) +# define seq_print_stack_trace (m, trace, spaces) do { } while (0)#endif #endif
kernel/stacktrace.c +17 -0
@@ -57,6 +57,23 @@ int snprint_stack_trace(char *buf, size_t size, }EXPORT_SYMBOL_GPL (snprint_stack_trace); +void seq_print_stack_trace (struct seq_file *m,struct stack_trace *trace, +int spaces) +{ +int i; + +if (WARN_ON (!trace->entries)) +return ; + +for (i =0 ; i < trace->nr_entries; i++) { +unsigned long ip = trace->entries[i]; + +seq_printf (m,"%*c[<%p>] %pS\n" ,1 + spaces,' ' , + (void *) ip, (void *) ip); + } +} +EXPORT_SYMBOL_GPL (seq_print_stack_trace); +/* * Architectures that do not implement save_stack_trace_tsk or * save_stack_trace_regs get this weak alias and a once-per-bootup warning
Signature · 7 lines
2.1.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 3/5] stacktrace: add seq_print_stack_trace()
Quoted 4 lines · Stefan Strogin
Add a function
seq_print_stack_trace()which prints stacktraces toseq_files.Signed-off-by Stefan Strogin <[email protected]>Reviewed-by SeongJae Park <[email protected]>
Quoted 65 lines
--- include/linux/stacktrace.h | 4 ++++ kernel/stacktrace.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+)include/linux/stacktrace.h +4
-0@@ -2,6 +2,7 @@#define __LINUX_STACKTRACE_H#include <linux/types.h> +#include <linux/seq_file.h> struct task_struct ;struct pt_regs ;@@ -22,6 +23,8 @@ extern void save_stack_trace_tsk(struct task_struct *tsk,extern void print_stack_trace (struct stack_trace *trace,int spaces);extern int snprint_stack_trace (char *buf,size_t size,struct stack_trace *trace,int spaces); +extern void seq_print_stack_trace (struct seq_file *m, +struct stack_trace *trace,int spaces);#ifdef CONFIG_USER_STACKTRACE_SUPPORT extern void save_stack_trace_user (struct stack_trace *trace);@@ -35,6 +38,7 @@ extern void save_stack_trace_user(struct stack_trace *trace);# define save_stack_trace_user (trace) do { } while (0)# define print_stack_trace (trace, spaces) do { } while (0)# define snprint_stack_trace (buf, size, trace, spaces) do { } while (0) +# define seq_print_stack_trace (m, trace, spaces) do { } while (0)#endif #endif kernel/stacktrace.c +17
-0@@ -57,6 +57,23 @@ int snprint_stack_trace(char *buf, size_t size, }EXPORT_SYMBOL_GPL (snprint_stack_trace); +void seq_print_stack_trace (struct seq_file *m,struct stack_trace *trace, +int spaces) +{ +int i; + +if (WARN_ON (!trace->entries)) +return ; + +for (i =0 ; i < trace->nr_entries; i++) { +unsigned long ip = trace->entries[i]; + +seq_printf (m,"%*c[<%p>] %pS\n" ,1 + spaces,' ' , + (void *) ip, (void *) ip); + } +} +EXPORT_SYMBOL_GPL (seq_print_stack_trace); +/* * Architectures that do not implement save_stack_trace_tsk or * save_stack_trace_regs get this weak alias and a once-per-bootup warning Signature · 1 line
2.1.0
Signature · 10 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +--<[email protected]>--<xmpp:[email protected]>--ooO--(_)--Ooo-- -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v4 4/5 mm: cma: add list of currently allocated CMA buffers to debugfs
In reply to Stefan StroginWhen CONFIG_CMA_BUFFER_LIST is configured a file is added to debugfs:
/sys/kernel/debug/cma/cma-<N>/buffers contains a list of currently allocated CMA buffers for each CMA region (N stands for number of CMA region).
Format is:
<base_phys_addr> - <end_phys_addr> (<size> kB), allocated by <PID> (<comm>)
When CONFIG_CMA_ALLOC_STACKTRACE is configured then stack traces are saved when the allocations are made. The stack traces are added to cma/cma-<N>/buffers for each buffer list entry.
Example:
root@debian:/sys/kernel/debug/cma# cat cma-0/buffers 0x2f400000 - 0x2f417000 (92 kB), allocated by pid 1 (swapper/0) [<c1142c4b>] cma_alloc+0x1bb/0x200 [<c143d28a>] dma_alloc_from_contiguous+0x3a/0x40 [<c10079d9>] dma_generic_alloc_coherent+0x89/0x160 [<c14456ce>] dmam_alloc_coherent+0xbe/0x100 [<c1487312>] ahci_port_start+0xe2/0x210 [<c146e0e0>] ata_host_start.part.28+0xc0/0x1a0 [<c1473650>] ata_host_activate+0xd0/0x110 [<c14881bf>] ahci_host_activate+0x3f/0x170 [<c14854e4>] ahci_init_one+0x764/0xab0 [<c12e415f>] pci_device_probe+0x6f/0xd0 [<c14378a8>] driver_probe_device+0x68/0x210 [<c1437b09>] __driver_attach+0x79/0x80 [<c1435eef>] bus_for_each_dev+0x4f/0x80 [<c143749e>] driver_attach+0x1e/0x20 [<c1437197>] bus_add_driver+0x157/0x200 [<c14381bd>] driver_register+0x5d/0xf0 <...>
--- mm/Kconfig | 17 +++++ mm/cma.c | 7 ++ mm/cma.h | 14 ++++ mm/cma_debug.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 243 insertions(+), 1 deletion(-)
mm/Kconfig +17 -0
@@ -523,6 +523,23 @@ config CMA_DEBUGFS help Turns on the DebugFS interface for CMA. +config CMA_BUFFER_LIST + bool "List of currently allocated CMA buffers in debugfs" + depends on CMA_DEBUGFS + help + /sys/kernel/debug/cma/cma-<N>/buffers contains a list of currently + allocated CMA buffers for each CMA region (N stands for number of + CMA region). + Format is: + <base_phys_addr> - <end_phys_addr> (<size> kB), allocated by <PID> (<comm>) + +config CMA_ALLOC_STACKTRACE + bool "Add stack trace to CMA buffer list" + depends on CMA_BUFFER_LIST && STACKTRACE + help + Add stack traces saved at the moment of allocation for each buffer + listed in /sys/kernel/debug/cma/cma-<N>/buffers. + config CMA_AREAS int "Maximum count of the CMA areas" depends on CMA
mm/cma.c +7 -0
@@ -133,6 +133,10 @@ static int __init cma_activate_area(struct cma *cma)INIT_HLIST_HEAD (&cma->mem_head);spin_lock_init (&cma->mem_head_lock);#endif +#ifdef CONFIG_CMA_BUFFER_LIST +INIT_LIST_HEAD (&cma->buffer_list); +mutex_init (&cma->list_lock); +#endif return 0 ;
@@ -416,6 +420,8 @@ struct page *cma_alloc(struct cma *cma, unsigned int count, unsigned int align) start = bitmap_no + mask +1 ; } +if (page) +cma_buffer_list_add (cma, pfn, count);trace_cma_alloc (cma, page, count);pr_debug ("%s(): returned %p\n" , __func__, page);
@@ -451,6 +457,7 @@ bool cma_release(struct cma *cma, const struct page *pages, unsigned int count)free_contig_range (pfn, count);cma_clear_bitmap (cma, pfn, count);trace_cma_release (cma, pfn, count); +cma_buffer_list_del (cma, pfn, count);return true; }
mm/cma.h +14 -0
@@ -1,6 +1,8 @@ #ifndef __MM_CMA_H__ #define __MM_CMA_H__ +#include <linux/sched.h> + struct cma { unsigned long base_pfn; unsigned long count;
@@ -11,8 +13,20 @@ struct cma {struct hlist_head mem_head;spinlock_t mem_head_lock;#endif +#ifdef CONFIG_CMA_BUFFER_LIST +struct list_head buffer_list; +struct mutex list_lock; +#endif }; +#ifdef CONFIG_CMA_BUFFER_LIST +extern int cma_buffer_list_add (struct cma *cma,unsigned long pfn,int count); +extern void cma_buffer_list_del (struct cma *cma,unsigned long pfn,int count); +#else +#define cma_buffer_list_add (cma, pfn, count) { } +#define cma_buffer_list_del (cma, pfn, count) { } +#endif +extern struct cma cma_areas[MAX_CMA_AREAS ];extern unsigned cma_area_count;
mm/cma_debug.c +205 -1
238 lines not on this page · raw message
Signature · 7 lines
2.1.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH v4 4/5] mm: cma: add list of currently allocated CMA buffers to debugfs
Quoted 33 lines · Stefan Strogin
When
CONFIG_CMA_BUFFER_LISTis configured a file is added to debugfs:
/sys/kernel/debug/cma/cma-<N>/buffers contains a list of currently allocated CMA buffers for each CMA region (N stands for number of CMA region).Format is:
<base_phys_addr> - <end_phys_addr> (<size> kB), allocated by <PID> (<comm>)When
CONFIG_CMA_ALLOC_STACKTRACEis configured then stack traces are saved when the allocations are made. The stack traces are added to cma/cma-<N>/buffers for each buffer list entry.Example:
root@debian:/sys/kernel/debug/cma# cat cma-0/buffers 0x2f400000 - 0x2f417000 (92 kB), allocated by pid 1 (swapper/0) [<c1142c4b>] cma_alloc+0x1bb/0x200 [<c143d28a>] dma_alloc_from_contiguous+0x3a/0x40 [<c10079d9>] dma_generic_alloc_coherent+0x89/0x160 [<c14456ce>] dmam_alloc_coherent+0xbe/0x100 [<c1487312>] ahci_port_start+0xe2/0x210 [<c146e0e0>] ata_host_start.part.28+0xc0/0x1a0 [<c1473650>] ata_host_activate+0xd0/0x110 [<c14881bf>] ahci_host_activate+0x3f/0x170 [<c14854e4>] ahci_init_one+0x764/0xab0 [<c12e415f>] pci_device_probe+0x6f/0xd0 [<c14378a8>] driver_probe_device+0x68/0x210 [<c1437b09>] __driver_attach+0x79/0x80 [<c1435eef>] bus_for_each_dev+0x4f/0x80 [<c143749e>] driver_attach+0x1e/0x20 [<c1437197>] bus_add_driver+0x157/0x200 [<c14381bd>] driver_register+0x5d/0xf0 <...>
Quoted 1 line
Signed-off-by Stefan Strogin <[email protected]>
Quoted 8 lines
mm/cma_debug.c +4
-0@@ -127,6 +240,93 @@ static int cma_alloc_write(void *data, u64 val)DEFINE_SIMPLE_ATTRIBUTE (cma_alloc_fops,NULL , cma_alloc_write,"%llu\n" ); +#ifdef CONFIG_CMA_BUFFER_LIST +static void *s_start (struct seq_file *seq,loff_t *ppos) +{ +struct cma *cma = seq->private;
mm/cma_debug.c static int cma_alloc_write(void *data, u64 val) · line 256
Quoted 10 lines
mm/cma_debug.c +10
-0+struct cma_buffer *cmabuf; +loff_t n = *ppos; + +mutex_lock (&cma->list_lock); + cmabuf =list_first_entry (&cma->buffer_list,typeof (*cmabuf), list); +list_for_each_entry (cmabuf, &cma->buffer_list, list) +if (n-- ==0 ) +return cmabuf; + +return 0 ;
return NULL;
Quoted 1 line
(quoted diff) +1
-0+}
Signature · 10 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +--<[email protected]>--<xmpp:[email protected]>--ooO--(_)--Ooo-- -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v4 5/5 mm: cma: add functions to get region pages counters
In reply to Stefan StroginFrom: Dmitry Safonov <[email protected]>
Here are two functions that provide interface to compute/get used size and size of biggest free chunk in cma region. Add that information to debugfs.
--- include/linux/cma.h | 2 ++ mm/cma.c | 30 ++++++++++++++++++++++++++++++ mm/cma_debug.c | 24 ++++++++++++++++++++++++ 3 files changed, 56 insertions(+)
include/linux/cma.h +2 -0
@@ -18,6 +18,8 @@ struct cma;extern unsigned long totalcma_pages;extern phys_addr_t cma_get_base (const struct cma *cma);extern unsigned long cma_get_size (const struct cma *cma); +extern unsigned long cma_get_used (struct cma *cma); +extern unsigned long cma_get_maxchunk (struct cma *cma); extern int __init cma_declare_contiguous(phys_addr_t base, phys_addr_t size, phys_addr_t limit,
mm/cma.c +30 -0
@@ -53,6 +53,36 @@ unsigned long cma_get_size(const struct cma *cma)return cma->count <<PAGE_SHIFT ; } +unsigned long cma_get_used (struct cma *cma) +{ +unsigned long ret =0 ; + +mutex_lock (&cma->lock); +/* pages counter is smaller than sizeof(int) */ + ret =bitmap_weight (cma->bitmap, (int )cma->count); +mutex_unlock (&cma->lock); + +return ret << cma->order_per_bit; +} + +unsigned long cma_get_maxchunk (struct cma *cma) +{ +unsigned long maxchunk =0 ; +unsigned long start, end =0 ; + +mutex_lock (&cma->lock); +for (;;) { + start =find_next_zero_bit (cma->bitmap, cma->count, end); +if (start >= cma->count) +break ; + end =find_next_bit (cma->bitmap, cma->count, start); + maxchunk =max (end - start, maxchunk); + } +mutex_unlock (&cma->lock); + +return maxchunk << cma->order_per_bit; +} +static unsigned long cma_bitmap_aligned_mask (const struct cma *cma,int align_order) {
mm/cma_debug.c +24 -0
@@ -146,6 +146,28 @@ static int cma_debugfs_get(void *data, u64 *val)DEFINE_SIMPLE_ATTRIBUTE (cma_debugfs_fops, cma_debugfs_get,NULL ,"%llu\n" ); +static int cma_used_get (void *data,u64 *val) +{ +struct cma *cma = data; + + *val =cma_get_used (cma); + +return 0 ; +} + +DEFINE_SIMPLE_ATTRIBUTE (cma_used_fops, cma_used_get,NULL ,"%llu\n" ); + +static int cma_maxchunk_get (void *data,u64 *val) +{ +struct cma *cma = data; + + *val =cma_get_maxchunk (cma); + +return 0 ; +} + +DEFINE_SIMPLE_ATTRIBUTE (cma_maxchunk_fops, cma_maxchunk_get,NULL ,"%llu\n" ); +static void cma_add_to_cma_mem_list (struct cma *cma,struct cma_mem *mem) {spin_lock (&cma->mem_head_lock);
@@ -349,6 +371,8 @@ static void cma_debugfs_add_one(struct cma *cma, int idx) &cma->count, &cma_debugfs_fops);debugfs_create_file ("order_per_bit" ,S_IRUGO , tmp, &cma->order_per_bit, &cma_debugfs_fops); +debugfs_create_file ("used" ,S_IRUGO , tmp, cma, &cma_used_fops); +debugfs_create_file ("maxchunk" ,S_IRUGO , tmp, cma, &cma_maxchunk_fops);#ifdef CONFIG_CMA_BUFFER_LIST debugfs_create_file ("buffers" ,S_IRUGO , tmp, cma, &cma_buffers_fops);
Signature · 1 line
2.1.0
Quoted 13 lines · Stefan Strogin
Hi all.
Here is the fourth version of a patch set that adds some debugging facility for CMA.
This patch set is based on next-20150316. It is also available on git:
git://github.com/stefanstrogin/linux-b cmainfo-v4We want an interface to see a list of currently allocated CMA buffers and some useful information about them (like
/proc/vmallocinfobut for physically contiguous buffers allocated with CMA).
Quoted 7 lines
For example. We want a big (megabytes) CMA buffer to be allocated in runtime in default CMA region. If someone already uses CMA then the big allocation could fail. If it happened then with such an interface we could find who used CMA at the moment of failure, who caused fragmentation and so on. Ftrace also would be helpful here, but with ftrace we can see the whole history of allocations and releases, whereas with this patch set we can see a snapshot of CMA region with actual information about its allocations.
Hello,
Hmm... I still don't think that this is really helpful to find root cause of fragmentation. Think about following example.
Assume 1024 MB CMA region.
128 MB allocation * 4
1 MB allocation
128 MB allocation
128 MB release * 4 (first 4)
try 512 MB allocation
With above sequences, fragmentation happens and 512 MB allocation would be failed. We can get information about 1 MB allocation and 128 MB one from the buffer list as you suggested, but, fragmentation are related to whole sequence of allocation/free history, not snapshot of allocation.
Thanks.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 34 lines · Joonsoo Kim
Quoted 13 lines · Stefan Strogin
Quoted 13 lines
Hi all.
Here is the fourth version of a patch set that adds some debugging facility for CMA.
This patch set is based on next-20150316. It is also available on git:
git://github.com/stefanstrogin/linux-b cmainfo-v4We want an interface to see a list of currently allocated CMA buffers and some useful information about them (like
/proc/vmallocinfobut for physically contiguous buffers allocated with CMA).Quoted 7 lines
Quoted 7 lines
For example. We want a big (megabytes) CMA buffer to be allocated in runtime in default CMA region. If someone already uses CMA then the big allocation could fail. If it happened then with such an interface we could find who used CMA at the moment of failure, who caused fragmentation and so on. Ftrace also would be helpful here, but with ftrace we can see the whole history of allocations and releases, whereas with this patch set we can see a snapshot of CMA region with actual information about its allocations.
Hello,
Hmm... I still don't think that this is really helpful to find root cause of fragmentation. Think about following example.
Assume 1024 MB CMA region.
128 MB allocation * 4
1 MB allocation
128 MB allocation
128 MB release * 4 (first 4)
try 512 MB allocation
Quoted 4 lines
With above sequences, fragmentation happens and 512 MB allocation would be failed. We can get information about 1 MB allocation and 128 MB one from the buffer list as you suggested, but, fragmentation are related to whole sequence of allocation/free history, not snapshot of allocation.
This is solvable by dumping task->comm in the tracepoint patch (1/5), right?
Thanks,
Sasha
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 35 lines · Sasha Levin
Quoted 34 lines · Joonsoo Kim
Quoted 13 lines · Stefan Strogin
Quoted 13 lines
Hi all.
Here is the fourth version of a patch set that adds some debugging facility for CMA.
This patch set is based on next-20150316. It is also available on git:
git://github.com/stefanstrogin/linux-b cmainfo-v4We want an interface to see a list of currently allocated CMA buffers and some useful information about them (like
/proc/vmallocinfobut for physically contiguous buffers allocated with CMA).Quoted 7 lines
Quoted 7 lines
For example. We want a big (megabytes) CMA buffer to be allocated in runtime in default CMA region. If someone already uses CMA then the big allocation could fail. If it happened then with such an interface we could find who used CMA at the moment of failure, who caused fragmentation and so on. Ftrace also would be helpful here, but with ftrace we can see the whole history of allocations and releases, whereas with this patch set we can see a snapshot of CMA region with actual information about its allocations.
Hello,
Hmm... I still don't think that this is really helpful to find root cause of fragmentation. Think about following example.
Assume 1024 MB CMA region.
128 MB allocation * 4
1 MB allocation
128 MB allocation
128 MB release * 4 (first 4)
try 512 MB allocation
Quoted 6 lines
Quoted 4 lines
With above sequences, fragmentation happens and 512 MB allocation would be failed. We can get information about 1 MB allocation and 128 MB one from the buffer list as you suggested, but, fragmentation are related to whole sequence of allocation/free history, not snapshot of allocation.
This is solvable by dumping
task->commin the tracepoint patch (1/5), right?
Yes, it can be solved by 1/5.
I mean that I'm not sure patch 4/5 is really needed or not.
Thanks.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>