Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/swapfile.c: optimize code in setup_clusters()

In the last 'for' loop inside setup_clusters(), using two local variable
'k' and 'j' are obvisouly redundant. Using 'j' is enough and simpler.

And also move macro SWAP_CLUSTER_COLS close to its only user
setup_clusters().

Link: https://lkml.kernel.org/r/20250205092721.9395-8-bhe@redhat.com
Signed-off-by: Baoquan He <bhe@redhat.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: Kairui Song <ryncsn@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Baoquan He and committed by
Andrew Morton
a46a6bc2 f80ddc14

+9 -10
+9 -10
mm/swapfile.c
··· 3127 3127 return maxpages; 3128 3128 } 3129 3129 3130 - #define SWAP_CLUSTER_INFO_COLS \ 3131 - DIV_ROUND_UP(L1_CACHE_BYTES, sizeof(struct swap_cluster_info)) 3132 - #define SWAP_CLUSTER_SPACE_COLS \ 3133 - DIV_ROUND_UP(SWAP_ADDRESS_SPACE_PAGES, SWAPFILE_CLUSTER) 3134 - #define SWAP_CLUSTER_COLS \ 3135 - max_t(unsigned int, SWAP_CLUSTER_INFO_COLS, SWAP_CLUSTER_SPACE_COLS) 3136 - 3137 3130 static int setup_swap_map_and_extents(struct swap_info_struct *si, 3138 3131 union swap_header *swap_header, 3139 3132 unsigned char *swap_map, ··· 3166 3173 return nr_extents; 3167 3174 } 3168 3175 3176 + #define SWAP_CLUSTER_INFO_COLS \ 3177 + DIV_ROUND_UP(L1_CACHE_BYTES, sizeof(struct swap_cluster_info)) 3178 + #define SWAP_CLUSTER_SPACE_COLS \ 3179 + DIV_ROUND_UP(SWAP_ADDRESS_SPACE_PAGES, SWAPFILE_CLUSTER) 3180 + #define SWAP_CLUSTER_COLS \ 3181 + max_t(unsigned int, SWAP_CLUSTER_INFO_COLS, SWAP_CLUSTER_SPACE_COLS) 3182 + 3169 3183 static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si, 3170 3184 union swap_header *swap_header, 3171 3185 unsigned long maxpages) 3172 3186 { 3173 3187 unsigned long nr_clusters = DIV_ROUND_UP(maxpages, SWAPFILE_CLUSTER); 3174 3188 struct swap_cluster_info *cluster_info; 3175 - unsigned long i, j, k, idx; 3189 + unsigned long i, j, idx; 3176 3190 int cpu, err = -ENOMEM; 3177 3191 3178 3192 cluster_info = kvcalloc(nr_clusters, sizeof(*cluster_info), GFP_KERNEL); ··· 3240 3240 * Reduce false cache line sharing between cluster_info and 3241 3241 * sharing same address space. 3242 3242 */ 3243 - for (k = 0; k < SWAP_CLUSTER_COLS; k++) { 3244 - j = k % SWAP_CLUSTER_COLS; 3243 + for (j = 0; j < SWAP_CLUSTER_COLS; j++) { 3245 3244 for (i = 0; i < DIV_ROUND_UP(nr_clusters, SWAP_CLUSTER_COLS); i++) { 3246 3245 struct swap_cluster_info *ci; 3247 3246 idx = i * SWAP_CLUSTER_COLS + j;