> Am 17.10.2020 um 00:38 schrieb Wei Yang <richard.weiyang@xxxxxxxxxxxxxxxxx>: > > On Fri, Oct 16, 2020 at 12:32:50PM +0200, David Hildenbrand wrote: >>>>> Ok, I seems to understand the logic now. >>>>> >>>>> But how we prevent ONLINE_PARTIAL memory block get offlined? There are three >>>>> calls in virtio_mem_set_fake_offline(), while all of them adjust page's flag. >>>>> How they hold reference to struct page? >>>> >>>> Sorry, I should have given you the right pointer. (similar to my other >>>> reply) >>>> >>>> We hold a reference either via >>>> >>>> 1. alloc_contig_range() >>> >>> I am not familiar with this one, need to spend some time to look into. >> >> Each individual page will have a pagecount of 1. >> >>> >>>> 2. memmap init code, when not calling generic_online_page(). >>> >>> I may miss some code here. Before online pages, memmaps are allocated in >>> section_activate(). They are supposed to be zero-ed. (I don't get the exact >>> code line.) I am not sure when we grab a refcount here. >> >> Best to refer to __init_single_page() -> init_page_count(). >> >> Each page that wasn't onlined via generic_online_page() has a refcount >> of 1 and looks like allocated. >> > > Thanks, I see the logic. > > online_pages() > move_pfn_range_to_zone() --- 1) > online_pages_range() --- 2) > > At 1), __init_single_page() would set page count to 1. At 2), > generic_online_page() would clear page count, while the call back would not. > > Then I am trying to search the place where un-zero page count prevent offline. > scan_movable_pages() would fail, since this is a PageOffline() and has 1 page > count. > > So the GUARD we prevent offline partial-onlined pages is > > (PageOffline && page_count) > > And your commit aa218795cb5fd583c94f > > mm: Allow to offline unmovable PageOffline() pages via MEM_GOING_OFFLINE > > is introduced to handle this case. > > That's pretty clear now. > I‘m happy to see that I am no longer the only person that understands all this magic :) Thanks for having a look / reviewing! >> -- >> Thanks, >> >> David / dhildenb > > -- > Wei Yang > Help you, Help me >