1
1
#include " aligned_page_pool.h"
2
- #include " util/string/builder.h"
3
2
4
3
#include < util/generic/yexception.h>
4
+ #include < util/stream/file.h>
5
5
#include < util/string/cast.h>
6
6
#include < util/system/align.h>
7
7
#include < util/system/compiler.h>
@@ -26,6 +26,30 @@ static_assert(MaxMidSize == 64 * 1024 * 1024, "Upper memory block 64 Mb");
26
26
27
27
namespace {
28
28
29
+ size_t GetMemoryMapsCount () {
30
+ size_t lineCount = 0 ;
31
+ TString line;
32
+ #if defined(_unix_)
33
+ TFileInput file (" /proc/self/maps" );
34
+ while (file.ReadLine (line)) ++lineCount;
35
+ #endif
36
+ return lineCount;
37
+ }
38
+
39
+ ui64 GetMaxMemoryMaps () {
40
+ ui64 maxMapCount = 0 ;
41
+ #if defined(_unix_)
42
+ maxMapCount = FromString<ui64>(TFileInput (" /proc/sys/vm/max_map_count" ).ReadAll ());
43
+ #endif
44
+ return maxMapCount;
45
+ }
46
+
47
+ TString GetMemoryMapsString () {
48
+ TStringStream ss;
49
+ ss << " (maps: " << GetMemoryMapsCount () << " vs " << GetMaxMemoryMaps () << " )" ;
50
+ return ss.Str ();
51
+ }
52
+
29
53
template <typename T, bool SysAlign>
30
54
class TGlobalPools ;
31
55
@@ -146,9 +170,15 @@ class TGlobalPools {
146
170
147
171
void DoMunmap (void * addr, size_t size) {
148
172
if (Y_UNLIKELY (0 != T::Munmap (addr, size))) {
173
+ TStringStream mmaps;
174
+ const auto lastError = LastSystemError ();
175
+ if (lastError == ENOMEM) {
176
+ mmaps << GetMemoryMapsString ();
177
+ }
178
+
149
179
ythrow yexception () << " Munmap(0x"
150
180
<< IntToString<16 >(reinterpret_cast <uintptr_t >(addr))
151
- << " , " << size << " ) failed: " << LastSystemErrorText ();
181
+ << " , " << size << " ) failed: " << LastSystemErrorText (lastError) << mmaps. Str ( );
152
182
}
153
183
154
184
i64 prev = TotalMmappedBytes.fetch_sub (size);
@@ -493,7 +523,14 @@ void* TAlignedPagePoolImpl<T>::Alloc(size_t size) {
493
523
auto allocSize = size + ALLOC_AHEAD_PAGES * POOL_PAGE_SIZE;
494
524
void * mem = globalPool.DoMmap (allocSize);
495
525
if (Y_UNLIKELY (MAP_FAILED == mem)) {
496
- ythrow yexception () << " Mmap failed to allocate " << (size + POOL_PAGE_SIZE) << " bytes: " << LastSystemErrorText ();
526
+ TStringStream mmaps;
527
+ const auto lastError = LastSystemError ();
528
+ if (lastError == ENOMEM) {
529
+ mmaps << GetMemoryMapsString ();
530
+ }
531
+
532
+ ythrow yexception () << " Mmap failed to allocate " << (size + POOL_PAGE_SIZE) << " bytes: "
533
+ << LastSystemErrorText (lastError) << mmaps.Str ();
497
534
}
498
535
499
536
res = AlignUp (mem, POOL_PAGE_SIZE);
@@ -641,7 +678,13 @@ void* GetAlignedPage(ui64 size) {
641
678
auto allocSize = Max<ui64>(MaxMidSize, size);
642
679
void * mem = pool.DoMmap (allocSize);
643
680
if (Y_UNLIKELY (MAP_FAILED == mem)) {
644
- ythrow yexception () << " Mmap failed to allocate " << allocSize << " bytes: " << LastSystemErrorText ();
681
+ TStringStream mmaps;
682
+ const auto lastError = LastSystemError ();
683
+ if (lastError == ENOMEM) {
684
+ mmaps << GetMemoryMapsString ();
685
+ }
686
+
687
+ ythrow yexception () << " Mmap failed to allocate " << allocSize << " bytes: " << LastSystemErrorText (lastError) << mmaps.Str ();
645
688
}
646
689
647
690
if (size < MaxMidSize) {
0 commit comments