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=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 75BBEC282CE for ; Tue, 4 Jun 2019 16:42:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4336C23CEC for ; Tue, 4 Jun 2019 16:42:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727897AbfFDQmv (ORCPT ); Tue, 4 Jun 2019 12:42:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51642 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727848AbfFDQmv (ORCPT ); Tue, 4 Jun 2019 12:42:51 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ABA292F8BE7; Tue, 4 Jun 2019 16:42:45 +0000 (UTC) Received: from [10.40.205.182] (unknown [10.40.205.182]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 59EC052F9; Tue, 4 Jun 2019 16:42:24 +0000 (UTC) Subject: Re: [RFC][Patch v10 1/2] mm: page_hinting: core infrastructure To: Alexander Duyck Cc: kvm list , LKML , linux-mm , Paolo Bonzini , lcapitulino@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com, Yang Zhang , Rik van Riel , David Hildenbrand , "Michael S. Tsirkin" , dodgen@google.com, Konrad Rzeszutek Wilk , dhildenb@redhat.com, Andrea Arcangeli References: <20190603170306.49099-1-nitesh@redhat.com> <20190603170306.49099-2-nitesh@redhat.com> <4cdfee20-126e-bc28-cf1c-2cfd484ca28e@redhat.com> <09e6caea-7000-b3e4-d297-df6bea78e127@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 YXlhbiBMYWwgPG5pbGFsQHJlZGhhdC5jb20+iQI9BBMBCAAnBQJZeKUKAhsjBQkJZgGABQsJ CAcCBhUICQoLAgQWAgMBAh4BAheAAAoJEKOGQNwGMqM56lE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Ln VujM7c/b4pps Organization: Red Hat Inc, Message-ID: <13b96507-6347-1702-7822-6efb0f1bbf20@redhat.com> Date: Tue, 4 Jun 2019 12:42:21 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="jf1umoW1bcFaPAaBAQpdkCcXl2MICRVIC" X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 04 Jun 2019 16:42:50 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --jf1umoW1bcFaPAaBAQpdkCcXl2MICRVIC Content-Type: multipart/mixed; boundary="hDVCrsXT6XY2ZnqUvudAAxDzhZ69HDqzd"; protected-headers="v1" From: Nitesh Narayan Lal To: Alexander Duyck Cc: kvm list , LKML , linux-mm , Paolo Bonzini , lcapitulino@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com, Yang Zhang , Rik van Riel , David Hildenbrand , "Michael S. Tsirkin" , dodgen@google.com, Konrad Rzeszutek Wilk , dhildenb@redhat.com, Andrea Arcangeli Message-ID: <13b96507-6347-1702-7822-6efb0f1bbf20@redhat.com> Subject: Re: [RFC][Patch v10 1/2] mm: page_hinting: core infrastructure References: <20190603170306.49099-1-nitesh@redhat.com> <20190603170306.49099-2-nitesh@redhat.com> <4cdfee20-126e-bc28-cf1c-2cfd484ca28e@redhat.com> <09e6caea-7000-b3e4-d297-df6bea78e127@redhat.com> In-Reply-To: --hDVCrsXT6XY2ZnqUvudAAxDzhZ69HDqzd Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US On 6/4/19 12:25 PM, Alexander Duyck wrote: > On Tue, Jun 4, 2019 at 9:08 AM Nitesh Narayan Lal w= rote: >> >> On 6/4/19 11:14 AM, Alexander Duyck wrote: >>> On Tue, Jun 4, 2019 at 5:55 AM Nitesh Narayan Lal = wrote: >>>> On 6/3/19 3:04 PM, Alexander Duyck wrote: >>>>> On Mon, Jun 3, 2019 at 10:04 AM Nitesh Narayan Lal wrote: >>>>>> This patch introduces the core infrastructure for free page hintin= g in >>>>>> virtual environments. It enables the kernel to track the free page= s which >>>>>> can be reported to its hypervisor so that the hypervisor could >>>>>> free and reuse that memory as per its requirement. >>>>>> >>>>>> While the pages are getting processed in the hypervisor (e.g., >>>>>> via MADV_FREE), the guest must not use them, otherwise, data loss >>>>>> would be possible. To avoid such a situation, these pages are >>>>>> temporarily removed from the buddy. The amount of pages removed >>>>>> temporarily from the buddy is governed by the backend(virtio-ballo= on >>>>>> in our case). >>>>>> >>>>>> To efficiently identify free pages that can to be hinted to the >>>>>> hypervisor, bitmaps in a coarse granularity are used. Only fairly = big >>>>>> chunks are reported to the hypervisor - especially, to not break u= p THP >>>>>> in the hypervisor - "MAX_ORDER - 2" on x86, and to save space. The= bits >>>>>> in the bitmap are an indication whether a page *might* be free, no= t a >>>>>> guarantee. A new hook after buddy merging sets the bits. >>>>>> >>>>>> Bitmaps are stored per zone, protected by the zone lock. A workque= ue >>>>>> asynchronously processes the bitmaps, trying to isolate and report= pages >>>>>> that are still free. The backend (virtio-balloon) is responsible f= or >>>>>> reporting these batched pages to the host synchronously. Once repo= rting/ >>>>>> freeing is complete, isolated pages are returned back to the buddy= =2E >>>>>> >>>>>> There are still various things to look into (e.g., memory hotplug,= more >>>>>> efficient locking, possible races when disabling). >>>>>> >>>>>> Signed-off-by: Nitesh Narayan Lal >>>>> So one thing I had thought about, that I don't believe that has bee= n >>>>> addressed in your solution, is to determine a means to guarantee >>>>> forward progress. If you have a noisy thread that is allocating and= >>>>> freeing some block of memory repeatedly you will be stuck processin= g >>>>> that and cannot get to the other work. Specifically if you have a z= one >>>>> where somebody is just cycling the number of pages needed to fill y= our >>>>> hinting queue how do you get around it and get to the data that is >>>>> actually code instead of getting stuck processing the noise? >>>> It should not matter. As every time the memory threshold is met, ent= ire >>>> bitmap >>>> is scanned and not just a chunk of memory for possible isolation. Th= is >>>> will guarantee >>>> forward progress. >>> So I think there may still be some issues. I see how you go from the >>> start to the end, but how to you loop back to the start again as page= s >>> are added? The init_hinting_wq doesn't seem to have a way to get back= >>> to the start again if there is still work to do after you have >>> completed your pass without queue_work_on firing off another thread. >>> >> That will be taken care as the part of a new job, which will be >> en-queued as soon >> as the free memory count for the respective zone will reach the thresh= old. > So does that mean that you have multiple threads all calling > queue_work_on until you get below the threshold? Every time a page of order MAX_ORDER - 2 is added to the buddy, free memory count will be incremented if the bit is not already set and its value will be checked against the threshold. > If so it seems like > that would get expensive since that is an atomic test and set > operation that would be hammered until you get below that threshold. Not sure if I understood "until you get below that threshold". Can you please explain? test_and_set_bit() will be called every time a page with MAX_ORDER -2 order is added to the buddy. (Not already hinted) --=20 Regards Nitesh --hDVCrsXT6XY2ZnqUvudAAxDzhZ69HDqzd-- --jf1umoW1bcFaPAaBAQpdkCcXl2MICRVIC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEkXcoRVGaqvbHPuAGo4ZA3AYyozkFAlz2n20ACgkQo4ZA3AYy ozmdDRAAk+lwKdGjRKO3i+yCypPjo6aKDjJ5F4vchzVyvZ8mswaTucpjf3YbljB9 n3FDj0nRISWOuk7ySVX/xFPBAWqWvIpb5HKCp/2ciK2uxuGBSnzpxSvyRQ2uSxmS fiegjiI3D2IPn6xFi6e5/Jt1zl1xz6W+DSfRHubRYU9nTiEpKzvSZ/DRC+CgUt8f 5A/F8Am+iKV1SCcwU/V0jp3T+w3Pj/qS/RwVm0l45aVc+f64nd008jzLWRo+XCTH Su2Q9w/6jztle6XPkxWq9JkZT3BZzKfDyrX2KdmWjdPvpTkx9lUUTlha/ly4FkW8 H+H0DSZLR+KRlZb1YF7qUtzzMBDstNFGr8QWwEJ2y7bSjwZ1HPut3DTudGlfwcja FL1bXALqy1KDN019sK+8Xiy4j/eZMxzpWBFoo1k8aB4x/OZDHH65Vxr67DshAfEf k5hso0+j1mUqIzEWqaLiNd4lSs46cfJEB7oVrfLUKdZDE22eS6OP73LMnYM1ooAh fygV+Ii0Iv4TLdevo23E83VKfdWJVY3n6jXqJwZLwoGxLUGKReRNbNREE7an6UjG xUulUGbH7TKrGq0RAIMCojAiVg+Er4JQlOzLsopuup56gsUrFJNrKvSUPCX4gJKJ Jbrq1bh0zkfV1QMl/2Nll1MGr6oaIt/Lyb+iUfzHGB6zCYXUelg= =RfpA -----END PGP SIGNATURE----- --jf1umoW1bcFaPAaBAQpdkCcXl2MICRVIC--