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.

kho: simplify page initialization in kho_restore_page()

When restoring a page (from kho_restore_pages()) or folio (from
kho_restore_folio()), KHO must initialize the struct page. The
initialization differs slightly depending on if a folio is requested or a
set of 0-order pages is requested.

Conceptually, it is quite simple to understand. When restoring 0-order
pages, each page gets a refcount of 1 and that's it. When restoring a
folio, head page gets a refcount of 1 and tail pages get 0.

kho_restore_page() tries to combine the two separate initialization flow
into one piece of code. While it works fine, it is more complicated to
read than it needs to be. Make the code simpler by splitting the two
initalization paths into two separate functions. This improves
readability by clearly showing how each type must be initialized.

Link: https://lkml.kernel.org/r/20260116112217.915803-3-pratyush@kernel.org
Signed-off-by: Pratyush Yadav <pratyush@kernel.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Alexander Graf <graf@amazon.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pratyush Yadav and committed by
Andrew Morton
8f108189 840fe43d

+26 -14
+26 -14
kernel/liveupdate/kexec_handover.c
··· 216 216 return 0; 217 217 } 218 218 219 + /* For physically contiguous 0-order pages. */ 220 + static void kho_init_pages(struct page *page, unsigned long nr_pages) 221 + { 222 + for (unsigned long i = 0; i < nr_pages; i++) 223 + set_page_count(page + i, 1); 224 + } 225 + 226 + static void kho_init_folio(struct page *page, unsigned int order) 227 + { 228 + unsigned long nr_pages = (1 << order); 229 + 230 + /* Head page gets refcount of 1. */ 231 + set_page_count(page, 1); 232 + 233 + /* For higher order folios, tail pages get a page count of zero. */ 234 + for (unsigned long i = 1; i < nr_pages; i++) 235 + set_page_count(page + i, 0); 236 + 237 + if (order > 0) 238 + prep_compound_page(page, order); 239 + } 240 + 219 241 static struct page *kho_restore_page(phys_addr_t phys, bool is_folio) 220 242 { 221 243 struct page *page = pfn_to_online_page(PHYS_PFN(phys)); 222 244 unsigned long nr_pages; 223 - unsigned int ref_cnt; 224 245 union kho_page_info info; 225 246 226 247 if (!page) ··· 259 238 260 239 /* Clear private to make sure later restores on this page error out. */ 261 240 page->private = 0; 262 - /* Head page gets refcount of 1. */ 263 - set_page_count(page, 1); 264 241 265 - /* 266 - * For higher order folios, tail pages get a page count of zero. 267 - * For physically contiguous order-0 pages every pages gets a page 268 - * count of 1 269 - */ 270 - ref_cnt = is_folio ? 0 : 1; 271 - for (unsigned long i = 1; i < nr_pages; i++) 272 - set_page_count(page + i, ref_cnt); 273 - 274 - if (is_folio && info.order) 275 - prep_compound_page(page, info.order); 242 + if (is_folio) 243 + kho_init_folio(page, info.order); 244 + else 245 + kho_init_pages(page, nr_pages); 276 246 277 247 /* Always mark headpage's codetag as empty to avoid accounting mismatch */ 278 248 clear_page_tag_ref(page);