From: "Jan Beulich" Subject: Re: [PATCH v2 3/3] xen: use idle vcpus to scrub pages Date: Fri, 25 Jul 2014 09:28:00 +0100 Message-ID: <53D231300200007800025E05@mail.emea.novell.com> References: <1404135584-29206-1-git-send-email-bob.liu@oracle.com> <1404135584-29206-3-git-send-email-bob.liu@oracle.com> <53B2979C020000780001EE97@mail.emea.novell.com> <53B2A8C7.9040601@oracle.com> <53B2CCD1020000780001F027@mail.emea.novell.com> <53C4F171.8060807@oracle.com> <53CF80400200007800024F2B@mail.emea.novell.com> <53D06A8B.7010804@oracle.com> <53D0C2D1020000780002556F@mail.emea.novell.com> <53D1A80F.9040509@oracle.com> <53D21AA40200007800025CA7@mail.emea.novell.com> <53D20734.8020902@oracle.com> <53D225060200007800025D2A@mail.emea.novell.com> <53D212E4.7070208@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XAarF-00016Q-47 for xen-devel@lists.xenproject.org; Fri, 25 Jul 2014 08:28:05 +0000 In-Reply-To: <53D212E4.7070208@oracle.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Bob Liu Cc: Bob Liu , keir@xen.org, ian.campbell@citrix.com, George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com, xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org >>> On 25.07.14 at 10:18, wrote: > On 07/25/2014 03:36 PM, Jan Beulich wrote: >>>>> On 25.07.14 at 09:28, wrote: >> >>> On 07/25/2014 02:51 PM, Jan Beulich wrote: >>>>>>> On 25.07.14 at 02:42, wrote: >>>> >>>>> On 07/24/2014 02:24 PM, Jan Beulich wrote: >>>>>>>>> On 24.07.14 at 04:08, wrote: >>>>>> >>>>>>> On 07/23/2014 03:28 PM, Jan Beulich wrote: >>>>>>>>>>> On 15.07.14 at 11:16, wrote: >>>>>>>>> After so many days I haven't make a workable solution if don't remove >>>>>>>>> pages temporarily. The hardest part is iterating the heap free list >>>>>>>>> without holding heap_lock because if holding the lock it might be heavy >>>>>>>>> lock contention. >>>>>>>>> So do you think it's acceptable if fixed all other concerns about this >>>>>>>>> patch? >>>>>>>> >>>>>>>> No, I don't think so. Instead I'm of the opinion that you may have >>>>>>>> worked in the wrong direction: Rather than not taking the heap lock >>>>>>>> at all, it may also be sufficient to shrink the lock holding time (i.e. >>>>>>>> avoid long loops with the lock held). >>>>>>>> >>>>>>> >>>>>>> But I still think have to drop pages from heap list temporarily else >>>>>>> heap lock must be taken for a long time to get rid of E.g. below race >>>>>>> condition. >>>>>>> >>>>>>> A: alloc path B: idle loop >>>>>>> >>>>>>> spin_lock(&heap_lock) >>>>>>> page_list_for_each( pg, &heap(node, zone, order) ) >>>>>>> if _PGC_need_scrub is set, break; >>>>>>> spin_unlock(&heap_lock) >>>>>>> >>>>>>> if ( test_bit(_PGC_need_scrub, pg) >>>>>>> >>>>>>> ^^^^ >>>>>>> spin_lock(&heap_lock) >>>>>>> delist page >>>>>>> spin_unlock(&heap_lock) >>>>>>> >>>>>>> write data to this page >>>>>>> >>>>>>> scrub_one_page(pg) >>>>>>> ^^^ will clean useful data >>>>>> >>>>>> No (and I'm sure I said so before): The only problem is with the >>>>>> linked list itself; the page contents are not a problem - the >>>>>> allocation path can simply wait for the already suggested >>>>>> _PGC_scrubbing flag to clear before returning. And as already >>>>> >>>>> The page contents are a problem if the race condition I mentioned in >>>>> previous email happen. >>>>> >>>>> Because there is a time window between checking the PGC_need_scrub flag >>>>> and doing the real scrub in idle thread, the idle thread will still >>>>> scrub a page after that page have been allocated by allocation path and >>>>> been used(and have been written some useful data). >>>> >>>> Did you really read all of my previous reply? >>> >>> Sure, may be I misunderstood your reply. >>> If the allocation path can wait for the flag there is no problem, but I >>> remember you suggested to do the scrubbing also in allocation path in >>> which case I think this race condition will happen. >> >> Two CPUs scrubbing the same page simultaneously is not a >> correctness problem, only a performance one: The ultimate result >> is a scrubbed page, but there may be unnecessary bus contention. >> > > Thank you for your patient! > > If CPU0 scrubbed a page in allocation path and then that page was > allocated successfully and then been written some data, but CPU1 didn't > recognize this situation and will scrub the same page again which will > clear the useful data by mistake. Did you read the earlier "Did you really read all of my previous reply?" and then go back and _read_ what was written there? Jan