[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/4] libpager: Do not throw away precious pages
From: |
Sergey Bugaev |
Subject: |
[PATCH 4/4] libpager: Do not throw away precious pages |
Date: |
Sat, 8 May 2021 18:31:44 +0300 |
The kernel invokes memory_object_data_return () with dirty = 0 in two
cases: if notification on eviction was requested, or when returning
precious pages. Properly distinguish between the two cases, and only
throw the clean page away in the former case.
---
libpager/data-return.c | 54 ++++++++++++++----------------------------
1 file changed, 18 insertions(+), 36 deletions(-)
diff --git a/libpager/data-return.c b/libpager/data-return.c
index 2cc9f1f8..304e88bc 100644
--- a/libpager/data-return.c
+++ b/libpager/data-return.c
@@ -93,23 +93,6 @@ _pager_do_write_request (struct pager *p,
pm_entries = &p->pagemap[offset / __vm_page_size];
- if (! dirty)
- {
- munmap ((void *) data, length);
- if (!kcopy) {
- /* Prepare notified array. */
- for (i = 0; i < npages; i++)
- notified[i] = (p->notify_on_evict
- && ! (pm_entries[i] & PM_PAGEINWAIT));
-
- goto notify;
- }
- else {
- _pager_allow_termination (p);
- goto release_out;
- }
- }
-
/* Make sure there are no other in-progress writes for any of these
pages before we begin. This imposes a little more serialization
than we really have to require (because *all* future writes on
@@ -118,26 +101,24 @@ _pager_do_write_request (struct pager *p,
/* XXX: Is this still needed? */
retry:
for (i = 0; i < npages; i++)
- if (pm_entries[i] & PM_PAGINGOUT)
- {
- pm_entries[i] |= PM_WRITEWAIT;
- pthread_cond_wait (&p->wakeup, &p->interlock);
- goto retry;
+ {
+ if ((initializing && (pm_entries[i] & PM_INIT)) ||
+ (!dirty && !(pm_entries[i] & PM_PRECIOUS)))
+ {
+ omit_data[i] = 1;
+ continue;
+ }
+ if (pm_entries[i] & PM_PAGINGOUT)
+ {
+ pm_entries[i] |= PM_WRITEWAIT;
+ pthread_cond_wait (&p->wakeup, &p->interlock);
+ goto retry;
}
+ }
/* Mark these pages as being paged out. */
- if (initializing)
- {
- for (i = 0; i < npages; i++)
- {
- if (pm_entries[i] & PM_INIT)
- omit_data[i] = 1;
- else
- pm_entries[i] |= PM_PAGINGOUT | PM_INIT;
- }
- }
- else
- for (i = 0; i < npages; i++)
+ for (i = 0; i < npages; i++)
+ if (!omit_data[i])
pm_entries[i] |= PM_PAGINGOUT | PM_INIT;
/* If this write occurs while a lock is pending, record
@@ -179,7 +160,9 @@ _pager_do_write_request (struct pager *p,
{
if (omit_data[i])
{
- notified[i] = 0;
+ notified[i] = (p->notify_on_evict
+ && !kcopy
+ && ! (pm_entries[i] & PM_PAGEINWAIT));
continue;
}
@@ -225,7 +208,6 @@ _pager_do_write_request (struct pager *p,
if (wakeup)
pthread_cond_broadcast (&p->wakeup);
- notify:
_pager_allow_termination (p);
pthread_mutex_unlock (&p->interlock);
--
2.31.1
- Re: [PATCH 6/6] libpager: Use libc heap for pagemap, (continued)
- [PATCH 3/6] libpager: Add error handling to various functions, Sergey Bugaev, 2021/05/06
- [PATCH 5/6] libpager: Fix overallocating pagemap, Sergey Bugaev, 2021/05/06
- And another patch..., Sergey Bugaev, 2021/05/06
- Re: And another patch..., Samuel Thibault, 2021/05/08
- Re: And another patch..., Sergey Bugaev, 2021/05/08
- [PATCH 0/4] _pager_do_write_request fixes, Sergey Bugaev, 2021/05/08
- [PATCH 3/4] libpager: Track which pages are precious, Sergey Bugaev, 2021/05/08
- [PATCH 4/4] libpager: Do not throw away precious pages,
Sergey Bugaev <=
- [PATCH 2/4] libpager: Store omit_data in an array, Sergey Bugaev, 2021/05/08
- [PATCH 1/4] libpager: pager_write_page () should not unmap page, Sergey Bugaev, 2021/05/08
- Re: [PATCH 1/4] libpager: pager_write_page () should not unmap page, Samuel Thibault, 2021/05/08
- Re: [PATCH 0/4] _pager_do_write_request fixes, Samuel Thibault, 2021/05/08