1
00:00:00,690 --> 00:00:02,700
In this lesson, you're going to be introduced

2
00:00:02,700 --> 00:00:05,070
to some common CPU and memory issues

3
00:00:05,070 --> 00:00:06,450
that occur within Linux,

4
00:00:06,450 --> 00:00:08,189
as well as important command tools

5
00:00:08,189 --> 00:00:09,693
that you can use to troubleshoot issues

6
00:00:09,693 --> 00:00:12,030
that you may find along the way.

7
00:00:12,030 --> 00:00:14,400
After all, sometimes unexpected behavior

8
00:00:14,400 --> 00:00:16,079
on the server side can occur

9
00:00:16,079 --> 00:00:17,010
and this can be caused

10
00:00:17,010 --> 00:00:19,680
by resource limitations on your system.

11
00:00:19,680 --> 00:00:20,880
Linux, by design,

12
00:00:20,880 --> 00:00:23,310
aims to use all of the available physical memory

13
00:00:23,310 --> 00:00:25,080
as efficiently as possible.

14
00:00:25,080 --> 00:00:28,500
But CPU and memory are two fundamental computing concepts

15
00:00:28,500 --> 00:00:30,750
and you need to be able to manage these crucial elements

16
00:00:30,750 --> 00:00:33,570
of a Linux system to ensure optimal performance

17
00:00:33,570 --> 00:00:36,420
while supporting the best user experience.

18
00:00:36,420 --> 00:00:38,640
There are many possible issues that could affect

19
00:00:38,640 --> 00:00:40,560
or be caused by the CPU.

20
00:00:40,560 --> 00:00:43,530
These issues may include an underperforming CPU

21
00:00:43,530 --> 00:00:46,110
for the desired level of speed and responsiveness.

22
00:00:46,110 --> 00:00:49,350
An overloaded CPU caused by too many requests resulting

23
00:00:49,350 --> 00:00:52,770
in a delay of response, or you can have non-functional cores

24
00:00:52,770 --> 00:00:55,290
or other things that are causing problems.

25
00:00:55,290 --> 00:00:56,730
You can use the information

26
00:00:56,730 --> 00:01:01,020
from /proc/cpuinfo to identify characteristics

27
00:01:01,020 --> 00:01:04,200
about your CPU that might indicate issues related

28
00:01:04,200 --> 00:01:06,450
to performance or a lack of support

29
00:01:06,450 --> 00:01:08,520
for specific features you might need.

30
00:01:08,520 --> 00:01:12,210
Some useful fields in the /proc/cpuinfo file

31
00:01:12,210 --> 00:01:13,530
include the processor,

32
00:01:13,530 --> 00:01:15,840
which refers to the number of logical cores,

33
00:01:15,840 --> 00:01:19,290
the vendor ID, which refers to the CPU manufacturer,

34
00:01:19,290 --> 00:01:21,750
the model name, the CPU megahertz,

35
00:01:21,750 --> 00:01:24,270
which refers to the logical core's clock speed

36
00:01:24,270 --> 00:01:27,000
and is measured out to the thousands decimal place.

37
00:01:27,000 --> 00:01:28,920
The cache size and the flags

38
00:01:28,920 --> 00:01:30,450
which refer to the characteristics

39
00:01:30,450 --> 00:01:33,840
about the CPU as well as the supported features.

40
00:01:33,840 --> 00:01:34,860
As you've seen,

41
00:01:34,860 --> 00:01:36,990
the system CTL command enables you

42
00:01:36,990 --> 00:01:39,360
to view kernel parameters at runtime.

43
00:01:39,360 --> 00:01:41,370
The uptime command will display the time

44
00:01:41,370 --> 00:01:43,800
from when the system started running as well.

45
00:01:43,800 --> 00:01:46,410
The output of the uptime command gives information

46
00:01:46,410 --> 00:01:47,670
about the current time,

47
00:01:47,670 --> 00:01:49,320
how long the system has been running,

48
00:01:49,320 --> 00:01:51,960
and how many users are currently logged in.

49
00:01:51,960 --> 00:01:54,420
Most relevant to the CPU troubleshooting, though,

50
00:01:54,420 --> 00:01:56,490
is the load average field.

51
00:01:56,490 --> 00:01:58,740
A CPU's load is going to be expressed

52
00:01:58,740 --> 00:02:00,270
as the number of processes

53
00:02:00,270 --> 00:02:03,840
that are either using or waiting to use that CPU.

54
00:02:03,840 --> 00:02:05,850
It can also include the number of processes

55
00:02:05,850 --> 00:02:08,610
in queue for storage input/output.

56
00:02:08,610 --> 00:02:11,640
Using uptime, you're going to be able to find the average load

57
00:02:11,640 --> 00:02:13,830
over three different periods of time.

58
00:02:13,830 --> 00:02:15,810
You can use these values to determine

59
00:02:15,810 --> 00:02:18,120
when your CPU has become overloaded,

60
00:02:18,120 --> 00:02:20,370
which may lead to performance issues.

61
00:02:20,370 --> 00:02:23,100
For example, if you have four logical cores

62
00:02:23,100 --> 00:02:26,580
and the load average of the last 15 minutes is 4.0,

63
00:02:26,580 --> 00:02:30,180
then that means your CPU was being fully utilized.

64
00:02:30,180 --> 00:02:32,460
If you're load average were 8.0,

65
00:02:32,460 --> 00:02:36,180
that means your CPU would be 100% overloaded.

66
00:02:36,180 --> 00:02:37,860
Now, one of the commands we can use

67
00:02:37,860 --> 00:02:42,284
to look at our system reports is known as sar, S-A-R.

68
00:02:42,284 --> 00:02:45,390
sar is going to display system usage reports based

69
00:02:45,390 --> 00:02:48,090
on data collected from system activity.

70
00:02:48,090 --> 00:02:50,610
These reports contain various different sections,

71
00:02:50,610 --> 00:02:53,310
and each of those sections consists of the type of data

72
00:02:53,310 --> 00:02:55,740
and the time at which that data was collected.

73
00:02:55,740 --> 00:02:57,780
The default mode of the sar command

74
00:02:57,780 --> 00:02:59,640
is going to display the CPU usage

75
00:02:59,640 --> 00:03:02,040
in various time increments for each category

76
00:03:02,040 --> 00:03:04,440
of resource that's accessed by the CPU.

77
00:03:04,440 --> 00:03:06,840
This includes your users, the system,

78
00:03:06,840 --> 00:03:09,210
input/output scheduling, and other things.

79
00:03:09,210 --> 00:03:11,163
It also displays the percentage of the CPU

80
00:03:11,163 --> 00:03:13,650
that was idle at any given time.

81
00:03:13,650 --> 00:03:15,750
At the bottom of the report is an average

82
00:03:15,750 --> 00:03:19,290
of each of these data points across the listed time periods.

83
00:03:19,290 --> 00:03:22,290
By default, sar reports are going to have data collected

84
00:03:22,290 --> 00:03:23,580
every 10 minutes.

85
00:03:23,580 --> 00:03:25,770
Though, you can use different options to filter

86
00:03:25,770 --> 00:03:27,690
and shape these reports as well.

87
00:03:27,690 --> 00:03:28,830
To use this command,

88
00:03:28,830 --> 00:03:31,980
simply type sar and the options you want.

89
00:03:31,980 --> 00:03:33,120
The next command we're going to talk

90
00:03:33,120 --> 00:03:37,020
about is sysctl or system control.

91
00:03:37,020 --> 00:03:38,910
The system control command can be used

92
00:03:38,910 --> 00:03:40,950
to troubleshoot CPU issues as well

93
00:03:40,950 --> 00:03:44,550
by retrieving CPU-based kernel parameters at runtime.

94
00:03:44,550 --> 00:03:47,790
One useful set of parameters concerns scheduling domains.

95
00:03:47,790 --> 00:03:49,530
Now scheduling domains are a method

96
00:03:49,530 --> 00:03:52,830
by which the kernel groups can take logical cores together

97
00:03:52,830 --> 00:03:54,420
and then share scheduling policies

98
00:03:54,420 --> 00:03:56,340
and other properties between them.

99
00:03:56,340 --> 00:03:58,560
These parameters will usually take the format

100
00:03:58,560 --> 00:04:00,813
of kernel.sched_domain.cpu#

101
00:04:03,488 --> 00:04:04,738
.domain#.param.

102
00:04:06,270 --> 00:04:07,800
Now another way to get information

103
00:04:07,800 --> 00:04:09,840
about your CPU and its architecture is

104
00:04:09,840 --> 00:04:12,090
to use the lscpu command.

105
00:04:12,090 --> 00:04:14,400
lscpu is a command line utility

106
00:04:14,400 --> 00:04:16,860
that's going to read the CPU architecture information

107
00:04:16,860 --> 00:04:20,910
from the sysfs and /proc/cpuinfo files

108
00:04:20,910 --> 00:04:22,860
and then print that to your terminal.

109
00:04:22,860 --> 00:04:24,420
The information here is going to include things

110
00:04:24,420 --> 00:04:27,270
like the number of CPUs, the threads, the cores,

111
00:04:27,270 --> 00:04:31,890
the sockets, and non-uniform memory access, or NUMA nodes.

112
00:04:31,890 --> 00:04:34,770
It's also going to be able to display CPU cache information

113
00:04:34,770 --> 00:04:38,610
and cache sharing as well as family, model, bogomips,

114
00:04:38,610 --> 00:04:41,790
byte order, and stepping of the CPU.

115
00:04:41,790 --> 00:04:43,860
Now, in addition to all the issues you can have

116
00:04:43,860 --> 00:04:47,640
with your CPU, you can also have issues caused by memory.

117
00:04:47,640 --> 00:04:49,980
Now, memory issues may include not having enough

118
00:04:49,980 --> 00:04:53,070
total memory to service all your processes at once

119
00:04:53,070 --> 00:04:55,020
or not having enough free memory

120
00:04:55,020 --> 00:04:57,630
to service new processes that need to be launched

121
00:04:57,630 --> 00:05:00,390
or processes that are unable to access memory,

122
00:05:00,390 --> 00:05:02,490
despite there being memory available

123
00:05:02,490 --> 00:05:05,280
or processes accessing too much memory

124
00:05:05,280 --> 00:05:07,200
and basically draining your system

125
00:05:07,200 --> 00:05:08,580
or you can have things

126
00:05:08,580 --> 00:05:10,950
that are leaving other processes without memory

127
00:05:10,950 --> 00:05:13,350
because they're sucking up all that extra memory.

128
00:05:13,350 --> 00:05:14,790
Or we can have a system

129
00:05:14,790 --> 00:05:17,070
that cannot quickly access files from a cache

130
00:05:17,070 --> 00:05:19,740
or a buffer because there's not enough physical memory

131
00:05:19,740 --> 00:05:22,410
and things are being put into a cache or buffer instead.

132
00:05:22,410 --> 00:05:24,780
And lots of other memory issues like this.

133
00:05:24,780 --> 00:05:26,790
Now to troubleshoot some of these issues,

134
00:05:26,790 --> 00:05:31,500
you can use information from the /proc/meminfo file.

135
00:05:31,500 --> 00:05:32,400
Now this will ensure

136
00:05:32,400 --> 00:05:34,350
that the system's RAM modules are performing

137
00:05:34,350 --> 00:05:36,240
to the specification you expect,

138
00:05:36,240 --> 00:05:37,920
and that the OS is consuming memory

139
00:05:37,920 --> 00:05:39,810
at the right rate that you expect

140
00:05:39,810 --> 00:05:42,660
and that your system has enough overall available memory

141
00:05:42,660 --> 00:05:44,640
to perform the tasks you want.

142
00:05:44,640 --> 00:05:45,930
Now, some useful fields

143
00:05:45,930 --> 00:05:50,220
in those /proc/meminfo file include things like memtotal,

144
00:05:50,220 --> 00:05:51,540
which refers to the total amount

145
00:05:51,540 --> 00:05:53,640
of physical memory in the system

146
00:05:53,640 --> 00:05:55,830
or memfree, which is the total amount

147
00:05:55,830 --> 00:05:58,110
of free memory that's available in that system

148
00:05:58,110 --> 00:05:59,430
at this time.

149
00:05:59,430 --> 00:06:01,020
Cached, this is going to refer

150
00:06:01,020 --> 00:06:02,760
to the total amount of physical memory

151
00:06:02,760 --> 00:06:04,920
that's being used as cache memory.

152
00:06:04,920 --> 00:06:07,650
Swaptotal, this refers to the total amount

153
00:06:07,650 --> 00:06:09,660
of swap space on your system.

154
00:06:09,660 --> 00:06:12,120
And swapfree, which refers to the total amount

155
00:06:12,120 --> 00:06:15,090
of swap space that is currently unused on your system.

156
00:06:15,090 --> 00:06:16,770
Dirty refers to the total amount

157
00:06:16,770 --> 00:06:19,200
of memory that is waiting to be written to storage

158
00:06:19,200 --> 00:06:21,210
and writeback refers to the total amount

159
00:06:21,210 --> 00:06:23,760
of memory currently being written to storage.

160
00:06:23,760 --> 00:06:26,100
Now the free command is another command we can use

161
00:06:26,100 --> 00:06:27,300
to look at our memory

162
00:06:27,300 --> 00:06:31,050
and free is going to parse the /proc/meminfo file

163
00:06:31,050 --> 00:06:34,500
for easier analysis for those memory usage statistics.

164
00:06:34,500 --> 00:06:37,050
Its default behavior is to display the information

165
00:06:37,050 --> 00:06:39,300
about system memory and the swap space

166
00:06:39,300 --> 00:06:41,400
as well and include the total memory,

167
00:06:41,400 --> 00:06:43,530
the total used, the total free,

168
00:06:43,530 --> 00:06:46,200
the total shared, the total buffered and cached,

169
00:06:46,200 --> 00:06:48,570
and the total available for starting new apps.

170
00:06:48,570 --> 00:06:50,370
There are several different command options

171
00:06:50,370 --> 00:06:52,350
that you can use with the free command.

172
00:06:52,350 --> 00:06:55,715
Things like -b, -k, -m,

173
00:06:55,715 --> 00:06:57,600
g, or -tera.

174
00:06:57,600 --> 00:06:59,730
And all those options will display the memory

175
00:06:59,730 --> 00:07:03,420
in either bytes, kilobytes, megabytes, gigabytes,

176
00:07:03,420 --> 00:07:05,430
or terabytes, respectively.

177
00:07:05,430 --> 00:07:08,370
If you use -s and the number of seconds you want,

178
00:07:08,370 --> 00:07:09,570
it will tell you how quickly

179
00:07:09,570 --> 00:07:11,790
you want to update the memory statistics based

180
00:07:11,790 --> 00:07:13,500
on the number of seconds you tell it to.

181
00:07:13,500 --> 00:07:17,524
So you might say -s10 to do it every 10 seconds.

182
00:07:17,524 --> 00:07:19,680
o is going to disable the display

183
00:07:19,680 --> 00:07:22,350
of the buffered or cached information.

184
00:07:22,350 --> 00:07:24,540
t is going to display the total line

185
00:07:24,540 --> 00:07:26,220
that's going to combine physical memory

186
00:07:26,220 --> 00:07:29,610
with swap space as one combined memory area.

187
00:07:29,610 --> 00:07:33,420
And -h will give you output that is more human readable.

188
00:07:33,420 --> 00:07:35,100
Now memory can also be cached

189
00:07:35,100 --> 00:07:37,230
and this means it's going to be stored temporarily

190
00:07:37,230 --> 00:07:39,570
so that the data can then be accessed more quickly

191
00:07:39,570 --> 00:07:40,770
in the future.

192
00:07:40,770 --> 00:07:41,910
Now, the buffers field

193
00:07:41,910 --> 00:07:46,050
inside the /proc/meminfo file indicates memory

194
00:07:46,050 --> 00:07:48,390
that has been assigned to a specific block device,

195
00:07:48,390 --> 00:07:49,800
like a hard drive.

196
00:07:49,800 --> 00:07:53,070
This memory can then be used to cache file system metadata

197
00:07:53,070 --> 00:07:54,960
like directory contents, permissions,

198
00:07:54,960 --> 00:07:56,610
and other things like that.

199
00:07:56,610 --> 00:07:58,800
The cached memory is going to be similar to this

200
00:07:58,800 --> 00:08:01,140
but instead of storing file metadata,

201
00:08:01,140 --> 00:08:04,020
it's going to store the actual contents of the file.

202
00:08:04,020 --> 00:08:06,420
So the buffers store metadata

203
00:08:06,420 --> 00:08:09,390
but cache is going to store the actual files.

204
00:08:09,390 --> 00:08:11,190
Now, when you use the free command,

205
00:08:11,190 --> 00:08:13,290
we can combine these two values together

206
00:08:13,290 --> 00:08:15,480
inside of our output as well.

207
00:08:15,480 --> 00:08:17,040
Another way to look at the information

208
00:08:17,040 --> 00:08:20,010
about your memory is to use the lsmem command.

209
00:08:20,010 --> 00:08:22,110
The lsmem command is going to list the ranges

210
00:08:22,110 --> 00:08:24,780
of available memory with our online status.

211
00:08:24,780 --> 00:08:26,610
This will show you all the different memory blocks

212
00:08:26,610 --> 00:08:30,750
that correspond to the memory blocks inside of the sysfs.

213
00:08:30,750 --> 00:08:33,059
This command will also show the memory block size,

214
00:08:33,059 --> 00:08:34,049
the device size,

215
00:08:34,049 --> 00:08:37,023
and the amount of memory in online or offline statuses.

216
00:08:37,980 --> 00:08:40,860
Another command we need to talk about is vmstat.

217
00:08:40,860 --> 00:08:44,039
Now vmstat is a command that displays various statistics

218
00:08:44,039 --> 00:08:45,630
about virtual memory.

219
00:08:45,630 --> 00:08:48,390
This includes things like our processes, our CPU,

220
00:08:48,390 --> 00:08:50,940
and our IO statistics, as well as our virtual memory

221
00:08:50,940 --> 00:08:52,740
when we use vmstat.

222
00:08:52,740 --> 00:08:55,200
Now by default, the report that you're going to get

223
00:08:55,200 --> 00:08:57,570
from vmstat is going to provide you with averages

224
00:08:57,570 --> 00:09:00,720
for each statistic since the last system boot up.

225
00:09:00,720 --> 00:09:03,390
But you can also specify a delay value

226
00:09:03,390 --> 00:09:05,190
to sample from a period of time.

227
00:09:05,190 --> 00:09:08,340
For instance, every 60 seconds, you want to get a new report,

228
00:09:08,340 --> 00:09:10,020
you can tell it to do that.

229
00:09:10,020 --> 00:09:11,760
Now, some memory-based statistics here

230
00:09:11,760 --> 00:09:14,250
are going to include total virtual memory available.

231
00:09:14,250 --> 00:09:15,360
The total virtual memory

232
00:09:15,360 --> 00:09:16,800
that's free for us to use,

233
00:09:16,800 --> 00:09:19,230
the total memory used in the buffers and cache,

234
00:09:19,230 --> 00:09:21,870
and the total memory that's used in swap spaces.

235
00:09:21,870 --> 00:09:23,670
Some CPU-based statistics

236
00:09:23,670 --> 00:09:26,370
are going to include time spent running user space,

237
00:09:26,370 --> 00:09:28,560
the time spent running in kernel space,

238
00:09:28,560 --> 00:09:31,050
the time spent idle, and the time spent waiting

239
00:09:31,050 --> 00:09:32,580
for input and output.

240
00:09:32,580 --> 00:09:35,700
To run the vmstat command, type in vmstat,

241
00:09:35,700 --> 00:09:39,360
the options, the delay with the counter, and then hit enter.

242
00:09:39,360 --> 00:09:41,340
It's recommended that you supply vmstat

243
00:09:41,340 --> 00:09:44,130
with a delay for more accurate report as well.

244
00:09:44,130 --> 00:09:48,240
For example, vmstat five five will run the command

245
00:09:48,240 --> 00:09:51,210
on a five-second delay for five different intervals,

246
00:09:51,210 --> 00:09:53,820
giving you a good average over that time.

247
00:09:53,820 --> 00:09:56,460
Another thing we want to talk about is OOM,

248
00:09:56,460 --> 00:09:59,340
the out of memory killer or OOM is a feature

249
00:09:59,340 --> 00:10:00,960
of the Linux kernel that determines

250
00:10:00,960 --> 00:10:02,940
what processes need to be killed

251
00:10:02,940 --> 00:10:05,790
when the system becomes extremely low on memory.

252
00:10:05,790 --> 00:10:08,850
The out of memory killer will continue to kill processes

253
00:10:08,850 --> 00:10:10,830
until enough free memory is made

254
00:10:10,830 --> 00:10:11,663
so that the kernel

255
00:10:11,663 --> 00:10:14,220
and the system can begin running smoothly again.

256
00:10:14,220 --> 00:10:16,710
Rather than killing processes at random though,

257
00:10:16,710 --> 00:10:19,560
the out of memory killer will leverage an algorithm

258
00:10:19,560 --> 00:10:22,650
that assigns each process an OOM score.

259
00:10:22,650 --> 00:10:23,940
The higher the score,

260
00:10:23,940 --> 00:10:26,670
the higher the chance that process has of being killed

261
00:10:26,670 --> 00:10:28,680
during an out of memory event.

262
00:10:28,680 --> 00:10:30,480
The assignment algorithm is going to consider

263
00:10:30,480 --> 00:10:32,910
what processes will free up the greatest amount of memory

264
00:10:32,910 --> 00:10:36,000
when killed as well as what processes are least important

265
00:10:36,000 --> 00:10:37,560
to system stability.

266
00:10:37,560 --> 00:10:39,480
Then it'll assign a score based

267
00:10:39,480 --> 00:10:41,970
on what it determines to be the most optimal targets

268
00:10:41,970 --> 00:10:43,260
for termination.

269
00:10:43,260 --> 00:10:46,170
Although this mechanism is mostly automated by the kernel,

270
00:10:46,170 --> 00:10:49,230
you do have the ability to control some of its behavior.

271
00:10:49,230 --> 00:10:51,300
You can mount the OOM control group

272
00:10:51,300 --> 00:10:53,070
as a desired mount point.

273
00:10:53,070 --> 00:10:54,270
And if, for example

274
00:10:54,270 --> 00:10:57,420
you want to designate a group of processes to be killed first,

275
00:10:57,420 --> 00:10:59,760
you can create a directory at this mount point

276
00:10:59,760 --> 00:11:02,070
and create a task file in this directory

277
00:11:02,070 --> 00:11:05,250
then list out the PIDs of the relevant processes.

278
00:11:05,250 --> 00:11:08,760
Then you can create an OOM.priority file

279
00:11:08,760 --> 00:11:11,880
with a higher integer value like 256

280
00:11:11,880 --> 00:11:14,010
to give the processes a higher priority

281
00:11:14,010 --> 00:11:16,590
for the OOM killer to take care of.

282
00:11:16,590 --> 00:11:19,560
Or to prevent a process from being killed entirely,

283
00:11:19,560 --> 00:11:22,740
you can assign it zero as a priority value.

284
00:11:22,740 --> 00:11:25,320
Now the configuration of swap space is another thing we need

285
00:11:25,320 --> 00:11:26,153
to think about

286
00:11:26,153 --> 00:11:27,240
because your swap space

287
00:11:27,240 --> 00:11:29,730
can help alleviate memory-related issues,

288
00:11:29,730 --> 00:11:31,260
especially when your system

289
00:11:31,260 --> 00:11:33,360
and applications request more memory

290
00:11:33,360 --> 00:11:35,460
than your system physically has.

291
00:11:35,460 --> 00:11:36,780
Now systems with a low amount

292
00:11:36,780 --> 00:11:38,520
of memory are particularly vulnerable

293
00:11:38,520 --> 00:11:40,260
to these issues of swapping.

294
00:11:40,260 --> 00:11:43,470
Swap space is not a replacement for adding more memory

295
00:11:43,470 --> 00:11:45,600
but it can help minimize system

296
00:11:45,600 --> 00:11:49,590
and application sluggishness, unresponsiveness, and crashes.

297
00:11:49,590 --> 00:11:52,410
Swap space can be of one of three types.

298
00:11:52,410 --> 00:11:54,420
A device swap space is configured

299
00:11:54,420 --> 00:11:56,190
when you partition the storage device

300
00:11:56,190 --> 00:11:59,220
to allow you to have some swap space on that disc.

301
00:11:59,220 --> 00:12:01,080
This will be used by the operating system

302
00:12:01,080 --> 00:12:03,030
to run larger applications.

303
00:12:03,030 --> 00:12:05,610
File system swap space is configured primarily

304
00:12:05,610 --> 00:12:07,230
when you install Linux.

305
00:12:07,230 --> 00:12:09,120
It's going to be used by the operating system

306
00:12:09,120 --> 00:12:10,680
as an emergency resource

307
00:12:10,680 --> 00:12:13,230
when the available swap space runs out.

308
00:12:13,230 --> 00:12:14,220
On the other hand,

309
00:12:14,220 --> 00:12:16,980
pseudo swap space enables large applications

310
00:12:16,980 --> 00:12:19,590
to run on computers with limited RAM.

311
00:12:19,590 --> 00:12:22,290
Swap files are created for storing data

312
00:12:22,290 --> 00:12:23,160
that's going to be transferred

313
00:12:23,160 --> 00:12:25,860
from a system's memory to a storage device.

314
00:12:25,860 --> 00:12:28,290
These things are dynamic and they change in size

315
00:12:28,290 --> 00:12:30,690
when the data's moved in and out of memory.

316
00:12:30,690 --> 00:12:33,120
Swap files are going to be used as a medium

317
00:12:33,120 --> 00:12:36,720
to transfer data from RAM into that storage device.

318
00:12:36,720 --> 00:12:39,450
A swap partition is an area of virtual memory

319
00:12:39,450 --> 00:12:42,390
on a storage device that complement the physical RAM

320
00:12:42,390 --> 00:12:43,740
in the computer.

321
00:12:43,740 --> 00:12:45,930
Swap partitions are used by Linux

322
00:12:45,930 --> 00:12:48,930
because they perform better than a swap file system.

323
00:12:48,930 --> 00:12:50,610
Now, if you want to create a swap space

324
00:12:50,610 --> 00:12:52,050
on a storage partition,

325
00:12:52,050 --> 00:12:54,360
you're going to use the make swap command

326
00:12:54,360 --> 00:12:57,090
which is M-K-S-W-A-P.

327
00:12:57,090 --> 00:12:59,970
The make swap command is going to be used to create swap space

328
00:12:59,970 --> 00:13:02,280
on a storage partition and is typically used

329
00:13:02,280 --> 00:13:05,340
when you want to move swap space to a different partition

330
00:13:05,340 --> 00:13:06,780
than the one it was originally created

331
00:13:06,780 --> 00:13:09,000
on during system installation.

332
00:13:09,000 --> 00:13:11,460
For example, let's say you wanted to save space

333
00:13:11,460 --> 00:13:13,500
on a low capacity boot drive.

334
00:13:13,500 --> 00:13:15,240
You could provide an option to be able

335
00:13:15,240 --> 00:13:18,180
to move that over to a new swap space.

336
00:13:18,180 --> 00:13:19,620
If you use -c,

337
00:13:19,620 --> 00:13:21,600
this option verifies that the device is free

338
00:13:21,600 --> 00:13:24,180
from bad sectors before mounting the swap space.

339
00:13:24,180 --> 00:13:26,223
Essentially it's a check disc.

340
00:13:26,223 --> 00:13:28,410
p is going to set the page size

341
00:13:28,410 --> 00:13:30,690
that's going to be used by the make swap command.

342
00:13:30,690 --> 00:13:34,530
And -l will activate the swap space using labels applied

343
00:13:34,530 --> 00:13:36,750
to partitions or file systems.

344
00:13:36,750 --> 00:13:39,720
Another command we have is known as swap on.

345
00:13:39,720 --> 00:13:43,260
The swap on command is used to activate a swap partition

346
00:13:43,260 --> 00:13:44,700
in a specified device.

347
00:13:44,700 --> 00:13:46,620
While the swap off command is used

348
00:13:46,620 --> 00:13:49,500
to deactivate the swap space on a device.

349
00:13:49,500 --> 00:13:51,300
Some of the frequently used swap on

350
00:13:51,300 --> 00:13:54,630
and swap off command options are swapon-e,

351
00:13:54,630 --> 00:13:57,360
which is used to skip devices that do not exist

352
00:13:57,360 --> 00:14:01,230
or swapon-a, which is used to activate all of the swap space

353
00:14:01,230 --> 00:14:04,260
or swapoff-a, which is just to deactivate all

354
00:14:04,260 --> 00:14:05,640
of your swap space.

355
00:14:05,640 --> 00:14:07,230
All right, so now that you're familiar with some

356
00:14:07,230 --> 00:14:09,510
of the basic command tools that you can use,

357
00:14:09,510 --> 00:14:12,060
including what they do and how they can help you,

358
00:14:12,060 --> 00:14:14,160
you're now going to be able to troubleshoot CPU

359
00:14:14,160 --> 00:14:15,600
and memory issues.

360
00:14:15,600 --> 00:14:17,760
When you're troubleshooting CPU and memory issues,

361
00:14:17,760 --> 00:14:21,390
remember, identify key information about the CPU

362
00:14:21,390 --> 00:14:26,250
and its logical cores using the /proc/cpuinfo file.

363
00:14:26,250 --> 00:14:29,670
Use the uptime command to identify CPU load averages

364
00:14:29,670 --> 00:14:30,840
and use the sar command

365
00:14:30,840 --> 00:14:34,170
to see what components are causing heavy load on your CPU.

366
00:14:34,170 --> 00:14:35,700
When you want to look at memory,

367
00:14:35,700 --> 00:14:38,550
you can identify key information about your memory usage

368
00:14:38,550 --> 00:14:41,700
by looking at the /proc/meminfo file,

369
00:14:41,700 --> 00:14:43,560
or you can use the free command

370
00:14:43,560 --> 00:14:46,200
to more easily analyze memory usage information

371
00:14:46,200 --> 00:14:48,990
and the vmstat command to retrieve more information

372
00:14:48,990 --> 00:14:51,270
on both your CPU and memory usage,

373
00:14:51,270 --> 00:14:53,190
as well as your virtual memory.

374
00:14:53,190 --> 00:14:56,730
Also, you may want to consider tweaking your OOM killer

375
00:14:56,730 --> 00:14:59,730
to spare or sacrifice specific processes

376
00:14:59,730 --> 00:15:01,320
when you're running low on memory.

377
00:15:01,320 --> 00:15:02,160
And finally,

378
00:15:02,160 --> 00:15:04,200
remember that you can always create more swap space

379
00:15:04,200 --> 00:15:06,000
if you need to because you ran out

380
00:15:06,000 --> 00:15:08,463
of physical memory by using your swap commands.

