From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAC56C433FE for ; Fri, 24 Dec 2021 06:23:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86C8E6B0088; Fri, 24 Dec 2021 01:23:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 81C716B0089; Fri, 24 Dec 2021 01:23:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E3D46B008A; Fri, 24 Dec 2021 01:23:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 5E7206B0088 for ; Fri, 24 Dec 2021 01:23:25 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1E25489D43 for ; Fri, 24 Dec 2021 06:23:25 +0000 (UTC) X-FDA: 78951695970.22.B4553B2 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf21.hostedemail.com (Postfix) with ESMTP id 3BE741C002C for ; Fri, 24 Dec 2021 06:23:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=2Qvg19ABRkEjG0icMTYZaPgGjGzCwiBx2r+pyLRWArs=; b=RE3UuaMOoXmjn1Vj/qXob7dnIj TKc3DeNAc9zKLHrCfPETn74UHPebqcWlBkjSQ+RRfShp4Gs4+sX/lri2KGt7kvYIzFCVWxY9TqD5n WL7p7bXVBp4b0gs5rBiOSRINHSS1P5SYFHmXsSZ5QEpZ/YK9CAEj+UKdv2OLrob+fbPY8ofcivC08 6thSjG40RCilPFr6ih6bPqlYNhwG9qAWJsPicVEoJ1sR4lt5HcNXO7dXME23pH2S5f8BslawLZno8 Xae8AlSSpXaGFMgbotqOfAX4xpeK1UeI7ZVHF6HQTL4IB5MHzU+nPb8AVQdBMLPF79//4hMGfsseV HVS1grmA==; Received: from p4fdb0b85.dip0.t-ipconnect.de ([79.219.11.133] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1n0dyy-00Dn58-LE; Fri, 24 Dec 2021 06:23:13 +0000 From: Christoph Hellwig To: Andrew Morton , Konrad Rzeszutek Wilk Cc: Hugh Dickins , Seth Jennings , Dan Streetman , Vitaly Wool , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 08/13] mm: simplify try_to_unuse Date: Fri, 24 Dec 2021 07:22:41 +0100 Message-Id: <20211224062246.1258487-9-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211224062246.1258487-1-hch@lst.de> References: <20211224062246.1258487-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3BE741C002C X-Stat-Signature: ne6xpu8rumgcm3udrmyux4pbsjrmhnyb Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=RE3UuaMO; spf=none (imf21.hostedemail.com: domain of BATV+afcec93cc8ffef6ccdbc+6697+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+afcec93cc8ffef6ccdbc+6697+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none X-HE-Tag: 1640327000-345215 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Remove the unused frontswap and pages_to_unuse arguments, and mark the function static now that the caller in frontswap is gone. Signed-off-by: Christoph Hellwig --- include/linux/frontswap.h | 7 ---- include/linux/shmem_fs.h | 3 +- include/linux/swapfile.h | 1 - mm/shmem.c | 33 +++------------- mm/swapfile.c | 83 +++++++++++---------------------------- 5 files changed, 30 insertions(+), 97 deletions(-) diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h index 73d7beb44f2b7..a9817d4fa74c1 100644 --- a/include/linux/frontswap.h +++ b/include/linux/frontswap.h @@ -7,13 +7,6 @@ #include #include =20 -/* - * Return code to denote that requested number of - * frontswap pages are unused(moved to page cache). - * Used in shmem_unuse and try_to_unuse. - */ -#define FRONTSWAP_PAGES_UNUSED 2 - struct frontswap_ops { void (*init)(unsigned); /* this swap type was just swapon'ed */ int (*store)(unsigned, pgoff_t, struct page *); /* store a page */ diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 166158b6e917a..e65b80ed09e77 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -83,8 +83,7 @@ extern void shmem_unlock_mapping(struct address_space *= mapping); extern struct page *shmem_read_mapping_page_gfp(struct address_space *ma= pping, pgoff_t index, gfp_t gfp_mask); extern void shmem_truncate_range(struct inode *inode, loff_t start, loff= _t end); -extern int shmem_unuse(unsigned int type, bool frontswap, - unsigned long *fs_pages_to_unuse); +int shmem_unuse(unsigned int type); =20 extern bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode, pgoff_t index); diff --git a/include/linux/swapfile.h b/include/linux/swapfile.h index e06febf629788..809cd01ef2c57 100644 --- a/include/linux/swapfile.h +++ b/include/linux/swapfile.h @@ -9,7 +9,6 @@ extern spinlock_t swap_lock; extern struct plist_head swap_active_head; extern struct swap_info_struct *swap_info[]; -extern int try_to_unuse(unsigned int, bool, unsigned long); extern unsigned long generic_max_swapfile_size(void); extern unsigned long max_swapfile_size(void); =20 diff --git a/mm/shmem.c b/mm/shmem.c index eb0fd90011308..421b2459929a2 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include =20 @@ -1146,7 +1145,7 @@ static void shmem_evict_inode(struct inode *inode) static int shmem_find_swap_entries(struct address_space *mapping, pgoff_t start, unsigned int nr_entries, struct page **entries, pgoff_t *indices, - unsigned int type, bool frontswap) + unsigned int type) { XA_STATE(xas, &mapping->i_pages, start); struct page *page; @@ -1167,9 +1166,6 @@ static int shmem_find_swap_entries(struct address_s= pace *mapping, entry =3D radix_to_swp_entry(page); if (swp_type(entry) !=3D type) continue; - if (frontswap && - !frontswap_test(swap_info[type], swp_offset(entry))) - continue; =20 indices[ret] =3D xas.xa_index; entries[ret] =3D page; @@ -1222,26 +1218,20 @@ static int shmem_unuse_swap_entries(struct inode = *inode, struct pagevec pvec, /* * If swap found in inode, free it and move page from swapcache to filec= ache. */ -static int shmem_unuse_inode(struct inode *inode, unsigned int type, - bool frontswap, unsigned long *fs_pages_to_unuse) +static int shmem_unuse_inode(struct inode *inode, unsigned int type) { struct address_space *mapping =3D inode->i_mapping; pgoff_t start =3D 0; struct pagevec pvec; pgoff_t indices[PAGEVEC_SIZE]; - bool frontswap_partial =3D (frontswap && *fs_pages_to_unuse > 0); int ret =3D 0; =20 pagevec_init(&pvec); do { unsigned int nr_entries =3D PAGEVEC_SIZE; =20 - if (frontswap_partial && *fs_pages_to_unuse < PAGEVEC_SIZE) - nr_entries =3D *fs_pages_to_unuse; - pvec.nr =3D shmem_find_swap_entries(mapping, start, nr_entries, - pvec.pages, indices, - type, frontswap); + pvec.pages, indices, type); if (pvec.nr =3D=3D 0) { ret =3D 0; break; @@ -1251,14 +1241,6 @@ static int shmem_unuse_inode(struct inode *inode, = unsigned int type, if (ret < 0) break; =20 - if (frontswap_partial) { - *fs_pages_to_unuse -=3D ret; - if (*fs_pages_to_unuse =3D=3D 0) { - ret =3D FRONTSWAP_PAGES_UNUSED; - break; - } - } - start =3D indices[pvec.nr - 1]; } while (true); =20 @@ -1270,8 +1252,7 @@ static int shmem_unuse_inode(struct inode *inode, u= nsigned int type, * device 'type' back into memory, so the swap device can be * unused. */ -int shmem_unuse(unsigned int type, bool frontswap, - unsigned long *fs_pages_to_unuse) +int shmem_unuse(unsigned int type) { struct shmem_inode_info *info, *next; int error =3D 0; @@ -1294,8 +1275,7 @@ int shmem_unuse(unsigned int type, bool frontswap, atomic_inc(&info->stop_eviction); mutex_unlock(&shmem_swaplist_mutex); =20 - error =3D shmem_unuse_inode(&info->vfs_inode, type, frontswap, - fs_pages_to_unuse); + error =3D shmem_unuse_inode(&info->vfs_inode, type); cond_resched(); =20 mutex_lock(&shmem_swaplist_mutex); @@ -4009,8 +3989,7 @@ int __init shmem_init(void) return 0; } =20 -int shmem_unuse(unsigned int type, bool frontswap, - unsigned long *fs_pages_to_unuse) +int shmem_unuse(unsigned int type, unsigned long *fs_pages_to_unuse) { return 0; } diff --git a/mm/swapfile.c b/mm/swapfile.c index df5930ccd93dd..82342c77791bb 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1923,8 +1923,7 @@ static int unuse_pte(struct vm_area_struct *vma, pm= d_t *pmd, =20 static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, unsigned long addr, unsigned long end, - unsigned int type, bool frontswap, - unsigned long *fs_pages_to_unuse) + unsigned int type) { struct page *page; swp_entry_t entry; @@ -1945,9 +1944,6 @@ static int unuse_pte_range(struct vm_area_struct *v= ma, pmd_t *pmd, continue; =20 offset =3D swp_offset(entry); - if (frontswap && !frontswap_test(si, offset)) - continue; - pte_unmap(pte); swap_map =3D &si->swap_map[offset]; page =3D lookup_swap_cache(entry, vma, addr); @@ -1979,11 +1975,6 @@ static int unuse_pte_range(struct vm_area_struct *= vma, pmd_t *pmd, try_to_free_swap(page); unlock_page(page); put_page(page); - - if (*fs_pages_to_unuse && !--(*fs_pages_to_unuse)) { - ret =3D FRONTSWAP_PAGES_UNUSED; - goto out; - } try_next: pte =3D pte_offset_map(pmd, addr); } while (pte++, addr +=3D PAGE_SIZE, addr !=3D end); @@ -1996,8 +1987,7 @@ static int unuse_pte_range(struct vm_area_struct *v= ma, pmd_t *pmd, =20 static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud= , unsigned long addr, unsigned long end, - unsigned int type, bool frontswap, - unsigned long *fs_pages_to_unuse) + unsigned int type) { pmd_t *pmd; unsigned long next; @@ -2009,8 +1999,7 @@ static inline int unuse_pmd_range(struct vm_area_st= ruct *vma, pud_t *pud, next =3D pmd_addr_end(addr, end); if (pmd_none_or_trans_huge_or_clear_bad(pmd)) continue; - ret =3D unuse_pte_range(vma, pmd, addr, next, type, - frontswap, fs_pages_to_unuse); + ret =3D unuse_pte_range(vma, pmd, addr, next, type); if (ret) return ret; } while (pmd++, addr =3D next, addr !=3D end); @@ -2019,8 +2008,7 @@ static inline int unuse_pmd_range(struct vm_area_st= ruct *vma, pud_t *pud, =20 static inline int unuse_pud_range(struct vm_area_struct *vma, p4d_t *p4d= , unsigned long addr, unsigned long end, - unsigned int type, bool frontswap, - unsigned long *fs_pages_to_unuse) + unsigned int type) { pud_t *pud; unsigned long next; @@ -2031,8 +2019,7 @@ static inline int unuse_pud_range(struct vm_area_st= ruct *vma, p4d_t *p4d, next =3D pud_addr_end(addr, end); if (pud_none_or_clear_bad(pud)) continue; - ret =3D unuse_pmd_range(vma, pud, addr, next, type, - frontswap, fs_pages_to_unuse); + ret =3D unuse_pmd_range(vma, pud, addr, next, type); if (ret) return ret; } while (pud++, addr =3D next, addr !=3D end); @@ -2041,8 +2028,7 @@ static inline int unuse_pud_range(struct vm_area_st= ruct *vma, p4d_t *p4d, =20 static inline int unuse_p4d_range(struct vm_area_struct *vma, pgd_t *pgd= , unsigned long addr, unsigned long end, - unsigned int type, bool frontswap, - unsigned long *fs_pages_to_unuse) + unsigned int type) { p4d_t *p4d; unsigned long next; @@ -2053,16 +2039,14 @@ static inline int unuse_p4d_range(struct vm_area_= struct *vma, pgd_t *pgd, next =3D p4d_addr_end(addr, end); if (p4d_none_or_clear_bad(p4d)) continue; - ret =3D unuse_pud_range(vma, p4d, addr, next, type, - frontswap, fs_pages_to_unuse); + ret =3D unuse_pud_range(vma, p4d, addr, next, type); if (ret) return ret; } while (p4d++, addr =3D next, addr !=3D end); return 0; } =20 -static int unuse_vma(struct vm_area_struct *vma, unsigned int type, - bool frontswap, unsigned long *fs_pages_to_unuse) +static int unuse_vma(struct vm_area_struct *vma, unsigned int type) { pgd_t *pgd; unsigned long addr, end, next; @@ -2076,16 +2060,14 @@ static int unuse_vma(struct vm_area_struct *vma, = unsigned int type, next =3D pgd_addr_end(addr, end); if (pgd_none_or_clear_bad(pgd)) continue; - ret =3D unuse_p4d_range(vma, pgd, addr, next, type, - frontswap, fs_pages_to_unuse); + ret =3D unuse_p4d_range(vma, pgd, addr, next, type); if (ret) return ret; } while (pgd++, addr =3D next, addr !=3D end); return 0; } =20 -static int unuse_mm(struct mm_struct *mm, unsigned int type, - bool frontswap, unsigned long *fs_pages_to_unuse) +static int unuse_mm(struct mm_struct *mm, unsigned int type) { struct vm_area_struct *vma; int ret =3D 0; @@ -2093,8 +2075,7 @@ static int unuse_mm(struct mm_struct *mm, unsigned = int type, mmap_read_lock(mm); for (vma =3D mm->mmap; vma; vma =3D vma->vm_next) { if (vma->anon_vma) { - ret =3D unuse_vma(vma, type, frontswap, - fs_pages_to_unuse); + ret =3D unuse_vma(vma, type); if (ret) break; } @@ -2110,7 +2091,7 @@ static int unuse_mm(struct mm_struct *mm, unsigned = int type, * if there are no inuse entries after prev till end of the map. */ static unsigned int find_next_to_unuse(struct swap_info_struct *si, - unsigned int prev, bool frontswap) + unsigned int prev) { unsigned int i; unsigned char count; @@ -2124,8 +2105,7 @@ static unsigned int find_next_to_unuse(struct swap_= info_struct *si, for (i =3D prev + 1; i < si->max; i++) { count =3D READ_ONCE(si->swap_map[i]); if (count && swap_count(count) !=3D SWAP_MAP_BAD) - if (!frontswap || frontswap_test(si, i)) - break; + break; if ((i % LATENCY_LIMIT) =3D=3D 0) cond_resched(); } @@ -2136,12 +2116,7 @@ static unsigned int find_next_to_unuse(struct swap= _info_struct *si, return i; } =20 -/* - * If the boolean frontswap is true, only unuse pages_to_unuse pages; - * pages_to_unuse=3D=3D0 means all pages; ignored if frontswap is false - */ -int try_to_unuse(unsigned int type, bool frontswap, - unsigned long pages_to_unuse) +static int try_to_unuse(unsigned int type) { struct mm_struct *prev_mm; struct mm_struct *mm; @@ -2155,13 +2130,10 @@ int try_to_unuse(unsigned int type, bool frontswa= p, if (!READ_ONCE(si->inuse_pages)) return 0; =20 - if (!frontswap) - pages_to_unuse =3D 0; - retry: - retval =3D shmem_unuse(type, frontswap, &pages_to_unuse); + retval =3D shmem_unuse(type); if (retval) - goto out; + return retval; =20 prev_mm =3D &init_mm; mmget(prev_mm); @@ -2178,11 +2150,10 @@ int try_to_unuse(unsigned int type, bool frontswa= p, spin_unlock(&mmlist_lock); mmput(prev_mm); prev_mm =3D mm; - retval =3D unuse_mm(mm, type, frontswap, &pages_to_unuse); - + retval =3D unuse_mm(mm, type); if (retval) { mmput(prev_mm); - goto out; + return retval; } =20 /* @@ -2199,7 +2170,7 @@ int try_to_unuse(unsigned int type, bool frontswap, i =3D 0; while (READ_ONCE(si->inuse_pages) && !signal_pending(current) && - (i =3D find_next_to_unuse(si, i, frontswap)) !=3D 0) { + (i =3D find_next_to_unuse(si, i)) !=3D 0) { =20 entry =3D swp_entry(type, i); page =3D find_get_page(swap_address_space(entry), i); @@ -2217,14 +2188,6 @@ int try_to_unuse(unsigned int type, bool frontswap= , try_to_free_swap(page); unlock_page(page); put_page(page); - - /* - * For frontswap, we just need to unuse pages_to_unuse, if - * it was specified. Need not check frontswap again here as - * we already zeroed out pages_to_unuse if not frontswap. - */ - if (pages_to_unuse && --pages_to_unuse =3D=3D 0) - goto out; } =20 /* @@ -2242,10 +2205,10 @@ int try_to_unuse(unsigned int type, bool frontswa= p, if (READ_ONCE(si->inuse_pages)) { if (!signal_pending(current)) goto retry; - retval =3D -EINTR; + return -EINTR; } -out: - return (retval =3D=3D FRONTSWAP_PAGES_UNUSED) ? 0 : retval; + + return 0; } =20 /* @@ -2577,7 +2540,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, speci= alfile) disable_swap_slots_cache_lock(); =20 set_current_oom_origin(); - err =3D try_to_unuse(p->type, false, 0); /* force unuse all pages */ + err =3D try_to_unuse(p->type); clear_current_oom_origin(); =20 if (err) { --=20 2.30.2