Skip to content

Commit e1479f7

Browse files
committed
Merge branch '5.5/zen-sauce' into 5.5/master
2 parents 0d3f2f2 + 983fd91 commit e1479f7

14 files changed

Lines changed: 209 additions & 35 deletions

File tree

fs/block_dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void kill_bdev(struct block_device *bdev)
7979
{
8080
struct address_space *mapping = bdev->bd_inode->i_mapping;
8181

82-
if (mapping->nrpages == 0 && mapping->nrexceptional == 0)
82+
if (mapping_empty(mapping))
8383
return;
8484

8585
invalidate_bh_lrus();

fs/dax.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,11 @@ static void *grab_mapping_entry(struct xa_state *xas,
478478
{
479479
unsigned long index = xas->xa_index;
480480
bool pmd_downgrade = false; /* splitting PMD entry into PTE entries? */
481+
int populated;
481482
void *entry;
482483

483484
retry:
485+
populated = 0;
484486
xas_lock_irq(xas);
485487
entry = get_unlocked_entry(xas, order);
486488

@@ -526,6 +528,8 @@ static void *grab_mapping_entry(struct xa_state *xas,
526528
xas_store(xas, NULL); /* undo the PMD join */
527529
dax_wake_entry(xas, entry, true);
528530
mapping->nrexceptional--;
531+
if (mapping_empty(mapping))
532+
populated = -1;
529533
entry = NULL;
530534
xas_set(xas, index);
531535
}
@@ -541,11 +545,17 @@ static void *grab_mapping_entry(struct xa_state *xas,
541545
dax_lock_entry(xas, entry);
542546
if (xas_error(xas))
543547
goto out_unlock;
548+
if (mapping_empty(mapping))
549+
populated++;
544550
mapping->nrexceptional++;
545551
}
546552

547553
out_unlock:
548554
xas_unlock_irq(xas);
555+
if (populated == -1)
556+
inode_pages_clear(mapping->host);
557+
else if (populated == 1)
558+
inode_pages_set(mapping->host);
549559
if (xas_nomem(xas, mapping_gfp_mask(mapping) & ~__GFP_HIGHMEM))
550560
goto retry;
551561
if (xas->xa_node == XA_ERROR(-ENOMEM))
@@ -631,6 +641,7 @@ static int __dax_invalidate_entry(struct address_space *mapping,
631641
pgoff_t index, bool trunc)
632642
{
633643
XA_STATE(xas, &mapping->i_pages, index);
644+
bool empty = false;
634645
int ret = 0;
635646
void *entry;
636647

@@ -645,10 +656,13 @@ static int __dax_invalidate_entry(struct address_space *mapping,
645656
dax_disassociate_entry(entry, mapping, trunc);
646657
xas_store(&xas, NULL);
647658
mapping->nrexceptional--;
659+
empty = mapping_empty(mapping);
648660
ret = 1;
649661
out:
650662
put_unlocked_entry(&xas, entry);
651663
xas_unlock_irq(&xas);
664+
if (empty)
665+
inode_pages_clear(mapping->host);
652666
return ret;
653667
}
654668

fs/drop_caches.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
2727
* we need to reschedule to avoid softlockups.
2828
*/
2929
if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) ||
30-
(inode->i_mapping->nrpages == 0 && !need_resched())) {
30+
(mapping_empty(inode->i_mapping) && !need_resched())) {
3131
spin_unlock(&inode->i_lock);
3232
continue;
3333
}

fs/inode.c

Lines changed: 103 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,26 +429,101 @@ static void inode_lru_list_add(struct inode *inode)
429429
inode->i_state |= I_REFERENCED;
430430
}
431431

432+
static void inode_lru_list_del(struct inode *inode)
433+
{
434+
if (list_lru_del(&inode->i_sb->s_inode_lru, &inode->i_lru))
435+
this_cpu_dec(nr_unused);
436+
}
437+
432438
/*
433439
* Add inode to LRU if needed (inode is unused and clean).
434440
*
435441
* Needs inode->i_lock held.
436442
*/
437-
void inode_add_lru(struct inode *inode)
443+
bool inode_add_lru(struct inode *inode)
438444
{
439-
if (!(inode->i_state & (I_DIRTY_ALL | I_SYNC |
440-
I_FREEING | I_WILL_FREE)) &&
441-
!atomic_read(&inode->i_count) && inode->i_sb->s_flags & SB_ACTIVE)
442-
inode_lru_list_add(inode);
445+
if (inode->i_state &
446+
(I_DIRTY_ALL | I_SYNC | I_FREEING | I_WILL_FREE | I_PAGES))
447+
return false;
448+
if (atomic_read(&inode->i_count))
449+
return false;
450+
if (!(inode->i_sb->s_flags & SB_ACTIVE))
451+
return false;
452+
inode_lru_list_add(inode);
453+
return true;
443454
}
444455

456+
/*
457+
* Usually, inodes become reclaimable when they are no longer
458+
* referenced and their page cache has been reclaimed. The following
459+
* API allows the VM to communicate cache population state to the VFS.
460+
*
461+
* However, on CONFIG_HIGHMEM we can't wait for the page cache to go
462+
* away: cache pages allocated in a large highmem zone could pin
463+
* struct inode memory allocated in relatively small lowmem zones. So
464+
* when CONFIG_HIGHMEM is enabled, we tie cache to the inode lifetime.
465+
*/
445466

446-
static void inode_lru_list_del(struct inode *inode)
467+
#ifndef CONFIG_HIGHMEM
468+
/**
469+
* inode_pages_set - mark the inode as holding page cache
470+
* @inode: the inode whose first cache page was just added
471+
*
472+
* Tell the VFS that this inode has populated page cache and must not
473+
* be reclaimed by the inode shrinker.
474+
*
475+
* The caller must hold the page lock of the just-added page: by
476+
* pinning the page, the page cache cannot become depopulated, and we
477+
* can safely set I_PAGES without a race check under the i_pages lock.
478+
*
479+
* This function acquires the i_lock.
480+
*/
481+
void inode_pages_set(struct inode *inode)
447482
{
483+
spin_lock(&inode->i_lock);
484+
if (!(inode->i_state & I_PAGES)) {
485+
inode->i_state |= I_PAGES;
486+
if (!list_empty(&inode->i_lru)) {
487+
count_vm_event(PGINODERESCUE);
488+
inode_lru_list_del(inode);
489+
}
490+
}
491+
spin_unlock(&inode->i_lock);
492+
}
448493

449-
if (list_lru_del(&inode->i_sb->s_inode_lru, &inode->i_lru))
450-
this_cpu_dec(nr_unused);
494+
/**
495+
* inode_pages_clear - mark the inode as not holding page cache
496+
* @inode: the inode whose last cache page was just removed
497+
*
498+
* Tell the VFS that the inode no longer holds page cache and that its
499+
* lifetime is to be handed over to the inode shrinker LRU.
500+
*
501+
* This function acquires the i_lock and the i_pages lock.
502+
*/
503+
void inode_pages_clear(struct inode *inode)
504+
{
505+
struct address_space *mapping = &inode->i_data;
506+
bool add_to_lru = false;
507+
unsigned long flags;
508+
509+
spin_lock(&inode->i_lock);
510+
511+
xa_lock_irqsave(&mapping->i_pages, flags);
512+
if ((inode->i_state & I_PAGES) && mapping_empty(mapping)) {
513+
inode->i_state &= ~I_PAGES;
514+
add_to_lru = true;
515+
}
516+
xa_unlock_irqrestore(&mapping->i_pages, flags);
517+
518+
if (add_to_lru) {
519+
WARN_ON_ONCE(!list_empty(&inode->i_lru));
520+
if (inode_add_lru(inode))
521+
__count_vm_event(PGINODEDELAYED);
522+
}
523+
524+
spin_unlock(&inode->i_lock);
451525
}
526+
#endif /* CONFIG_HIGHMEM */
452527

453528
/**
454529
* inode_sb_list_add - add inode to the superblock list of inodes
@@ -741,6 +816,8 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
741816
if (!spin_trylock(&inode->i_lock))
742817
return LRU_SKIP;
743818

819+
WARN_ON_ONCE(inode->i_state & I_PAGES);
820+
744821
/*
745822
* Referenced or dirty inodes are still in use. Give them another pass
746823
* through the LRU as we canot reclaim them now.
@@ -760,7 +837,18 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
760837
return LRU_ROTATE;
761838
}
762839

763-
if (inode_has_buffers(inode) || inode->i_data.nrpages) {
840+
/*
841+
* Usually, populated inodes shouldn't be on the shrinker LRU,
842+
* but they can be briefly visible when a new page is added to
843+
* an inode that was already linked but inode_pages_set()
844+
* hasn't run yet to move them off.
845+
*
846+
* The other exception is on HIGHMEM systems: highmem cache
847+
* can pin lowmem struct inodes, and we might be in dire
848+
* straits in the lower zones. Purge cache to free the inode.
849+
*/
850+
if (inode_has_buffers(inode) || !mapping_empty(&inode->i_data)) {
851+
#ifdef CONFIG_HIGHMEM
764852
__iget(inode);
765853
spin_unlock(&inode->i_lock);
766854
spin_unlock(lru_lock);
@@ -777,6 +865,12 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
777865
iput(inode);
778866
spin_lock(lru_lock);
779867
return LRU_RETRY;
868+
#else
869+
list_lru_isolate(lru, &inode->i_lru);
870+
spin_unlock(&inode->i_lock);
871+
this_cpu_dec(nr_unused);
872+
return LRU_REMOVED;
873+
#endif
780874
}
781875

782876
WARN_ON(inode->i_state & I_NEW);

fs/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ extern int vfs_open(const struct path *, struct file *);
137137
* inode.c
138138
*/
139139
extern long prune_icache_sb(struct super_block *sb, struct shrink_control *sc);
140-
extern void inode_add_lru(struct inode *inode);
140+
extern bool inode_add_lru(struct inode *inode);
141141
extern int dentry_needs_remove_privs(struct dentry *dentry);
142142

143143
/*

include/linux/fs.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,11 @@ static inline void mapping_allow_writable(struct address_space *mapping)
585585
atomic_inc(&mapping->i_mmap_writable);
586586
}
587587

588+
static inline bool mapping_empty(struct address_space *mapping)
589+
{
590+
return mapping->nrpages + mapping->nrexceptional == 0;
591+
}
592+
588593
/*
589594
* Use sequence counter to get consistent i_size on 32-bit processors.
590595
*/
@@ -2139,6 +2144,9 @@ static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
21392144
*
21402145
* I_CREATING New object's inode in the middle of setting up.
21412146
*
2147+
* I_PAGES Inode is holding page cache that needs to get reclaimed
2148+
* first before the inode can go onto the shrinker LRU.
2149+
*
21422150
* Q: What is the difference between I_WILL_FREE and I_FREEING?
21432151
*/
21442152
#define I_DIRTY_SYNC (1 << 0)
@@ -2161,6 +2169,7 @@ static inline void init_sync_kiocb(struct kiocb *kiocb, struct file *filp)
21612169
#define I_WB_SWITCH (1 << 13)
21622170
#define I_OVL_INUSE (1 << 14)
21632171
#define I_CREATING (1 << 15)
2172+
#define I_PAGES (1 << 16)
21642173

21652174
#define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC)
21662175
#define I_DIRTY (I_DIRTY_INODE | I_DIRTY_PAGES)
@@ -3079,6 +3088,14 @@ static inline void remove_inode_hash(struct inode *inode)
30793088
__remove_inode_hash(inode);
30803089
}
30813090

3091+
#ifndef CONFIG_HIGHMEM
3092+
extern void inode_pages_set(struct inode *inode);
3093+
extern void inode_pages_clear(struct inode *inode);
3094+
#else
3095+
static inline void inode_pages_set(struct inode *inode) {}
3096+
static inline void inode_pages_clear(struct inode *inode) {}
3097+
#endif
3098+
30823099
extern void inode_sb_list_add(struct inode *inode);
30833100

30843101
#ifdef CONFIG_BLOCK

include/linux/pagemap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ int add_to_page_cache_locked(struct page *page, struct address_space *mapping,
609609
int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
610610
pgoff_t index, gfp_t gfp_mask);
611611
extern void delete_from_page_cache(struct page *page);
612-
extern void __delete_from_page_cache(struct page *page, void *shadow);
612+
extern bool __delete_from_page_cache(struct page *page, void *shadow);
613613
int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask);
614614
void delete_from_page_cache_batch(struct address_space *mapping,
615615
struct pagevec *pvec);

include/linux/vm_event_item.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
3838
#ifdef CONFIG_NUMA
3939
PGSCAN_ZONE_RECLAIM_FAILED,
4040
#endif
41-
PGINODESTEAL, SLABS_SCANNED, KSWAPD_INODESTEAL,
41+
SLABS_SCANNED,
42+
PGINODESTEAL, KSWAPD_INODESTEAL, PGINODERESCUE, PGINODEDELAYED,
4243
KSWAPD_LOW_WMARK_HIT_QUICKLY, KSWAPD_HIGH_WMARK_HIT_QUICKLY,
4344
PAGEOUTRUN, PGROTATED,
4445
DROP_PAGECACHE, DROP_SLAB,

0 commit comments

Comments
 (0)