Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ubifs: Convert ubifs_vm_page_mkwrite() to use a folio

Replace six implicit calls to compound_head() with one.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>

authored by

Matthew Wilcox (Oracle) and committed by
Richard Weinberger
85ffbf55 0c2d140c

+28 -18
+10
Documentation/mm/page_cache.rst
··· 3 3 ========== 4 4 Page Cache 5 5 ========== 6 + 7 + The page cache is the primary way that the user and the rest of the kernel 8 + interact with filesystems. It can be bypassed (e.g. with O_DIRECT), 9 + but normal reads, writes and mmaps go through the page cache. 10 + 11 + Folios 12 + ====== 13 + 14 + The folio is the unit of memory management within the page cache. 15 + Operations
+18 -18
fs/ubifs/file.c
··· 1514 1514 */ 1515 1515 static vm_fault_t ubifs_vm_page_mkwrite(struct vm_fault *vmf) 1516 1516 { 1517 - struct page *page = vmf->page; 1517 + struct folio *folio = page_folio(vmf->page); 1518 1518 struct inode *inode = file_inode(vmf->vma->vm_file); 1519 1519 struct ubifs_info *c = inode->i_sb->s_fs_info; 1520 1520 struct timespec64 now = current_time(inode); 1521 1521 struct ubifs_budget_req req = { .new_page = 1 }; 1522 1522 int err, update_time; 1523 1523 1524 - dbg_gen("ino %lu, pg %lu, i_size %lld", inode->i_ino, page->index, 1524 + dbg_gen("ino %lu, pg %lu, i_size %lld", inode->i_ino, folio->index, 1525 1525 i_size_read(inode)); 1526 1526 ubifs_assert(c, !c->ro_media && !c->ro_mount); 1527 1527 ··· 1529 1529 return VM_FAULT_SIGBUS; /* -EROFS */ 1530 1530 1531 1531 /* 1532 - * We have not locked @page so far so we may budget for changing the 1533 - * page. Note, we cannot do this after we locked the page, because 1532 + * We have not locked @folio so far so we may budget for changing the 1533 + * folio. Note, we cannot do this after we locked the folio, because 1534 1534 * budgeting may cause write-back which would cause deadlock. 1535 1535 * 1536 - * At the moment we do not know whether the page is dirty or not, so we 1537 - * assume that it is not and budget for a new page. We could look at 1536 + * At the moment we do not know whether the folio is dirty or not, so we 1537 + * assume that it is not and budget for a new folio. We could look at 1538 1538 * the @PG_private flag and figure this out, but we may race with write 1539 - * back and the page state may change by the time we lock it, so this 1539 + * back and the folio state may change by the time we lock it, so this 1540 1540 * would need additional care. We do not bother with this at the 1541 1541 * moment, although it might be good idea to do. Instead, we allocate 1542 - * budget for a new page and amend it later on if the page was in fact 1542 + * budget for a new folio and amend it later on if the folio was in fact 1543 1543 * dirty. 1544 1544 * 1545 1545 * The budgeting-related logic of this function is similar to what we ··· 1562 1562 return VM_FAULT_SIGBUS; 1563 1563 } 1564 1564 1565 - lock_page(page); 1566 - if (unlikely(page->mapping != inode->i_mapping || 1567 - page_offset(page) > i_size_read(inode))) { 1568 - /* Page got truncated out from underneath us */ 1565 + folio_lock(folio); 1566 + if (unlikely(folio->mapping != inode->i_mapping || 1567 + folio_pos(folio) >= i_size_read(inode))) { 1568 + /* Folio got truncated out from underneath us */ 1569 1569 goto sigbus; 1570 1570 } 1571 1571 1572 - if (PagePrivate(page)) 1572 + if (folio->private) 1573 1573 release_new_page_budget(c); 1574 1574 else { 1575 - if (!PageChecked(page)) 1575 + if (!folio_test_checked(folio)) 1576 1576 ubifs_convert_page_budget(c); 1577 - attach_page_private(page, (void *)1); 1577 + folio_attach_private(folio, (void *)1); 1578 1578 atomic_long_inc(&c->dirty_pg_cnt); 1579 - __set_page_dirty_nobuffers(page); 1579 + filemap_dirty_folio(folio->mapping, folio); 1580 1580 } 1581 1581 1582 1582 if (update_time) { ··· 1592 1592 ubifs_release_dirty_inode_budget(c, ui); 1593 1593 } 1594 1594 1595 - wait_for_stable_page(page); 1595 + folio_wait_stable(folio); 1596 1596 return VM_FAULT_LOCKED; 1597 1597 1598 1598 sigbus: 1599 - unlock_page(page); 1599 + folio_unlock(folio); 1600 1600 ubifs_release_budget(c, &req); 1601 1601 return VM_FAULT_SIGBUS; 1602 1602 }