Skip to content

Commit 91e79d2

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm: convert DAX lock/unlock page to lock/unlock folio
The one caller of DAX lock/unlock page already calls compound_head(), so use page_folio() instead, then use a folio throughout the DAX code to remove uses of page->mapping and page->index. [[email protected]: add comment to mf_generic_kill_procss(), simplify mf_generic_kill_procs:folio initialization] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Jane Chu <[email protected]> Acked-by: Naoya Horiguchi <[email protected]> Cc: Dan Williams <[email protected]> Cc: Jane Chu <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent bc0c335 commit 91e79d2

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

fs/dax.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -412,23 +412,23 @@ static struct page *dax_busy_page(void *entry)
412412
return NULL;
413413
}
414414

415-
/*
416-
* dax_lock_page - Lock the DAX entry corresponding to a page
417-
* @page: The page whose entry we want to lock
415+
/**
416+
* dax_lock_folio - Lock the DAX entry corresponding to a folio
417+
* @folio: The folio whose entry we want to lock
418418
*
419419
* Context: Process context.
420-
* Return: A cookie to pass to dax_unlock_page() or 0 if the entry could
420+
* Return: A cookie to pass to dax_unlock_folio() or 0 if the entry could
421421
* not be locked.
422422
*/
423-
dax_entry_t dax_lock_page(struct page *page)
423+
dax_entry_t dax_lock_folio(struct folio *folio)
424424
{
425425
XA_STATE(xas, NULL, 0);
426426
void *entry;
427427

428-
/* Ensure page->mapping isn't freed while we look at it */
428+
/* Ensure folio->mapping isn't freed while we look at it */
429429
rcu_read_lock();
430430
for (;;) {
431-
struct address_space *mapping = READ_ONCE(page->mapping);
431+
struct address_space *mapping = READ_ONCE(folio->mapping);
432432

433433
entry = NULL;
434434
if (!mapping || !dax_mapping(mapping))
@@ -447,11 +447,11 @@ dax_entry_t dax_lock_page(struct page *page)
447447

448448
xas.xa = &mapping->i_pages;
449449
xas_lock_irq(&xas);
450-
if (mapping != page->mapping) {
450+
if (mapping != folio->mapping) {
451451
xas_unlock_irq(&xas);
452452
continue;
453453
}
454-
xas_set(&xas, page->index);
454+
xas_set(&xas, folio->index);
455455
entry = xas_load(&xas);
456456
if (dax_is_locked(entry)) {
457457
rcu_read_unlock();
@@ -467,10 +467,10 @@ dax_entry_t dax_lock_page(struct page *page)
467467
return (dax_entry_t)entry;
468468
}
469469

470-
void dax_unlock_page(struct page *page, dax_entry_t cookie)
470+
void dax_unlock_folio(struct folio *folio, dax_entry_t cookie)
471471
{
472-
struct address_space *mapping = page->mapping;
473-
XA_STATE(xas, &mapping->i_pages, page->index);
472+
struct address_space *mapping = folio->mapping;
473+
XA_STATE(xas, &mapping->i_pages, folio->index);
474474

475475
if (S_ISCHR(mapping->host->i_mode))
476476
return;

include/linux/dax.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ int dax_writeback_mapping_range(struct address_space *mapping,
159159

160160
struct page *dax_layout_busy_page(struct address_space *mapping);
161161
struct page *dax_layout_busy_page_range(struct address_space *mapping, loff_t start, loff_t end);
162-
dax_entry_t dax_lock_page(struct page *page);
163-
void dax_unlock_page(struct page *page, dax_entry_t cookie);
162+
dax_entry_t dax_lock_folio(struct folio *folio);
163+
void dax_unlock_folio(struct folio *folio, dax_entry_t cookie);
164164
dax_entry_t dax_lock_mapping_entry(struct address_space *mapping,
165165
unsigned long index, struct page **page);
166166
void dax_unlock_mapping_entry(struct address_space *mapping,
@@ -182,14 +182,14 @@ static inline int dax_writeback_mapping_range(struct address_space *mapping,
182182
return -EOPNOTSUPP;
183183
}
184184

185-
static inline dax_entry_t dax_lock_page(struct page *page)
185+
static inline dax_entry_t dax_lock_folio(struct folio *folio)
186186
{
187-
if (IS_DAX(page->mapping->host))
187+
if (IS_DAX(folio->mapping->host))
188188
return ~0UL;
189189
return 0;
190190
}
191191

192-
static inline void dax_unlock_page(struct page *page, dax_entry_t cookie)
192+
static inline void dax_unlock_folio(struct folio *folio, dax_entry_t cookie)
193193
{
194194
}
195195

mm/memory-failure.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,32 +1713,35 @@ static void unmap_and_kill(struct list_head *to_kill, unsigned long pfn,
17131713
kill_procs(to_kill, flags & MF_MUST_KILL, false, pfn, flags);
17141714
}
17151715

1716+
/*
1717+
* Only dev_pagemap pages get here, such as fsdax when the filesystem
1718+
* either do not claim or fails to claim a hwpoison event, or devdax.
1719+
* The fsdax pages are initialized per base page, and the devdax pages
1720+
* could be initialized either as base pages, or as compound pages with
1721+
* vmemmap optimization enabled. Devdax is simplistic in its dealing with
1722+
* hwpoison, such that, if a subpage of a compound page is poisoned,
1723+
* simply mark the compound head page is by far sufficient.
1724+
*/
17161725
static int mf_generic_kill_procs(unsigned long long pfn, int flags,
17171726
struct dev_pagemap *pgmap)
17181727
{
1719-
struct page *page = pfn_to_page(pfn);
1728+
struct folio *folio = pfn_folio(pfn);
17201729
LIST_HEAD(to_kill);
17211730
dax_entry_t cookie;
17221731
int rc = 0;
17231732

1724-
/*
1725-
* Pages instantiated by device-dax (not filesystem-dax)
1726-
* may be compound pages.
1727-
*/
1728-
page = compound_head(page);
1729-
17301733
/*
17311734
* Prevent the inode from being freed while we are interrogating
17321735
* the address_space, typically this would be handled by
17331736
* lock_page(), but dax pages do not use the page lock. This
17341737
* also prevents changes to the mapping of this pfn until
17351738
* poison signaling is complete.
17361739
*/
1737-
cookie = dax_lock_page(page);
1740+
cookie = dax_lock_folio(folio);
17381741
if (!cookie)
17391742
return -EBUSY;
17401743

1741-
if (hwpoison_filter(page)) {
1744+
if (hwpoison_filter(&folio->page)) {
17421745
rc = -EOPNOTSUPP;
17431746
goto unlock;
17441747
}
@@ -1760,7 +1763,7 @@ static int mf_generic_kill_procs(unsigned long long pfn, int flags,
17601763
* Use this flag as an indication that the dax page has been
17611764
* remapped UC to prevent speculative consumption of poison.
17621765
*/
1763-
SetPageHWPoison(page);
1766+
SetPageHWPoison(&folio->page);
17641767

17651768
/*
17661769
* Unlike System-RAM there is no possibility to swap in a
@@ -1769,11 +1772,11 @@ static int mf_generic_kill_procs(unsigned long long pfn, int flags,
17691772
* SIGBUS (i.e. MF_MUST_KILL)
17701773
*/
17711774
flags |= MF_ACTION_REQUIRED | MF_MUST_KILL;
1772-
collect_procs(page, &to_kill, true);
1775+
collect_procs(&folio->page, &to_kill, true);
17731776

1774-
unmap_and_kill(&to_kill, pfn, page->mapping, page->index, flags);
1777+
unmap_and_kill(&to_kill, pfn, folio->mapping, folio->index, flags);
17751778
unlock:
1776-
dax_unlock_page(page, cookie);
1779+
dax_unlock_folio(folio, cookie);
17771780
return rc;
17781781
}
17791782

0 commit comments

Comments
 (0)