Opened 4 years ago

Last modified 4 years ago

#16622 new bug

kernel: system_info.used_pages don't include mapped files

Reported by: X512 Owned by: nobody
Priority: normal Milestone: Unscheduled
Component: System/Kernel Version: R1/Development
Keywords: Cc: mmlr
Blocked By: Blocking:
Platform: All

Description (last modified by X512)

This is hrev54741.

As discussed here, mapping files to read-only areas almost not affect system_info.used_pages that is used by most memory inspecting utilities, but it actually consumes memory and make allocations not possible if too many files are mapped. system_info.free_memory provides correct information about free memory but is also seems to include disk cache that can be freed to release memory for allocations.

If memory mapped files are consuming memory, they should be included in system_info.used_pages.

Actually it is not required to reserve memory for read-only mapped files because it can be handled in similar way as disk cache: load file contents on demand and unload when memory is needed by someone else. This approach do not violate no overcommit policy. If program change area protection and enable copy-on-write, attempt may failed with out of memory if memory can't be reserved.

system_info.used_pages is calculated here.

Attachments (1)

MMap.cpp (1.0 KB ) - added by X512 4 years ago.
Test program.

Download all attachments as: .zip

Change History (6)

by X512, 4 years ago

Attachment: MMap.cpp added

Test program.

comment:1 by X512, 4 years ago

I attached test program that reproduce problem.

Steps to reproduce.

  1. Run dd if=/dev/random of=TestFile bs=1M count=32
  2. Run gcc MMap.cpp -o MMapTest
  3. Run MMapTest
  4. MMapTest will get out of memory and freeze. system_info.free_memory will be almost zero, system_info.needed_memory will be 32 MB, system_info.used_pages will be almost unaffected. System will be in OOM state, running applications and doing other tasks that need to allocate memory will fail.
  5. Press Ctrl+C to terminate.

comment:2 by X512, 4 years ago

Description: modified (diff)

comment:3 by X512, 4 years ago

In test program it is also possible to use shared memory for multiple memory mappings of same file.

Version 0, edited 4 years ago by X512 (next)

comment:4 by waddlesplash, 4 years ago

This is probably an accounting/flags mix-up somewhere. Regular disk cache memory (not mapped) is part of the "cache" memory, which the VM will readily steal (non-dirty) pages from when it needs to allocate actual memory. mmap'ed files actually utilize the disk cache subsystem, so somehow I guess when files are mmap'ed, their pages are actually reserved and can no longer be stolen. Seems like some kind of a bug indeed.

comment:5 by X512, 4 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.