@@ -1667,9 +1667,9 @@ static inline void set_page_links(struct page *page, enum zone_type zone,
* folio_nr_pages - The number of pages in the folio.
* @folio: The folio.
*
- * Return: A number which is a power of two.
+ * Return: A number which is a non-negative power of two.
*/
-static inline unsigned long folio_nr_pages(struct folio *folio)
+static inline long folio_nr_pages(struct folio *folio)
{
return compound_nr(&folio->page);
}
@@ -1733,8 +1733,10 @@ static inline int arch_make_page_accessible(struct page *page)
#ifndef HAVE_ARCH_MAKE_FOLIO_ACCESSIBLE
static inline int arch_make_folio_accessible(struct folio *folio)
{
- int ret, i;
- for (i = 0; i < folio_nr_pages(folio); i++) {
+ int ret;
+ long i, nr = folio_nr_pages(folio);
+
+ for (i = 0; i < nr; i++) {
ret = arch_make_page_accessible(folio_page(folio, i));
if (ret)
break;
@@ -32,7 +32,7 @@ static inline int page_is_file_lru(struct page *page)
static __always_inline void update_lru_size(struct lruvec *lruvec,
enum lru_list lru, enum zone_type zid,
- int nr_pages)
+ long nr_pages)
{
struct pglist_data *pgdat = lruvec_pgdat(lruvec);
@@ -6693,7 +6693,7 @@ void mem_cgroup_calculate_protection(struct mem_cgroup *root,
static int charge_memcg(struct folio *folio, struct mem_cgroup *memcg,
gfp_t gfp)
{
- unsigned int nr_pages = folio_nr_pages(folio);
+ long nr_pages = folio_nr_pages(folio);
int ret;
ret = try_charge(memcg, gfp, nr_pages);
@@ -6847,7 +6847,7 @@ static void uncharge_batch(const struct uncharge_gather *ug)
static void uncharge_folio(struct folio *folio, struct uncharge_gather *ug)
{
- unsigned long nr_pages;
+ long nr_pages;
struct mem_cgroup *memcg;
struct obj_cgroup *objcg;
bool use_objcg = folio_memcg_kmem(folio);
@@ -6962,7 +6962,7 @@ void mem_cgroup_uncharge_list(struct list_head *page_list)
void mem_cgroup_migrate(struct folio *old, struct folio *new)
{
struct mem_cgroup *memcg;
- unsigned int nr_pages = folio_nr_pages(new);
+ long nr_pages = folio_nr_pages(new);
unsigned long flags;
VM_BUG_ON_FOLIO(!folio_test_locked(old), old);
@@ -383,7 +383,7 @@ int folio_migrate_mapping(struct address_space *mapping,
struct zone *oldzone, *newzone;
int dirty;
int expected_count = expected_page_refs(mapping, &folio->page) + extra_count;
- int nr = folio_nr_pages(folio);
+ long nr = folio_nr_pages(folio);
if (!mapping) {
/* Anonymous page without mapping */
@@ -2547,7 +2547,7 @@ void folio_account_redirty(struct folio *folio)
struct inode *inode = mapping->host;
struct bdi_writeback *wb;
struct wb_lock_cookie cookie = {};
- unsigned nr = folio_nr_pages(folio);
+ long nr = folio_nr_pages(folio);
wb = unlocked_inode_to_wb_begin(inode, &cookie);
current->nr_dirtied -= nr;
@@ -2574,7 +2574,7 @@ bool folio_redirty_for_writepage(struct writeback_control *wbc,
struct folio *folio)
{
bool ret;
- unsigned nr = folio_nr_pages(folio);
+ long nr = folio_nr_pages(folio);
wbc->pages_skipped += nr;
ret = filemap_dirty_folio(folio->mapping, folio);
@@ -324,7 +324,7 @@ void lru_note_cost_folio(struct folio *folio)
static void __folio_activate(struct folio *folio, struct lruvec *lruvec)
{
if (!folio_test_active(folio) && !folio_test_unevictable(folio)) {
- int nr_pages = folio_nr_pages(folio);
+ long nr_pages = folio_nr_pages(folio);
lruvec_del_folio(lruvec, folio);
folio_set_active(folio);
@@ -1004,7 +1004,7 @@ EXPORT_SYMBOL(__pagevec_release);
static void __pagevec_lru_add_fn(struct folio *folio, struct lruvec *lruvec)
{
int was_unevictable = folio_test_clear_unevictable(folio);
- int nr_pages = folio_nr_pages(folio);
+ long nr_pages = folio_nr_pages(folio);
VM_BUG_ON_FOLIO(folio_test_lru(folio), folio);
@@ -649,7 +649,7 @@ void *page_rmapping(struct page *page)
*/
bool folio_mapped(struct folio *folio)
{
- int i, nr;
+ long i, nr;
if (folio_single(folio))
return atomic_read(&folio->_mapcount) >= 0;
@@ -730,8 +730,8 @@ EXPORT_SYMBOL_GPL(__page_mapcount);
void folio_copy(struct folio *dst, struct folio *src)
{
- unsigned i = 0;
- unsigned nr = folio_nr_pages(src);
+ long i = 0;
+ long nr = folio_nr_pages(src);
for (;;) {
copy_highpage(folio_page(dst, i), folio_page(src, i));
@@ -1064,12 +1064,10 @@ EXPORT_SYMBOL(page_offline_end);
#ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_FOLIO
void flush_dcache_folio(struct folio *folio)
{
- unsigned int n = folio_nr_pages(folio);
+ long i, nr = folio_nr_pages(folio);
- do {
- n--;
- flush_dcache_page(folio_page(folio, n));
- } while (n);
+ for (i = 0; i < nr; i++)
+ flush_dcache_page(folio_page(folio, i));
}
EXPORT_SYMBOL(flush_dcache_folio);
#endif