repo: Only use mmap() for metadata > 16k
See http://stackoverflow.com/questions/258091/when-should-i-use-mmap-for-file-access and https://lwn.net/Articles/591978/ I didn't really notice much performance difference in some small tests, but I happened to be stracing and realized we were `mmap()`ing even for 50 bytes which is not very useful, so let's not do it. Closes: #489 Approved by: alexlarsson
This commit is contained in:
parent
8dbb104cdc
commit
e127070550
|
|
@ -2544,6 +2544,7 @@ load_metadata_internal (OstreeRepo *self,
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
char loose_path_buf[_OSTREE_LOOSE_PATH_MAX];
|
char loose_path_buf[_OSTREE_LOOSE_PATH_MAX];
|
||||||
|
struct stat stbuf;
|
||||||
glnx_fd_close int fd = -1;
|
glnx_fd_close int fd = -1;
|
||||||
g_autoptr(GInputStream) ret_stream = NULL;
|
g_autoptr(GInputStream) ret_stream = NULL;
|
||||||
g_autoptr(GVariant) ret_variant = NULL;
|
g_autoptr(GVariant) ret_variant = NULL;
|
||||||
|
|
@ -2565,23 +2566,39 @@ load_metadata_internal (OstreeRepo *self,
|
||||||
|
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
{
|
{
|
||||||
|
if (fstat (fd, &stbuf) < 0)
|
||||||
|
{
|
||||||
|
glnx_set_error_from_errno (error);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (out_variant)
|
if (out_variant)
|
||||||
{
|
{
|
||||||
GMappedFile *mfile;
|
/* http://stackoverflow.com/questions/258091/when-should-i-use-mmap-for-file-access */
|
||||||
|
if (stbuf.st_size > 16*1024)
|
||||||
|
{
|
||||||
|
GMappedFile *mfile;
|
||||||
|
|
||||||
mfile = g_mapped_file_new_from_fd (fd, FALSE, error);
|
mfile = g_mapped_file_new_from_fd (fd, FALSE, error);
|
||||||
if (!mfile)
|
if (!mfile)
|
||||||
goto out;
|
goto out;
|
||||||
ret_variant = g_variant_new_from_data (ostree_metadata_variant_type (objtype),
|
ret_variant = g_variant_new_from_data (ostree_metadata_variant_type (objtype),
|
||||||
g_mapped_file_get_contents (mfile),
|
g_mapped_file_get_contents (mfile),
|
||||||
g_mapped_file_get_length (mfile),
|
g_mapped_file_get_length (mfile),
|
||||||
TRUE,
|
TRUE,
|
||||||
(GDestroyNotify) g_mapped_file_unref,
|
(GDestroyNotify) g_mapped_file_unref,
|
||||||
mfile);
|
mfile);
|
||||||
g_variant_ref_sink (ret_variant);
|
g_variant_ref_sink (ret_variant);
|
||||||
|
}
|
||||||
if (out_size)
|
else
|
||||||
*out_size = g_variant_get_size (ret_variant);
|
{
|
||||||
|
GBytes *data = glnx_fd_readall_bytes (fd, cancellable, error);
|
||||||
|
if (!data)
|
||||||
|
goto out;
|
||||||
|
ret_variant = g_variant_new_from_bytes (ostree_metadata_variant_type (objtype),
|
||||||
|
data, TRUE);
|
||||||
|
g_variant_ref_sink (ret_variant);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (out_stream)
|
else if (out_stream)
|
||||||
{
|
{
|
||||||
|
|
@ -2589,15 +2606,10 @@ load_metadata_internal (OstreeRepo *self,
|
||||||
if (!ret_stream)
|
if (!ret_stream)
|
||||||
goto out;
|
goto out;
|
||||||
fd = -1; /* Transfer ownership */
|
fd = -1; /* Transfer ownership */
|
||||||
if (out_size)
|
|
||||||
{
|
|
||||||
struct stat stbuf;
|
|
||||||
|
|
||||||
if (!glnx_stream_fstat ((GFileDescriptorBased*)ret_stream, &stbuf, error))
|
|
||||||
goto out;
|
|
||||||
*out_size = stbuf.st_size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (out_size)
|
||||||
|
*out_size = stbuf.st_size;
|
||||||
}
|
}
|
||||||
else if (self->parent_repo)
|
else if (self->parent_repo)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue