File Coverage

lib/Mojo/IOLoop/ReadWriteProcess/CGroup/v1/Memory.pm
Criterion Covered Total %
statement 29 29 100.0
branch n/a
condition n/a
subroutine 25 25 100.0
pod 0 23 0.0
total 54 77 70.1


line stmt bran cond sub pod time code
1             package Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Memory;
2              
3 15     15   105 use Mojo::Base -base;
  15         32  
  15         91  
4              
5             use constant {
6              
7             # show various statistics
8 15         16044 STAT_INTERFACE => 'memory.stat',
9              
10             # show current usage for memory
11             CURRENT_INTERFACE => 'memory.usage_in_bytes',
12              
13             # show current usage for memory+Swap
14             CURRENT_AND_SWAP_INTERFACE => 'memory.memsw.usage_in_bytes',
15              
16             # set/show limit of memory usage
17             LIMIT_INTERFACE => 'memory.limit_in_bytes',
18              
19             # show current usage for memory
20             LIMIT_AND_SWAP_INTERFACE => 'memory.memsw.limit_in_bytes',
21              
22             # show the number of memory usage hits limits
23             FAILCNT_INTERFACE => 'memory.failcnt',
24              
25             # show max memory usage recorded
26             MAX_RECORDED_INTERFACE => 'memory.max_usage_in_bytes',
27              
28             # show max memory+Swap usage recorded
29             MAX_RECORDED_AND_SWAP_INTERFACE => 'memory.memsw.max_usage_in_bytes',
30              
31             # set/show soft limit of memory usage
32             SOFT_LIMIT_INTERFACE => 'memory.soft_limit_in_bytes',
33              
34             # set/show hierarchical account enabled
35             USE_HIERARCHY_INTERFACE => 'memory.use_hierarchy',
36              
37             # trigger forced move charge to parent
38             FORCE_EMPTY_INTERFACE => 'memory.force_empty',
39              
40             # set memory pressure notifications
41             PRESSURE_LEVEL_INTERFACE => 'memory.pressure_level',
42              
43             # set/show swappiness parameter of vmscan (See sysctl's vm.swappiness)
44             SWAPPINESS_INTERFACE => 'memory.swappiness',
45              
46             # set/show controls of moving charges
47             MOVE_CHARGE_AT_IMMIGRATE_INTERFACE => 'memory.move_charge_at_immigrate',
48              
49             # set/show oom controls.
50             OOM_CONTROL_INTERFACE => 'memory.oom_control',
51              
52             # show the number of memory usage per numa node
53             NUMA_STAT_INTERFACE => 'memory.numa_stat',
54              
55             # set/show hard limit for kernel memory
56             KMEM_LIMIT_INTERFACE => 'memory.kmem.limit_in_bytes',
57              
58             # show current kernel memory allocation
59             KMEM_USAGE_INTERFACE => 'memory.kmem.usage_in_bytes',
60              
61             # show the number of kernel memory usage hits limits
62             KMEM_FAILCNT_INTERFACE => 'memory.kmem.failcnt',
63              
64             # show max kernel memory usage recorded
65             KMEM_MAX_RECORDED_INTERFACE => 'memory.kmem.max_usage_in_bytes',
66              
67             # set/show hard limit for tcp buf memory
68             KMEM_TCP_LIMIT_INTERFACE => 'memory.kmem.tcp.limit_in_bytes',
69              
70             # show current tcp buf memory allocation
71             KMEM_TCP_USAGE_INTERFACE => 'memory.kmem.tcp.usage_in_bytes',
72              
73             # show the number of tcp buf memory usage hits limits
74             KMEM_TCP_FAILCNT_INTERFACE => 'memory.kmem.tcp.failcnt',
75              
76             # show max tcp buf memory usage recorded
77             KMEM_TCP_MAX_USAGE_INTERFACE => 'memory.kmem.tcp.max_usage_in_bytes',
78              
79 15     15   3142 };
  15         31  
80              
81             has cgroup => sub { Mojo::IOLoop::ReadWriteProcess::CGroup::v1->new };
82              
83 1     1 0 867 sub current { shift->cgroup->_list(CURRENT_INTERFACE) }
84 1     1 0 829 sub stat { shift->cgroup->_list(STAT_INTERFACE) }
85 1     1 0 830 sub swap_current { shift->cgroup->_list(CURRENT_AND_SWAP_INTERFACE) }
86 2     2 0 1676 sub limit { shift->cgroup->_setget(LIMIT_INTERFACE, @_) }
87 1     1 0 828 sub failcnt { shift->cgroup->_list(FAILCNT_INTERFACE) }
88 1     1 0 827 sub observed_max_usage { shift->cgroup->_list(MAX_RECORDED_INTERFACE) }
89              
90             sub observed_swap_max_usage {
91 1     1 0 826 shift->cgroup->_list(MAX_RECORDED_AND_SWAP_INTERFACE);
92             }
93 2     2 0 1634 sub use_hierarchy { shift->cgroup->_setget(USE_HIERARCHY_INTERFACE, @_) }
94 2     2 0 1665 sub soft_limit { shift->cgroup->_setget(SOFT_LIMIT_INTERFACE, @_) }
95 2     2 0 1658 sub force_empty { shift->cgroup->_setget(FORCE_EMPTY_INTERFACE, @_) }
96 2     2 0 1713 sub pressure_level { shift->cgroup->_setget(PRESSURE_LEVEL_INTERFACE, @_) }
97 2     2 0 1705 sub swappiness { shift->cgroup->_setget(SWAPPINESS_INTERFACE, @_) }
98              
99             sub move_charge {
100 2     2 0 1740 shift->cgroup->_setget(MOVE_CHARGE_AT_IMMIGRATE_INTERFACE, @_);
101             }
102 2     2 0 1680 sub oom_control { shift->cgroup->_setget(OOM_CONTROL_INTERFACE, @_) }
103 1     1 0 860 sub numa_stat { shift->cgroup->_list(NUMA_STAT_INTERFACE) }
104 2     2 0 1726 sub kmem_limit { shift->cgroup->_setget(KMEM_LIMIT_INTERFACE, @_) }
105 1     1 0 836 sub kmem_usage { shift->cgroup->_list(KMEM_USAGE_INTERFACE) }
106 1     1 0 838 sub kmem_failcnt { shift->cgroup->_list(KMEM_FAILCNT_INTERFACE) }
107 1     1 0 853 sub kmem_max_usage { shift->cgroup->_list(KMEM_MAX_RECORDED_INTERFACE) }
108 2     2 0 1664 sub kmem_tcp_limit { shift->cgroup->_setget(KMEM_TCP_LIMIT_INTERFACE, @_) }
109 1     1 0 835 sub kmem_tcp_usage { shift->cgroup->_list(KMEM_TCP_USAGE_INTERFACE) }
110 1     1 0 838 sub kmem_tcp_failcnt { shift->cgroup->_list(KMEM_TCP_FAILCNT_INTERFACE) }
111 1     1 0 823 sub kmem_tcp_max_usage { shift->cgroup->_list(KMEM_TCP_MAX_USAGE_INTERFACE) }
112              
113             1;
114              
115             =encoding utf-8
116              
117             =head1 NAME
118              
119             Mojo::IOLoop::ReadWriteProcess::CGroup::v1::Memory - CGroups v1 Memory Controller
120              
121             =head1 SYNOPSIS
122              
123             use Mojo::IOLoop::ReadWriteProcess::CGroup::v1;
124              
125             my $cgroup = Mojo::IOLoop::ReadWriteProcess::CGroup::v1->new( name => "test" );
126              
127             $cgroup->memory->current;
128              
129             =head1 DESCRIPTION
130              
131             This module uses features that are only available on Linux,
132             and requires cgroups and capability for unshare syscalls to achieve pid isolation.
133              
134             =head1 METHODS
135              
136             L inherits all methods from L and implements
137             the following new ones.
138              
139             =head1 LICENSE
140              
141             Copyright (C) Ettore Di Giacinto.
142              
143             This library is free software; you can redistribute it and/or modify
144             it under the same terms as Perl itself.
145              
146             =head1 AUTHOR
147              
148             Ettore Di Giacinto Eedigiacinto@suse.comE
149              
150             =cut