Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
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
Иван Мажукин
mpd
Commits
8753e558
Commit
8753e558
authored
Sep 19, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/HugeAllocator: move MADV_DONTFORK setting to HugeForkCow()
Enforcing MADV_DONTFORK is a surprising limitation for this library which aims to be generic.
parent
f6691579
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
7 deletions
+38
-7
AsyncInputStream.cxx
src/input/AsyncInputStream.cxx
+4
-1
ThreadInputStream.cxx
src/input/ThreadInputStream.cxx
+2
-0
HugeAllocator.cxx
src/util/HugeAllocator.cxx
+9
-6
HugeAllocator.hxx
src/util/HugeAllocator.hxx
+21
-0
SliceBuffer.hxx
src/util/SliceBuffer.hxx
+2
-0
No files found.
src/input/AsyncInputStream.cxx
View file @
8753e558
...
...
@@ -38,7 +38,10 @@ AsyncInputStream::AsyncInputStream(EventLoop &event_loop, const char *_url,
deferred_seek
(
event_loop
,
BIND_THIS_METHOD
(
DeferredSeek
)),
allocation
(
_buffer_size
),
buffer
((
uint8_t
*
)
allocation
.
get
(),
_buffer_size
),
resume_at
(
_resume_at
)
{}
resume_at
(
_resume_at
)
{
allocation
.
ForkCow
(
false
);
}
AsyncInputStream
::~
AsyncInputStream
()
{
...
...
src/input/ThreadInputStream.cxx
View file @
8753e558
...
...
@@ -53,6 +53,8 @@ ThreadInputStream::Start()
void
*
p
=
HugeAllocate
(
buffer_size
);
assert
(
p
!=
nullptr
);
HugeForkCow
(
p
,
buffer_size
,
false
);
buffer
=
new
CircularBuffer
<
uint8_t
>
((
uint8_t
*
)
p
,
buffer_size
);
thread
.
Start
();
}
...
...
src/util/HugeAllocator.cxx
View file @
8753e558
...
...
@@ -73,12 +73,6 @@ HugeAllocate(size_t size)
madvise
(
p
,
size
,
MADV_HUGEPAGE
);
#endif
#ifdef MADV_DONTFORK
/* just in case MPD needs to fork, don't copy this allocation
to the child process, to reduce overhead */
madvise
(
p
,
size
,
MADV_DONTFORK
);
#endif
return
p
;
}
...
...
@@ -89,6 +83,15 @@ HugeFree(void *p, size_t size) noexcept
}
void
HugeForkCow
(
void
*
p
,
size_t
size
,
bool
enable
)
noexcept
{
#ifdef MADV_DONTFORK
madvise
(
p
,
AlignToPageSize
(
size
),
enable
?
MADV_DOFORK
:
MADV_DONTFORK
);
#endif
}
void
HugeDiscard
(
void
*
p
,
size_t
size
)
noexcept
{
#ifdef MADV_DONTNEED
...
...
src/util/HugeAllocator.hxx
View file @
8753e558
...
...
@@ -57,6 +57,13 @@ void
HugeFree
(
void
*
p
,
size_t
size
)
noexcept
;
/**
* Control whether this allocation is copied to newly forked child
* processes. Disabling that makes forking a little bit cheaper.
*/
void
HugeForkCow
(
void
*
p
,
size_t
size
,
bool
enable
)
noexcept
;
/**
* Discard any data stored in the allocation and give the memory back
* to the kernel. After returning, the allocation still exists and
* can be reused at any time, but its contents are undefined.
...
...
@@ -81,6 +88,11 @@ HugeFree(void *p, gcc_unused size_t size) noexcept
}
static
inline
void
HugeForkCow
(
void
*
,
size_t
,
bool
)
noexcept
{
}
static
inline
void
HugeDiscard
(
void
*
p
,
size_t
size
)
noexcept
{
VirtualAlloc
(
p
,
size
,
MEM_RESET
,
PAGE_NOACCESS
);
...
...
@@ -107,6 +119,11 @@ HugeFree(void *_p, size_t) noexcept
}
static
inline
void
HugeForkCow
(
void
*
,
size_t
,
bool
)
noexcept
{
}
static
inline
void
HugeDiscard
(
void
*
,
size_t
)
noexcept
{
}
...
...
@@ -140,6 +157,10 @@ public:
return
*
this
;
}
void
ForkCow
(
bool
enable
)
noexcept
{
HugeForkCow
(
data
,
size
,
enable
);
}
void
Discard
()
noexcept
{
HugeDiscard
(
data
,
size
);
}
...
...
src/util/SliceBuffer.hxx
View file @
8753e558
...
...
@@ -74,6 +74,8 @@ public:
:
n_max
(
_count
),
data
((
Slice
*
)
HugeAllocate
(
CalcAllocationSize
()))
{
assert
(
n_max
>
0
);
HugeForkCow
(
data
,
CalcAllocationSize
(),
false
);
}
~
SliceBuffer
()
{
...
...
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