summaryrefslogtreecommitdiffstats
path: root/library/include/slabinfo.h
blob: f63ca79e83cafa98401be8d565e6144c8f9516db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * slabinfo.h - slab pools related declarations for libproc2
 *
 * Copyright © 2015-2023 Jim Warner <james.warner@comcast.net>
 * Copyright © 2015-2023 Craig Small <csmall@dropbear.xyz>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef PROCPS_SLABINFO_H
#define PROCPS_SLABINFO_H

#ifdef __cplusplus
extern "C "{
#endif

enum slabinfo_item {
    SLABINFO_noop,              //        ( never altered )
    SLABINFO_extra,             //        ( reset to zero )
                                //  returns        origin, see proc(5)
                                //  -------        -------------------
    SLAB_NAME,                  //      str        /proc/slabinfo
    SLAB_NUM_OBJS,              //    u_int         "
    SLAB_ACTIVE_OBJS,           //    u_int         "
    SLAB_OBJ_SIZE,              //    u_int         "
    SLAB_OBJ_PER_SLAB,          //    u_int         "
    SLAB_NUMS_SLABS,            //    u_int         "
    SLAB_ACTIVE_SLABS,          //    u_int         "
    SLAB_PAGES_PER_SLAB,        //    u_int         "
    SLAB_PERCENT_USED,          //    u_int        derived from ACTIVE_OBJS / NUM_OBJS
    SLAB_SIZE_TOTAL,            //   ul_int        derived from page size * NUMS_SLABS * PAGES_PER_SLAB

    SLABS_CACHES_TOTAL,         //    u_int        derived from all caches
    SLABS_CACHES_ACTIVE,        //    u_int         "
    SLABS_NUM_OBJS,             //    u_int         "
    SLABS_ACTIVE_OBJS,          //    u_int         "
    SLABS_OBJ_SIZE_AVG,         //    u_int         "
    SLABS_OBJ_SIZE_MIN,         //    u_int         "
    SLABS_OBJ_SIZE_MAX,         //    u_int         "
    SLABS_NUMS_SLABS,           //    u_int         "
    SLABS_ACTIVE_SLABS,         //    u_int         "
    SLABS_PAGES_TOTAL,          //    u_int         "
    SLABS_SIZE_ACTIVE,          //   ul_int         "
    SLABS_SIZE_TOTAL,           //   ul_int         "

    SLABS_DELTA_CACHES_TOTAL,   //    s_int        derived from above
    SLABS_DELTA_CACHES_ACTIVE,  //    s_int         "
    SLABS_DELTA_NUM_OBJS,       //    s_int         "
    SLABS_DELTA_ACTIVE_OBJS,    //    s_int         "
    SLABS_DELTA_OBJ_SIZE_AVG,   //    s_int         "
    SLABS_DELTA_OBJ_SIZE_MIN,   //    s_int         "
    SLABS_DELTA_OBJ_SIZE_MAX,   //    s_int         "
    SLABS_DELTA_NUMS_SLABS,     //    s_int         "
    SLABS_DELTA_ACTIVE_SLABS,   //    s_int         "
    SLABS_DELTA_PAGES_TOTAL,    //    s_int         "
    SLABS_DELTA_SIZE_ACTIVE,    //    s_int         "
    SLABS_DELTA_SIZE_TOTAL      //    s_int         "
};

enum slabinfo_sort_order {
    SLABINFO_SORT_ASCEND   = +1,
    SLABINFO_SORT_DESCEND  = -1
};


struct slabinfo_result {
    enum slabinfo_item item;
    union {
        signed int     s_int;
        unsigned int   u_int;
        unsigned long  ul_int;
        char          *str;
    } result;
};

struct slabinfo_stack {
    struct slabinfo_result *head;
};

struct slabinfo_reaped {
    int total;
    struct slabinfo_stack **stacks;
};

struct slabinfo_info;


#define SLABINFO_GET( info, actual_enum, type ) ( { \
    struct slabinfo_result *r = procps_slabinfo_get( info, actual_enum ); \
    r ? r->result . type : 0; } )

#define SLABINFO_VAL( relative_enum, type, stack, info ) \
    stack -> head [ relative_enum ] . result . type


int procps_slabinfo_new   (struct slabinfo_info **info);
int procps_slabinfo_ref   (struct slabinfo_info  *info);
int procps_slabinfo_unref (struct slabinfo_info **info);

struct slabinfo_result *procps_slabinfo_get (
    struct slabinfo_info *info,
    enum slabinfo_item item);

struct slabinfo_reaped *procps_slabinfo_reap (
    struct slabinfo_info *info,
    enum slabinfo_item *items,
    int numitems);

struct slabinfo_stack *procps_slabinfo_select (
    struct slabinfo_info *info,
    enum slabinfo_item *items,
    int numitems);

struct slabinfo_stack **procps_slabinfo_sort (
    struct slabinfo_info *info,
    struct slabinfo_stack *stacks[],
    int numstacked,
    enum slabinfo_item sortitem,
    enum slabinfo_sort_order order);


#ifdef XTRA_PROCPS_DEBUG
# include "xtra-procps-debug.h"
#endif
#ifdef __cplusplus
}
#endif
#endif