Back to home page

OSCL-LXR

 
 

    


0001 .. _page_owner:
0002 
0003 ==================================================
0004 page owner: Tracking about who allocated each page
0005 ==================================================
0006 
0007 Introduction
0008 ============
0009 
0010 page owner is for the tracking about who allocated each page.
0011 It can be used to debug memory leak or to find a memory hogger.
0012 When allocation happens, information about allocation such as call stack
0013 and order of pages is stored into certain storage for each page.
0014 When we need to know about status of all pages, we can get and analyze
0015 this information.
0016 
0017 Although we already have tracepoint for tracing page allocation/free,
0018 using it for analyzing who allocate each page is rather complex. We need
0019 to enlarge the trace buffer for preventing overlapping until userspace
0020 program launched. And, launched program continually dump out the trace
0021 buffer for later analysis and it would change system behaviour with more
0022 possibility rather than just keeping it in memory, so bad for debugging.
0023 
0024 page owner can also be used for various purposes. For example, accurate
0025 fragmentation statistics can be obtained through gfp flag information of
0026 each page. It is already implemented and activated if page owner is
0027 enabled. Other usages are more than welcome.
0028 
0029 page owner is disabled by default. So, if you'd like to use it, you need
0030 to add "page_owner=on" to your boot cmdline. If the kernel is built
0031 with page owner and page owner is disabled in runtime due to not enabling
0032 boot option, runtime overhead is marginal. If disabled in runtime, it
0033 doesn't require memory to store owner information, so there is no runtime
0034 memory overhead. And, page owner inserts just two unlikely branches into
0035 the page allocator hotpath and if not enabled, then allocation is done
0036 like as the kernel without page owner. These two unlikely branches should
0037 not affect to allocation performance, especially if the static keys jump
0038 label patching functionality is available. Following is the kernel's code
0039 size change due to this facility.
0040 
0041 - Without page owner::
0042 
0043    text    data     bss     dec     hex filename
0044    48392   2333     644   51369    c8a9 mm/page_alloc.o
0045 
0046 - With page owner::
0047 
0048    text    data     bss     dec     hex filename
0049    48800   2445     644   51889    cab1 mm/page_alloc.o
0050    6662     108      29    6799    1a8f mm/page_owner.o
0051    1025       8       8    1041     411 mm/page_ext.o
0052 
0053 Although, roughly, 8 KB code is added in total, page_alloc.o increase by
0054 520 bytes and less than half of it is in hotpath. Building the kernel with
0055 page owner and turning it on if needed would be great option to debug
0056 kernel memory problem.
0057 
0058 There is one notice that is caused by implementation detail. page owner
0059 stores information into the memory from struct page extension. This memory
0060 is initialized some time later than that page allocator starts in sparse
0061 memory system, so, until initialization, many pages can be allocated and
0062 they would have no owner information. To fix it up, these early allocated
0063 pages are investigated and marked as allocated in initialization phase.
0064 Although it doesn't mean that they have the right owner information,
0065 at least, we can tell whether the page is allocated or not,
0066 more accurately. On 2GB memory x86-64 VM box, 13343 early allocated pages
0067 are catched and marked, although they are mostly allocated from struct
0068 page extension feature. Anyway, after that, no page is left in
0069 un-tracking state.
0070 
0071 Usage
0072 =====
0073 
0074 1) Build user-space helper::
0075 
0076         cd tools/vm
0077         make page_owner_sort
0078 
0079 2) Enable page owner: add "page_owner=on" to boot cmdline.
0080 
0081 3) Do the job that you want to debug.
0082 
0083 4) Analyze information from page owner::
0084 
0085         cat /sys/kernel/debug/page_owner > page_owner_full.txt
0086         ./page_owner_sort page_owner_full.txt sorted_page_owner.txt
0087 
0088    The general output of ``page_owner_full.txt`` is as follows::
0089 
0090         Page allocated via order XXX, ...
0091         PFN XXX ...
0092         // Detailed stack
0093 
0094         Page allocated via order XXX, ...
0095         PFN XXX ...
0096         // Detailed stack
0097 
0098    The ``page_owner_sort`` tool ignores ``PFN`` rows, puts the remaining rows
0099    in buf, uses regexp to extract the page order value, counts the times
0100    and pages of buf, and finally sorts them according to the parameter(s).
0101 
0102    See the result about who allocated each page
0103    in the ``sorted_page_owner.txt``. General output::
0104 
0105         XXX times, XXX pages:
0106         Page allocated via order XXX, ...
0107         // Detailed stack
0108 
0109    By default, ``page_owner_sort`` is sorted according to the times of buf.
0110    If you want to sort by the page nums of buf, use the ``-m`` parameter.
0111    The detailed parameters are:
0112 
0113    fundamental function::
0114 
0115         Sort:
0116                 -a              Sort by memory allocation time.
0117                 -m              Sort by total memory.
0118                 -p              Sort by pid.
0119                 -P              Sort by tgid.
0120                 -n              Sort by task command name.
0121                 -r              Sort by memory release time.
0122                 -s              Sort by stack trace.
0123                 -t              Sort by times (default).
0124                 --sort <order>  Specify sorting order.  Sorting syntax is [+|-]key[,[+|-]key[,...]].
0125                                 Choose a key from the **STANDARD FORMAT SPECIFIERS** section. The "+" is
0126                                 optional since default direction is increasing numerical or lexicographic
0127                                 order. Mixed use of abbreviated and complete-form of keys is allowed.
0128 
0129                 Examples:
0130                                 ./page_owner_sort <input> <output> --sort=n,+pid,-tgid
0131                                 ./page_owner_sort <input> <output> --sort=at
0132 
0133    additional function::
0134 
0135         Cull:
0136                 --cull <rules>
0137                                 Specify culling rules.Culling syntax is key[,key[,...]].Choose a
0138                                 multi-letter key from the **STANDARD FORMAT SPECIFIERS** section.
0139 
0140                 <rules> is a single argument in the form of a comma-separated list,
0141                 which offers a way to specify individual culling rules.  The recognized
0142                 keywords are described in the **STANDARD FORMAT SPECIFIERS** section below.
0143                 <rules> can be specified by the sequence of keys k1,k2, ..., as described in
0144                 the STANDARD SORT KEYS section below. Mixed use of abbreviated and
0145                 complete-form of keys is allowed.
0146 
0147                 Examples:
0148                                 ./page_owner_sort <input> <output> --cull=stacktrace
0149                                 ./page_owner_sort <input> <output> --cull=st,pid,name
0150                                 ./page_owner_sort <input> <output> --cull=n,f
0151 
0152         Filter:
0153                 -f              Filter out the information of blocks whose memory has been released.
0154 
0155         Select:
0156                 --pid <pidlist>         Select by pid. This selects the blocks whose process ID
0157                                         numbers appear in <pidlist>.
0158                 --tgid <tgidlist>       Select by tgid. This selects the blocks whose thread
0159                                         group ID numbers appear in <tgidlist>.
0160                 --name <cmdlist>        Select by task command name. This selects the blocks whose
0161                                         task command name appear in <cmdlist>.
0162 
0163                 <pidlist>, <tgidlist>, <cmdlist> are single arguments in the form of a comma-separated list,
0164                 which offers a way to specify individual selecting rules.
0165 
0166 
0167                 Examples:
0168                                 ./page_owner_sort <input> <output> --pid=1
0169                                 ./page_owner_sort <input> <output> --tgid=1,2,3
0170                                 ./page_owner_sort <input> <output> --name name1,name2
0171 
0172 STANDARD FORMAT SPECIFIERS
0173 ==========================
0174 ::
0175 
0176   For --sort option:
0177 
0178         KEY             LONG            DESCRIPTION
0179         p               pid             process ID
0180         tg              tgid            thread group ID
0181         n               name            task command name
0182         st              stacktrace      stack trace of the page allocation
0183         T               txt             full text of block
0184         ft              free_ts         timestamp of the page when it was released
0185         at              alloc_ts        timestamp of the page when it was allocated
0186         ator            allocator       memory allocator for pages
0187 
0188   For --curl option:
0189 
0190         KEY             LONG            DESCRIPTION
0191         p               pid             process ID
0192         tg              tgid            thread group ID
0193         n               name            task command name
0194         f               free            whether the page has been released or not
0195         st              stacktrace      stack trace of the page allocation
0196         ator            allocator       memory allocator for pages