Keith Packard
2009-Dec-31 20:49 UTC
[Fontconfig] [PATCH 1/2] Use MAP_POPULATE to eliminate startup page faults.
MAP_POPULATE fills in the PTEs with the pages for the font cache files
eliminating the per-page faults which would otherwise be necessary as the
cache is scanned to match the first font.
---
src/fccache.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/src/fccache.c b/src/fccache.c
index 69e1a6b..a59e0a3 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -552,6 +552,10 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat, struct stat
*dir_stat)
if (fd_stat->st_size >= FC_CACHE_MIN_MMAP)
{
#if defined(HAVE_MMAP) || defined(__CYGWIN__)
+#ifndef MAP_POPULATE
+#define MAP_POPULATE 0
+#endif
+ cache = mmap (0, fd_stat->st_size, PROT_READ, MAP_SHARED | MAP_POPULATE,
fd, 0);
cache = mmap (0, fd_stat->st_size, PROT_READ, MAP_SHARED, fd, 0);
if (cache == MAP_FAILED)
cache = NULL;
--
1.6.5.7
This eliminates several warnings about improper const usage as well as
making it more prevalent in the implementation.
Signed-off-by: Keith Packard <keithp at keithp.com>
---
fc-lang/fc-lang.c | 6 +++---
src/fccache.c | 2 +-
src/fccfg.c | 8 ++++----
src/fcint.h | 18 +++++++++---------
src/fcxml.c | 14 +++++++-------
5 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/fc-lang/fc-lang.c b/fc-lang/fc-lang.c
index 21d568d..5b776b7 100644
--- a/fc-lang/fc-lang.c
+++ b/fc-lang/fc-lang.c
@@ -129,7 +129,7 @@ static const FcCharSet *
scan (FILE *f, char *file, FcCharSetFreezer *freezer)
{
FcCharSet *c = 0;
- FcCharSet *n;
+ const FcCharSet *n;
int start, end, ucs4;
char line[1024];
int lineno = 0;
@@ -155,7 +155,7 @@ scan (FILE *f, char *file, FcCharSetFreezer *freezer)
c = FcCharSetCreate ();
if (!FcCharSetMerge (c, n, NULL))
fatal (file, lineno, "out of memory");
- FcCharSetDestroy (n);
+ FcCharSetDestroy ((FcCharSet *) n);
continue;
}
if (strchr (line, ''-''))
@@ -232,7 +232,7 @@ typedef struct _Entry {
static int compare (const void *a, const void *b)
{
const Entry const *as = a, *bs = b;
- return FcStrCmpIgnoreCase (as->file, bs->file);
+ return FcStrCmpIgnoreCase ((const FcChar8 *) as->file, (const FcChar8 *)
bs->file);
}
#define MAX_LANG 1024
diff --git a/src/fccache.c b/src/fccache.c
index a59e0a3..b00de08 100644
--- a/src/fccache.c
+++ b/src/fccache.c
@@ -944,7 +944,7 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
*/
if (cache->size < FC_CACHE_MIN_MMAP &&
(skip = FcCacheFindByAddr (cache)) &&
- FcStat (cache_hashed, &cache_stat))
+ FcStat ((const char *) cache_hashed, &cache_stat))
{
skip->cache_dev = cache_stat.st_dev;
skip->cache_ino = cache_stat.st_ino;
diff --git a/src/fccfg.c b/src/fccfg.c
index 0f89b57..ee9dadc 100644
--- a/src/fccfg.c
+++ b/src/fccfg.c
@@ -866,7 +866,7 @@ FcConfigCompareValue (const FcValue *left_o,
#define FcDoubleTrunc(d) ((d) >= 0 ? _FcDoubleFloor (d) : -_FcDoubleFloor
(-(d)))
static FcValue
-FcConfigEvaluate (FcPattern *p, FcExpr *e)
+FcConfigEvaluate (FcPattern *p, const FcExpr *e)
{
FcValue v, vl, vr;
FcResult r;
@@ -908,7 +908,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
v = FcValueSave (v);
break;
case FcOpConst:
- if (FcNameConstant (e->u.constant, &v.u.i))
+ if (FcNameConstant ((FcChar8 *) e->u.constant, &v.u.i))
v.type = FcTypeInteger;
else
v.type = FcTypeVoid;
@@ -1136,7 +1136,7 @@ FcConfigMatchValueList (FcPattern *p,
FcValueList *values)
{
FcValueList *ret = 0;
- FcExpr *e = t->expr;
+ const FcExpr *e = t->expr;
FcValue value;
FcValueList *v;
@@ -1177,7 +1177,7 @@ FcConfigMatchValueList (FcPattern *p,
}
static FcValueList *
-FcConfigValues (FcPattern *p, FcExpr *e, FcValueBinding binding)
+FcConfigValues (FcPattern *p, const FcExpr *e, FcValueBinding binding)
{
FcValueList *l;
diff --git a/src/fcint.h b/src/fcint.h
index 233b4c3..b847779 100644
--- a/src/fcint.h
+++ b/src/fcint.h
@@ -233,16 +233,16 @@ typedef enum _FcOp {
typedef struct _FcExpr {
FcOp op;
union {
- int ival;
- double dval;
- FcChar8 *sval;
- FcMatrix *mval;
- FcBool bval;
- FcCharSet *cval;
- FcObject object;
- FcChar8 *constant;
+ int ival;
+ double dval;
+ const FcChar8 *sval;
+ const FcMatrix *mval;
+ FcBool bval;
+ const FcCharSet *cval;
+ FcObject object;
+ const FcChar8 *constant;
struct {
- struct _FcExpr *left, *right;
+ const struct _FcExpr *left, *right;
} tree;
} u;
} FcExpr;
diff --git a/src/fcxml.c b/src/fcxml.c
index 9428468..6a5a452 100644
--- a/src/fcxml.c
+++ b/src/fcxml.c
@@ -61,7 +61,7 @@
#endif
static void
-FcExprDestroy (FcExpr *e);
+FcExprDestroy (const FcExpr *e);
void
FcTestDestroy (FcTest *test)
@@ -171,7 +171,7 @@ FcExprCreateOp (FcConfig *config, FcExpr *left, FcOp op,
FcExpr *right)
}
static void
-FcExprDestroy (FcExpr *e)
+FcExprDestroy (const FcExpr *e)
{
if (!e)
return;
@@ -183,10 +183,10 @@ FcExprDestroy (FcExpr *e)
case FcOpString:
break;
case FcOpMatrix:
- FcMatrixFree (e->u.mval);
+ FcMatrixFree ((FcMatrix *) e->u.mval);
break;
case FcOpCharSet:
- FcCharSetDestroy (e->u.cval);
+ FcCharSetDestroy ((FcCharSet *) e->u.cval);
break;
case FcOpBool:
break;
@@ -232,7 +232,7 @@ FcExprDestroy (FcExpr *e)
break;
}
- e->op = FcOpNil;
+ ((FcExpr *) e)->op = FcOpNil;
}
void
@@ -525,7 +525,7 @@ FcTypecheckValue (FcConfigParse *parse, FcType value, FcType
type)
}
static void
-FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType type)
+FcTypecheckExpr (FcConfigParse *parse, const FcExpr *expr, FcType type)
{
const FcObjectType *o;
const FcConstant *c;
@@ -559,7 +559,7 @@ FcTypecheckExpr (FcConfigParse *parse, FcExpr *expr, FcType
type)
FcTypecheckValue (parse, o->type, type);
break;
case FcOpConst:
- c = FcNameGetConstant (expr->u.constant);
+ c = FcNameGetConstant ((FcChar8 *) expr->u.constant);
if (c)
{
o = FcNameGetObjectType (c->object);
--
1.6.5.7
Behdad Esfahbod
2009-Dec-31 20:54 UTC
[Fontconfig] [PATCH 1/2] Use MAP_POPULATE to eliminate startup page faults.
On 12/31/2009 09:49 PM, Keith Packard wrote:> + cache = mmap (0, fd_stat->st_size, PROT_READ, MAP_SHARED | MAP_POPULATE, fd, 0);Hi Keith, The mmap manpage says: MAP_POPULATE is only supported for private mappings since Linux 2.6.23. Does the POPULATE do anything with MAP_SHARED? An alternative would be calling fadvise(). Thanks, behdad
Keith Packard
2010-Jan-01 00:27 UTC
[Fontconfig] [PATCH 1/2] Use MAP_POPULATE to eliminate startup page faults.
On Thu, 31 Dec 2009 21:54:10 +0100, Behdad Esfahbod <behdad at behdad.org> wrote:> The mmap manpage says: MAP_POPULATE is only supported for private mappings > since Linux 2.6.23. Does the POPULATE do anything with MAP_SHARED?Hrm. I recall measuring this a while ago and finding some difference in the page fault counts, but I cannot replicate that now (even after fixing my patch to not call mmap twice). I''d say you can discard this patch.> An alternative would be calling fadvise().This also has no effect: posix_fadvise(fd, 0, fd_stat->st_size, POSIX_FADV_WILLNEED)) Looks like whatever effect I measured has disappeared in more recent kernels. -- keith.packard at intel.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20091231/ffd86223/attachment.pgp