Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
G
glog
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
glog
Commits
96f66565
Commit
96f66565
authored
Jul 06, 2017
by
Shinichiro Hamaji
Committed by
GitHub
Jul 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #145 from pixelb/rate-limit-posix-fadvise
rate limit calls to posix_fadvise()
parents
80bec2ba
dacd2967
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
11 deletions
+14
-11
logging.cc
src/logging.cc
+14
-11
No files found.
src/logging.cc
View file @
96f66565
...
@@ -114,11 +114,6 @@ GLOG_DEFINE_bool(drop_log_memory, true, "Drop in-memory buffers of log contents.
...
@@ -114,11 +114,6 @@ GLOG_DEFINE_bool(drop_log_memory, true, "Drop in-memory buffers of log contents.
"Logs can grow very quickly and they are rarely read before they "
"Logs can grow very quickly and they are rarely read before they "
"need to be evicted from memory. Instead, drop them from memory "
"need to be evicted from memory. Instead, drop them from memory "
"as soon as they are flushed to disk."
);
"as soon as they are flushed to disk."
);
_START_GOOGLE_NAMESPACE_
namespace
logging
{
static
const
int64
kPageSize
=
getpagesize
();
}
_END_GOOGLE_NAMESPACE_
#endif
#endif
// By default, errors (including fatal errors) get logged to stderr as
// By default, errors (including fatal errors) get logged to stderr as
...
@@ -438,6 +433,7 @@ class LogFileObject : public base::Logger {
...
@@ -438,6 +433,7 @@ class LogFileObject : public base::Logger {
FILE
*
file_
;
FILE
*
file_
;
LogSeverity
severity_
;
LogSeverity
severity_
;
uint32
bytes_since_flush_
;
uint32
bytes_since_flush_
;
uint32
dropped_mem_length_
;
uint32
file_length_
;
uint32
file_length_
;
unsigned
int
rollover_attempt_
;
unsigned
int
rollover_attempt_
;
int64
next_flush_time_
;
// cycle count at which to flush log
int64
next_flush_time_
;
// cycle count at which to flush log
...
@@ -839,6 +835,7 @@ LogFileObject::LogFileObject(LogSeverity severity,
...
@@ -839,6 +835,7 @@ LogFileObject::LogFileObject(LogSeverity severity,
file_
(
NULL
),
file_
(
NULL
),
severity_
(
severity
),
severity_
(
severity
),
bytes_since_flush_
(
0
),
bytes_since_flush_
(
0
),
dropped_mem_length_
(
0
),
file_length_
(
0
),
file_length_
(
0
),
rollover_attempt_
(
kRolloverAttemptFrequency
-
1
),
rollover_attempt_
(
kRolloverAttemptFrequency
-
1
),
next_flush_time_
(
0
)
{
next_flush_time_
(
0
)
{
...
@@ -976,7 +973,7 @@ void LogFileObject::Write(bool force_flush,
...
@@ -976,7 +973,7 @@ void LogFileObject::Write(bool force_flush,
PidHasChanged
())
{
PidHasChanged
())
{
if
(
file_
!=
NULL
)
fclose
(
file_
);
if
(
file_
!=
NULL
)
fclose
(
file_
);
file_
=
NULL
;
file_
=
NULL
;
file_length_
=
bytes_since_flush_
=
0
;
file_length_
=
bytes_since_flush_
=
dropped_mem_length_
=
0
;
rollover_attempt_
=
kRolloverAttemptFrequency
-
1
;
rollover_attempt_
=
kRolloverAttemptFrequency
-
1
;
}
}
...
@@ -1116,11 +1113,17 @@ void LogFileObject::Write(bool force_flush,
...
@@ -1116,11 +1113,17 @@ void LogFileObject::Write(bool force_flush,
(
CycleClock_Now
()
>=
next_flush_time_
)
)
{
(
CycleClock_Now
()
>=
next_flush_time_
)
)
{
FlushUnlocked
();
FlushUnlocked
();
#ifdef OS_LINUX
#ifdef OS_LINUX
if
(
FLAGS_drop_log_memory
)
{
// Only consider files >= 3MiB
if
(
file_length_
>=
logging
::
kPageSize
)
{
if
(
FLAGS_drop_log_memory
&&
file_length_
>=
(
3
<<
20
))
{
// don't evict the most recent page
// Don't evict the most recent 1-2MiB so as not to impact a tailer
uint32
len
=
file_length_
&
~
(
logging
::
kPageSize
-
1
);
// of the log file and to avoid page rounding issue on linux < 4.7
posix_fadvise
(
fileno
(
file_
),
0
,
len
,
POSIX_FADV_DONTNEED
);
uint32
total_drop_length
=
(
file_length_
&
~
((
1
<<
20
)
-
1
))
-
(
1
<<
20
);
uint32
this_drop_length
=
total_drop_length
-
dropped_mem_length_
;
if
(
this_drop_length
>=
(
2
<<
20
))
{
// Only advise when >= 2MiB to drop
posix_fadvise
(
fileno
(
file_
),
dropped_mem_length_
,
this_drop_length
,
POSIX_FADV_DONTNEED
);
dropped_mem_length_
=
total_drop_length
;
}
}
}
}
#endif
#endif
...
...
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