From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76516C3A59D for ; Fri, 16 Aug 2019 18:36:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 46FA02086C for ; Fri, 16 Aug 2019 18:36:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727514AbfHPSgN convert rfc822-to-8bit (ORCPT ); Fri, 16 Aug 2019 14:36:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39472 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727286AbfHPSgN (ORCPT ); Fri, 16 Aug 2019 14:36:13 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44BFE307C947; Fri, 16 Aug 2019 18:36:12 +0000 (UTC) Received: from [10.40.205.21] (unknown [10.40.205.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C454A100197A; Fri, 16 Aug 2019 18:35:53 +0000 (UTC) Subject: Re: [RFC][Patch v12 1/2] mm: page_reporting: core infrastructure To: Alexander Duyck Cc: kvm list , LKML , linux-mm , virtio-dev@lists.oasis-open.org, Paolo Bonzini , lcapitulino@redhat.com, Pankaj Gupta , "Wang, Wei W" , Yang Zhang , Rik van Riel , David Hildenbrand , "Michael S. Tsirkin" , dodgen@google.com, Konrad Rzeszutek Wilk , dhildenb@redhat.com, Andrea Arcangeli , john.starks@microsoft.com, Dave Hansen , Michal Hocko , cohuck@redhat.com References: <20190812131235.27244-1-nitesh@redhat.com> <20190812131235.27244-2-nitesh@redhat.com> <6d5b57ca-41ff-5c54-ab20-2b1631a6ce29@redhat.com> <09c6fbef-fa53-3a25-d3d6-460b9b6b2020@redhat.com> <6241ef40-9403-1cb0-4e91-a1b86fcf1388@redhat.com> From: Nitesh Narayan Lal Openpgp: preference=signencrypt Autocrypt: addr=nitesh@redhat.com; prefer-encrypt=mutual; keydata= mQINBFl4pQoBEADT/nXR2JOfsCjDgYmE2qonSGjkM1g8S6p9UWD+bf7YEAYYYzZsLtbilFTe z4nL4AV6VJmC7dBIlTi3Mj2eymD/2dkKP6UXlliWkq67feVg1KG+4UIp89lFW7v5Y8Muw3Fm uQbFvxyhN8n3tmhRe+ScWsndSBDxYOZgkbCSIfNPdZrHcnOLfA7xMJZeRCjqUpwhIjxQdFA7 n0s0KZ2cHIsemtBM8b2WXSQG9CjqAJHVkDhrBWKThDRF7k80oiJdEQlTEiVhaEDURXq+2XmG jpCnvRQDb28EJSsQlNEAzwzHMeplddfB0vCg9fRk/kOBMDBtGsTvNT9OYUZD+7jaf0gvBvBB lbKmmMMX7uJB+ejY7bnw6ePNrVPErWyfHzR5WYrIFUtgoR3LigKnw5apzc7UIV9G8uiIcZEn C+QJCK43jgnkPcSmwVPztcrkbC84g1K5v2Dxh9amXKLBA1/i+CAY8JWMTepsFohIFMXNLj+B RJoOcR4HGYXZ6CAJa3Glu3mCmYqHTOKwezJTAvmsCLd3W7WxOGF8BbBjVaPjcZfavOvkin0u DaFvhAmrzN6lL0msY17JCZo046z8oAqkyvEflFbC0S1R/POzehKrzQ1RFRD3/YzzlhmIowkM BpTqNBeHEzQAlIhQuyu1ugmQtfsYYq6FPmWMRfFPes/4JUU/PQARAQABtCVOaXRlc2ggTmFy YXlhbiBMYWwgPG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sC+Rp0o3KNc+GXTR+GSVq87Xfuhx0LRST NK9ZhT0+qkiN7npFLtNtbzwqaqceq3XhafmCiw8xrtzCnlB/C4SiBr/93Ip4kihXJ0EuHSLn VujM7c/b4pps Organization: Red Hat Inc, Message-ID: Date: Fri, 16 Aug 2019 14:35:50 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Content-Language: en-US X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 16 Aug 2019 18:36:12 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On 8/15/19 7:00 PM, Alexander Duyck wrote: > On Thu, Aug 15, 2019 at 12:23 PM Nitesh Narayan Lal wrote: [...] >>>>>>> +} >>>>>>> + >>>>>>> +/** >>>>>>> + * __page_reporting_enqueue - tracks the freed page in the respective zone's >>>>>>> + * bitmap and enqueues a new page reporting job to the workqueue if possible. >>>>>>> + */ >>>>>>> +void __page_reporting_enqueue(struct page *page) >>>>>>> +{ >>>>>>> + struct page_reporting_config *phconf; >>>>>>> + struct zone *zone; >>>>>>> + >>>>>>> + rcu_read_lock(); >>>>>>> + /* >>>>>>> + * We should not process this page if either page reporting is not >>>>>>> + * yet completely enabled or it has been disabled by the backend. >>>>>>> + */ >>>>>>> + phconf = rcu_dereference(page_reporting_conf); >>>>>>> + if (!phconf) >>>>>>> + return; >>>>>>> + >>>>>>> + zone = page_zone(page); >>>>>>> + bitmap_set_bit(page, zone); >>>>>>> + >>>>>>> + /* >>>>>>> + * We should not enqueue a job if a previously enqueued reporting work >>>>>>> + * is in progress or we don't have enough free pages in the zone. >>>>>>> + */ >>>>>>> + if (atomic_read(&zone->free_pages) >= phconf->max_pages && >>>>>>> + !atomic_cmpxchg(&phconf->refcnt, 0, 1)) >>>>>> This doesn't make any sense to me. Why are you only incrementing the >>>>>> refcount if it is zero? Combining this with the assignment above, this >>>>>> isn't really a refcnt. It is just an oversized bitflag. >>>>> The intent for having an extra variable was to ensure that at a time only one >>>>> reporting job is enqueued. I do agree that for that purpose I really don't need >>>>> a reference counter and I should have used something like bool >>>>> 'page_hinting_active'. But with bool, I think there could be a possible chance >>>>> of race. Maybe I should rename this variable and keep it as atomic. >>>>> Any thoughts? >>>> You could just use a bitflag to achieve what you are doing here. That >>>> is the primary use case for many of the test_and_set_bit type >>>> operations. However one issue with doing it as a bitflag is that you >>>> have no way of telling that you took care of all requesters. >>> I think you are right, I might end up missing on certain reporting >>> opportunities in some special cases. Specifically when the pages which are >>> part of this new reporting request belongs to a section of the bitmap which >>> has already been scanned. Although, I have failed to reproduce this kind of >>> situation in an actual setup. >>> >>>> That is >>>> where having an actual reference count comes in handy as you know >>>> exactly how many zones are requesting to be reported on. >>> True. >>> >>>>>> Also I am pretty sure this results in the opportunity to miss pages >>>>>> because there is nothing to prevent you from possibly missing a ton of >>>>>> pages you could hint on if a large number of pages are pushed out all >>>>>> at once and then the system goes idle in terms of memory allocation >>>>>> and freeing. >>>>> I was looking at how you are enqueuing/processing reporting jobs for each zone. >>>>> I am wondering if I should also consider something on similar lines as having >>>>> that I might be able to address the concern which you have raised above. But it >>>>> would also mean that I have to add an additional flag in the zone_flags. :) >>>> You could do it either in the zone or outside the zone as yet another >>>> bitmap. I decided to put the flags inside the zone because there was a >>>> number of free bits there and it should be faster since we were >>>> already using the zone structure. >>> There are two possibilities which could happen while I am reporting: >>> 1. Another request might come in for a different zone. >>> 2. Another request could come in for the same zone and the pages belong to a >>> section of the bitmap which has already been scanned. >>> >>> Having a per zone flag to indicate reporting status will solve the first >>> issue and to an extent the second as well. Having refcnt will possibly solve >>> both of them. What I am wondering about is that in my case I could easily >>> impact the performance negatively by performing more bitmap scanning. >>> >>> >> I realized that it may not be possible for me to directly adopt either refcnt >> or zone flags just because of the way I have page reporting setup right now. >> >> For now, I will just replace the refcnt with a bitflag as that should work >> for most of the cases. Nevertheless, I will also keep looking for a better way. > If nothing else something you could consider is a refcnt for the > number of bits you have set in your bitfield. Then all you would need > to be doing is replace the cmpxchg with just a atomic_fetch_inc and > what you would need to do is have your worker thread track how many > bits it has cleared and subtract that from the refcnt at the end. Thanks, I will think about this suggestion as well. Based on your previous suggestion and what you have already proposed in your series I can think of a way to atleast ensure reporting for zones freeing pages after getting scanned in wq. (In case I decide to go ahead with this approach I will mention that this change is based on your series. Please do let me know if there is a better way to give credit) However, a situation where the same zone is reporting pages from the bitmap section already scanned with zero freeing activity on other zones, may not be entirely handled. In any case, I think what I have in my mind will be better than what I have right now. I will try to implement and test it to see if it can actually work. -- Thanks Nitesh