Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
b06bb6bb
Commit
b06bb6bb
authored
Apr 05, 2016
by
Vishnu kannan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OOM Score adjusting logic in kubelet should handle containers that exit quickly.
Signed-off-by:
Vishnu kannan
<
vishnuk@google.com
>
parent
bf0e6e00
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
35 deletions
+31
-35
oom_linux.go
pkg/util/oom/oom_linux.go
+18
-16
oom_linux_test.go
pkg/util/oom/oom_linux_test.go
+12
-18
procfs.go
pkg/util/procfs/procfs.go
+1
-1
No files found.
pkg/util/oom/oom_linux.go
View file @
b06bb6bb
...
@@ -20,7 +20,6 @@ package oom
...
@@ -20,7 +20,6 @@ package oom
import
(
import
(
"fmt"
"fmt"
"io/ioutil"
"os"
"os"
"path"
"path"
"strconv"
"strconv"
...
@@ -49,16 +48,6 @@ func getPids(cgroupName string) ([]int, error) {
...
@@ -49,16 +48,6 @@ func getPids(cgroupName string) ([]int, error) {
return
fsManager
.
GetPids
()
return
fsManager
.
GetPids
()
}
}
func
syscallNotExists
(
err
error
)
bool
{
if
err
==
nil
{
return
false
}
if
e
,
ok
:=
err
.
(
*
os
.
SyscallError
);
ok
&&
os
.
IsNotExist
(
e
)
{
return
true
}
return
false
}
// Writes 'value' to /proc/<pid>/oom_score_adj. PID = 0 means self
// Writes 'value' to /proc/<pid>/oom_score_adj. PID = 0 means self
// Returns os.ErrNotExist if the `pid` does not exist.
// Returns os.ErrNotExist if the `pid` does not exist.
func
applyOOMScoreAdj
(
pid
int
,
oomScoreAdj
int
)
error
{
func
applyOOMScoreAdj
(
pid
int
,
oomScoreAdj
int
)
error
{
...
@@ -78,12 +67,19 @@ func applyOOMScoreAdj(pid int, oomScoreAdj int) error {
...
@@ -78,12 +67,19 @@ func applyOOMScoreAdj(pid int, oomScoreAdj int) error {
value
:=
strconv
.
Itoa
(
oomScoreAdj
)
value
:=
strconv
.
Itoa
(
oomScoreAdj
)
var
err
error
var
err
error
for
i
:=
0
;
i
<
maxTries
;
i
++
{
for
i
:=
0
;
i
<
maxTries
;
i
++
{
if
err
=
ioutil
.
WriteFile
(
oomScoreAdjPath
,
[]
byte
(
value
),
0700
);
err
!=
nil
{
f
,
err
:=
os
.
Open
(
oomScoreAdjPath
)
if
syscallNotExists
(
err
)
{
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
return
os
.
ErrNotExist
return
os
.
ErrNotExist
}
}
err
=
fmt
.
Errorf
(
"failed to apply oom-score-adj to pid %d (%v)"
,
pid
,
err
)
err
=
fmt
.
Errorf
(
"failed to apply oom-score-adj to pid %d (%v)"
,
pid
,
err
)
continue
}
if
_
,
err
:=
f
.
Write
([]
byte
(
value
));
err
!=
nil
{
err
=
fmt
.
Errorf
(
"failed to apply oom-score-adj to pid %d (%v)"
,
pid
,
err
)
continue
}
}
return
nil
}
}
return
err
return
err
}
}
...
@@ -96,20 +92,26 @@ func (oomAdjuster *OOMAdjuster) applyOOMScoreAdjContainer(cgroupName string, oom
...
@@ -96,20 +92,26 @@ func (oomAdjuster *OOMAdjuster) applyOOMScoreAdjContainer(cgroupName string, oom
continueAdjusting
:=
false
continueAdjusting
:=
false
pidList
,
err
:=
oomAdjuster
.
pidLister
(
cgroupName
)
pidList
,
err
:=
oomAdjuster
.
pidLister
(
cgroupName
)
if
err
!=
nil
{
if
err
!=
nil
{
if
syscallNotExists
(
err
)
{
if
os
.
IsNotExist
(
err
)
{
// Nothing to do since the container doesn't exist anymore.
// Nothing to do since the container doesn't exist anymore.
return
os
.
ErrNotExist
return
os
.
ErrNotExist
}
}
continueAdjusting
=
true
continueAdjusting
=
true
glog
.
Error
f
(
"Error getting process list for cgroup %s: %+v"
,
cgroupName
,
err
)
glog
.
V
(
10
)
.
Info
f
(
"Error getting process list for cgroup %s: %+v"
,
cgroupName
,
err
)
}
else
if
len
(
pidList
)
==
0
{
}
else
if
len
(
pidList
)
==
0
{
glog
.
V
(
10
)
.
Infof
(
"Pid list is empty"
)
continueAdjusting
=
true
continueAdjusting
=
true
}
else
{
}
else
{
for
_
,
pid
:=
range
pidList
{
for
_
,
pid
:=
range
pidList
{
if
!
adjustedProcessSet
[
pid
]
{
if
!
adjustedProcessSet
[
pid
]
{
continueAdjusting
=
true
glog
.
V
(
10
)
.
Infof
(
"pid %d needs to be set"
,
pid
)
if
err
=
oomAdjuster
.
ApplyOOMScoreAdj
(
pid
,
oomScoreAdj
);
err
==
nil
{
if
err
=
oomAdjuster
.
ApplyOOMScoreAdj
(
pid
,
oomScoreAdj
);
err
==
nil
{
adjustedProcessSet
[
pid
]
=
true
adjustedProcessSet
[
pid
]
=
true
}
else
if
err
==
os
.
ErrNotExist
{
continue
}
else
{
glog
.
V
(
10
)
.
Infof
(
"cannot adjust oom score for pid %d - %v"
,
pid
,
err
)
continueAdjusting
=
true
}
}
// Processes can come and go while we try to apply oom score adjust value. So ignore errors here.
// Processes can come and go while we try to apply oom score adjust value. So ignore errors here.
}
}
...
...
pkg/util/oom/oom_linux_test.go
View file @
b06bb6bb
...
@@ -19,7 +19,10 @@ limitations under the License.
...
@@ -19,7 +19,10 @@ limitations under the License.
package
oom
package
oom
import
(
import
(
"os"
"testing"
"testing"
"github.com/stretchr/testify/assert"
)
)
// Converts a sequence of PID lists into a PID lister.
// Converts a sequence of PID lists into a PID lister.
...
@@ -62,10 +65,9 @@ func applyOOMScoreAdjContainerTester(pidListSequence [][]int, maxTries int, appl
...
@@ -62,10 +65,9 @@ func applyOOMScoreAdjContainerTester(pidListSequence [][]int, maxTries int, appl
}
else
if
err
!=
nil
{
}
else
if
err
!=
nil
{
return
return
}
}
// Check that OOM scores were applied to the right processes.
// Check that OOM scores were applied to the right processes.
if
len
(
appliedPids
)
!=
len
(
pidOOMs
)
{
if
len
(
appliedPids
)
!=
len
(
pidOOMs
)
{
t
.
Errorf
(
"Applied OOM scores to incorrect number of processes
"
)
t
.
Errorf
(
"Applied OOM scores to incorrect number of processes
- %+v vs %v"
,
appliedPids
,
pidOOMs
)
return
return
}
}
for
_
,
pid
:=
range
appliedPids
{
for
_
,
pid
:=
range
appliedPids
{
...
@@ -82,29 +84,21 @@ func TestOOMScoreAdjContainer(t *testing.T) {
...
@@ -82,29 +84,21 @@ func TestOOMScoreAdjContainer(t *testing.T) {
pidListSequence1
:=
[][]
int
{
pidListSequence1
:=
[][]
int
{
{
1
,
2
},
{
1
,
2
},
}
}
applyOOMScoreAdjContainerTester
(
pidListSequence1
,
1
,
nil
,
true
,
t
)
applyOOMScoreAdjContainerTester
(
pidListSequence1
,
1
,
[]
int
{
1
,
2
},
false
,
t
)
applyOOMScoreAdjContainerTester
(
pidListSequence1
,
2
,
[]
int
{
1
,
2
},
false
,
t
)
applyOOMScoreAdjContainerTester
(
pidListSequence1
,
3
,
[]
int
{
1
,
2
},
false
,
t
)
pidListSequence3
:=
[][]
int
{
{
1
,
2
},
{
1
,
2
,
4
,
5
},
{
2
,
1
,
4
,
5
,
3
},
}
applyOOMScoreAdjContainerTester
(
pidListSequence3
,
1
,
nil
,
true
,
t
)
applyOOMScoreAdjContainerTester
(
pidListSequence3
,
2
,
nil
,
true
,
t
)
applyOOMScoreAdjContainerTester
(
pidListSequence3
,
3
,
nil
,
true
,
t
)
applyOOMScoreAdjContainerTester
(
pidListSequence3
,
4
,
[]
int
{
1
,
2
,
3
,
4
,
5
},
false
,
t
)
pidListSequenceLag
:=
[][]
int
{
pidListSequenceLag
:=
[][]
int
{
{},
{},
{},
{},
{},
{},
{
1
,
2
,
4
},
{
1
,
2
,
4
},
{
1
,
2
,
4
,
5
},
}
}
for
i
:=
1
;
i
<
5
;
i
++
{
for
i
:=
1
;
i
<
4
;
i
++
{
applyOOMScoreAdjContainerTester
(
pidListSequenceLag
,
i
,
nil
,
true
,
t
)
applyOOMScoreAdjContainerTester
(
pidListSequenceLag
,
i
,
nil
,
true
,
t
)
}
}
applyOOMScoreAdjContainerTester
(
pidListSequenceLag
,
6
,
[]
int
{
1
,
2
,
4
,
5
},
false
,
t
)
applyOOMScoreAdjContainerTester
(
pidListSequenceLag
,
4
,
[]
int
{
1
,
2
,
4
},
false
,
t
)
}
func
TestPidListerFailure
(
t
*
testing
.
T
)
{
_
,
err
:=
getPids
(
"/does/not/exist"
)
assert
.
True
(
t
,
os
.
IsNotExist
(
err
),
"expected getPids to return not exists error. Got %v"
,
err
)
}
}
pkg/util/procfs/procfs.go
View file @
b06bb6bb
...
@@ -49,7 +49,7 @@ func (pfs *ProcFS) GetFullContainerName(pid int) (string, error) {
...
@@ -49,7 +49,7 @@ func (pfs *ProcFS) GetFullContainerName(pid int) (string, error) {
filePath
:=
path
.
Join
(
"/proc"
,
strconv
.
Itoa
(
pid
),
"cgroup"
)
filePath
:=
path
.
Join
(
"/proc"
,
strconv
.
Itoa
(
pid
),
"cgroup"
)
content
,
err
:=
ioutil
.
ReadFile
(
filePath
)
content
,
err
:=
ioutil
.
ReadFile
(
filePath
)
if
err
!=
nil
{
if
err
!=
nil
{
if
e
,
ok
:=
err
.
(
*
os
.
SyscallError
);
ok
&&
os
.
IsNotExist
(
e
)
{
if
os
.
IsNotExist
(
err
)
{
return
""
,
os
.
ErrNotExist
return
""
,
os
.
ErrNotExist
}
}
return
""
,
err
return
""
,
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment