From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: [PATCH 3/4] Swapping Date: Sat, 13 Oct 2007 18:17:27 -0500 Message-ID: <47115207.3090909@codemonkey.ws> References: <47102919.6070802@qumranet.com> <471124D4.3090901@codemonkey.ws> <471126D9.4030204@qumranet.com> <47112D66.4020500@qumranet.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org To: Izik Eidus Return-path: In-Reply-To: <47112D66.4020500-atKUWr5tajBWk0Htik3J/w@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org Izik Eidus wrote: > Izik Eidus wrote: >> Anthony Liguori wrote: >>> Izik Eidus wrote: >>>> >>>> @@ -1058,8 +1038,27 @@ struct page *gfn_to_page(struct kvm *kvm, >>>> gfn_t gfn) >>>> >>>> gfn = unalias_gfn(kvm, gfn); >>>> slot = __gfn_to_memslot(kvm, gfn); >>>> - if (!slot) >>>> + if (!slot) { >>>> + get_page(bad_page); >>>> return bad_page; >>>> + } >>>> + if (slot->user_alloc) { >>>> + struct page *page[1]; >>>> + int npages; >>>> + >>>> + down_read(¤t->mm->mmap_sem); >>>> + npages = get_user_pages(current, current->mm, >>>> + slot->userspace_addr >>>> + + (gfn - slot->base_gfn) * PAGE_SIZE, 1, >>>> + 1, 0, page, NULL); >>>> + up_read(¤t->mm->mmap_sem); >>>> + if (npages != 1) { >>>> + get_page(bad_page); >>>> + return bad_page; >>>> + } >>>> + return page[0]; >>>> >>> >>> Wouldn't it be necessary to assign page[0] to slot->phys_mem[gfn - >>> slot->base_gfn]? >> > sorry, it seems like i missunderstand you in the answer i gave you. > it wouldnt be necessary to assign page[0] to slot->phys_mem[gfn - > slot->base_gfn], beacuse phys_mem wont have any memory allocate by > this time. > > with this patch, we are not holding anymore (when using userspace > allocation) array of all the memory at phys_mem. > beacuse now that the pages are swappable, the physical address pointed > by the virtual address all the time change (for example when swapping > happn) > so no one promise us that slot->phys_mem[gfn - slot->base_gfn] will > really point to page holding the gfn page. > > so what we did, is throw away the phys_mem array (also nice beacuse it > waste less ram), and at runtime we are getting the pages by using the > virtual address > beacuse the reference of the page get increased, it promised us that > untill we release it point to the gfn (release it by doing put_page) > > hope i was more clear this time :) Yes, that makes sense! I wonder if there's a more elegant way dealing with older userspaces. For instance, is there any reason why we can allocate a userspace memory region on behalf of userspace. That way swap would even work with older userspaces. Regards, Anthony Liguori ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/