From c1e81855bc8ad2a9078906b5f7ba808f388842ab Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Fri, 17 Sep 2021 09:55:12 -0700 Subject: [PATCH] demand_paging: eviction/nru: fix incorrect dirty bit return val In k_mem_paging_eviction_select(), the returned dirty bit value may not be actually associated with the page selected, but rather the last page examined. So fix this. Signed-off-by: Daniel Leung --- subsys/demand_paging/eviction/nru.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/subsys/demand_paging/eviction/nru.c b/subsys/demand_paging/eviction/nru.c index 650f54feb2..05bc33c359 100644 --- a/subsys/demand_paging/eviction/nru.c +++ b/subsys/demand_paging/eviction/nru.c @@ -45,6 +45,7 @@ struct z_page_frame *k_mem_paging_eviction_select(bool *dirty_ptr) unsigned int last_prec = 4U; struct z_page_frame *last_pf = NULL, *pf; bool accessed; + bool last_dirty = false; bool dirty = false; uintptr_t flags, phys; @@ -71,18 +72,20 @@ struct z_page_frame *k_mem_paging_eviction_select(bool *dirty_ptr) if (prec == 0) { /* If we find a not accessed, clean page we're done */ last_pf = pf; + last_dirty = dirty; break; } if (prec < last_prec) { last_prec = prec; last_pf = pf; + last_dirty = dirty; } } /* Shouldn't ever happen unless every page is pinned */ __ASSERT(last_pf != NULL, "no page to evict"); - *dirty_ptr = dirty; + *dirty_ptr = last_dirty; return last_pf; }