Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1042555pxu; Wed, 6 Jan 2021 10:44:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJzackF+mS2l/xklgSdwuvj8HpjcpfbmfGvt4aK8y9SI1yAGEGfRYvccVCEgstFh5N51RpNH X-Received: by 2002:a17:906:7118:: with SMTP id x24mr3748436ejj.333.1609958679522; Wed, 06 Jan 2021 10:44:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609958679; cv=none; d=google.com; s=arc-20160816; b=Mpee/OX3L5Rt9EKYGCytDL45reOdSDlkF/bq+FIxRfLd94llWT2AIMvpxMABdJjH9n Qy+gDxRCKc7NfIBCQaEnoNz2wRgf6E5fwvMJmJ+RESsP2+7nzS+VuZ2ajJdKvs9i4Xk1 +V1AxHYkCd664EfuCzQAbF1L2wTCphJY99yAPJRCG9zbpMohWFRa3LFAS7utr2JKfDhj bi2D/lLa0o6W+wSv8iJs/vfT6/dMIwvTpyY6fIyNukBYJl9q87nDKG2uIQkFHIHDx3WM h0WWU//qP+/Di2gGYFU1yOoiX+Udv1xY70MQBxLPvmQuBhuMfvQkdzF0I8DXKlqwXiuX OU1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=LXbQyuhu8MJhuWLpzCR+mt3CN6/MAbyKTSN+t0WIyKg=; b=nGF+WQXtvKSlfML24aX23sn6PcWSFwlI6li9EMiHfGVxoQ1cXML5qvv9GIl3rfUCko roHVoHACOxEroHtTEoAg3r0NlW58UgNq/YGnAT9/EJvqbpmqxtrMDKny0bbsuTLt5kBr g4+AgXVTlbss/B1s9HXy14XctvDlZyTLAK1p17/8pZ1uSpzTVcwyVpjvrL26McS8Az6J Ww3pyl8lp1l6w0wGDrlMPjEy9QMw74seMN+ZGrH107XzDlD0cnjTtCMPcvsIc4NbV4oU JHcyYbN06mK40A+XDWixDdYxc/+jB6SPhg67CsYTEYeHkLPPO8kW2dT9kPAuP6AsPqzy dX6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pybeZ3LJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l2si1225225ede.232.2021.01.06.10.44.15; Wed, 06 Jan 2021 10:44:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pybeZ3LJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726438AbhAFSnP (ORCPT + 99 others); Wed, 6 Jan 2021 13:43:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbhAFSnN (ORCPT ); Wed, 6 Jan 2021 13:43:13 -0500 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5220C06134C for ; Wed, 6 Jan 2021 10:42:33 -0800 (PST) Received: by mail-io1-xd36.google.com with SMTP id z5so3628473iob.11 for ; Wed, 06 Jan 2021 10:42:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LXbQyuhu8MJhuWLpzCR+mt3CN6/MAbyKTSN+t0WIyKg=; b=pybeZ3LJXJM520ZUF/lF5e+DMV6pDbodJA58CCMaXrvOWT5plLY3BDk1bQ9mWsRHkA dog0zUHHVZCTLKeYETnRnjTcjxsh5rjMh8MhP4MeuxUu7CeQRNT2+qO6nupBj+E4gDxd hHi58oRS9SQ+cTjV6NVNnuWf86EW8PljAr8VdQx3ZB2EKpSKRXTpb/OgR4EjFDQDyqzF eVt5uwZFLdvcruoeERL3XwixAfem1OQu7bPo0MXcHQ30/mzs3jVLk2mtDWmdrnGqejic DuOxaeRtcVYVPUqN8w1QGzTZoYgFFaoJxPs1ibjxiNqqM2BKCKwabhlCrGaorooqMeJB VS/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LXbQyuhu8MJhuWLpzCR+mt3CN6/MAbyKTSN+t0WIyKg=; b=d2ouA+V/eQU95Q4sHtdFh2VZKhRna/e8GGoVsXJoj/DN6mvbdl/2eVEuqJrd0rRTUz wWmph64mmGbkUwPozG4s5uL/YCwoijapjP0iV3Jc+HFD83/SQAtYtpocBMWV+xSbsWRD zoY4VcUtwdocKjXCyN6eHSQ+S+On+ipxedppLTEpg2e/udWT50ESVuO+piH9u81S7pdN bkXyLKC4D4mkUV3tRnWfoZD8+kRfI3nFlQ+b66J+v5y5Q3E73XdsW+MuuZWqNYJDP9X0 wuQ4L7ezdcRkMsnpoUWmhmuzdr2zRzdboQdcloE/ecYB5AKSI2Yt4I4h3CXBr9tzlyqT hz/Q== X-Gm-Message-State: AOAM533BZ5CpVk/V8KioGtk4GKtEXBHysUAxEqeuivWK5Zi/gUnp5t9X jBaUx7BvFPHYdyjjQXe8zYvbljOwftH8agRepag= X-Received: by 2002:a5d:9a82:: with SMTP id c2mr3913038iom.38.1609958552867; Wed, 06 Jan 2021 10:42:32 -0800 (PST) MIME-Version: 1.0 References: <20210106034806.GA1146@open-light-1.localdomain> In-Reply-To: <20210106034806.GA1146@open-light-1.localdomain> From: Alexander Duyck Date: Wed, 6 Jan 2021 10:42:21 -0800 Message-ID: Subject: Re: [PATCH 2/6] mm: let user decide page reporting option To: Alexander Duyck , Mel Gorman , Andrew Morton , Andrea Arcangeli , Dan Williams , "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , Dave Hansen , Michal Hocko , Liang Li , Mike Kravetz , linux-mm , LKML , virtualization@lists.linux-foundation.org Cc: Liang Li Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 5, 2021 at 7:48 PM Liang Li wrote: > > Some key parameters for page reporting are now hard coded, different > users of the framework may have their special requirements, make > these parameter configrable and let the user decide them. > > Cc: Alexander Duyck > Cc: Mel Gorman > Cc: Andrea Arcangeli > Cc: Dan Williams > Cc: Dave Hansen > Cc: David Hildenbrand > Cc: Michal Hocko > Cc: Andrew Morton > Cc: Alex Williamson > Cc: Michael S. Tsirkin > Cc: Liang Li > Signed-off-by: Liang Li > --- > drivers/virtio/virtio_balloon.c | 3 +++ > include/linux/page_reporting.h | 3 +++ > mm/page_reporting.c | 13 +++++++++---- > mm/page_reporting.h | 6 +++--- > 4 files changed, 18 insertions(+), 7 deletions(-) > > diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c > index 8985fc2cea86..684bcc39ef5a 100644 > --- a/drivers/virtio/virtio_balloon.c > +++ b/drivers/virtio/virtio_balloon.c > @@ -993,6 +993,9 @@ static int virtballoon_probe(struct virtio_device *vdev) > goto out_unregister_oom; > } > > + vb->pr_dev_info.mini_order = pageblock_order; > + vb->pr_dev_info.batch_size = 16 * 1024 * 1024; /* 16M */ > + vb->pr_dev_info.delay_jiffies = 2 * HZ; /* 2 seconds */ > err = page_reporting_register(&vb->pr_dev_info); > if (err) > goto out_unregister_oom; > diff --git a/include/linux/page_reporting.h b/include/linux/page_reporting.h > index 3b99e0ec24f2..63e1e9fbcaa2 100644 > --- a/include/linux/page_reporting.h > +++ b/include/linux/page_reporting.h > @@ -13,6 +13,9 @@ struct page_reporting_dev_info { > int (*report)(struct page_reporting_dev_info *prdev, > struct scatterlist *sg, unsigned int nents); > > + unsigned long batch_size; > + unsigned long delay_jiffies; > + int mini_order; > /* work struct for processing reports */ > struct delayed_work work; > > diff --git a/mm/page_reporting.c b/mm/page_reporting.c > index 694df981ddd2..39bc6a9d7b73 100644 > --- a/mm/page_reporting.c > +++ b/mm/page_reporting.c > @@ -13,6 +13,7 @@ > #define PAGE_REPORTING_DELAY (2 * HZ) > static struct page_reporting_dev_info __rcu *pr_dev_info __read_mostly; > unsigned long page_report_batch_size __read_mostly = 16 * 1024 * 1024UL; > +int page_report_mini_order = pageblock_order; > > enum { > PAGE_REPORTING_IDLE = 0, > @@ -44,7 +45,7 @@ __page_reporting_request(struct page_reporting_dev_info *prdev) > * now we are limiting this to running no more than once every > * couple of seconds. > */ > - schedule_delayed_work(&prdev->work, PAGE_REPORTING_DELAY); > + schedule_delayed_work(&prdev->work, prdev->delay_jiffies); > } > So this ends up being the reason why you needed to add the batch size value. However I don't really see it working as expected since you could essentially have 1 page freed 4M times that could trigger your page zeroing logic. So for example if a NIC is processing frames and ends up freeing and then reallocating some small batch of pages this could would be running often even though there isn't really all that many pages that needed zeroing. > /* notify prdev of free page reporting request */ > @@ -230,7 +231,7 @@ page_reporting_process_zone(struct page_reporting_dev_info *prdev, > > /* Generate minimum watermark to be able to guarantee progress */ > watermark = low_wmark_pages(zone) + > - (PAGE_REPORTING_CAPACITY << PAGE_REPORTING_MIN_ORDER); > + (PAGE_REPORTING_CAPACITY << prdev->mini_order); > > /* > * Cancel request if insufficient free memory or if we failed With the page order being able to be greatly reduced this could have a significant impact on if this code really has any value. Previously we were able to guarantee a pretty significant number of higher order pages free. With this we might only be guaranteeing something like 32 4K pages which is pretty small compared to what can end up being pulled out at the higher end. > @@ -240,7 +241,7 @@ page_reporting_process_zone(struct page_reporting_dev_info *prdev, > return err; > > /* Process each free list starting from lowest order/mt */ > - for (order = PAGE_REPORTING_MIN_ORDER; order < MAX_ORDER; order++) { > + for (order = prdev->mini_order; order < MAX_ORDER; order++) { > for (mt = 0; mt < MIGRATE_TYPES; mt++) { > /* We do not pull pages from the isolate free list */ > if (is_migrate_isolate(mt)) > @@ -307,7 +308,7 @@ static void page_reporting_process(struct work_struct *work) > */ > state = atomic_cmpxchg(&prdev->state, state, PAGE_REPORTING_IDLE); > if (state == PAGE_REPORTING_REQUESTED) > - schedule_delayed_work(&prdev->work, PAGE_REPORTING_DELAY); > + schedule_delayed_work(&prdev->work, prdev->delay_jiffies); > } > > static DEFINE_MUTEX(page_reporting_mutex); > @@ -335,6 +336,8 @@ int page_reporting_register(struct page_reporting_dev_info *prdev) > /* Assign device to allow notifications */ > rcu_assign_pointer(pr_dev_info, prdev); > > + page_report_mini_order = prdev->mini_order; > + page_report_batch_size = prdev->batch_size; > /* enable page reporting notification */ > if (!static_key_enabled(&page_reporting_enabled)) { > static_branch_enable(&page_reporting_enabled); > @@ -352,6 +355,8 @@ void page_reporting_unregister(struct page_reporting_dev_info *prdev) > mutex_lock(&page_reporting_mutex); > > if (rcu_access_pointer(pr_dev_info) == prdev) { > + if (static_key_enabled(&page_reporting_enabled)) > + static_branch_disable(&page_reporting_enabled); > /* Disable page reporting notification */ > RCU_INIT_POINTER(pr_dev_info, NULL); > synchronize_rcu(); If we are going to use this we are using it. Once we NULL out the prdev that should stop page reporting from running. We shouldn't be relying on the static key. > diff --git a/mm/page_reporting.h b/mm/page_reporting.h > index b8fb3bbb345f..86ac6ffad970 100644 > --- a/mm/page_reporting.h > +++ b/mm/page_reporting.h > @@ -9,9 +9,9 @@ > #include > #include > #include > +#include > > -#define PAGE_REPORTING_MIN_ORDER pageblock_order > - > +extern int page_report_mini_order; > extern unsigned long page_report_batch_size; > > #ifdef CONFIG_PAGE_REPORTING > @@ -42,7 +42,7 @@ static inline void page_reporting_notify_free(unsigned int order) > return; > > /* Determine if we have crossed reporting threshold */ > - if (order < PAGE_REPORTING_MIN_ORDER) > + if (order < page_report_mini_order) > return; This is another case where it might make sense to look at placing the code in __page_reporting_notify if we are going to allow this to be a dynamically configurable value. > batch_size += (1 << order) << PAGE_SHIFT; > -- > 2.18.2 > >