performance implications of releasing resources and context switches
- From: Ambrose Silk <silky@xxxxxxxxxxxxxx>
- Date: Mon, 28 Jul 2008 11:33:36 -0400
I've been brainstorming on how to speed up an application I'm working on and have observed that it spends a lot of time in system calls, so I'm looking at ways of reducing their number. In particular one of the prime offenders is mmap; there are thousands of mmap/munmap sequences. Similar for open/close.
It seems there might be a performance benefit to forgoing the munmap() and close() calls and letting them be handled by _exit() instead. As I read the docs, _exit() is a single system call (thus 1 context switch) which guarantees to remove all mappings, close all open files, etc.
To date I've been trying to make my code "pure": close every open file descriptor, unmap every mapping, etc. But it's beginning to seem that there's a tension between purity and speed here. So am I right that _exit() can clean up more efficiently than can multiple calls from user space?
In fact I can imagine a useful library to help with this. In the same way that file writes are not flushed to disk right away, there could be a user-space library which holds a list of close() and munmap() requests. If an open() or mmap() fails with "too many open files" it could flush its cache but otherwise hold onto them and let exit processing handle them.
BTW, I'd prefer for this not to descend into a "don't-do-that" fest. I agree that it's generally best to clean up after yourself and that in most cases the benefits to stability and clean code outweigh the performance costs. But there will be occasional cases when they don't.
A. Silk
.
- Follow-Ups:
- Re: performance implications of releasing resources and context switches
- From: David Schwartz
- Re: performance implications of releasing resources and context switches
- From: Gordon Burditt
- Re: performance implications of releasing resources and context switches
- From: fjblurt
- Re: performance implications of releasing resources and context switches
- Prev by Date: Re: File Unique ID
- Next by Date: Re: File Unique ID
- Previous by thread: File Unique ID
- Next by thread: Re: performance implications of releasing resources and context switches
- Index(es):
Relevant Pages
|