Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp445268ybi; Fri, 26 Jul 2019 12:29:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOIG0aWbUCqKA1O45JkY4YmBMsELIeGSgIrLEtYbTSfRhY3GaHnzFWCcTb9c6iH2lFe9Uh X-Received: by 2002:a63:6f41:: with SMTP id k62mr47005711pgc.32.1564169342334; Fri, 26 Jul 2019 12:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564169342; cv=none; d=google.com; s=arc-20160816; b=xofnOirsZNzpkq/eQRD+/nj699lflWaFJ2GMMv1q/IvRwK6NUTSRDw8BnadEJzLkHb ITX9edVJjJLYR/wfrkVkW6s8ERm6vhBhV6LUuk6m9PfB0RqMz55PlrajdksmO1VZgBHb s3fCyLrB4HQ3RwiI1h4iGza4x6y0Yid97FPSm/mXtF/RiVAHQAvAMIL+NEU0Ro+s8Eus FYVbWW+s2A0Zz87WOD/z2RIG+vy8d6sB0yZXUmhb55ZlNdoQGosfwQKSLCcFgDCdvje8 VJGCH94IeNDXCoHpk31isrNh7lXLHanSH72VQQcZCrJmd9zRM8Q1gXP/K++UM1brlJaJ QZcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=Mt0OfoqR00Muu9JYwElLbZSfbHbB+FrDjJVuktnQLrs=; b=YM1PS1MkngLwqo70sIJtMGFpuW697UFW4kuQnvYomxKMQaAHA/WlfyZgnmX7nMIYOa wbTL6FB3kkUoRw1wjMh0VSfnri6TvwOZCb9hXVuK3itUhzpk4K/O45/GZHOLgC4JGZD6 n/ZpAEv+4DMmT+EPj+rC6F5F0j604P65B4p33TbpYoAdHgZTdAfQ++/HADoyrTY5lpiE JjVwPjXKCP3y2RP2RQDITuq1j4VIXWDd7VGyF3dGILrgSpmzR1KZHFm211iHutma8TVF gT0akFh13kkLj7wQswqrWTSidmR5vJigm7zK+VHkddXprTuMrYvvdIWGHzC8IXqjNJHU PpUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si19298113plh.265.2019.07.26.12.28.47; Fri, 26 Jul 2019 12:29:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727249AbfGZQlM (ORCPT + 99 others); Fri, 26 Jul 2019 12:41:12 -0400 Received: from mga17.intel.com ([192.55.52.151]:37330 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725298AbfGZQlM (ORCPT ); Fri, 26 Jul 2019 12:41:12 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jul 2019 09:38:08 -0700 X-IronPort-AV: E=Sophos;i="5.64,311,1559545200"; d="scan'208";a="175655606" Received: from ahduyck-desk1.jf.intel.com ([10.7.198.76]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jul 2019 09:38:08 -0700 Message-ID: Subject: Re: [PATCH v2 4/5] mm: Introduce Hinted pages From: Alexander Duyck To: Nitesh Narayan Lal , Alexander Duyck , kvm@vger.kernel.org, david@redhat.com, mst@redhat.com, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org Cc: yang.zhang.wz@gmail.com, pagupta@redhat.com, riel@surriel.com, konrad.wilk@oracle.com, lcapitulino@redhat.com, wei.w.wang@intel.com, aarcange@redhat.com, pbonzini@redhat.com, dan.j.williams@intel.com Date: Fri, 26 Jul 2019 09:38:08 -0700 In-Reply-To: <49a49a38-b1f4-d5c0-f5f1-a6bed57a03d2@redhat.com> References: <20190724165158.6685.87228.stgit@localhost.localdomain> <20190724170259.6685.18028.stgit@localhost.localdomain> <49a49a38-b1f4-d5c0-f5f1-a6bed57a03d2@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5 (3.30.5-1.fc29) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2019-07-26 at 08:24 -0400, Nitesh Narayan Lal wrote: > On 7/24/19 1:03 PM, Alexander Duyck wrote: > > From: Alexander Duyck > > > > > > +/* > > + * The page hinting cycle consists of 4 stages, fill, react, drain, and idle. > > + * We will cycle through the first 3 stages until we fail to obtain any > > + * pages, in that case we will switch to idle. > > + */ > > +static void page_hinting_cycle(struct zone *zone, > > + struct page_hinting_dev_info *phdev) > > +{ > > + /* > > + * Guarantee boundaries and stats are populated before we > > + * start placing hinted pages in the zone. > > + */ > > + if (page_hinting_populate_metadata(zone)) > > + return; > > + > > + spin_lock(&zone->lock); > > + > > + /* set bit indicating boundaries are present */ > > + set_bit(ZONE_PAGE_HINTING_ACTIVE, &zone->flags); > > + > > + do { > > + /* Pull pages out of allocator into a scaterlist */ > > + unsigned int num_hints = page_hinting_fill(zone, phdev); > > + > > + /* no pages were acquired, give up */ > > + if (!num_hints) > > + break; > > + > > + spin_unlock(&zone->lock); > > Is there any recommendation in general about how/where we should lock and unlock > zones in the code? For instance, over here you have a zone lock outside the loop > and you are unlocking it inside the loop and then re-acquiring it. > My guess is we should be fine as long as: > 1. We are not holding the lock for a very long time. > 2. We are making sure that if we have a zone lock we are releasing it before > returning from the function. So as a general rule the first two you mention work. Basically what you want to do is work with some sort of bounded limit when you are holding the lock so you know it will be released in a timely fashion. The reason for dropping the lock inside of the loop s because we will end up sleeping while we wait for the virtio-balloon device to process the pages. So it makes sense to release the lock, process the pages, and then reacquire the lock so that we can return the pages and grab another 16 pages.