Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5856989imm; Mon, 23 Jul 2018 07:15:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdXagjO/JB764ve0Hi0nEaNa+bACFDcUCQVqqJIreNY/FrDLN0JEyJtXMtCLYvaWQhnMwrB X-Received: by 2002:a63:a619:: with SMTP id t25-v6mr12166707pge.288.1532355346892; Mon, 23 Jul 2018 07:15:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532355346; cv=none; d=google.com; s=arc-20160816; b=gvhn9yr4KJGceILJrsMpt5P/z6a5+dUTzEg4v8F8F/KhGRwbI7khD0WDl9y0EqeCAJ LeEu+4Bl2ogdzDKygVsU4NBbPXc83bJ+FOt7JBSnJ4Ql3LHGLxe6SbAh8PhwgPAVvN4v DOJw1cWN8Ung2vK0KbOZ0DA1DVAhP18s9vU5pFOcrTNxvDutDWH82IQQA3QmbWihlSKZ fkKsbDTsAqKBVvgFBDYa22aQiolCW4eKAwGkhE+oq3pvAXtqHE98NO+21CyXhrupiVN3 R6qKj+D69KuZQ5G/FyuYilgTj2afja+JCjeMK+j85YP94ILJ+DscQsqLkAG4focOmS6h Uhiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=xgT9XX3MLw2K2p4sFkg1Y6rcQmwIRASrgYNg1Qq0ePY=; b=WT60qNf+UVSSu/Ev/D2qM9MpisXCYPxaSJPa8ykV/Ph1IQYda0747GNFyLUctSI6aP VAAjgyi5jCX+1skIGac3qMeXydDzjHJhegt3SXUBMLf4G3kY2CnLUgO37AT9Tg8jDZlK BxOu6hAqU2ZRLfC9WoNEd/DrHLjz1NmAf9nwCFSfCe7rh1zJ7wjjwuYJqTv0KHH1xYU0 xtjJ0qMIVvqBxEsgZYxZqnlHswChKWmKsm1YgQuy7rOohIPDf5OCOYlOEET+fKuNiuGV x0pUcKR/tdyBzUW1G07pAKILwyETI046khPYUAyXrscghvDoP3oRqG9NpqV453AnOerc yKoQ== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 17-v6si9162623pgw.648.2018.07.23.07.15.31; Mon, 23 Jul 2018 07:15:46 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388392AbeGWPOr (ORCPT + 99 others); Mon, 23 Jul 2018 11:14:47 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45490 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388153AbeGWPOr (ORCPT ); Mon, 23 Jul 2018 11:14:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D47E402346D; Mon, 23 Jul 2018 14:13:19 +0000 (UTC) Received: from redhat.com (ovpn-123-242.rdu2.redhat.com [10.10.123.242]) by smtp.corp.redhat.com (Postfix) with SMTP id AD13A111DD0B; Mon, 23 Jul 2018 14:13:12 +0000 (UTC) Date: Mon, 23 Jul 2018 17:13:11 +0300 From: "Michael S. Tsirkin" To: Wei Wang Cc: virtio-dev@lists.oasis-open.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-mm@kvack.org, mhocko@kernel.org, akpm@linux-foundation.org, torvalds@linux-foundation.org, pbonzini@redhat.com, liliang.opensource@gmail.com, yang.zhang.wz@gmail.com, quan.xu0@gmail.com, nilal@redhat.com, riel@redhat.com, peterx@redhat.com Subject: Re: [PATCH v36 2/5] virtio_balloon: replace oom notifier with shrinker Message-ID: <20180723170826-mutt-send-email-mst@kernel.org> References: <1532075585-39067-1-git-send-email-wei.w.wang@intel.com> <1532075585-39067-3-git-send-email-wei.w.wang@intel.com> <20180722174125-mutt-send-email-mst@kernel.org> <5B55AE56.5030404@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5B55AE56.5030404@intel.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 23 Jul 2018 14:13:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 23 Jul 2018 14:13:19 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mst@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 23, 2018 at 06:30:46PM +0800, Wei Wang wrote: > On 07/22/2018 10:48 PM, Michael S. Tsirkin wrote: > > On Fri, Jul 20, 2018 at 04:33:02PM +0800, Wei Wang wrote: > > > +static unsigned long virtio_balloon_shrinker_scan(struct shrinker *shrinker, > > > + struct shrink_control *sc) > > > +{ > > > + unsigned long pages_to_free = balloon_pages_to_shrink, > > > + pages_freed = 0; > > > + struct virtio_balloon *vb = container_of(shrinker, > > > + struct virtio_balloon, shrinker); > > > + > > > + /* > > > + * One invocation of leak_balloon can deflate at most > > > + * VIRTIO_BALLOON_ARRAY_PFNS_MAX balloon pages, so we call it > > > + * multiple times to deflate pages till reaching > > > + * balloon_pages_to_shrink pages. > > > + */ > > > + while (vb->num_pages && pages_to_free) { > > > + pages_to_free = balloon_pages_to_shrink - pages_freed; > > > + pages_freed += leak_balloon(vb, pages_to_free); > > > + } > > > + update_balloon_size(vb); > > Are you sure that this is never called if count returned 0? > > Yes. Please see do_shrink_slab, it just returns if count is 0. > > > > > > + > > > + return pages_freed / VIRTIO_BALLOON_PAGES_PER_PAGE; > > > +} > > > + > > > +static unsigned long virtio_balloon_shrinker_count(struct shrinker *shrinker, > > > + struct shrink_control *sc) > > > +{ > > > + struct virtio_balloon *vb = container_of(shrinker, > > > + struct virtio_balloon, shrinker); > > > + > > > + /* > > > + * We continue to use VIRTIO_BALLOON_F_DEFLATE_ON_OOM to handle the > > > + * case when shrinker needs to be invoked to relieve memory pressure. > > > + */ > > > + if (!virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) > > > + return 0; > > So why not skip notifier registration when deflate on oom > > is clear? > > Sounds good, thanks. > > > > vb->vb_dev_info.inode->i_mapping->a_ops = &balloon_aops; > > #endif > > + err = virtio_balloon_register_shrinker(vb); > > + if (err) > > + goto out_del_vqs; > > So we can get scans before device is ready. Leak will fail > > then. Why not register later after device is ready? > > Probably no. > > - it would be better not to set device ready when register_shrinker failed. That's very rare so I won't be too worried. > - When the device isn't ready, ballooning won't happen, that is, > vb->num_pages will be 0, which results in shrinker_count=0 and shrinker_scan > won't be called. > > So I think it would be better to have shrinker registered before > device_ready. > > Best, > Wei