Commit 83ee0e20 authored by Zhang Yi's avatar Zhang Yi
Browse files

filemap: support disable large folios on active inode

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9DN5Z


CVE: NA

--------------------------------

Since commit 730633f0 ("mm: Protect operations adding pages to page
cache with invalidate_lock"), mapping->invalidate_lock can protect us
from adding new folios into page cache. So it's possible to disable
active inodes' large folios support, even through it might be dangerous.
Filesystems can disable it under mapping->invalidate_lock and drop all
page cache before dropping AS_LARGE_FOLIO_SUPPORT.

Signed-off-by: default avatarZhang Yi <yi.zhang@huawei.com>
parent c691783a
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -344,6 +344,20 @@ static inline void mapping_set_large_folios(struct address_space *mapping)
	__set_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags);
}

/**
 * mapping_clear_large_folios() - The file disable supports large folios.
 * @mapping: The file.
 *
 * The filesystem have to make sure the file is in atomic context and all
 * cached folios have been cleared under mapping->invalidate_lock before
 * calling this function.
 */
static inline void mapping_clear_large_folios(struct address_space *mapping)
{
	WARN_ON_ONCE(!rwsem_is_locked(&mapping->invalidate_lock));
	__clear_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags);
}

/*
 * Large folio support currently depends on THP.  These dependencies are
 * being worked on but are not yet fixed.
+6 −0
Original line number Diff line number Diff line
@@ -510,6 +510,12 @@ void page_cache_ra_order(struct readahead_control *ractl,
	}

	filemap_invalidate_lock_shared(mapping);

	if (unlikely(!mapping_large_folio_support(mapping))) {
		filemap_invalidate_unlock_shared(mapping);
		goto fallback;
	}

	while (index <= limit) {
		unsigned int order = new_order;