summaryrefslogtreecommitdiff
path: root/console
diff options
context:
space:
mode:
authorJustus Winter <justus@gnupg.org>2016-05-22 19:35:10 +0200
committerJustus Winter <justus@gnupg.org>2016-08-07 23:28:45 +0200
commit0e3a795af98b6441d0a9928036e140978511e272 (patch)
tree801984832811a5f7bb24c847e07b5b47900e9737 /console
parentceae83bd25aadee094ec9d3a95cf27510cea2037 (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 'console')
-rw-r--r--console/pager.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/console/pager.c b/console/pager.c
index 05074a75..d60935a1 100644
--- a/console/pager.c
+++ b/console/pager.c
@@ -49,12 +49,11 @@ static struct pager_requests *pager_requests;
void
pager_clear_user_data (struct user_pager_info *upi)
{
- int idx;
+ size_t idx;
for (idx = 0; idx < upi->memobj_npages; idx++)
if (upi->memobj_pages[idx])
vm_deallocate (mach_task_self (), upi->memobj_pages[idx], vm_page_size);
- free (upi);
}
@@ -148,21 +147,17 @@ user_pager_create (struct user_pager *user_pager, unsigned int npages,
error_t err;
struct user_pager_info *upi;
- upi = calloc (1, sizeof (struct user_pager_info)
- + sizeof (vm_address_t) * npages);
- if (!upi)
+ /* XXX Are the values 1 and MEMORY_OBJECT_COPY_DELAY correct? */
+ user_pager->pager = \
+ pager_create_alloc (sizeof *upi + sizeof (vm_address_t) * npages,
+ pager_bucket, 1, MEMORY_OBJECT_COPY_DELAY, 0);
+ if (!user_pager->pager)
return errno;
+ upi = pager_get_upi (user_pager->pager);
upi->memobj_npages = npages;
+ memset (upi->memobj_pages, 0, sizeof (vm_address_t) * npages);
- /* XXX Are the values 1 and MEMORY_OBJECT_COPY_DELAY correct? */
- user_pager->pager = pager_create (upi, pager_bucket,
- 1, MEMORY_OBJECT_COPY_DELAY, 0);
- if (!user_pager->pager)
- {
- free (upi);
- return errno;
- }
user_pager->memobj = pager_get_port (user_pager->pager);
ports_port_deref (user_pager->pager);
@@ -182,7 +177,6 @@ user_pager_create (struct user_pager *user_pager, unsigned int npages,
VM_INHERIT_NONE);
if (err)
{
- /* UPI will be cleaned up by libpager. */
mach_port_deallocate (mach_task_self (), user_pager->memobj);
return err;
}