close various race windows for swap
Subsystems (4)
v4 cover close various race windows for swap
Hi all,
When I was investigating the swap code, I found some possible race windows. This series aims to fix all these races. But using current get/put_swap_device() to guard against concurrent swapoff for swap_readpage() looks terrible because swap_readpage() may take really long time. And to reduce the performance overhead on the hot-path as much as possible, it appears we can use the percpu_ref to close this race window(as suggested by Huang, Ying). The patch 1 adds percpu_ref support for swap and most of the remaining patches try to use this to close various race windows. More details can be found in the respective changelogs. Thanks!
v3->v4:
some commit log and comment enhance per Huang, Ying put get/put_swap_device() in shmem_swapin_page() per Huang, Ying collect Reviewed-by tag
v2->v3:
some commit log and comment enhance per Huang, Ying remove ref_initialized field
squash PATCH 1-2
v1->v2:
reorganize the patch-2/5
various enhance and fixup per Huang, Ying
Many thanks for the comments of Huang, Ying, Dennis Zhou and Tim Chen.
Miaohe Lin (4):
mm/swapfile: use percpu_ref to serialize against concurrent swapoff
swap: fix do_swap_page() race with swapoff
mm/swap: remove confusing checking for non_swap_entry() in
swap_ra_info()
mm/shmem: fix shmem_swapin() race with swapoff
include/linux/swap.h | 14 ++++++-- mm/memory.c | 11 ++++-- mm/shmem.c | 11 ++++++ mm/swap_state.c | 6 ---- mm/swapfile.c | 79 +++++++++++++++++++++++++++----------------- 5 files changed, 81 insertions(+), 40 deletions(-)
Signature · 1 line
2.19.1
PATCH v4 1/4 mm/swapfile: use percpu_ref to serialize against concurrent swapoff
Using current get/put_swap_device() to guard against concurrent swapoff for some swap ops, e.g. swap_readpage(), looks terrible because they might take really long time. This patch adds the percpu_ref support to serialize against concurrent swapoff(as suggested by Huang, Ying). Also we remove the SWP_VALID flag because it's used together with RCU solution.
--- include/linux/swap.h | 5 +-- mm/swapfile.c | 79 +++++++++++++++++++++++++++----------------- 2 files changed, 52 insertions(+), 32 deletions(-)
include/linux/swap.h +3 -2
@@ -177,7 +177,6 @@ enum {SWP_PAGE_DISCARD = (1 <<10 ),/* freed swap page-cluster discards */ SWP_STABLE_WRITES = (1 <<11 ),/* no overwrite PG_writeback pages */ SWP_SYNCHRONOUS_IO = (1 <<12 ),/* synchronous IO is efficient */ -SWP_VALID = (1 <<13 ),/* swap is valid to be operated on? */ /* add others here before... */ SWP_SCANNING = (1 << 14), /* refcount in scan_swap_map */ };
@@ -240,6 +239,7 @@ struct swap_cluster_list {* The in-memory structure used to track swap areas. */ struct swap_info_struct { +struct percpu_ref users;/* indicate and keep swap device valid. */ unsigned long flags;/* SWP_USED etc: see above */ signed short prio;/* swap priority of this type */ struct plist_node list;/* entry in swap_active_head */
@@ -260,6 +260,7 @@ struct swap_info_struct {struct block_device *bdev;/* swap device or bdev of swap file */ struct file *swap_file;/* seldom referenced */ unsigned int old_block_size;/* seldom referenced */ +struct completion comp;/* seldom referenced */ #ifdef CONFIG_FRONTSWAP unsigned long *frontswap_map;/* frontswap in-use, one bit per page */ atomic_t frontswap_pages;/* frontswap pages in-use counter */
@@ -511,7 +512,7 @@ sector_t swap_page_sector(struct page *page);static inline void put_swap_device (struct swap_info_struct *si) { -rcu_read_unlock (); +percpu_ref_put (&si->users); }#else /* CONFIG_SWAP */
mm/swapfile.c +49 -30
154 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH v4 2/4 swap: fix do_swap_page() race with swapoff
In reply to Miaohe LinWhen I was investigating the swap code, I found the below possible race window:
CPU 1 CPU 2
----- -----do_swap_page
if (data_race(si->flags & SWP_SYNCHRONOUS_IO)
swap_readpage
if (data_race(sis->flags & SWP_FS_OPS)) {
swapoff
..
p->swap_file = NULL;
..
struct file *swap_file = sis->swap_file;
struct address_space *mapping = swap_file->f_mapping;[oops!]Note that for the pages that are swapped in through swap cache, this isn't an issue. Because the page is locked, and the swap entry will be marked with SWAP_HAS_CACHE, so swapoff() can not proceed until the page has been unlocked.
Fix this race by using get/put_swap_device() to guard against concurrent swapoff.
--- include/linux/swap.h | 9 +++++++++ mm/memory.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-)
include/linux/swap.h +9 -0
@@ -527,6 +527,15 @@ static inline struct swap_info_struct *swp_swap_info(swp_entry_t entry)return NULL ; } +static inline struct swap_info_struct *get_swap_device (swp_entry_t entry) +{ +return NULL ; +} + +static inline void put_swap_device (struct swap_info_struct *si) +{ +} +#define swap_address_space (entry) (NULL)#define get_nr_swap_pages () 0L#define total_swap_pages 0L
mm/memory.c +9 -2
@@ -3311,6 +3311,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;struct page *page =NULL , *swapcache; +struct swap_info_struct *si =NULL ;swp_entry_t entry;pte_t pte;int locked;
@@ -3338,14 +3339,16 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) goto out; } +/* Prevent swapoff from happening to us. */ + si =get_swap_device (entry); +if (unlikely (!si)) + goto out;delayacct_set_flag (current,DELAYACCT_PF_SWAPIN ); page =lookup_swap_cache (entry, vma, vmf->address); swapcache = page;if (!page) { -struct swap_info_struct *si =swp_swap_info (entry); -if (data_race (si->flags &SWP_SYNCHRONOUS_IO ) &&__swap_count (entry) ==1 ) {/* skip swapcache */
@@ -3514,6 +3517,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) unlock:pte_unmap_unlock (vmf->pte, vmf->ptl); out: +if (si) +put_swap_device (si);return ret; out_nomap:pte_unmap_unlock (vmf->pte, vmf->ptl);
@@ -3525,6 +3530,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)unlock_page (swapcache);put_page (swapcache); } +if (si) +put_swap_device (si);return ret; }
Signature · 1 line
2.19.1
Re: [PATCH v4 2/4] swap: fix do_swap_page() race with swapoff
Quoted 21 lines · Miaohe Lin
When I was investigating the swap code, I found the below possible race window:
CPU 1 CPU 2
----- -----do_swap_page
if (data_race(si->flags & SWP_SYNCHRONOUS_IO)
swap_readpageif (data_race(sis->flags & SWP_FS_OPS)) { swapoff .. p->swap_file = NULL; .. struct file *swap_file = sis->swap_file; struct address_space *mapping = swap_file->f_mapping;[oops!]Note that for the pages that are swapped in through swap cache, this isn't an issue. Because the page is locked, and the swap entry will be marked with
SWAP_HAS_CACHE, soswapoff()can not proceed until the page has been unlocked.
Quoted 6 lines
Fix this race by using get/put_swap_device() to guard against concurrent swapoff.
Fixes 0bcac06f27d7 ("mm,swap: skip swapcache for swapin of synchronous device")Signed-off-by Miaohe Lin <[email protected]>
Best Regards,
Huang, Ying
Quoted 73 lines
--- include/linux/swap.h | 9 +++++++++ mm/memory.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-)include/linux/swap.h +9
-0@@ -527,6 +527,15 @@ static inline struct swap_info_struct *swp_swap_info(swp_entry_t entry)return NULL ; } +static inline struct swap_info_struct *get_swap_device (swp_entry_t entry) +{ +return NULL ; +} + +static inline void put_swap_device (struct swap_info_struct *si) +{ +} +#define swap_address_space (entry) (NULL)#define get_nr_swap_pages () 0L#define total_swap_pages 0Lmm/memory.c +9
-2@@ -3311,6 +3311,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) {struct vm_area_struct *vma = vmf->vma;struct page *page =NULL , *swapcache; +struct swap_info_struct *si =NULL ;swp_entry_t entry;pte_t pte;int locked;@@ -3338,14 +3339,16 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) goto out; } +/* Prevent swapoff from happening to us. */ + si =get_swap_device (entry); +if (unlikely (!si)) + goto out;delayacct_set_flag (current,DELAYACCT_PF_SWAPIN ); page =lookup_swap_cache (entry, vma, vmf->address); swapcache = page;if (!page) { -struct swap_info_struct *si =swp_swap_info (entry); -if (data_race (si->flags &SWP_SYNCHRONOUS_IO ) &&__swap_count (entry) ==1 ) {/* skip swapcache */ @@ -3514,6 +3517,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) unlock:pte_unmap_unlock (vmf->pte, vmf->ptl); out: +if (si) +put_swap_device (si);return ret; out_nomap:pte_unmap_unlock (vmf->pte, vmf->ptl);@@ -3525,6 +3530,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf)unlock_page (swapcache);put_page (swapcache); } +if (si) +put_swap_device (si);return ret; }
PATCH v4 3/4 mm/swap: remove confusing checking for non_swap_entry() in swap_ra_info()
In reply to Miaohe LinThe non_swap_entry() was used for working with VMA based swap readahead via commit ec560175c0b6 ("mm, swap: VMA based swap readahead"). At that time, the non_swap_entry() checking is necessary because the function is called before checking that in do_swap_page(). Then it's moved to swap_ra_info() since commit eaf649ebc3ac ("mm: swap: clean up swap readahead"). After that, the non_swap_entry() checking is unnecessary, because swap_ra_info() is called after non_swap_entry() has been checked already. The resulting code is confusing as the non_swap_entry() check looks racy now because while we released the pte lock, somebody else might have faulted in this pte. So we should check whether it's swap pte first to guard against such race or swap_type will be unexpected. But the race isn't important because it will not cause problem. We would have enough checking when we really operate the PTE entries later. So we remove the non_swap_entry() check here to avoid confusion.
--- mm/swap_state.c | 6 ------ 1 file changed, 6 deletions(-)
mm/swap_state.c +0 -6
@@ -721,7 +721,6 @@ static void swap_ra_info(struct vm_fault *vmf, {struct vm_area_struct *vma = vmf->vma;unsigned long ra_val; -swp_entry_t entry;unsigned long faddr, pfn, fpfn;unsigned long start, end;pte_t *pte, *orig_pte;
@@ -739,11 +738,6 @@ static void swap_ra_info(struct vm_fault *vmf, faddr = vmf->address; orig_pte = pte =pte_offset_map (vmf->pmd, faddr); - entry =pte_to_swp_entry (*pte); -if ((unlikely (non_swap_entry (entry)))) { -pte_unmap (orig_pte); -return ; - } fpfn =PFN_DOWN (faddr); ra_val =GET_SWAP_RA_VAL (vma);
Signature · 1 line
2.19.1
Re: [PATCH v4 3/4] mm/swap: remove confusing checking for non_swap_entry() in swap_ra_info()
Quoted 15 lines · Miaohe Lin
The
non_swap_entry()was used for working with VMA based swap readahead via commitec560175c0b6("mm, swap: VMA based swap readahead"). At that time, thenon_swap_entry()checking is necessary because the function is called before checking that indo_swap_page(). Then it's moved toswap_ra_info()since commiteaf649ebc3ac("mm: swap: clean up swap readahead"). After that, thenon_swap_entry()checking is unnecessary, becauseswap_ra_info()is called afternon_swap_entry()has been checked already. The resulting code is confusing as thenon_swap_entry()check looks racy now because while we released the pte lock, somebody else might have faulted in this pte. So we should check whether it's swap pte first to guard against such race orswap_typewill be unexpected. But the race isn't important because it will not cause problem. We would have enough checking when we really operate the PTE entries later. So we remove thenon_swap_entry()check here to avoid confusion.
Quoted 1 line
Signed-off-by Miaohe Lin <[email protected]>
Best Regards,
Huang, Ying
Quoted 28 lines
--- mm/swap_state.c | 6 ------ 1 file changed, 6 deletions(-)mm/swap_state.c +0
-6@@ -721,7 +721,6 @@ static void swap_ra_info(struct vm_fault *vmf, {struct vm_area_struct *vma = vmf->vma;unsigned long ra_val; -swp_entry_t entry;unsigned long faddr, pfn, fpfn;unsigned long start, end;pte_t *pte, *orig_pte;@@ -739,11 +738,6 @@ static void swap_ra_info(struct vm_fault *vmf, faddr = vmf->address; orig_pte = pte =pte_offset_map (vmf->pmd, faddr); - entry =pte_to_swp_entry (*pte); -if ((unlikely (non_swap_entry (entry)))) { -pte_unmap (orig_pte); -return ; - } fpfn =PFN_DOWN (faddr); ra_val =GET_SWAP_RA_VAL (vma);
PATCH v4 4/4 mm/shmem: fix shmem_swapin() race with swapoff
In reply to Miaohe LinWhen I was investigating the swap code, I found the below possible race window:
CPU 1 CPU 2
----- -----shmem_swapin
swap_cluster_readahead
if (likely(si->flags & (SWP_BLKDEV | SWP_FS_OPS))) {
swapoff
..
si->swap_file = NULL;
..
struct inode *inode = si->swap_file->f_mapping->host;[oops!]Close this race window by using get/put_swap_device() to guard against concurrent swapoff.
--- mm/shmem.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
mm/shmem.c +11 -0
@@ -1696,6 +1696,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,struct address_space *mapping = inode->i_mapping;struct shmem_inode_info *info =SHMEM_I (inode);struct mm_struct *charge_mm = vma ? vma->vm_mm : current->mm; +struct swap_info_struct *si;struct page *page;swp_entry_t swap;int error;
@@ -1704,6 +1705,12 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index, swap =radix_to_swp_entry (*pagep); *pagep =NULL ; +/* Prevent swapoff from happening to us. */ + si =get_swap_device (swap); +if (unlikely (!si)) { + error =EINVAL ; + goto failed; + }/* Look it up and read it in.. */ page =lookup_swap_cache (swap,NULL ,0 );if (!page) {
@@ -1720,6 +1727,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index, goto failed; } } +put_swap_device (si);/* We have to do this with page locked to prevent races */ lock_page (page);
@@ -1775,6 +1783,9 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,put_page (page); } +if (si) +put_swap_device (si); +return error; }
Signature · 1 line
2.19.1
Re: [PATCH v4 4/4] mm/shmem: fix shmem_swapin() race with swapoff
Quoted 49 lines · Miaohe Lin
When I was investigating the swap code, I found the below possible race window:
CPU 1 CPU 2
----- -----shmem_swapin
swap_cluster_readaheadif (likely(si->flags & (SWP_BLKDEV | SWP_FS_OPS))) { swapoff .. si->swap_file = NULL; .. struct inode *inode = si->swap_file->f_mapping->host;[oops!]Close this race window by using get/put_swap_device() to guard against concurrent swapoff.
Fixes 8fd2e0b505d1 ("mm: swap: check if swap backing device is congested or not")Signed-off-by Miaohe Lin <[email protected]>--- mm/shmem.c | 11 +++++++++++ 1 file changed, 11 insertions(+)mm/shmem.c +7
-0@@ -1696,6 +1696,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,struct address_space *mapping = inode->i_mapping;struct shmem_inode_info *info =SHMEM_I (inode);struct mm_struct *charge_mm = vma ? vma->vm_mm : current->mm; +struct swap_info_struct *si;struct page *page;swp_entry_t swap;int error;@@ -1704,6 +1705,12 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index, swap =radix_to_swp_entry (*pagep); *pagep =NULL ; +/* Prevent swapoff from happening to us. */ + si =get_swap_device (swap); +if (unlikely (!si)) { + error =EINVAL ; + goto failed; + }/* Look it up and read it in.. */ page =lookup_swap_cache (swap,NULL ,0 );if (!page) {
mm/shmem.c static int shmem_swapin_page(struct inode *inode, pgoff_t index, · line 1730
Quoted 4 lines
mm/shmem.c +1
-0@@ -1720,6 +1727,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index, goto failed; } } +put_swap_device (si);
I think it's better to put_swap_device() just before returning from the function. It's not a big issue to slow down swapoff() a little. And this will make the logic easier to be understood.
Best Regards,
Huang, Ying
Quoted 12 lines
mm/shmem.c +3
-0/* We have to do this with page locked to prevent races */ lock_page (page);@@ -1775,6 +1783,9 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,put_page (page); } +if (si) +put_swap_device (si); +return error; }
Re: [PATCH v4 4/4] mm/shmem: fix shmem_swapin() race with swapoff
Quoted 51 lines · Ying
Quoted 49 lines · Miaohe Lin
When I was investigating the swap code, I found the below possible race window:
CPU 1 CPU 2
----- -----shmem_swapin
swap_cluster_readaheadif (likely(si->flags & (SWP_BLKDEV | SWP_FS_OPS))) { swapoff .. si->swap_file = NULL; .. struct inode *inode = si->swap_file->f_mapping->host;[oops!]Close this race window by using get/put_swap_device() to guard against concurrent swapoff.
Fixes 8fd2e0b505d1 ("mm: swap: check if swap backing device is congested or not")Signed-off-by Miaohe Lin <[email protected]>--- mm/shmem.c | 11 +++++++++++ 1 file changed, 11 insertions(+)mm/shmem.c +7
-0@@ -1696,6 +1696,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,struct address_space *mapping = inode->i_mapping;struct shmem_inode_info *info =SHMEM_I (inode);struct mm_struct *charge_mm = vma ? vma->vm_mm : current->mm; +struct swap_info_struct *si;struct page *page;swp_entry_t swap;int error;@@ -1704,6 +1705,12 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index, swap =radix_to_swp_entry (*pagep); *pagep =NULL ; +/* Prevent swapoff from happening to us. */ + si =get_swap_device (swap); +if (unlikely (!si)) { + error =EINVAL ; + goto failed; + }/* Look it up and read it in.. */ page =lookup_swap_cache (swap,NULL ,0 );if (!page) {@@ -1720,6 +1727,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,
Quoted 9 lines
mm/shmem.c static int shmem_swapin_page(struct inode *inode, pgoff_t index, · line 1730
Quoted 4 lines
mm/shmem.c +1
-0goto failed; } } +put_swap_device (si);I think it's better to
put_swap_device()just before returning from the function. It's not a big issue to slow downswapoff()a little. And this will make the logic easier to be understood.
shmem_swapin_page() already has a methed, i.e. locked page, to prevent races. I was intended to not mix with that. But your suggestion is good as this will make the logic easier to be understood.
Just to make sure, is this what you mean? Many thanks!
mm/shmem.c +12 -0
@@ -1696,6 +1696,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,struct address_space *mapping = inode->i_mapping;struct shmem_inode_info *info =SHMEM_I (inode);struct mm_struct *charge_mm = vma ? vma->vm_mm : current->mm; +struct swap_info_struct *si;struct page *page;swp_entry_t swap;int error;
@@ -1704,6 +1705,12 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index, swap =radix_to_swp_entry (*pagep); *pagep =NULL ; +/* Prevent swapoff from happening to us. */ + si =get_swap_device (swap); +if (unlikely (!si)) { + error =EINVAL ; + goto failed; + }/* Look it up and read it in.. */ page =lookup_swap_cache (swap,NULL ,0 );if (!page) {
@@ -1765,6 +1772,8 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,swap_free (swap); *pagep = page; +if (si) +put_swap_device (si);return 0 ; failed:if (!shmem_confirm_swap (mapping, index, swap))
@@ -1775,6 +1784,9 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,put_page (page); } +if (si) +put_swap_device (si); +return error; }
Quoted 17 lines
Best Regards,
Huang, Yingmm/shmem.c static int shmem_swapin_page(struct inode *inode, pgoff_t index, · line 1790
Quoted 12 lines
mm/shmem.c +3
-0/* We have to do this with page locked to prevent races */ lock_page (page);@@ -1775,6 +1783,9 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,put_page (page); } +if (si) +put_swap_device (si); +return error; }.
Re: [PATCH v4 4/4] mm/shmem: fix shmem_swapin() race with swapoff
Quoted 11 lines · Miaohe Lin
Quoted 4 lines · Ying
I think it's better to
put_swap_device()just before returning from the function. It's not a big issue to slow downswapoff()a little. And this will make the logic easier to be understood.
shmem_swapin_page()already has a methed, i.e. locked page, to prevent races. I was intended to not mix with that. But your suggestion is good as this will make the logic easier to be understood.Just to make sure, is this what you mean? Many thanks!
Yes. Just a minor comment.
Quoted 14 lines
mm/shmem.c +1
-0@@ -1696,6 +1696,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,struct address_space *mapping = inode->i_mapping;struct shmem_inode_info *info =SHMEM_I (inode);struct mm_struct *charge_mm = vma ? vma->vm_mm : current->mm; +struct swap_info_struct *si;struct page *page;swp_entry_t swap;int error;
mm/shmem.c static int shmem_swapin_page(struct inode *inode, pgoff_t index, · line 1710
Quoted 6 lines
mm/shmem.c +3
-0@@ -1704,6 +1705,12 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index, swap =radix_to_swp_entry (*pagep); *pagep =NULL ; +/* Prevent swapoff from happening to us. */ + si =get_swap_device (swap); +if (unlikely (!si)) {
I don't think it's necessary to use unlikely() here.
Best Regards,
Huang, Ying
Quoted 28 lines
mm/shmem.c +8
-0+ error =EINVAL ; + goto failed; + }/* Look it up and read it in.. */ page =lookup_swap_cache (swap,NULL ,0 );if (!page) {@@ -1765,6 +1772,8 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,swap_free (swap); *pagep = page; +if (si) +put_swap_device (si);return 0 ; failed:if (!shmem_confirm_swap (mapping, index, swap))@@ -1775,6 +1784,9 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,put_page (page); } +if (si) +put_swap_device (si); +return error; }Quoted 3 lines
Best Regards,
Huang, Ying
Re: [PATCH v4 4/4] mm/shmem: fix shmem_swapin() race with swapoff
Quoted 33 lines · Ying
Quoted 11 lines · Miaohe Lin
Quoted 4 lines · Ying
I think it's better to
put_swap_device()just before returning from the function. It's not a big issue to slow downswapoff()a little. And this will make the logic easier to be understood.
shmem_swapin_page()already has a methed, i.e. locked page, to prevent races. I was intended to not mix with that. But your suggestion is good as this will make the logic easier to be understood.Just to make sure, is this what you mean? Many thanks!
Yes. Just a minor comment.
Quoted 17 lines
mm/shmem.c +1
-0@@ -1696,6 +1696,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,struct address_space *mapping = inode->i_mapping;struct shmem_inode_info *info =SHMEM_I (inode);struct mm_struct *charge_mm = vma ? vma->vm_mm : current->mm; +struct swap_info_struct *si;struct page *page;swp_entry_t swap;int error;@@ -1704,6 +1705,12 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index, swap =radix_to_swp_entry (*pagep); *pagep =NULL ;
Quoted 6 lines
mm/shmem.c static int shmem_swapin_page(struct inode *inode, pgoff_t index, · line 1710
Quoted 3 lines
mm/shmem.c +3
-0+/* Prevent swapoff from happening to us. */ + si =get_swap_device (swap); +if (unlikely (!si)) {I don't think it's necessary to use
unlikely()here.
Will do in next version. Thanks!
Quoted 33 lines
Best Regards,
Huang, YingQuoted 25 lines
mm/shmem.c +8
-0+ error =EINVAL ; + goto failed; + }/* Look it up and read it in.. */ page =lookup_swap_cache (swap,NULL ,0 );if (!page) {@@ -1765,6 +1772,8 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,swap_free (swap); *pagep = page; +if (si) +put_swap_device (si);return 0 ; failed:if (!shmem_confirm_swap (mapping, index, swap))@@ -1775,6 +1784,9 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index,put_page (page); } +if (si) +put_swap_device (si); +return error; }Quoted 3 lines
Quoted 3 lines
Best Regards,
Huang, Ying.