Skip to content

Commit fc9a07e

Browse files
akpm00Linus Torvalds
authored andcommitted
invalidate_mapping_pages(): add cond_resched
invalidate_mapping_pages() can sometimes take a long time (millions of pages to free). Long enough for the softlockup detector to trigger. We used to have a cond_resched() in there but I took it out because the drop_caches code calls invalidate_mapping_pages() under inode_lock. The patch adds a nasty flag and puts the cond_resched() back. Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4542681 commit fc9a07e

3 files changed

Lines changed: 27 additions & 16 deletions

File tree

‎fs/drop_caches.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static void drop_pagecache_sb(struct super_block *sb)
2020
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
2121
if (inode->i_state & (I_FREEING|I_WILL_FREE))
2222
continue;
23-
invalidate_mapping_pages(inode->i_mapping, 0, -1);
23+
__invalidate_mapping_pages(inode->i_mapping, 0, -1, true);
2424
}
2525
spin_unlock(&inode_lock);
2626
}

‎include/linux/fs.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,9 @@ extern int __invalidate_device(struct block_device *);
16101610
extern int invalidate_partition(struct gendisk *, int);
16111611
#endif
16121612
extern int invalidate_inodes(struct super_block *);
1613+
unsigned long __invalidate_mapping_pages(struct address_space *mapping,
1614+
pgoff_t start, pgoff_t end,
1615+
bool be_atomic);
16131616
unsigned long invalidate_mapping_pages(struct address_space *mapping,
16141617
pgoff_t start, pgoff_t end);
16151618

‎mm/truncate.c‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,8 @@ void truncate_inode_pages(struct address_space *mapping, loff_t lstart)
253253
}
254254
EXPORT_SYMBOL(truncate_inode_pages);
255255

256-
/**
257-
* invalidate_mapping_pages - Invalidate all the unlocked pages of one inode
258-
* @mapping: the address_space which holds the pages to invalidate
259-
* @start: the offset 'from' which to invalidate
260-
* @end: the offset 'to' which to invalidate (inclusive)
261-
*
262-
* This function only removes the unlocked pages, if you want to
263-
* remove all the pages of one inode, you must call truncate_inode_pages.
264-
*
265-
* invalidate_mapping_pages() will not block on IO activity. It will not
266-
* invalidate pages which are dirty, locked, under writeback or mapped into
267-
* pagetables.
268-
*/
269-
unsigned long invalidate_mapping_pages(struct address_space *mapping,
270-
pgoff_t start, pgoff_t end)
256+
unsigned long __invalidate_mapping_pages(struct address_space *mapping,
257+
pgoff_t start, pgoff_t end, bool be_atomic)
271258
{
272259
struct pagevec pvec;
273260
pgoff_t next = start;
@@ -308,9 +295,30 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
308295
break;
309296
}
310297
pagevec_release(&pvec);
298+
if (likely(!be_atomic))
299+
cond_resched();
311300
}
312301
return ret;
313302
}
303+
304+
/**
305+
* invalidate_mapping_pages - Invalidate all the unlocked pages of one inode
306+
* @mapping: the address_space which holds the pages to invalidate
307+
* @start: the offset 'from' which to invalidate
308+
* @end: the offset 'to' which to invalidate (inclusive)
309+
*
310+
* This function only removes the unlocked pages, if you want to
311+
* remove all the pages of one inode, you must call truncate_inode_pages.
312+
*
313+
* invalidate_mapping_pages() will not block on IO activity. It will not
314+
* invalidate pages which are dirty, locked, under writeback or mapped into
315+
* pagetables.
316+
*/
317+
unsigned long invalidate_mapping_pages(struct address_space *mapping,
318+
pgoff_t start, pgoff_t end)
319+
{
320+
return __invalidate_mapping_pages(mapping, start, end, false);
321+
}
314322
EXPORT_SYMBOL(invalidate_mapping_pages);
315323

316324
/*

0 commit comments

Comments
 (0)