eina: fallback for case where file system doesn't handle MAP_HUGETLB properly.

SVN revision: 64181
This commit is contained in:
Cedric BAIL 2011-10-19 16:09:14 +00:00
parent a396da70de
commit e40386c4f9
1 changed files with 33 additions and 10 deletions

View File

@ -138,6 +138,8 @@ struct _Eina_File_Map
unsigned long int length; unsigned long int length;
int refcount; int refcount;
Eina_Bool hugetlb : 1;
}; };
static Eina_Hash *_eina_file_cache = NULL; static Eina_Hash *_eina_file_cache = NULL;
@ -431,17 +433,13 @@ _eina_file_map_key_hash(const unsigned long int *key, int key_length __UNUSED__)
#ifndef MAP_POPULATE #ifndef MAP_POPULATE
static int static int
_eina_file_map_populate(char *map, unsigned int size) _eina_file_map_populate(char *map, unsigned int size, Eina_Bool hugetlb)
{ {
int r = 0xDEADBEEF; int r = 0xDEADBEEF;
int i; int i;
int s; int s;
#ifdef MAP_HUGETLB s = hugetlb ? EINA_HUGE_PAGE : EINA_SMALL_PAGE;
s = size > EINA_HUGE_PAGE ? EINA_HUGE_PAGE : EINA_SMALL_PAGE;
#else
s = EINA_SMALL_PAGE;
#endif
for (i = 0; i < size; i += s) for (i = 0; i < size; i += s)
r ^= map[i]; r ^= map[i];
@ -453,7 +451,7 @@ _eina_file_map_populate(char *map, unsigned int size)
#endif #endif
static int static int
_eina_file_map_rule_apply(Eina_File_Populate rule, void *addr, unsigned long int size) _eina_file_map_rule_apply(Eina_File_Populate rule, void *addr, unsigned long int size, Eina_Bool hugetlb)
{ {
int tmp = 42; int tmp = 42;
int flag = MADV_RANDOM; int flag = MADV_RANDOM;
@ -470,7 +468,9 @@ _eina_file_map_rule_apply(Eina_File_Populate rule, void *addr, unsigned long int
#ifndef MAP_POPULATE #ifndef MAP_POPULATE
if (rule == EINA_FILE_POPULATE) if (rule == EINA_FILE_POPULATE)
tmp ^= _eina_file_map_populate(addr, size); tmp ^= _eina_file_map_populate(addr, size, hugetlb);
#else
(void) hugetlb;
#endif #endif
return tmp; return tmp;
@ -1041,10 +1041,22 @@ eina_file_map_all(Eina_File *file, Eina_File_Populate rule)
eina_lock_take(&file->lock); eina_lock_take(&file->lock);
if (file->global_map == MAP_FAILED) if (file->global_map == MAP_FAILED)
file->global_map = mmap(NULL, file->length, PROT_READ, flags, file->fd, 0); file->global_map = mmap(NULL, file->length, PROT_READ, flags, file->fd, 0);
#ifdef MAP_HUGETLB
if ((file->global_map == MAP_FAILED) && (flags & MAP_HUGETLB))
{
flags &= ~MAP_HUGETLB;
file->global_map = mmap(NULL, file->length, PROT_READ, flags, file->fd, 0);
}
#endif
if (file->global_map != MAP_FAILED) if (file->global_map != MAP_FAILED)
{ {
_eina_file_map_rule_apply(rule, file->global_map, file->length); Eina_Bool hugetlb = EINA_FALSE;
#ifdef MAP_HUGETLB
hugetlb = !!(flags & MAP_HUGETLB);
#endif
_eina_file_map_rule_apply(rule, file->global_map, file->length, hugetlb);
file->global_refcount++; file->global_refcount++;
ret = file->global_map; ret = file->global_map;
} }
@ -1093,6 +1105,17 @@ eina_file_map_new(Eina_File *file, Eina_File_Populate rule,
if (!map) goto on_error; if (!map) goto on_error;
map->map = mmap(NULL, length, PROT_READ, flags, file->fd, offset); map->map = mmap(NULL, length, PROT_READ, flags, file->fd, offset);
#ifdef MAP_HUGETLB
if (map->map == MAP_FAILED && (flags & MAP_HUGETLB))
{
flags &= ~MAP_HUGETLB;
map->map = mmap(NULL, length, PROT_READ, flags, file->fd, offset);
}
map->hugetlb = !!(flags & MAP_HUGETLB);
#else
map->hugetlb = EINA_FALSE;
#endif
map->offset = offset; map->offset = offset;
map->length = length; map->length = length;
map->refcount = 0; map->refcount = 0;
@ -1105,7 +1128,7 @@ eina_file_map_new(Eina_File *file, Eina_File_Populate rule,
map->refcount++; map->refcount++;
_eina_file_map_rule_apply(rule, map->map, length); _eina_file_map_rule_apply(rule, map->map, length, map->hugetlb);
eina_lock_release(&file->lock); eina_lock_release(&file->lock);