Re: [PATCH v6 4/6] zsmalloc: Add a LRU to zs_pool to keep track of zspages in LRU order
From: Johannes Weiner
Date: Tue Nov 22 2022 - 12:43:24 EST
On Tue, Nov 22, 2022 at 10:52:58AM +0900, Sergey Senozhatsky wrote:
> On (22/11/18 16:15), Nhat Pham wrote:
> [..]
> > @@ -1249,6 +1267,15 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle,
> > obj_to_location(obj, &page, &obj_idx);
> > zspage = get_zspage(page);
> >
> > +#ifdef CONFIG_ZPOOL
> > + /* Move the zspage to front of pool's LRU */
> > + if (mm == ZS_MM_WO) {
> > + if (!list_empty(&zspage->lru))
> > + list_del(&zspage->lru);
> > + list_add(&zspage->lru, &pool->lru);
> > + }
> > +#endif
>
> Do we consider pages that were mapped for MM_RO/MM_RW as cold?
> I wonder why, we use them, so technically they are not exactly
> "least recently used".
This is a swap LRU. Per definition there are no ongoing accesses to
the memory while the page is swapped out that would make it "hot". A
new entry is hot, then ages to the tail until it gets either written
back or swaps back in. Because of that, the zswap backends have
traditionally had the lru-add in the allocation function (zs_malloc,
zbud_alloc, z3fold_alloc).
Minchan insisted we move it here for zsmalloc, since 'update lru on
data access' is more generic. Unfortunately, one of the data accesses
is when we write the swap entry to disk - during reclaim when the page
is isolated from the LRU! Obviously we MUST NOT put it back on the LRU
mid-reclaim.
So now we have very generic LRU code, and exactly one usecase that
needs exceptions from the generic behavior.
The code is raising questions, not surprisingly. We can add a lengthy
comment to it - a variant of the above text?
My vote would still be to just move it back to zs_malloc, where it
makes sense, is easier to explain, and matches the other backends.