Skip to content

Commit

Permalink
dax: Hash on XArray instead of mapping
Browse files Browse the repository at this point in the history
Since the XArray is embedded in the struct address_space, its address
contains exactly as much entropy as the address of the mapping.  This
patch is purely preparatory for later patches which will simplify the
wait/wake interfaces.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
  • Loading branch information
Matthew Wilcox committed Oct 21, 2018
1 parent a77d19f commit ec4907f
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions fs/dax.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static int dax_is_empty_entry(void *entry)
* DAX page cache entry locking
*/
struct exceptional_entry_key {
struct address_space *mapping;
struct xarray *xa;
pgoff_t entry_start;
};

Expand All @@ -125,7 +125,7 @@ struct wait_exceptional_entry_queue {
struct exceptional_entry_key key;
};

static wait_queue_head_t *dax_entry_waitqueue(struct address_space *mapping,
static wait_queue_head_t *dax_entry_waitqueue(struct xarray *xa,
pgoff_t index, void *entry, struct exceptional_entry_key *key)
{
unsigned long hash;
Expand All @@ -138,21 +138,21 @@ static wait_queue_head_t *dax_entry_waitqueue(struct address_space *mapping,
if (dax_is_pmd_entry(entry))
index &= ~PG_PMD_COLOUR;

key->mapping = mapping;
key->xa = xa;
key->entry_start = index;

hash = hash_long((unsigned long)mapping ^ index, DAX_WAIT_TABLE_BITS);
hash = hash_long((unsigned long)xa ^ index, DAX_WAIT_TABLE_BITS);
return wait_table + hash;
}

static int wake_exceptional_entry_func(wait_queue_entry_t *wait, unsigned int mode,
int sync, void *keyp)
static int wake_exceptional_entry_func(wait_queue_entry_t *wait,
unsigned int mode, int sync, void *keyp)
{
struct exceptional_entry_key *key = keyp;
struct wait_exceptional_entry_queue *ewait =
container_of(wait, struct wait_exceptional_entry_queue, wait);

if (key->mapping != ewait->key.mapping ||
if (key->xa != ewait->key.xa ||
key->entry_start != ewait->key.entry_start)
return 0;
return autoremove_wake_function(wait, mode, sync, NULL);
Expand All @@ -163,13 +163,13 @@ static int wake_exceptional_entry_func(wait_queue_entry_t *wait, unsigned int mo
* The important information it's conveying is whether the entry at
* this index used to be a PMD entry.
*/
static void dax_wake_mapping_entry_waiter(struct address_space *mapping,
static void dax_wake_mapping_entry_waiter(struct xarray *xa,
pgoff_t index, void *entry, bool wake_all)
{
struct exceptional_entry_key key;
wait_queue_head_t *wq;

wq = dax_entry_waitqueue(mapping, index, entry, &key);
wq = dax_entry_waitqueue(xa, index, entry, &key);

/*
* Checking for locked entry and prepare_to_wait_exclusive() happens
Expand Down Expand Up @@ -248,7 +248,8 @@ static void *__get_unlocked_mapping_entry(struct address_space *mapping,
return entry;
}

wq = dax_entry_waitqueue(mapping, index, entry, &ewait.key);
wq = dax_entry_waitqueue(&mapping->i_pages, index, entry,
&ewait.key);
prepare_to_wait_exclusive(wq, &ewait.wait,
TASK_UNINTERRUPTIBLE);
xa_unlock_irq(&mapping->i_pages);
Expand Down Expand Up @@ -289,7 +290,7 @@ static void unlock_mapping_entry(struct address_space *mapping, pgoff_t index)
}
unlock_slot(mapping, slot);
xa_unlock_irq(&mapping->i_pages);
dax_wake_mapping_entry_waiter(mapping, index, entry, false);
dax_wake_mapping_entry_waiter(&mapping->i_pages, index, entry, false);
}

static void put_locked_mapping_entry(struct address_space *mapping,
Expand All @@ -309,7 +310,7 @@ static void put_unlocked_mapping_entry(struct address_space *mapping,
return;

/* We have to wake up next waiter for the page cache entry lock */
dax_wake_mapping_entry_waiter(mapping, index, entry, false);
dax_wake_mapping_entry_waiter(&mapping->i_pages, index, entry, false);
}

static unsigned long dax_entry_size(void *entry)
Expand Down Expand Up @@ -578,8 +579,8 @@ static void *grab_mapping_entry(struct address_space *mapping, pgoff_t index,
dax_disassociate_entry(entry, mapping, false);
radix_tree_delete(&mapping->i_pages, index);
mapping->nrexceptional--;
dax_wake_mapping_entry_waiter(mapping, index, entry,
true);
dax_wake_mapping_entry_waiter(&mapping->i_pages,
index, entry, true);
}

entry = dax_make_locked(0, size_flag | DAX_EMPTY);
Expand Down

0 comments on commit ec4907f

Please sign in to comment.