Skip to content

Commit f04e9eb

Browse files
kosakitorvalds
authored andcommitted
swap: use an array for the LRU pagevecs
Turn the pagevecs into an array just like the LRUs. This significantly cleans up the source code and reduces the size of the kernel by about 13kB after all the LRU lists have been created further down in the split VM patch series. Signed-off-by: Rik van Riel <riel@redhat.com> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b69408e commit f04e9eb

4 files changed

Lines changed: 55 additions & 66 deletions

File tree

‎include/linux/pagevec.h‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ struct pagevec {
2323
void __pagevec_release(struct pagevec *pvec);
2424
void __pagevec_release_nonlru(struct pagevec *pvec);
2525
void __pagevec_free(struct pagevec *pvec);
26-
void __pagevec_lru_add(struct pagevec *pvec);
27-
void __pagevec_lru_add_active(struct pagevec *pvec);
26+
void ____pagevec_lru_add(struct pagevec *pvec, enum lru_list lru);
2827
void pagevec_strip(struct pagevec *pvec);
2928
unsigned pagevec_lookup(struct pagevec *pvec, struct address_space *mapping,
3029
pgoff_t start, unsigned nr_pages);
@@ -81,6 +80,16 @@ static inline void pagevec_free(struct pagevec *pvec)
8180
__pagevec_free(pvec);
8281
}
8382

83+
static inline void __pagevec_lru_add(struct pagevec *pvec)
84+
{
85+
____pagevec_lru_add(pvec, LRU_INACTIVE);
86+
}
87+
88+
static inline void __pagevec_lru_add_active(struct pagevec *pvec)
89+
{
90+
____pagevec_lru_add(pvec, LRU_ACTIVE);
91+
}
92+
8493
static inline void pagevec_lru_add(struct pagevec *pvec)
8594
{
8695
if (pagevec_count(pvec))

‎include/linux/swap.h‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,29 @@ extern unsigned int nr_free_pagecache_pages(void);
171171

172172

173173
/* linux/mm/swap.c */
174-
extern void lru_cache_add(struct page *);
175-
extern void lru_cache_add_active(struct page *);
174+
extern void __lru_cache_add(struct page *, enum lru_list lru);
175+
extern void lru_cache_add_lru(struct page *, enum lru_list lru);
176176
extern void activate_page(struct page *);
177177
extern void mark_page_accessed(struct page *);
178178
extern void lru_add_drain(void);
179179
extern int lru_add_drain_all(void);
180180
extern void rotate_reclaimable_page(struct page *page);
181181
extern void swap_setup(void);
182182

183+
/**
184+
* lru_cache_add: add a page to the page lists
185+
* @page: the page to add
186+
*/
187+
static inline void lru_cache_add(struct page *page)
188+
{
189+
__lru_cache_add(page, LRU_INACTIVE);
190+
}
191+
192+
static inline void lru_cache_add_active(struct page *page)
193+
{
194+
__lru_cache_add(page, LRU_ACTIVE);
195+
}
196+
183197
/* linux/mm/vmscan.c */
184198
extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
185199
gfp_t gfp_mask);

‎mm/migrate.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,7 @@ int migrate_prep(void)
5555

5656
static inline void move_to_lru(struct page *page)
5757
{
58-
if (PageActive(page)) {
59-
/*
60-
* lru_cache_add_active checks that
61-
* the PG_active bit is off.
62-
*/
63-
ClearPageActive(page);
64-
lru_cache_add_active(page);
65-
} else {
66-
lru_cache_add(page);
67-
}
58+
lru_cache_add_lru(page, page_lru(page));
6859
put_page(page);
6960
}
7061

‎mm/swap.c‎

Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
/* How many pages do we try to swap or page in/out together? */
3535
int page_cluster;
3636

37-
static DEFINE_PER_CPU(struct pagevec, lru_add_pvecs);
38-
static DEFINE_PER_CPU(struct pagevec, lru_add_active_pvecs);
37+
static DEFINE_PER_CPU(struct pagevec[NR_LRU_LISTS], lru_add_pvecs);
3938
static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
4039

4140
/*
@@ -186,28 +185,29 @@ void mark_page_accessed(struct page *page)
186185

187186
EXPORT_SYMBOL(mark_page_accessed);
188187

189-
/**
190-
* lru_cache_add: add a page to the page lists
191-
* @page: the page to add
192-
*/
193-
void lru_cache_add(struct page *page)
188+
void __lru_cache_add(struct page *page, enum lru_list lru)
194189
{
195-
struct pagevec *pvec = &get_cpu_var(lru_add_pvecs);
190+
struct pagevec *pvec = &get_cpu_var(lru_add_pvecs)[lru];
196191

197192
page_cache_get(page);
198193
if (!pagevec_add(pvec, page))
199-
__pagevec_lru_add(pvec);
194+
____pagevec_lru_add(pvec, lru);
200195
put_cpu_var(lru_add_pvecs);
201196
}
202197

203-
void lru_cache_add_active(struct page *page)
198+
/**
199+
* lru_cache_add_lru - add a page to a page list
200+
* @page: the page to be added to the LRU.
201+
* @lru: the LRU list to which the page is added.
202+
*/
203+
void lru_cache_add_lru(struct page *page, enum lru_list lru)
204204
{
205-
struct pagevec *pvec = &get_cpu_var(lru_add_active_pvecs);
205+
if (PageActive(page)) {
206+
ClearPageActive(page);
207+
}
206208

207-
page_cache_get(page);
208-
if (!pagevec_add(pvec, page))
209-
__pagevec_lru_add_active(pvec);
210-
put_cpu_var(lru_add_active_pvecs);
209+
VM_BUG_ON(PageLRU(page) || PageActive(page));
210+
__lru_cache_add(page, lru);
211211
}
212212

213213
/*
@@ -217,15 +217,15 @@ void lru_cache_add_active(struct page *page)
217217
*/
218218
static void drain_cpu_pagevecs(int cpu)
219219
{
220+
struct pagevec *pvecs = per_cpu(lru_add_pvecs, cpu);
220221
struct pagevec *pvec;
222+
int lru;
221223

222-
pvec = &per_cpu(lru_add_pvecs, cpu);
223-
if (pagevec_count(pvec))
224-
__pagevec_lru_add(pvec);
225-
226-
pvec = &per_cpu(lru_add_active_pvecs, cpu);
227-
if (pagevec_count(pvec))
228-
__pagevec_lru_add_active(pvec);
224+
for_each_lru(lru) {
225+
pvec = &pvecs[lru - LRU_BASE];
226+
if (pagevec_count(pvec))
227+
____pagevec_lru_add(pvec, lru);
228+
}
229229

230230
pvec = &per_cpu(lru_rotate_pvecs, cpu);
231231
if (pagevec_count(pvec)) {
@@ -380,7 +380,7 @@ void __pagevec_release_nonlru(struct pagevec *pvec)
380380
* Add the passed pages to the LRU, then drop the caller's refcount
381381
* on them. Reinitialises the caller's pagevec.
382382
*/
383-
void __pagevec_lru_add(struct pagevec *pvec)
383+
void ____pagevec_lru_add(struct pagevec *pvec, enum lru_list lru)
384384
{
385385
int i;
386386
struct zone *zone = NULL;
@@ -397,42 +397,17 @@ void __pagevec_lru_add(struct pagevec *pvec)
397397
}
398398
VM_BUG_ON(PageLRU(page));
399399
SetPageLRU(page);
400-
add_page_to_inactive_list(zone, page);
400+
if (is_active_lru(lru))
401+
SetPageActive(page);
402+
add_page_to_lru_list(zone, page, lru);
401403
}
402404
if (zone)
403405
spin_unlock_irq(&zone->lru_lock);
404406
release_pages(pvec->pages, pvec->nr, pvec->cold);
405407
pagevec_reinit(pvec);
406408
}
407409

408-
EXPORT_SYMBOL(__pagevec_lru_add);
409-
410-
void __pagevec_lru_add_active(struct pagevec *pvec)
411-
{
412-
int i;
413-
struct zone *zone = NULL;
414-
415-
for (i = 0; i < pagevec_count(pvec); i++) {
416-
struct page *page = pvec->pages[i];
417-
struct zone *pagezone = page_zone(page);
418-
419-
if (pagezone != zone) {
420-
if (zone)
421-
spin_unlock_irq(&zone->lru_lock);
422-
zone = pagezone;
423-
spin_lock_irq(&zone->lru_lock);
424-
}
425-
VM_BUG_ON(PageLRU(page));
426-
SetPageLRU(page);
427-
VM_BUG_ON(PageActive(page));
428-
SetPageActive(page);
429-
add_page_to_active_list(zone, page);
430-
}
431-
if (zone)
432-
spin_unlock_irq(&zone->lru_lock);
433-
release_pages(pvec->pages, pvec->nr, pvec->cold);
434-
pagevec_reinit(pvec);
435-
}
410+
EXPORT_SYMBOL(____pagevec_lru_add);
436411

437412
/*
438413
* Try to drop buffers from the pages in a pagevec

0 commit comments

Comments
 (0)