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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83B18C433FE for ; Thu, 7 Oct 2021 20:57:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2058761212 for ; Thu, 7 Oct 2021 20:57:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2058761212 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5C3016B006C; Thu, 7 Oct 2021 16:57:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 54B406B0071; Thu, 7 Oct 2021 16:57:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EC386B0072; Thu, 7 Oct 2021 16:57:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0125.hostedemail.com [216.40.44.125]) by kanga.kvack.org (Postfix) with ESMTP id 2C3D66B006C for ; Thu, 7 Oct 2021 16:57:09 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D79BA31E50 for ; Thu, 7 Oct 2021 20:57:08 +0000 (UTC) X-FDA: 78670851336.22.584DFBD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id 1A4759001B5D for ; Thu, 7 Oct 2021 20:56:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=RABX8J2srv3C6osF1FF6BJqf6QLlRmQ/+dUCynHymZs=; b=l//gb6pP1+4/TOdVyem3gQfS8g 6vpf+7I7xyfdnQpRyUKORxZxwQc9Xlv1pSsmyVxcQNZwmIHKEhR3FLPaEQ+QH7p2dzVZ3OMFW7C4K sXKn1qIs3U/LqBCTzVhJVCvSbFvHmhM9KWJxH2fAS22efMubNDmWyz/MZqWzWlbkhh/e2JJ5G9huV t2JUJ1BClJ+TS6OsJv/w/oGwRmchSTOcgisW3HYBB5h1TbtBjZ6dr1DpGgRLRIB+TkhQldRv6ElcR UTw2bRuPdLbS+oo0y/O8Xzze8byfl9japz7MGYpwfjGcNnhZKXm50CLiZfNq+Ey3A+ekLCBo4dfLq zFjIaDog==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYaQD-002SIQ-3z; Thu, 07 Oct 2021 20:55:27 +0000 Date: Thu, 7 Oct 2021 21:55:21 +0100 From: Matthew Wilcox To: Andrew Morton Cc: Mel Gorman , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: Optimise put_pages_list() Message-ID: References: <20211007192138.561673-1-willy@infradead.org> <20211007123109.6a49c7c625e414acf7546c89@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211007123109.6a49c7c625e414acf7546c89@linux-foundation.org> X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1A4759001B5D X-Stat-Signature: w77nbrzoui8hamk9ft5r36a8skzi7zy9 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="l//gb6pP"; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1633640167-772090 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Oct 07, 2021 at 12:31:09PM -0700, Andrew Morton wrote: > On Thu, 7 Oct 2021 20:21:37 +0100 "Matthew Wilcox (Oracle)" wrote: > > > Instead of calling put_page() one page at a time, pop pages off > > the list if their refcount was too high and pass the remainder to > > put_unref_page_list(). This should be a speed improvement, but I have > > no measurements to support that. Current callers do not care about > > performance, but I hope to add some which do. > > Don't you think it would actually be slower to take an additional pass > across the list? If the list is long enough to cause cache thrashing. > Maybe it's faster for small lists. My first response is an appeal to authority -- release_pages() does this same thing. Only it takes an array, constructs a list and passes that to put_unref_page_list(). So if that's slower (and lists _are_ slower than arrays), we should have a put_unref_page_array(). Second, we can follow through the code paths and reason about it. Before: while (!list_empty(pages)) { put_page(victim); page = compound_head(page); if (put_page_testzero(page)) __put_page(page); __put_single_page(page) __page_cache_release(page); mem_cgroup_uncharge(page); <--- free_unref_page(page, 0); free_unref_page_prepare() local_lock_irqsave(&pagesets.lock, flags); free_unref_page_commit(page, pfn, migratetype, order); local_unlock_irqrestore(&pagesets.lock, flags); After: free_unref_page_list(pages); list_for_each_entry_safe(page, next, list, lru) { if (!free_unref_page_prepare(page, pfn, 0)) { } local_lock_irqsave(&pagesets.lock, flags); list_for_each_entry_safe(page, next, list, lru) { free_unref_page_commit() } local_unlock_irqrestore(&pagesets.lock, flags); So the major win here is that we disable/enable interrupts once per batch rather than once per page.