Skip to content

Commit

Permalink
mm/workingset: Convert workingset_refault to take a folio
Browse files Browse the repository at this point in the history
This nets us 178 bytes of savings from removing calls to compound_head.
The three callers all grow a little, but each of them will be converted
to use folios soon, so that's fine.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
  • Loading branch information
Matthew Wilcox (Oracle) authored and intel-lab-lkp committed May 5, 2021
1 parent 99cf224 commit b1883a3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions include/linux/swap.h
Expand Up @@ -323,7 +323,7 @@ static inline swp_entry_t folio_swap_entry(struct folio *folio)
/* linux/mm/workingset.c */
void workingset_age_nonresident(struct lruvec *lruvec, unsigned long nr_pages);
void *workingset_eviction(struct page *page, struct mem_cgroup *target_memcg);
void workingset_refault(struct page *page, void *shadow);
void workingset_refault(struct folio *folio, void *shadow);
void workingset_activation(struct folio *folio);

/* Only track the nodes of mappings with shadow entries */
Expand All @@ -344,7 +344,7 @@ extern unsigned long nr_free_buffer_pages(void);
/* linux/mm/swap.c */
extern void lru_note_cost(struct lruvec *lruvec, bool file,
unsigned int nr_pages);
extern void lru_note_cost_page(struct page *);
extern void lru_note_cost_folio(struct folio *);
extern void lru_cache_add(struct page *);
void mark_page_accessed(struct page *);
void folio_mark_accessed(struct folio *);
Expand Down
2 changes: 1 addition & 1 deletion mm/filemap.c
Expand Up @@ -979,7 +979,7 @@ int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
*/
WARN_ON_ONCE(PageActive(page));
if (!(gfp_mask & __GFP_WRITE) && shadow)
workingset_refault(page, shadow);
workingset_refault(page_folio(page), shadow);
lru_cache_add(page);
}
return ret;
Expand Down
3 changes: 2 additions & 1 deletion mm/memory.c
Expand Up @@ -3364,7 +3364,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)

shadow = get_shadow_from_swap_cache(entry);
if (shadow)
workingset_refault(page, shadow);
workingset_refault(page_folio(page),
shadow);

lru_cache_add(page);

Expand Down
6 changes: 3 additions & 3 deletions mm/swap.c
Expand Up @@ -311,10 +311,10 @@ void lru_note_cost(struct lruvec *lruvec, bool file, unsigned int nr_pages)
} while ((lruvec = parent_lruvec(lruvec)));
}

void lru_note_cost_page(struct page *page)
void lru_note_cost_folio(struct folio *folio)
{
lru_note_cost(mem_cgroup_page_lruvec(page, page_pgdat(page)),
page_is_file_lru(page), thp_nr_pages(page));
lru_note_cost(mem_cgroup_folio_lruvec(folio, folio_pgdat(folio)),
folio_is_file_lru(folio), folio_nr_pages(folio));
}

static void __activate_page(struct page *page, struct lruvec *lruvec)
Expand Down
2 changes: 1 addition & 1 deletion mm/swap_state.c
Expand Up @@ -503,7 +503,7 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
mem_cgroup_swapin_uncharge_swap(entry);

if (shadow)
workingset_refault(page, shadow);
workingset_refault(page_folio(page), shadow);

/* Caller will initiate read into locked page */
lru_cache_add(page);
Expand Down
34 changes: 17 additions & 17 deletions mm/workingset.c
Expand Up @@ -271,17 +271,17 @@ void *workingset_eviction(struct page *page, struct mem_cgroup *target_memcg)
}

/**
* workingset_refault - evaluate the refault of a previously evicted page
* @page: the freshly allocated replacement page
* @shadow: shadow entry of the evicted page
* workingset_refault - evaluate the refault of a previously evicted folio
* @page: the freshly allocated replacement folio
* @shadow: shadow entry of the evicted folio
*
* Calculates and evaluates the refault distance of the previously
* evicted page in the context of the node and the memcg whose memory
* evicted folio in the context of the node and the memcg whose memory
* pressure caused the eviction.
*/
void workingset_refault(struct page *page, void *shadow)
void workingset_refault(struct folio *folio, void *shadow)
{
bool file = page_is_file_lru(page);
bool file = folio_is_file_lru(folio);
struct mem_cgroup *eviction_memcg;
struct lruvec *eviction_lruvec;
unsigned long refault_distance;
Expand All @@ -299,10 +299,10 @@ void workingset_refault(struct page *page, void *shadow)
rcu_read_lock();
/*
* Look up the memcg associated with the stored ID. It might
* have been deleted since the page's eviction.
* have been deleted since the folio's eviction.
*
* Note that in rare events the ID could have been recycled
* for a new cgroup that refaults a shared page. This is
* for a new cgroup that refaults a shared folio. This is
* impossible to tell from the available data. However, this
* should be a rare and limited disturbance, and activations
* are always speculative anyway. Ultimately, it's the aging
Expand Down Expand Up @@ -338,14 +338,14 @@ void workingset_refault(struct page *page, void *shadow)
refault_distance = (refault - eviction) & EVICTION_MASK;

/*
* The activation decision for this page is made at the level
* The activation decision for this folio is made at the level
* where the eviction occurred, as that is where the LRU order
* during page reclaim is being determined.
* during folio reclaim is being determined.
*
* However, the cgroup that will own the page is the one that
* However, the cgroup that will own the folio is the one that
* is actually experiencing the refault event.
*/
memcg = page_memcg(page);
memcg = folio_memcg(folio);
lruvec = mem_cgroup_lruvec(memcg, pgdat);

inc_lruvec_state(lruvec, WORKINGSET_REFAULT_BASE + file);
Expand Down Expand Up @@ -373,15 +373,15 @@ void workingset_refault(struct page *page, void *shadow)
if (refault_distance > workingset_size)
goto out;

SetPageActive(page);
workingset_age_nonresident(lruvec, thp_nr_pages(page));
folio_set_active_flag(folio);
workingset_age_nonresident(lruvec, folio_nr_pages(folio));
inc_lruvec_state(lruvec, WORKINGSET_ACTIVATE_BASE + file);

/* Page was active prior to eviction */
/* Folio was active prior to eviction */
if (workingset) {
SetPageWorkingset(page);
folio_set_workingset_flag(folio);
/* XXX: Move to lru_cache_add() when it supports new vs putback */
lru_note_cost_page(page);
lru_note_cost_folio(folio);
inc_lruvec_state(lruvec, WORKINGSET_RESTORE_BASE + file);
}
out:
Expand Down

0 comments on commit b1883a3

Please sign in to comment.