Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2258283ybg; Thu, 24 Oct 2019 07:13:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyBWiGFaJ1gc7qll1C2Q7bt8HTb9QKCaYYJso/leHL6XxMRrwkZUrYJPjZMO4qqYgerS7Us X-Received: by 2002:a50:d717:: with SMTP id t23mr2099622edi.231.1571926388186; Thu, 24 Oct 2019 07:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571926388; cv=none; d=google.com; s=arc-20160816; b=BvijGpo3+uwj4SIP6cE7Ymy0/D3YVxZl5WzLrbAwLSjM7ywU4UVTrB+OAqWlWrN6Ps VKmTmjDZTPFbcGPjw66/2ir8bGzrwN1ml7jialAwrkpZtZU49WUE1gNG3ySvRFQL4nlL MHQPmXf80N6OGLZJoPBtLLxHBmAUD3bzHMgGNZ+9xYZLDh3tHQsc1eZ3OiXO6C42myNI myuDnTDZVRrbGBvkyMl0Fo+4+AGf8KEyfN1IbDSTpE6RHNmXKz/LeWn8iFXX7NsQaj/A PVs8FpKJ6JGZcA4EN301g/s+1u1bGv70Hmrudqe9nQ90yZ8osdMOQrYQ7ab3jVOHJW6f WFfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=0dQGrpqMo4Ibli5Nqpa1FPIxIzUDeRaW7GzwMvozZDk=; b=k8SimfDpcO1tyMxFG8hhuqA1O2fB0TUBGCjoA8QSV3FTSL3KeapFI29IH80N9EOgBw qRppTAS2QGEKcjd7pPM+MvqSfp4zY+dZrb6nKmeBBS1iSqx6+KY56MyZRKaz4/ZVZzfz JaXpbYWB8DgxKdTWPkk9XPJnZ9UzCh4PFhe7u8y+Li2oLA1aHiBmT8lelsSOrZILpmru y2F4GjA1IrI/Ih809H7rb7UN9YzoGrvw4bA7KBtBB5QzBXxGnqaCscLTjbNWMnYmaLaA YbyIXPvsjO3V7TuSdJ6PSwp+6pJWB7U6GBT1r1+IylOXkMjlhUlmGPciVrdF5oG3RZel 3ANQ== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cb1si679016ejb.200.2019.10.24.07.12.28; Thu, 24 Oct 2019 07:13:08 -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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406668AbfJWUDJ (ORCPT + 99 others); Wed, 23 Oct 2019 16:03:09 -0400 Received: from mx2.suse.de ([195.135.220.15]:43436 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2405410AbfJWUDC (ORCPT ); Wed, 23 Oct 2019 16:03:02 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 53304B545; Wed, 23 Oct 2019 20:02:59 +0000 (UTC) Date: Wed, 23 Oct 2019 22:02:56 +0200 From: Michal Hocko To: Waiman Long Cc: Andrew Morton , Mel Gorman , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Johannes Weiner , Roman Gushchin , Vlastimil Babka , Konstantin Khlebnikov , Jann Horn , Song Liu , Greg Kroah-Hartman , Rafael Aquini Subject: Re: [PATCH 1/2] mm, vmstat: Release zone lock more frequently when reading /proc/pagetypeinfo Message-ID: <20191023200256.GP17610@dhcp22.suse.cz> References: <20191023102737.32274-3-mhocko@kernel.org> <20191023173423.12532-1-longman@redhat.com> <20191023180121.GN17610@dhcp22.suse.cz> <58a9adaf-9a1c-398b-dce1-cb30997807c1@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <58a9adaf-9a1c-398b-dce1-cb30997807c1@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 23-10-19 14:14:14, Waiman Long wrote: > On 10/23/19 2:01 PM, Michal Hocko wrote: > > On Wed 23-10-19 13:34:22, Waiman Long wrote: > >> With a threshold of 100000, it is still possible that the zone lock > >> will be held for a very long time in the worst case scenario where all > >> the counts are just below the threshold. With up to 6 migration types > >> and 11 orders, it means up to 6.6 millions. > >> > >> Track the total number of list iterations done since the acquisition > >> of the zone lock and release it whenever 100000 iterations or more have > >> been completed. This will cap the lock hold time to no more than 200,000 > >> list iterations. > >> > >> Signed-off-by: Waiman Long > >> --- > >> mm/vmstat.c | 18 ++++++++++++++---- > >> 1 file changed, 14 insertions(+), 4 deletions(-) > >> > >> diff --git a/mm/vmstat.c b/mm/vmstat.c > >> index 57ba091e5460..c5b82fdf54af 100644 > >> --- a/mm/vmstat.c > >> +++ b/mm/vmstat.c > >> @@ -1373,6 +1373,7 @@ static void pagetypeinfo_showfree_print(struct seq_file *m, > >> pg_data_t *pgdat, struct zone *zone) > >> { > >> int order, mtype; > >> + unsigned long iteration_count = 0; > >> > >> for (mtype = 0; mtype < MIGRATE_TYPES; mtype++) { > >> seq_printf(m, "Node %4d, zone %8s, type %12s ", > >> @@ -1397,15 +1398,24 @@ static void pagetypeinfo_showfree_print(struct seq_file *m, > >> * of pages in this order should be more than > >> * sufficient > >> */ > >> - if (++freecount >= 100000) { > >> + if (++freecount > 100000) { > >> overflow = true; > >> - spin_unlock_irq(&zone->lock); > >> - cond_resched(); > >> - spin_lock_irq(&zone->lock); > >> + freecount--; > >> break; > >> } > >> } > >> seq_printf(m, "%s%6lu ", overflow ? ">" : "", freecount); > >> + /* > >> + * Take a break and release the zone lock when > >> + * 100000 or more entries have been iterated. > >> + */ > >> + iteration_count += freecount; > >> + if (iteration_count >= 100000) { > >> + iteration_count = 0; > >> + spin_unlock_irq(&zone->lock); > >> + cond_resched(); > >> + spin_lock_irq(&zone->lock); > >> + } > > Aren't you overengineering this a bit? If you are still worried then we > > can simply cond_resched for each order > > diff --git a/mm/vmstat.c b/mm/vmstat.c > > index c156ce24a322..ddb89f4e0486 100644 > > --- a/mm/vmstat.c > > +++ b/mm/vmstat.c > > @@ -1399,13 +1399,13 @@ static void pagetypeinfo_showfree_print(struct seq_file *m, > > */ > > if (++freecount >= 100000) { > > overflow = true; > > - spin_unlock_irq(&zone->lock); > > - cond_resched(); > > - spin_lock_irq(&zone->lock); > > break; > > } > > } > > seq_printf(m, "%s%6lu ", overflow ? ">" : "", freecount); > > + spin_unlock_irq(&zone->lock); > > + cond_resched(); > > + spin_lock_irq(&zone->lock); > > } > > seq_putc(m, '\n'); > > } > > > > I do not have a strong opinion here but I can fold this into my patch 2. > > If the free list is empty or is very short, there is probably no need to > release and reacquire the lock. How about adding a check for a lower > bound like: Again, does it really make any sense to micro optimize something like this. It is a debugging tool. I would rather go simple. -- Michal Hocko SUSE Labs