简体   繁体   English

我应该管理页面还是只依靠虚拟内存?

[英]Should I manage pages or just lean on virtual memory?

I'm writing a database-style thing in C (ie it will store and operate on about 500,000 records). 我正在用C编写数据库风格的东西(即它将存储和操作大约500,000条记录)。 I'm going to be running it in a memory-constrained environment (VPS) so I don't want memory usage to balloon. 我将在内存受限的环境(VPS)中运行它,所以我不希望内存使用量增加。 I'm not going to be handling huge amounts of data - perhaps up to 200MB in total, but I want the memory footprint to remain in the region of 30MB (pulling these numbers out of the air). 我不打算处理大量的数据 - 总共可能高达200MB,但我希望内存占用空间保持在30MB(将这些数字从空中拉出)。

My instinct is doing my own page handling (real databases do this), but I have received advice saying that I should just allocate it all and allow the OS to do the VM paging for me. 我的直觉是我自己的页面处理(真正的数据库这样做),但我收到的建议说我应该只分配它并允许操作系统为我做VM分页。 My numbers will never rise above this order of magnitude. 我的数字永远不会超过这个数量级。 Which is the best choice in this case? 在这种情况下哪个是最佳选择?

Assuming the second choice, at what point would it be sensible for a program to do its own paging? 假设第二种选择,在什么时候程序进行自己的分页是否明智? Obviously RDBMsses that can handle gigabytes must do this, but there must be a point along the scale at which the question is worth asking. 显然,可以处理千兆字节的RDBMsses必须这样做,但在问题值得提出的规模上必须有一点。

Thanks! 谢谢!

Use malloc until it's running. 使用malloc直到它运行。 Then and only then , start profiling. 然后,只有这样 ,开始分析。 If you run into the same performance issues as the proprietary and mainstream "real databases", you will naturally begin to perform cache/page/alignment optimizations. 如果遇到与专有和主流“真实数据库”相同的性能问题,您自然会开始执行缓存/页面/对齐优化。 These things can easily be slotted in after you have a working database, and are orthogonal to having a working database. 在拥有可用的数据库之后,可以轻松地插入这些内容,并且与具有工作数据库正交。

The database management systems that perform their own paging also benefit from the investment of huge research efforts to make sure their paging algorithms function well under varying system and load conditions. 执行自己的分页的数据库管理系统也受益于大量研究工作的投入,以确保其分页算法在不同的系统和负载条件下运行良好。 Unless you have a similar set of resources at your disposal I'd recommend against taking that approach. 除非您拥有类似的资源,否则我建议不要采取这种方法。

The OS paging system you have at your disposal has already benefit from tuning efforts of many people. 您可以随意使用的OS分页系统已经受益于许多人的调优工作。

There are, however, some things you can do to tune your OS to benefit database type access (large sequential I/O operations) vs. the typical desktop tuning (mix of seq. and random I/O). 但是,您可以采取一些措施来调整操作系统以使数据库类型访问(大型顺序I / O操作)与典型的桌面调优(seq。和随机I / O的混合)相比。

In short, if you are a one man team or a small team, you probably should make use of existing tools rather than trying to roll your own in that particular area. 简而言之,如果你是一个单人团队或一个小团队,你可能应该利用现有的工具,而不是试图在那个特定领域自己动手。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM