diff options
author | Justus Winter <justus@gnupg.org> | 2016-05-22 19:35:10 +0200 |
---|---|---|
committer | Justus Winter <justus@gnupg.org> | 2016-08-07 23:28:45 +0200 |
commit | 0e3a795af98b6441d0a9928036e140978511e272 (patch) | |
tree | 801984832811a5f7bb24c847e07b5b47900e9737 /libpager | |
parent | ceae83bd25aadee094ec9d3a95cf27510cea2037 (diff) |
libpager: provide 'pager_create_alloc'
Add a variant to 'pager_create' that allocates memory for the user
hook next to the pager data increasing locality.
* console/pager.c (pager_clear_user_data): Fix type of 'idx', do not
free 'upi'.
(user_pager_create): Use the new function.
* doc/hurd.texi: Document new function.
* ext2fs/pager.c (pager_clear_user_data): Don't free 'upi'.
(diskfs_get_filemap): Use the new function.
* fatfs/pager.c (pager_clear_user_data): Don't free 'upi'.
(diskfs_get_filemap): Use the new function.
* isofs/pager.c (pager_clear_user_data): Don't free 'upi'.
(diskfs_get_filemap): Use the new function.
* libpager/pager-create.c (_pager_create): New generic allocation
function.
(pager_create): Use the new generic function.
(pager_create_alloc): New function.
* libpager/pager.h (pager_create_alloc): New prototype.
Diffstat (limited to 'libpager')
-rw-r--r-- | libpager/pager-create.c | 50 | ||||
-rw-r--r-- | libpager/pager.h | 8 |
2 files changed, 49 insertions, 9 deletions
diff --git a/libpager/pager-create.c b/libpager/pager-create.c index b583f023..b3b7c8f0 100644 --- a/libpager/pager-create.c +++ b/libpager/pager-create.c @@ -17,21 +17,19 @@ #include "priv.h" -/* Create and return a new pager with user info UPI. */ -struct pager * -pager_create (struct user_pager_info *upi, - struct port_bucket *bucket, - boolean_t may_cache, - memory_object_copy_strategy_t copy_strategy, - boolean_t notify_on_evict) +static struct pager * +_pager_create (size_t size, + struct port_bucket *bucket, + boolean_t may_cache, + memory_object_copy_strategy_t copy_strategy, + boolean_t notify_on_evict) { struct pager *p; - errno = ports_create_port (_pager_class, bucket, sizeof (struct pager), &p); + errno = ports_create_port (_pager_class, bucket, sizeof *p + size, &p); if (errno) return 0; - p->upi = upi; p->pager_state = NOTINIT; pthread_mutex_init (&p->interlock, NULL); pthread_cond_init (&p->wakeup, NULL); @@ -50,6 +48,40 @@ pager_create (struct user_pager_info *upi, return p; } +/* Create and return a new pager with user info UPI. */ +struct pager * +pager_create (struct user_pager_info *upi, + struct port_bucket *bucket, + boolean_t may_cache, + memory_object_copy_strategy_t copy_strategy, + boolean_t notify_on_evict) +{ + struct pager *p; + + p = _pager_create (0, bucket, may_cache, copy_strategy, notify_on_evict); + if (p) + p->upi = upi; + + return p; +} + +struct pager * +pager_create_alloc (size_t u_pager_size, + struct port_bucket *bucket, + boolean_t may_cache, + memory_object_copy_strategy_t copy_strategy, + boolean_t notify_on_evict) +{ + struct pager *p; + + p = _pager_create (u_pager_size, bucket, may_cache, copy_strategy, + notify_on_evict); + if (p) + p->upi = (struct user_pager_info *) ((char *) p + sizeof *p); + + return p; +} + /* This causes the function to be run at startup by compiler magic. */ static void create_class (void) __attribute__ ((constructor)); diff --git a/libpager/pager.h b/libpager/pager.h index df4db686..d2a8d397 100644 --- a/libpager/pager.h +++ b/libpager/pager.h @@ -69,6 +69,14 @@ pager_create (struct user_pager_info *u_pager, memory_object_copy_strategy_t copy_strategy, boolean_t notify_on_evict); +/* Likewise, but also allocate space for the user hook. */ +struct pager * +pager_create_alloc (size_t u_pager_size, + struct port_bucket *bucket, + boolean_t may_cache, + memory_object_copy_strategy_t copy_strategy, + boolean_t notify_on_evict); + /* Return the user_pager_info struct associated with a pager. */ struct user_pager_info * pager_get_upi (struct pager *p); |