1 // SPDX-License-Identifier: GPL-2.0
3 * linux/mm/swap_state.c
5 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
6 * Swap reorganised 29.12.95, Stephen Tweedie
8 * Rewritten to use page cache, (C) 1998 Stephen Tweedie
11 #include <linux/gfp.h>
12 #include <linux/kernel_stat.h>
13 #include <linux/swap.h>
14 #include <linux/swapops.h>
15 #include <linux/init.h>
16 #include <linux/pagemap.h>
17 #include <linux/backing-dev.h>
18 #include <linux/blkdev.h>
19 #include <linux/pagevec.h>
20 #include <linux/migrate.h>
21 #include <linux/vmalloc.h>
22 #include <linux/swap_slots.h>
23 #include <linux/huge_mm.h>
25 #include <asm/pgtable.h>
29 * swapper_space is a fiction, retained to simplify the path through
30 * vmscan's shrink_page_list.
32 static const struct address_space_operations swap_aops
= {
33 .writepage
= swap_writepage
,
34 .set_page_dirty
= swap_set_page_dirty
,
35 #ifdef CONFIG_MIGRATION
36 .migratepage
= migrate_page
,
40 struct address_space
*swapper_spaces
[MAX_SWAPFILES
] __read_mostly
;
41 static unsigned int nr_swapper_spaces
[MAX_SWAPFILES
] __read_mostly
;
42 static bool enable_vma_readahead __read_mostly
= true;
44 #define SWAP_RA_WIN_SHIFT (PAGE_SHIFT / 2)
45 #define SWAP_RA_HITS_MASK ((1UL << SWAP_RA_WIN_SHIFT) - 1)
46 #define SWAP_RA_HITS_MAX SWAP_RA_HITS_MASK
47 #define SWAP_RA_WIN_MASK (~PAGE_MASK & ~SWAP_RA_HITS_MASK)
49 #define SWAP_RA_HITS(v) ((v) & SWAP_RA_HITS_MASK)
50 #define SWAP_RA_WIN(v) (((v) & SWAP_RA_WIN_MASK) >> SWAP_RA_WIN_SHIFT)
51 #define SWAP_RA_ADDR(v) ((v) & PAGE_MASK)
53 #define SWAP_RA_VAL(addr, win, hits) \
54 (((addr) & PAGE_MASK) | \
55 (((win) << SWAP_RA_WIN_SHIFT) & SWAP_RA_WIN_MASK) | \
56 ((hits) & SWAP_RA_HITS_MASK))
58 /* Initial readahead hits is 4 to start up with a small window */
59 #define GET_SWAP_RA_VAL(vma) \
60 (atomic_long_read(&(vma)->swap_readahead_info) ? : 4)
62 #define INC_CACHE_INFO(x) do { swap_cache_info.x++; } while (0)
63 #define ADD_CACHE_INFO(x, nr) do { swap_cache_info.x += (nr); } while (0)
66 unsigned long add_total
;
67 unsigned long del_total
;
68 unsigned long find_success
;
69 unsigned long find_total
;
72 unsigned long total_swapcache_pages(void)
74 unsigned int i
, j
, nr
;
75 unsigned long ret
= 0;
76 struct address_space
*spaces
;
79 for (i
= 0; i
< MAX_SWAPFILES
; i
++) {
81 * The corresponding entries in nr_swapper_spaces and
82 * swapper_spaces will be reused only after at least
83 * one grace period. So it is impossible for them
84 * belongs to different usage.
86 nr
= nr_swapper_spaces
[i
];
87 spaces
= rcu_dereference(swapper_spaces
[i
]);
90 for (j
= 0; j
< nr
; j
++)
91 ret
+= spaces
[j
].nrpages
;
97 static atomic_t swapin_readahead_hits
= ATOMIC_INIT(4);
99 void show_swap_cache_info(void)
101 printk("%lu pages in swap cache\n", total_swapcache_pages());
102 printk("Swap cache stats: add %lu, delete %lu, find %lu/%lu\n",
103 swap_cache_info
.add_total
, swap_cache_info
.del_total
,
104 swap_cache_info
.find_success
, swap_cache_info
.find_total
);
105 printk("Free swap = %ldkB\n",
106 get_nr_swap_pages() << (PAGE_SHIFT
- 10));
107 printk("Total swap = %lukB\n", total_swap_pages
<< (PAGE_SHIFT
- 10));
111 * __add_to_swap_cache resembles add_to_page_cache_locked on swapper_space,
112 * but sets SwapCache flag and private instead of mapping and index.
114 int __add_to_swap_cache(struct page
*page
, swp_entry_t entry
)
116 int error
, i
, nr
= hpage_nr_pages(page
);
117 struct address_space
*address_space
;
118 pgoff_t idx
= swp_offset(entry
);
120 VM_BUG_ON_PAGE(!PageLocked(page
), page
);
121 VM_BUG_ON_PAGE(PageSwapCache(page
), page
);
122 VM_BUG_ON_PAGE(!PageSwapBacked(page
), page
);
124 page_ref_add(page
, nr
);
125 SetPageSwapCache(page
);
127 address_space
= swap_address_space(entry
);
128 xa_lock_irq(&address_space
->i_pages
);
129 for (i
= 0; i
< nr
; i
++) {
130 set_page_private(page
+ i
, entry
.val
+ i
);
131 error
= radix_tree_insert(&address_space
->i_pages
,
136 if (likely(!error
)) {
137 address_space
->nrpages
+= nr
;
138 __mod_node_page_state(page_pgdat(page
), NR_FILE_PAGES
, nr
);
139 ADD_CACHE_INFO(add_total
, nr
);
142 * Only the context which have set SWAP_HAS_CACHE flag
143 * would call add_to_swap_cache().
144 * So add_to_swap_cache() doesn't returns -EEXIST.
146 VM_BUG_ON(error
== -EEXIST
);
147 set_page_private(page
+ i
, 0UL);
149 radix_tree_delete(&address_space
->i_pages
, idx
+ i
);
150 set_page_private(page
+ i
, 0UL);
152 ClearPageSwapCache(page
);
153 page_ref_sub(page
, nr
);
155 xa_unlock_irq(&address_space
->i_pages
);
161 int add_to_swap_cache(struct page
*page
, swp_entry_t entry
, gfp_t gfp_mask
)
165 error
= radix_tree_maybe_preload_order(gfp_mask
, compound_order(page
));
167 error
= __add_to_swap_cache(page
, entry
);
168 radix_tree_preload_end();
174 * This must be called only on pages that have
175 * been verified to be in the swap cache.
177 void __delete_from_swap_cache(struct page
*page
)
179 struct address_space
*address_space
;
180 int i
, nr
= hpage_nr_pages(page
);
184 VM_BUG_ON_PAGE(!PageLocked(page
), page
);
185 VM_BUG_ON_PAGE(!PageSwapCache(page
), page
);
186 VM_BUG_ON_PAGE(PageWriteback(page
), page
);
188 entry
.val
= page_private(page
);
189 address_space
= swap_address_space(entry
);
190 idx
= swp_offset(entry
);
191 for (i
= 0; i
< nr
; i
++) {
192 radix_tree_delete(&address_space
->i_pages
, idx
+ i
);
193 set_page_private(page
+ i
, 0);
195 ClearPageSwapCache(page
);
196 address_space
->nrpages
-= nr
;
197 __mod_node_page_state(page_pgdat(page
), NR_FILE_PAGES
, -nr
);
198 ADD_CACHE_INFO(del_total
, nr
);
202 * add_to_swap - allocate swap space for a page
203 * @page: page we want to move to swap
205 * Allocate swap space for the page and add the page to the
206 * swap cache. Caller needs to hold the page lock.
208 int add_to_swap(struct page
*page
)
213 VM_BUG_ON_PAGE(!PageLocked(page
), page
);
214 VM_BUG_ON_PAGE(!PageUptodate(page
), page
);
216 entry
= get_swap_page(page
);
221 * Radix-tree node allocations from PF_MEMALLOC contexts could
222 * completely exhaust the page allocator. __GFP_NOMEMALLOC
223 * stops emergency reserves from being allocated.
225 * TODO: this could cause a theoretical memory reclaim
226 * deadlock in the swap out path.
229 * Add it to the swap cache.
231 err
= add_to_swap_cache(page
, entry
,
232 __GFP_HIGH
|__GFP_NOMEMALLOC
|__GFP_NOWARN
);
233 /* -ENOMEM radix-tree allocation failure */
236 * add_to_swap_cache() doesn't return -EEXIST, so we can safely
237 * clear SWAP_HAS_CACHE flag.
241 * Normally the page will be dirtied in unmap because its pte should be
242 * dirty. A special case is MADV_FREE page. The page'e pte could have
243 * dirty bit cleared but the page's SwapBacked bit is still set because
244 * clearing the dirty bit and SwapBacked bit has no lock protected. For
245 * such page, unmap will not set dirty bit for it, so page reclaim will
246 * not write the page out. This can cause data corruption when the page
247 * is swap in later. Always setting the dirty bit for the page solves
250 set_page_dirty(page
);
255 put_swap_page(page
, entry
);
260 * This must be called only on pages that have
261 * been verified to be in the swap cache and locked.
262 * It will never put the page into the free list,
263 * the caller has a reference on the page.
265 void delete_from_swap_cache(struct page
*page
)
268 struct address_space
*address_space
;
270 entry
.val
= page_private(page
);
272 address_space
= swap_address_space(entry
);
273 xa_lock_irq(&address_space
->i_pages
);
274 __delete_from_swap_cache(page
);
275 xa_unlock_irq(&address_space
->i_pages
);
277 put_swap_page(page
, entry
);
278 page_ref_sub(page
, hpage_nr_pages(page
));
282 * If we are the only user, then try to free up the swap cache.
284 * Its ok to check for PageSwapCache without the page lock
285 * here because we are going to recheck again inside
286 * try_to_free_swap() _with_ the lock.
289 static inline void free_swap_cache(struct page
*page
)
291 if (PageSwapCache(page
) && !page_mapped(page
) && trylock_page(page
)) {
292 try_to_free_swap(page
);
298 * Perform a free_page(), also freeing any swap cache associated with
299 * this page if it is the last user of the page.
301 void free_page_and_swap_cache(struct page
*page
)
303 free_swap_cache(page
);
304 if (!is_huge_zero_page(page
))
309 * Passed an array of pages, drop them all from swapcache and then release
310 * them. They are removed from the LRU and freed if this is their last use.
312 void free_pages_and_swap_cache(struct page
**pages
, int nr
)
314 struct page
**pagep
= pages
;
318 for (i
= 0; i
< nr
; i
++)
319 free_swap_cache(pagep
[i
]);
320 release_pages(pagep
, nr
);
323 static inline bool swap_use_vma_readahead(void)
325 return READ_ONCE(enable_vma_readahead
) && !atomic_read(&nr_rotate_swap
);
329 * Lookup a swap entry in the swap cache. A found page will be returned
330 * unlocked and with its refcount incremented - we rely on the kernel
331 * lock getting page table operations atomic even if we drop the page
332 * lock before returning.
334 struct page
*lookup_swap_cache(swp_entry_t entry
, struct vm_area_struct
*vma
,
339 page
= find_get_page(swap_address_space(entry
), swp_offset(entry
));
341 INC_CACHE_INFO(find_total
);
343 bool vma_ra
= swap_use_vma_readahead();
346 INC_CACHE_INFO(find_success
);
348 * At the moment, we don't support PG_readahead for anon THP
349 * so let's bail out rather than confusing the readahead stat.
351 if (unlikely(PageTransCompound(page
)))
354 readahead
= TestClearPageReadahead(page
);
356 unsigned long ra_val
;
359 ra_val
= GET_SWAP_RA_VAL(vma
);
360 win
= SWAP_RA_WIN(ra_val
);
361 hits
= SWAP_RA_HITS(ra_val
);
363 hits
= min_t(int, hits
+ 1, SWAP_RA_HITS_MAX
);
364 atomic_long_set(&vma
->swap_readahead_info
,
365 SWAP_RA_VAL(addr
, win
, hits
));
369 count_vm_event(SWAP_RA_HIT
);
371 atomic_inc(&swapin_readahead_hits
);
378 struct page
*__read_swap_cache_async(swp_entry_t entry
, gfp_t gfp_mask
,
379 struct vm_area_struct
*vma
, unsigned long addr
,
380 bool *new_page_allocated
)
382 struct page
*found_page
, *new_page
= NULL
;
383 struct address_space
*swapper_space
= swap_address_space(entry
);
385 *new_page_allocated
= false;
389 * First check the swap cache. Since this is normally
390 * called after lookup_swap_cache() failed, re-calling
391 * that would confuse statistics.
393 found_page
= find_get_page(swapper_space
, swp_offset(entry
));
398 * Just skip read ahead for unused swap slot.
399 * During swap_off when swap_slot_cache is disabled,
400 * we have to handle the race between putting
401 * swap entry in swap cache and marking swap slot
402 * as SWAP_HAS_CACHE. That's done in later part of code or
403 * else swap_off will be aborted if we return NULL.
405 if (!__swp_swapcount(entry
) && swap_slot_cache_enabled
)
409 * Get a new page to read into from swap.
412 new_page
= alloc_page_vma(gfp_mask
, vma
, addr
);
414 break; /* Out of memory */
418 * call radix_tree_preload() while we can wait.
420 err
= radix_tree_maybe_preload(gfp_mask
& GFP_RECLAIM_MASK
);
425 * Swap entry may have been freed since our caller observed it.
427 err
= swapcache_prepare(entry
);
428 if (err
== -EEXIST
) {
429 radix_tree_preload_end();
431 * We might race against get_swap_page() and stumble
432 * across a SWAP_HAS_CACHE swap_map entry whose page
433 * has not been brought into the swapcache yet.
438 if (err
) { /* swp entry is obsolete ? */
439 radix_tree_preload_end();
443 /* May fail (-ENOMEM) if radix-tree node allocation failed. */
444 __SetPageLocked(new_page
);
445 __SetPageSwapBacked(new_page
);
446 err
= __add_to_swap_cache(new_page
, entry
);
448 radix_tree_preload_end();
450 * Initiate read into locked page and return.
452 lru_cache_add_anon(new_page
);
453 *new_page_allocated
= true;
456 radix_tree_preload_end();
457 __ClearPageLocked(new_page
);
459 * add_to_swap_cache() doesn't return -EEXIST, so we can safely
460 * clear SWAP_HAS_CACHE flag.
462 put_swap_page(new_page
, entry
);
463 } while (err
!= -ENOMEM
);
471 * Locate a page of swap in physical memory, reserving swap cache space
472 * and reading the disk if it is not already cached.
473 * A failure return means that either the page allocation failed or that
474 * the swap entry is no longer in use.
476 struct page
*read_swap_cache_async(swp_entry_t entry
, gfp_t gfp_mask
,
477 struct vm_area_struct
*vma
, unsigned long addr
, bool do_poll
)
479 bool page_was_allocated
;
480 struct page
*retpage
= __read_swap_cache_async(entry
, gfp_mask
,
481 vma
, addr
, &page_was_allocated
);
483 if (page_was_allocated
)
484 swap_readpage(retpage
, do_poll
);
489 static unsigned int __swapin_nr_pages(unsigned long prev_offset
,
490 unsigned long offset
,
495 unsigned int pages
, last_ra
;
498 * This heuristic has been found to work well on both sequential and
499 * random loads, swapping to hard disk or to SSD: please don't ask
500 * what the "+ 2" means, it just happens to work well, that's all.
505 * We can have no readahead hits to judge by: but must not get
506 * stuck here forever, so check for an adjacent offset instead
507 * (and don't even bother to check whether swap type is same).
509 if (offset
!= prev_offset
+ 1 && offset
!= prev_offset
- 1)
512 unsigned int roundup
= 4;
513 while (roundup
< pages
)
518 if (pages
> max_pages
)
521 /* Don't shrink readahead too fast */
522 last_ra
= prev_win
/ 2;
529 static unsigned long swapin_nr_pages(unsigned long offset
)
531 static unsigned long prev_offset
;
532 unsigned int hits
, pages
, max_pages
;
533 static atomic_t last_readahead_pages
;
535 max_pages
= 1 << READ_ONCE(page_cluster
);
539 hits
= atomic_xchg(&swapin_readahead_hits
, 0);
540 pages
= __swapin_nr_pages(READ_ONCE(prev_offset
), offset
, hits
,
542 atomic_read(&last_readahead_pages
));
544 WRITE_ONCE(prev_offset
, offset
);
545 atomic_set(&last_readahead_pages
, pages
);
551 * swap_cluster_readahead - swap in pages in hope we need them soon
552 * @entry: swap entry of this memory
553 * @gfp_mask: memory allocation flags
554 * @vmf: fault information
556 * Returns the struct page for entry and addr, after queueing swapin.
558 * Primitive swap readahead code. We simply read an aligned block of
559 * (1 << page_cluster) entries in the swap area. This method is chosen
560 * because it doesn't cost us any seek time. We also make sure to queue
561 * the 'original' request together with the readahead ones...
563 * This has been extended to use the NUMA policies from the mm triggering
566 * Caller must hold down_read on the vma->vm_mm if vmf->vma is not NULL.
568 struct page
*swap_cluster_readahead(swp_entry_t entry
, gfp_t gfp_mask
,
569 struct vm_fault
*vmf
)
572 unsigned long entry_offset
= swp_offset(entry
);
573 unsigned long offset
= entry_offset
;
574 unsigned long start_offset
, end_offset
;
576 struct swap_info_struct
*si
= swp_swap_info(entry
);
577 struct blk_plug plug
;
578 bool do_poll
= true, page_allocated
;
579 struct vm_area_struct
*vma
= vmf
->vma
;
580 unsigned long addr
= vmf
->address
;
582 mask
= swapin_nr_pages(offset
) - 1;
587 /* Read a page_cluster sized and aligned cluster around offset. */
588 start_offset
= offset
& ~mask
;
589 end_offset
= offset
| mask
;
590 if (!start_offset
) /* First page is swap header. */
592 if (end_offset
>= si
->max
)
593 end_offset
= si
->max
- 1;
595 blk_start_plug(&plug
);
596 for (offset
= start_offset
; offset
<= end_offset
; offset
++) {
597 /* Ok, do the async read-ahead now */
598 page
= __read_swap_cache_async(
599 swp_entry(swp_type(entry
), offset
),
600 gfp_mask
, vma
, addr
, &page_allocated
);
603 if (page_allocated
) {
604 swap_readpage(page
, false);
605 if (offset
!= entry_offset
) {
606 SetPageReadahead(page
);
607 count_vm_event(SWAP_RA
);
612 blk_finish_plug(&plug
);
614 lru_add_drain(); /* Push any new pages onto the LRU now */
616 return read_swap_cache_async(entry
, gfp_mask
, vma
, addr
, do_poll
);
619 int init_swap_address_space(unsigned int type
, unsigned long nr_pages
)
621 struct address_space
*spaces
, *space
;
624 nr
= DIV_ROUND_UP(nr_pages
, SWAP_ADDRESS_SPACE_PAGES
);
625 spaces
= kvcalloc(nr
, sizeof(struct address_space
), GFP_KERNEL
);
628 for (i
= 0; i
< nr
; i
++) {
630 INIT_RADIX_TREE(&space
->i_pages
, GFP_ATOMIC
|__GFP_NOWARN
);
631 atomic_set(&space
->i_mmap_writable
, 0);
632 space
->a_ops
= &swap_aops
;
633 /* swap cache doesn't use writeback related tags */
634 mapping_set_no_writeback_tags(space
);
636 nr_swapper_spaces
[type
] = nr
;
637 rcu_assign_pointer(swapper_spaces
[type
], spaces
);
642 void exit_swap_address_space(unsigned int type
)
644 struct address_space
*spaces
;
646 spaces
= swapper_spaces
[type
];
647 nr_swapper_spaces
[type
] = 0;
648 rcu_assign_pointer(swapper_spaces
[type
], NULL
);
653 static inline void swap_ra_clamp_pfn(struct vm_area_struct
*vma
,
657 unsigned long *start
,
660 *start
= max3(lpfn
, PFN_DOWN(vma
->vm_start
),
661 PFN_DOWN(faddr
& PMD_MASK
));
662 *end
= min3(rpfn
, PFN_DOWN(vma
->vm_end
),
663 PFN_DOWN((faddr
& PMD_MASK
) + PMD_SIZE
));
666 static void swap_ra_info(struct vm_fault
*vmf
,
667 struct vma_swap_readahead
*ra_info
)
669 struct vm_area_struct
*vma
= vmf
->vma
;
670 unsigned long ra_val
;
672 unsigned long faddr
, pfn
, fpfn
;
673 unsigned long start
, end
;
674 pte_t
*pte
, *orig_pte
;
675 unsigned int max_win
, hits
, prev_win
, win
, left
;
680 max_win
= 1 << min_t(unsigned int, READ_ONCE(page_cluster
),
681 SWAP_RA_ORDER_CEILING
);
687 faddr
= vmf
->address
;
688 orig_pte
= pte
= pte_offset_map(vmf
->pmd
, faddr
);
689 entry
= pte_to_swp_entry(*pte
);
690 if ((unlikely(non_swap_entry(entry
)))) {
695 fpfn
= PFN_DOWN(faddr
);
696 ra_val
= GET_SWAP_RA_VAL(vma
);
697 pfn
= PFN_DOWN(SWAP_RA_ADDR(ra_val
));
698 prev_win
= SWAP_RA_WIN(ra_val
);
699 hits
= SWAP_RA_HITS(ra_val
);
700 ra_info
->win
= win
= __swapin_nr_pages(pfn
, fpfn
, hits
,
702 atomic_long_set(&vma
->swap_readahead_info
,
703 SWAP_RA_VAL(faddr
, win
, 0));
710 /* Copy the PTEs because the page table may be unmapped */
712 swap_ra_clamp_pfn(vma
, faddr
, fpfn
, fpfn
+ win
, &start
, &end
);
713 else if (pfn
== fpfn
+ 1)
714 swap_ra_clamp_pfn(vma
, faddr
, fpfn
- win
+ 1, fpfn
+ 1,
717 left
= (win
- 1) / 2;
718 swap_ra_clamp_pfn(vma
, faddr
, fpfn
- left
, fpfn
+ win
- left
,
721 ra_info
->nr_pte
= end
- start
;
722 ra_info
->offset
= fpfn
- start
;
723 pte
-= ra_info
->offset
;
727 tpte
= ra_info
->ptes
;
728 for (pfn
= start
; pfn
!= end
; pfn
++)
734 static struct page
*swap_vma_readahead(swp_entry_t fentry
, gfp_t gfp_mask
,
735 struct vm_fault
*vmf
)
737 struct blk_plug plug
;
738 struct vm_area_struct
*vma
= vmf
->vma
;
744 struct vma_swap_readahead ra_info
= {0,};
746 swap_ra_info(vmf
, &ra_info
);
747 if (ra_info
.win
== 1)
750 blk_start_plug(&plug
);
751 for (i
= 0, pte
= ra_info
.ptes
; i
< ra_info
.nr_pte
;
754 if (pte_none(pentry
))
756 if (pte_present(pentry
))
758 entry
= pte_to_swp_entry(pentry
);
759 if (unlikely(non_swap_entry(entry
)))
761 page
= __read_swap_cache_async(entry
, gfp_mask
, vma
,
762 vmf
->address
, &page_allocated
);
765 if (page_allocated
) {
766 swap_readpage(page
, false);
767 if (i
!= ra_info
.offset
) {
768 SetPageReadahead(page
);
769 count_vm_event(SWAP_RA
);
774 blk_finish_plug(&plug
);
777 return read_swap_cache_async(fentry
, gfp_mask
, vma
, vmf
->address
,
782 * swapin_readahead - swap in pages in hope we need them soon
783 * @entry: swap entry of this memory
784 * @gfp_mask: memory allocation flags
785 * @vmf: fault information
787 * Returns the struct page for entry and addr, after queueing swapin.
789 * It's a main entry function for swap readahead. By the configuration,
790 * it will read ahead blocks by cluster-based(ie, physical disk based)
791 * or vma-based(ie, virtual address based on faulty address) readahead.
793 struct page
*swapin_readahead(swp_entry_t entry
, gfp_t gfp_mask
,
794 struct vm_fault
*vmf
)
796 return swap_use_vma_readahead() ?
797 swap_vma_readahead(entry
, gfp_mask
, vmf
) :
798 swap_cluster_readahead(entry
, gfp_mask
, vmf
);
802 static ssize_t
vma_ra_enabled_show(struct kobject
*kobj
,
803 struct kobj_attribute
*attr
, char *buf
)
805 return sprintf(buf
, "%s\n", enable_vma_readahead
? "true" : "false");
807 static ssize_t
vma_ra_enabled_store(struct kobject
*kobj
,
808 struct kobj_attribute
*attr
,
809 const char *buf
, size_t count
)
811 if (!strncmp(buf
, "true", 4) || !strncmp(buf
, "1", 1))
812 enable_vma_readahead
= true;
813 else if (!strncmp(buf
, "false", 5) || !strncmp(buf
, "0", 1))
814 enable_vma_readahead
= false;
820 static struct kobj_attribute vma_ra_enabled_attr
=
821 __ATTR(vma_ra_enabled
, 0644, vma_ra_enabled_show
,
822 vma_ra_enabled_store
);
824 static struct attribute
*swap_attrs
[] = {
825 &vma_ra_enabled_attr
.attr
,
829 static struct attribute_group swap_attr_group
= {
833 static int __init
swap_init_sysfs(void)
836 struct kobject
*swap_kobj
;
838 swap_kobj
= kobject_create_and_add("swap", mm_kobj
);
840 pr_err("failed to create swap kobject\n");
843 err
= sysfs_create_group(swap_kobj
, &swap_attr_group
);
845 pr_err("failed to register swap group\n");
851 kobject_put(swap_kobj
);
854 subsys_initcall(swap_init_sysfs
);