From: Luis Chamberlain <mcgrof@kernel.org>
To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org,
brauner@kernel.org, djwong@kernel.org
Cc: p.raghav@samsung.com, da.gomez@samsung.com,
rohan.puri@samsung.com, rpuri.linux@gmail.com,
a.manzanares@samsung.com, dave@stgolabs.net,
yosryahmed@google.com, keescook@chromium.org, hare@suse.de,
kbusch@kernel.org, mcgrof@kernel.org, patches@lists.linux.dev,
linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [RFC v2 3/8] shmem: account for high order folios
Date: Fri, 26 May 2023 00:55:47 -0700 [thread overview]
Message-ID: <20230526075552.363524-4-mcgrof@kernel.org> (raw)
In-Reply-To: <20230526075552.363524-1-mcgrof@kernel.org>
shmem uses the shem_info_inode alloced, swapped to account
for allocated pages and swapped pages. In preparation for high
order folios adjust the accounting to use folio_nr_pages().
This should produce no functional changes yet as higher order
folios are not yet used or supported in shmem.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
mm/shmem.c | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index a947f2678a39..7bea4c5cb83a 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -803,15 +803,15 @@ unsigned long shmem_partial_swap_usage(struct address_space *mapping,
pgoff_t start, pgoff_t end)
{
XA_STATE(xas, &mapping->i_pages, start);
- struct page *page;
+ struct folio *folio;
unsigned long swapped = 0;
rcu_read_lock();
- xas_for_each(&xas, page, end - 1) {
- if (xas_retry(&xas, page))
+ xas_for_each(&xas, folio, end - 1) {
+ if (xas_retry(&xas, folio))
continue;
- if (xa_is_value(page))
- swapped++;
+ if (xa_is_value(folio))
+ swapped += (folio_nr_pages(folio));
if (need_resched()) {
xas_pause(&xas);
@@ -938,10 +938,12 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
folio = fbatch.folios[i];
if (xa_is_value(folio)) {
+ long swaps_freed;
if (unfalloc)
continue;
- nr_swaps_freed += !shmem_free_swap(mapping,
- indices[i], folio);
+ swaps_freed = folio_nr_pages(folio);
+ if (!shmem_free_swap(mapping, indices[i], folio))
+ nr_swaps_freed += swaps_freed;
continue;
}
@@ -1007,14 +1009,16 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,
folio = fbatch.folios[i];
if (xa_is_value(folio)) {
+ long swaps_freed;
if (unfalloc)
continue;
+ swaps_freed = folio_nr_pages(folio);
if (shmem_free_swap(mapping, indices[i], folio)) {
/* Swap was replaced by page: retry */
index = indices[i];
break;
}
- nr_swaps_freed++;
+ nr_swaps_freed += swaps_freed;
continue;
}
@@ -1445,7 +1449,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
NULL) == 0) {
spin_lock_irq(&info->lock);
shmem_recalc_inode(inode);
- info->swapped++;
+ info->swapped += folio_nr_pages(folio);
spin_unlock_irq(&info->lock);
swap_shmem_alloc(swap);
@@ -1720,6 +1724,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index,
struct shmem_inode_info *info = SHMEM_I(inode);
swp_entry_t swapin_error;
void *old;
+ long num_swap_pages;
swapin_error = make_swapin_error_entry();
old = xa_cmpxchg_irq(&mapping->i_pages, index,
@@ -1729,6 +1734,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index,
return;
folio_wait_writeback(folio);
+ num_swap_pages = folio_nr_pages(folio);
delete_from_swap_cache(folio);
spin_lock_irq(&info->lock);
/*
@@ -1736,8 +1742,8 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index,
* be 0 when inode is released and thus trigger WARN_ON(inode->i_blocks) in
* shmem_evict_inode.
*/
- info->alloced--;
- info->swapped--;
+ info->alloced -= num_swap_pages;
+ info->swapped -= num_swap_pages;
shmem_recalc_inode(inode);
spin_unlock_irq(&info->lock);
swap_free(swap);
@@ -1827,7 +1833,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
goto failed;
spin_lock_irq(&info->lock);
- info->swapped--;
+ info->swapped -= folio_nr_pages(folio);
shmem_recalc_inode(inode);
spin_unlock_irq(&info->lock);
@@ -2542,8 +2548,8 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd,
goto out_delete_from_cache;
spin_lock_irq(&info->lock);
- info->alloced++;
- inode->i_blocks += PAGE_SECTORS;
+ info->alloced += folio_nr_pages(folio);
+ inode->i_blocks += PAGE_SECTORS << folio_order(folio);
shmem_recalc_inode(inode);
spin_unlock_irq(&info->lock);
--
2.39.2
next prev parent reply other threads:[~2023-05-26 7:56 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-26 7:55 [RFC v2 0/8] add support for blocksize > PAGE_SIZE Luis Chamberlain
2023-05-26 7:55 ` [RFC v2 1/8] page_flags: add is_folio_hwpoison() Luis Chamberlain
2023-05-26 13:51 ` Matthew Wilcox
2023-05-26 15:40 ` Keith Busch
2023-05-26 7:55 ` [RFC v2 2/8] shmem: convert to use is_folio_hwpoison() Luis Chamberlain
2023-05-26 14:32 ` Matthew Wilcox
2023-05-26 17:41 ` Luis Chamberlain
2023-05-26 18:41 ` Matthew Wilcox
2023-05-26 7:55 ` Luis Chamberlain [this message]
2023-05-26 7:55 ` [RFC v2 4/8] shmem: add helpers to get block size Luis Chamberlain
2023-05-26 7:55 ` [RFC v2 5/8] shmem: account for larger blocks sizes for shmem_default_max_blocks() Luis Chamberlain
2023-05-26 7:55 ` [RFC v2 6/8] shmem: consider block size in shmem_default_max_inodes() Luis Chamberlain
2023-05-26 7:55 ` [RFC v2 7/8] shmem: add high order page support Luis Chamberlain
2023-05-26 7:55 ` [RFC v2 8/8] shmem: add support to customize block size order Luis Chamberlain
2023-05-26 8:07 ` [RFC v2 0/8] add support for blocksize > PAGE_SIZE Luis Chamberlain
2023-05-26 8:14 ` Christoph Hellwig
2023-05-26 8:18 ` Luis Chamberlain
2023-05-26 8:28 ` Christoph Hellwig
2023-05-26 8:35 ` Luis Chamberlain
2023-05-26 13:54 ` Matthew Wilcox
2023-05-26 17:33 ` Luis Chamberlain
2023-05-26 18:43 ` Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230526075552.363524-4-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=a.manzanares@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=da.gomez@samsung.com \
--cc=dave@stgolabs.net \
--cc=djwong@kernel.org \
--cc=hare@suse.de \
--cc=hughd@google.com \
--cc=kbusch@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=p.raghav@samsung.com \
--cc=patches@lists.linux.dev \
--cc=rohan.puri@samsung.com \
--cc=rpuri.linux@gmail.com \
--cc=willy@infradead.org \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).