History

mm,thp: avoid writes to file with THP in pagecache

In previous patch, an application could put part of its text section in THP via madvise(). These THPs will be protected from writes when the application is still running (TXTBSY). However, after the application exits, the file is available for writes. This patch avoids writes to file THP by dropping page cache for the file when the file is open for write. A new counter nr_thps is added to struct address_space. In do_dentry_open(), if the file is open for write and nr_thps is non-zero, we drop page cache for the whole file.

Song Liu committed 7 years ago

Commit 09d91cd1 parent 99cb0db5 files · +47 −1Browse files

Showing the changes to include/linux (1 of 5 files). Show all

Unified · Split

include/linux/fs.h+32−0
@@ -429,6 +429,7 @@ int pagecache_write_end(struct file *, struct address_space *mapping, · 428 unmodified lines
429 * @i_pages: Cached pages.429 * @i_pages: Cached pages.
430 * @gfp_mask: Memory allocation flags to use for allocating pages.430 * @gfp_mask: Memory allocation flags to use for allocating pages.
431 * @i_mmap_writable: Number of VM_SHARED mappings.431 * @i_mmap_writable: Number of VM_SHARED mappings.
432 * @nr_thps: Number of THPs in the pagecache (non-shmem only).
432 * @i_mmap: Tree of private and shared mappings.433 * @i_mmap: Tree of private and shared mappings.
433 * @i_mmap_rwsem: Protects @i_mmap and @i_mmap_writable.434 * @i_mmap_rwsem: Protects @i_mmap and @i_mmap_writable.
434 * @nrpages: Number of page entries, protected by the i_pages lock.435 * @nrpages: Number of page entries, protected by the i_pages lock.
@@ -446,6 +447,10 @@ struct address_space { · 11 unmodified lines
446 struct xarray i_pages;447 struct xarray i_pages;
447 gfp_t gfp_mask;448 gfp_t gfp_mask;
448 atomic_t i_mmap_writable;449 atomic_t i_mmap_writable;
450#ifdef CONFIG_READ_ONLY_THP_FOR_FS
451 /* number of thp, only for non-shmem files */
452 atomic_t nr_thps;
453#endif
449 struct rb_root_cached i_mmap;454 struct rb_root_cached i_mmap;
450 struct rw_semaphore i_mmap_rwsem;455 struct rw_semaphore i_mmap_rwsem;
451 unsigned long nrpages;456 unsigned long nrpages;
@@ -2798,6 +2803,33 @@ static inline errseq_t filemap_sample_wb_err(struct address_space *mapping) · 2346 unmodified lines
2798 return errseq_sample(&mapping->wb_err);2803 return errseq_sample(&mapping->wb_err);
2799}2804}
2800 2805
2806static inline int filemap_nr_thps(struct address_space *mapping)
2807{
2808#ifdef CONFIG_READ_ONLY_THP_FOR_FS
2809 return atomic_read(&mapping->nr_thps);
2810#else
2811 return 0;
2812#endif
2813}
2814
2815static inline void filemap_nr_thps_inc(struct address_space *mapping)
2816{
2817#ifdef CONFIG_READ_ONLY_THP_FOR_FS
2818 atomic_inc(&mapping->nr_thps);
2819#else
2820 WARN_ON_ONCE(1);
2821#endif
2822}
2823
2824static inline void filemap_nr_thps_dec(struct address_space *mapping)
2825{
2826#ifdef CONFIG_READ_ONLY_THP_FOR_FS
2827 atomic_dec(&mapping->nr_thps);
2828#else
2829 WARN_ON_ONCE(1);
2830#endif
2831}
2832
2801extern int vfs_fsync_range(struct file *file, loff_t start, loff_t end,2833extern int vfs_fsync_range(struct file *file, loff_t start, loff_t end,
2802 int datasync);2834 int datasync);
2803extern int vfs_fsync(struct file *file, int datasync);2835extern int vfs_fsync(struct file *file, int datasync);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t