Skip to content

Commit c3e30cf

Browse files
committed
more detail on memory-mapped file access in mongodb, clarification of soft vs. hard page faults, better definition of the working set as it pertains to mongodb
1 parent b86b6e2 commit c3e30cf

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

draft/faq/storage.txt

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,60 @@ the :doc:`complete list of FAQs </faq>` or post your question to the
1818
What are Memory Mapped Files?
1919
-----------------------------
2020

21-
Memory mapped files are ____
21+
Memory mapped files are segments of virtual memory which have been assigned a direct byte-for-byte correlation with some portion of a file or resource. Once present, this correlation between the file and the memory space permits applications to treat the mapped portion as if it were primary memory.
2222

23-
What is the working set?
24-
------------------------
25-
26-
The working set is ____
27-
28-
A common misconception in using MongoDB is that the working set can be
29-
reduced to a discrete value. It's important to understand that the
30-
working set is simply a way of thinking about the data one is
31-
accessing and that which MongoDB is working with frequently.
32-
33-
For instance, if you are running a map/reduce job in which the job
34-
reads every document, then your working set is every document.
35-
Conversely, if your map/reduce job only reads the most recent 100
36-
documents, then the working set will be those 100 documents.
37-
38-
How does memory-mapped file access work?
23+
How does memory-mapped file access work in MongoDB?
3924
----------------------------------------
4025

41-
MongoDB uses memory-mapped files for its data file management.
26+
MongoDB uses memory-mapped files for memory management.
4227

43-
When MongoDB memory-maps the data files (for, say, a map/reduce
44-
query), you're letting the OS know you'd like the contents of the
45-
files available as if they were in some portion of memory.
28+
MongoDB memory maps the files when they are first accessed; you're letting the OS know you'd like the contents of the files available as if they were in some portion of memory. It should be noted that each OS caches its own components in memory, and also provides memory buffers for network connections and disk drivers in addition to applications.
4629

47-
This doesn't necessarily mean it's in memory already-- when you go to
30+
This doesn't necessarily mean the files are in memory already-- when you go to
4831
access any point, the OS checks if this 'page' is in physical ram or
49-
not.
32+
not.
5033

51-
If it is, it returns whatever's in memory in that location. If
52-
it's not, then it will fetch that portion of the file, make sure it's
53-
in memory, and then return it to you.
34+
If the page is already in memory, it returns whatever's in memory in that location. If the page is not in memory, then it will fetch that portion of the file, make sure it's in memory, and then return it to you.
5435

5536
Writing works in the same fashion-- MongoDB tries to write to a memory
56-
page. If it's in RAM, then it works quickly (just swapping some bits
37+
page. If the page is in RAM, then it works quickly (just swapping some bits
5738
in the memory). The page will then be marked as 'dirty' and the OS
5839
will take care of flushing it back to disk, persisting your changes.
5940

41+
6042
What are page faults?
6143
---------------------
6244

6345
Page faults will occur if you're attempting to access some part of a
6446
memory-mapped file that *isn't* in memory.
6547

6648
This could potentially force the OS to find some not-recently-used
67-
page in physical RAM, get rid of it (maaybe write it back to disk if
49+
page in physical RAM, get rid of it (maybe write it back to disk if
6850
it's changed since it loaded), go back to disk, read the page, and
6951
load it into RAM...an expensive task, overall.
7052

7153
What is the difference between soft and hard page faults?
7254
---------------------------------------------------------
7355

56+
A page fault implies a "hard" page fault, which requires disk access. A "soft" page fault merely moves memory pages from one list to another, and is not as expensive.
57+
7458
What tools can I use to investigate storage use in MongoDB?
7559
-----------------------------------------------------------
60+
61+
There is a command whose output provides the current state of the "active" database, see :doc: 'Database Statistics Reference </reference/database-statistics>'.
62+
63+
What is the working set?
64+
------------------------
65+
66+
The working set is an approximation of the set of pages that a certain process will access in the future (say, during the next 't' time units), and more specifically is suggested to be an indication of what pages ought to be kept in main memory to allow most progress to be made in the execution of that process.
67+
68+
A common misconception in using MongoDB is that the working set can be
69+
reduced to a discrete value. It's important to understand that the
70+
working set is simply a way of thinking about the data one is
71+
accessing and that which MongoDB is working with frequently.
72+
73+
For instance, if you are running a query that has to do a full table scan, then your working set is every document scanned.
74+
Conversely, if your query only reads the most recent 100
75+
documents, then the working set will be those 100 documents.
76+
77+
-----------------------------------------------------------

0 commit comments

Comments
 (0)