Skip to content

Commit 9c972fd

Browse files
committed
memory/SlicePool: add option populate
1 parent eabea22 commit 9c972fd

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/memory/SliceArea.hxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public:
5555
}
5656

5757
void ForkCow(bool inherit) noexcept;
58+
void Populate() noexcept;
59+
void CollapseHugePages() noexcept;
5860

5961
bool IsEmpty() const noexcept {
6062
return allocated_count == 0;

src/memory/SlicePool.cxx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,33 @@ SlicePool::ForkCow(bool inherit) noexcept
273273
area.ForkCow(fork_cow);
274274
}
275275

276+
inline void
277+
SliceArea::Populate() noexcept
278+
{
279+
PagesPopulateWrite(this, pool.area_size);
280+
}
281+
282+
inline void
283+
SliceArea::CollapseHugePages() noexcept
284+
{
285+
::CollapseHugePages(this, pool.area_size);
286+
}
287+
288+
void
289+
SlicePool::Populate() noexcept
290+
{
291+
populate = true;
292+
293+
if (areas.empty() && empty_areas.empty() && full_areas.empty())
294+
CreateArea().CollapseHugePages();
295+
}
296+
276297
void
277298
SlicePool::Compress() noexcept
278299
{
279-
for (auto &area : areas)
280-
area.Compress();
300+
if (!populate)
301+
for (auto &area : areas)
302+
area.Compress();
281303

282304
empty_areas.clear_and_dispose(SliceArea::Disposer());
283305

@@ -302,6 +324,8 @@ SlicePool::CreateArea() noexcept
302324
{
303325
auto *area = SliceArea::New(*this);
304326
area->ForkCow(fork_cow);
327+
if (populate)
328+
area->Populate();
305329
empty_areas.push_front(*area);
306330
return *area;
307331
}

src/memory/SlicePool.hxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class SlicePool {
6161

6262
bool fork_cow = true;
6363

64+
bool populate = false;
65+
6466
public:
6567
SlicePool(std::size_t _slice_size, unsigned _slices_per_area,
6668
const char *_vma_name) noexcept;
@@ -76,6 +78,13 @@ public:
7678
*/
7779
void ForkCow(bool inherit) noexcept;
7880

81+
/**
82+
* Always been at least one area completely populated (using
83+
* MADV_POPULATE_WRITE). This reduces waits for Linux kernel
84+
* VM compaction/migration.
85+
*/
86+
void Populate() noexcept;
87+
7988
void AddStats(AllocatorStats &stats, const AreaList &list) const noexcept;
8089

8190
[[gnu::pure]]

0 commit comments

Comments
 (0)