lkml.org 
[lkml]   [2022]   [Mar]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5 03/22] cachefiles: introduce on-demand read mode
On Mon, Mar 21, 2022 at 03:30:52PM +0000, David Howells wrote:
> Matthew Wilcox <willy@infradead.org> wrote:
>
> > Absolutely; just use xa_lock() to protect both setting & testing the
> > flag.
>
> How should Jeffle deal with xarray dropping the lock internally in order to do
> an allocation and then taking it again (actually in patch 5)?

There are a number of ways to handle this. I'll outline two; others
are surely possible.

option 1:

add side:

xa_lock();
if (!DEAD)
xa_store(GFP_KERNEL);
if (DEAD)
xa_erase();
xa_unlock();

destroy side:

xa_lock();
set DEAD;
xa_for_each()
xa_erase();
xa_unlock();

That has the problem (?) that it might be temporarily possible to see
a newly-added entry in a DEAD array.

If that is a problem, you can use xa_reserve() on the add side, followed
by overwriting it or removing it, depending on the state of the DEAD flag.

If you really want to, you can decompose the add side so that you always
check the DEAD flag before doing the store, ie:

do {
xas_lock();
if (DEAD)
xas_set_error(-EINVAL);
else
xas_store();
xas_unlock();
} while (xas_nomem(GFP_KERNEL));

\
 
 \ /
  Last update: 2022-09-17 16:18    [W:0.037 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site