Some trivial cleanups for shmem
Subsystems (2)
Baolin Wang
reviewercover Some trivial cleanups for shmem
Hi,
Patch 1 - Patch 5 do some trivial cleanups and refactoring for shmem. Patch 6 adds myself as shmem reviewer.
Baolin Wang (6):
mm: shmem: drop the unused macro
mm: shmem: remove 'fadvise()' comments
mm: shmem: remove duplicate error validation
mm: shmem: change the return value of shmem_find_swap_entries()
mm: shmem: factor out the within_size logic into a new helper
MAINTAINERS: add myself as shmem reviewer
MAINTAINERS | 1 + mm/shmem.c | 76 ++++++++++++++++++++++++++--------------------------- 2 files changed, 39 insertions(+), 38 deletions(-)
Signature · 1 line
2.39.3
Baolin Wang
reviewerPATCH 1/6 mm: shmem: drop the unused macro
Drop the unused 'BLOCKS_PER_PAGE' macro.
--- mm/shmem.c | 1 - 1 file changed, 1 deletion(-)
mm/shmem.c +0 -1
@@ -86,7 +86,6 @@ static struct vfsmount *shm_mnt __ro_after_init;#include "internal.h" -#define BLOCKS_PER_PAGE (PAGE_SIZE/512)#define VM_ACCT (size) (PAGE_ALIGN(size) >> PAGE_SHIFT)/* Pretend that each entry is of this size in directory's i_size */
Signature · 1 line
2.39.3
Baolin Wang
reviewerPATCH 2/6 mm: shmem: remove 'fadvise()' comments
In reply to Baolin WangSimilar to commit 255ff62d1586 ("docs: tmpfs: drop 'fadvise()' from the documentation"), fadvise() has no HUGEPAGE advise currently. Remove the confusing fadvise() comments.
--- mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/shmem.c +2 -2
@@ -525,9 +525,9 @@ static bool shmem_confirm_swap(struct address_space *mapping,* enables huge pages for the mount; * SHMEM_HUGE_WITHIN_SIZE: * only allocate huge pages if the page will be fully within i_size, -* also respect fadvise()/madvise() hints; +* also respect madvise() hints; * SHMEM_HUGE_ADVISE: -* only allocate huge pages if requested with fadvise()/madvise(); +* only allocate huge pages if requested with madvise(); */ #define SHMEM_HUGE_NEVER 0
Signature · 1 line
2.39.3
Baolin Wang
reviewerPATCH 3/6 mm: shmem: remove duplicate error validation
In reply to Baolin WangRemove duplicate error code checks for 'start' and 'end', as the get_order_from_str() will only return -EINVAL if the cmdline string is configured incorrectly.
--- mm/shmem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/shmem.c +3 -3
@@ -5650,19 +5650,19 @@ static int __init setup_thp_shmem(char *str) THP_ORDERS_ALL_FILE_DEFAULT); } -if (start == -EINVAL ) { +if (start <0 ) {pr_err ("invalid size %s in thp_shmem boot parameter\n" , start_size); goto err; } -if (end == -EINVAL ) { +if (end <0 ) {pr_err ("invalid size %s in thp_shmem boot parameter\n" , end_size); goto err; } -if (start <0 || end <0 || start > end) +if (start > end) goto err; nr = end - start +1 ;
Signature · 1 line
2.39.3
Baolin Wang
reviewerPATCH 4/6 mm: shmem: change the return value of shmem_find_swap_entries()
In reply to Baolin WangThe shmem_find_swap_entries() originally returned the index corresponding to the swap entry, but no callers used this return value. It should return the number of entries that were found like other functions, which can be used by the callers.
No functional changes.
--- mm/shmem.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
mm/shmem.c +6 -6
@@ -1379,9 +1379,9 @@ static void shmem_evict_inode(struct inode *inode)#endif } -static int shmem_find_swap_entries (struct address_space *mapping, -pgoff_t start,struct folio_batch *fbatch, -pgoff_t *indices,unsigned int type) +static unsigned int shmem_find_swap_entries (struct address_space *mapping, +pgoff_t start,struct folio_batch *fbatch, +pgoff_t *indices,unsigned int type) {XA_STATE (xas, &mapping->i_pages, start);struct folio *folio;
@@ -1414,7 +1414,7 @@ static int shmem_find_swap_entries(struct address_space *mapping, }rcu_read_unlock (); -return xas.xa_index; +return folio_batch_count (fbatch); }/*
@@ -1461,8 +1461,8 @@ static int shmem_unuse_inode(struct inode *inode, unsigned int type) do { folio_batch_init(&fbatch); - shmem_find_swap_entries(mapping, start, &fbatch, indices, type); - if (folio_batch_count(&fbatch) == 0) { + if (!shmem_find_swap_entries(mapping, start, &fbatch, + indices, type)) { ret = 0; break; }
Signature · 1 line
2.39.3
Baolin Wang
reviewerPATCH 5/6 mm: shmem: factor out the within_size logic into a new helper
In reply to Baolin WangFactor out the within_size logic into a new helper to remove duplicate code.
--- mm/shmem.c | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-)
mm/shmem.c +27 -26
@@ -590,6 +590,28 @@ shmem_mapping_size_orders(struct address_space *mapping, pgoff_t index, loff_t wreturn order >0 ?BIT (order +1 ) -1 :0 ; } +static unsigned int shmem_get_orders_within_size (struct inode *inode, +unsigned long within_size_orders,pgoff_t index, +loff_t write_end) +{ +pgoff_t aligned_index; +unsigned long order; +loff_t i_size; + + order =highest_order (within_size_orders); +while (within_size_orders) { + aligned_index =round_up (index +1 ,1 << order); + i_size =max (write_end,i_size_read (inode)); + i_size =round_up (i_size,PAGE_SIZE ); +if (i_size >>PAGE_SHIFT >= aligned_index) +return within_size_orders; + + order =next_order (&within_size_orders, order); + } + +return 0 ; +} + static unsigned int shmem_huge_global_enabled(struct inode *inode, pgoff_t index, loff_t write_end, bool shmem_huge_force, struct vm_area_struct *vma,
@@ -598,9 +620,6 @@ static unsigned int shmem_huge_global_enabled(struct inode *inode, pgoff_t indexunsigned int maybe_pmd_order =HPAGE_PMD_ORDER >MAX_PAGECACHE_ORDER ?0 :BIT (HPAGE_PMD_ORDER );unsigned long within_size_orders; -unsigned int order; -pgoff_t aligned_index; -loff_t i_size;if (!S_ISREG (inode->i_mode))return 0 ;
@@ -634,16 +653,11 @@ static unsigned int shmem_huge_global_enabled(struct inode *inode, pgoff_t index within_size_orders =shmem_mapping_size_orders (inode->i_mapping, index, write_end); - order =highest_order (within_size_orders); -while (within_size_orders) { - aligned_index =round_up (index +1 ,1 << order); - i_size =max (write_end,i_size_read (inode)); - i_size =round_up (i_size,PAGE_SIZE ); -if (i_size >>PAGE_SHIFT >= aligned_index) -return within_size_orders; + within_size_orders =shmem_get_orders_within_size (inode, within_size_orders, + index, write_end); +if (within_size_orders >0 ) +return within_size_orders; - order =next_order (&within_size_orders, order); - } fallthrough;case SHMEM_HUGE_ADVISE :if (vm_flags &VM_HUGEPAGE )
@@ -1756,10 +1770,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode,unsigned long mask =READ_ONCE (huge_shmem_orders_always);unsigned long within_size_orders =READ_ONCE (huge_shmem_orders_within_size);unsigned long vm_flags = vma ? vma->vm_flags :0 ; -pgoff_t aligned_index;unsigned int global_orders; -loff_t i_size; -int order;if (thp_disabled_by_hw () || (vma &&vma_thp_disabled (vma, vm_flags)))return 0 ;
@@ -1785,17 +1796,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode,return READ_ONCE (huge_shmem_orders_inherit);/* Allow mTHP that will be fully within i_size. */ - order =highest_order (within_size_orders); -while (within_size_orders) { - aligned_index =round_up (index +1 ,1 << order); - i_size =round_up (i_size_read (inode),PAGE_SIZE ); -if (i_size >>PAGE_SHIFT >= aligned_index) { - mask |= within_size_orders; -break ; - } - - order =next_order (&within_size_orders, order); - } + mask |=shmem_get_orders_within_size (inode, within_size_orders, index,0 );if (vm_flags &VM_HUGEPAGE ) mask |=READ_ONCE (huge_shmem_orders_madvise);
Signature · 1 line
2.39.3
Baolin Wang
reviewerPATCH 6/6 MAINTAINERS: add myself as shmem reviewer
In reply to Baolin WangIn the past year, I've primarily focused on shmem and added several features to it, such as support for mTHP, large folio swap-out and swap-in support, mTHP collapse support, skipping swapcache, and tmpfs support for large folios, and so on. Meanwhile I've also been helping with testing and reviewing shmem related patches.
So I am willing to continue assisting with testing and reviewing shmem related patches. Let me be Cc'd on patches related to shmem.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -23883,6 +23883,7 @@ F: drivers/hwmon/tmp513.c TMPFS (SHMEM FILESYSTEM) M: Hugh Dickins <[email protected]> +R: Baolin Wang <[email protected]> L: [email protected] S: Maintained F: include/linux/shmem_fs.h
Signature · 1 line
2.39.3