From: Daniel Gomez <da.gomez@samsung.com>
To: "minchan@kernel.org" <minchan@kernel.org>,
"senozhatsky@chromium.org" <senozhatsky@chromium.org>,
"axboe@kernel.dk" <axboe@kernel.dk>,
"djwong@kernel.org" <djwong@kernel.org>,
"willy@infradead.org" <willy@infradead.org>,
"hughd@google.com" <hughd@google.com>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"mcgrof@kernel.org" <mcgrof@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"linux-xfs@vger.kernel.org" <linux-xfs@vger.kernel.org>,
"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>
Cc: "gost.dev@samsung.com" <gost.dev@samsung.com>,
Pankaj Raghav <p.raghav@samsung.com>,
Daniel Gomez <da.gomez@samsung.com>
Subject: [PATCH 3/6] shmem: account for large order folios
Date: Fri, 15 Sep 2023 09:51:26 +0000 [thread overview]
Message-ID: <20230915095042.1320180-4-da.gomez@samsung.com> (raw)
In-Reply-To: <20230915095042.1320180-1-da.gomez@samsung.com>
From: Luis Chamberlain <mcgrof@kernel.org>
shmem uses the shem_info_inode alloced, swapped to account
for allocated pages and swapped pages. In preparation for large
order folios adjust the accounting to use folio_nr_pages().
This should produce no functional changes yet as larger order
folios are not yet used or supported in shmem.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
mm/shmem.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index 8b3823e4d344..836d44584796 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -869,16 +869,16 @@ 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;
unsigned long max = end - 1;
rcu_read_lock();
- xas_for_each(&xas, page, max) {
- if (xas_retry(&xas, page))
+ xas_for_each(&xas, folio, max) {
+ if (xas_retry(&xas, folio))
continue;
- if (xa_is_value(page))
- swapped++;
+ if (xa_is_value(folio))
+ swapped += (folio_nr_pages(folio));
if (xas.xa_index == max)
break;
if (need_resched()) {
@@ -1006,10 +1006,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;
}
@@ -1075,14 +1077,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;
}
@@ -1528,7 +1532,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
if (add_to_swap_cache(folio, swap,
__GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN,
NULL) == 0) {
- shmem_recalc_inode(inode, 0, 1);
+ shmem_recalc_inode(inode, 0, folio_nr_pages(folio));
swap_shmem_alloc(swap);
shmem_delete_from_page_cache(folio, swp_to_radix_entry(swap));
@@ -1801,6 +1805,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index,
struct address_space *mapping = inode->i_mapping;
swp_entry_t swapin_error;
void *old;
+ long num_swap_pages;
swapin_error = make_poisoned_swp_entry();
old = xa_cmpxchg_irq(&mapping->i_pages, index,
@@ -1810,13 +1815,14 @@ 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);
/*
* Don't treat swapin error folio as alloced. Otherwise inode->i_blocks
* won't be 0 when inode is released and thus trigger WARN_ON(i_blocks)
* in shmem_evict_inode().
*/
- shmem_recalc_inode(inode, -1, -1);
+ shmem_recalc_inode(inode, num_swap_pages, num_swap_pages);
swap_free(swap);
}
@@ -1903,7 +1909,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
if (error)
goto failed;
- shmem_recalc_inode(inode, 0, -1);
+ shmem_recalc_inode(inode, 0, folio_nr_pages(folio));
if (sgp == SGP_WRITE)
folio_mark_accessed(folio);
@@ -2663,7 +2669,7 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd,
if (ret)
goto out_delete_from_cache;
- shmem_recalc_inode(inode, 1, 0);
+ shmem_recalc_inode(inode, folio_nr_pages(folio), 0);
folio_unlock(folio);
return 0;
out_delete_from_cache:
--
2.39.2
next prev parent reply other threads:[~2023-09-15 9:51 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20230915095123eucas1p2c23d8a8d910f5a8e9fd077dd9579ad0a@eucas1p2.samsung.com>
2023-09-15 9:51 ` [PATCH 0/6] shmem: high order folios support in write path Daniel Gomez
[not found] ` <CGME20230915095124eucas1p1eb0e0ef883f6316cf14c349404a51150@eucas1p1.samsung.com>
2023-09-15 9:51 ` [PATCH 1/6] filemap: make the folio order calculation shareable Daniel Gomez
2023-09-15 13:40 ` Matthew Wilcox
2023-09-18 8:41 ` Daniel Gomez
2023-09-18 18:09 ` Luis Chamberlain
2023-09-18 18:24 ` Matthew Wilcox
2023-09-18 18:42 ` Luis Chamberlain
[not found] ` <CGME20230915095126eucas1p2cf75674dab8a81228f493a7200f4a1ba@eucas1p2.samsung.com>
2023-09-15 9:51 ` [PATCH 2/6] shmem: drop BLOCKS_PER_PAGE macro Daniel Gomez
[not found] ` <CGME20230915095128eucas1p2885c3add58d82413d9c1d17832d3d281@eucas1p2.samsung.com>
2023-09-15 9:51 ` Daniel Gomez [this message]
2023-09-15 12:14 ` [PATCH 3/6] shmem: account for large order folios Matthew Wilcox
2023-09-15 13:44 ` Matthew Wilcox
[not found] ` <CGME20230915095129eucas1p1383d75c6d62056afbb20b78a3ec15234@eucas1p1.samsung.com>
2023-09-15 9:51 ` [PATCH 4/6] shmem: add order parameter support to shmem_alloc_folio Daniel Gomez
2023-09-15 12:19 ` Matthew Wilcox
[not found] ` <CGME20230915095131eucas1p1010e364cd1c351e5b7379954bd237a3d@eucas1p1.samsung.com>
2023-09-15 9:51 ` [PATCH 5/6] shmem: add file length in shmem_get_folio path Daniel Gomez
2023-09-15 15:37 ` Matthew Wilcox
[not found] ` <CGME20230915095133eucas1p267bade2888b7fcd2e1ea8e13e21c495f@eucas1p2.samsung.com>
2023-09-15 9:51 ` [PATCH 6/6] shmem: add large folios support to the write path Daniel Gomez
2023-09-15 18:26 ` Yosry Ahmed
2023-09-18 8:00 ` Daniel Gomez
2023-09-18 18:55 ` Yosry Ahmed
2023-09-19 13:27 ` Daniel Gomez
2023-09-19 16:00 ` Yosry Ahmed
2023-09-19 21:46 ` Luis Chamberlain
2023-09-19 21:51 ` Yosry Ahmed
2023-09-15 15:29 ` [PATCH 0/6] shmem: high order folios support in " David Hildenbrand
2023-09-15 15:34 ` Matthew Wilcox
2023-09-15 15:36 ` David Hildenbrand
2023-09-15 15:40 ` Matthew Wilcox
2023-09-15 15:43 ` David Hildenbrand
2023-09-18 7:32 ` Daniel Gomez
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=20230915095042.1320180-4-da.gomez@samsung.com \
--to=da.gomez@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=djwong@kernel.org \
--cc=gost.dev@samsung.com \
--cc=hughd@google.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=minchan@kernel.org \
--cc=p.raghav@samsung.com \
--cc=senozhatsky@chromium.org \
--cc=willy@infradead.org \
/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