bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/4] libpager: Store omit_data in an array


From: Sergey Bugaev
Subject: [PATCH 2/4] libpager: Store omit_data in an array
Date: Sat, 8 May 2021 18:31:42 +0300

While this is less efficient than using a single bit per page,
there is no guarantee that the kernel will not send us more than
32 pages at a time. Indeed, one can easily craft a situation where
it will send more by unmapping a large mapping.

Also, this function already uses on-stack arrays for tracking other
information about the pages; so do the same for whether the data
should be omited.
---
 libpager/data-return.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libpager/data-return.c b/libpager/data-return.c
index c0f5aaf7..db2f84e6 100644
--- a/libpager/data-return.c
+++ b/libpager/data-return.c
@@ -38,12 +38,12 @@ _pager_do_write_request (struct pager *p,
   short *pm_entries;
   int npages, i;
   char *notified;
+  char *omit_data;
   error_t *pagerrs;
   struct lock_request *lr;
   struct lock_list {struct lock_request *lr;
                    struct lock_list *next;} *lock_list, *ll;
   int wakeup;
-  int omitdata = 0;
 
   if (!p
       || p->port.class != _pager_class)
@@ -78,6 +78,9 @@ _pager_do_write_request (struct pager *p,
   npages = length / __vm_page_size;
   pagerrs = alloca (npages * sizeof (error_t));
 
+  omit_data = alloca (npages * (sizeof *omit_data));
+  memset (omit_data, 0, npages * (sizeof *omit_data));
+
   notified = alloca (npages * (sizeof *notified));
 #ifndef NDEBUG
   memset (notified, -1, npages * (sizeof *notified));
@@ -125,11 +128,10 @@ _pager_do_write_request (struct pager *p,
   /* Mark these pages as being paged out.  */
   if (initializing)
     {
-      assert_backtrace (npages <= 32);
       for (i = 0; i < npages; i++)
        {
          if (pm_entries[i] & PM_INIT)
-           omitdata |= 1 << i;
+           omit_data[i] = 1;
          else
            pm_entries[i] |= PM_PAGINGOUT | PM_INIT;
        }
@@ -162,7 +164,7 @@ _pager_do_write_request (struct pager *p,
      but until the pager library interface is changed, this will have to do. */
 
   for (i = 0; i < npages; i++)
-    if (!(omitdata & (1 << i)))
+    if (!omit_data[i])
       pagerrs[i] = pager_write_page (p->upi,
                                     offset + (vm_page_size * i),
                                     data + (vm_page_size * i));
@@ -175,7 +177,7 @@ _pager_do_write_request (struct pager *p,
   wakeup = 0;
   for (i = 0; i < npages; i++)
     {
-      if (omitdata & (1 << i))
+      if (omit_data[i])
        {
          notified[i] = 0;
          continue;
-- 
2.31.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]