Bug 532039 - Improve perf of IsLowMemory. r=bsmedberg.

This commit is contained in:
Doug Turner 2009-12-02 00:24:19 -08:00
Родитель 82584b3c16
Коммит edc6925e37
1 изменённых файлов: 18 добавлений и 7 удалений

Просмотреть файл

@ -61,7 +61,7 @@
#include <osso-mem.h>
#include <fcntl.h>
#include <unistd.h>
const char* kHighMark = "/sys/kernel/high_watermark";
static const char kHighMark[] = "/sys/kernel/high_watermark";
#endif
// Some platforms notify you when system memory is low, others do not.
@ -129,14 +129,25 @@ nsMemoryImpl::IsLowMemory(PRBool *result)
*result = (stat.ullAvailPageFile < kRequiredMemory) &&
((float)stat.ullAvailPageFile / stat.ullTotalPageFile) < 0.1;
#elif defined(NS_OSSO)
int fd = open (kHighMark, O_RDONLY);
if (fd == -1) {
*result = PR_FALSE;
return NS_OK;
// We see about 1/4 of the cost by caching the fd and using
// rewind. XXX leaking this fd.
static int osso_highmark_fd = -1;
if (osso_highmark_fd == -1) {
osso_highmark_fd = open (kHighMark, O_RDONLY);
if (osso_highmark_fd == -1) {
NS_ERROR("can't find the osso highmark file");
*result = PR_FALSE;
return NS_OK;
}
}
// be kind, rewind.
lseek(osso_highmark_fd, 0L, SEEK_SET);
int c = 0;
read (fd, &c, 1);
close(fd);
read (osso_highmark_fd, &c, 1);
*result = (c == '1');
#else
*result = PR_FALSE;