Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1731625pxb; Thu, 7 Oct 2021 14:00:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxVyI5duGW6MXCEuU5B+LyGZrwW4FN6vbEjo9F2mlzI6/dmtIEipYELNex/Vk6dqd2Yp2X X-Received: by 2002:a05:6402:2682:: with SMTP id w2mr9186563edd.185.1633640455628; Thu, 07 Oct 2021 14:00:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633640455; cv=none; d=google.com; s=arc-20160816; b=XGAxUcysYX+POvsvMLbXWVqyCiinsWagtm1kSc2tLSF3XDJDN/4YRJZLnf/BwHYNeR FNX6cC2Z1Ee+TMQ8dYc8F+z6sD5enmhiPwK7Qo79DKRTh1NzyyRJGixcUMe/Ic0UC+vg kslZ4Gs43yofsBC5f2J37LZYctUT0EY7BVWf3ybbD/9TyUleo1HYtzXZgr4yVdmo+HWs ajHvPy3SAms0fq4zO1bTV0brlr4HsBYLYdWldf+OwFTf4NuRwbh3TDzZIoxhSovK6Ysk DbVzXvzt3nK7RRzOsXD36jBizMwA7IttqvAPKOQVAuYHKKxyz87UMawgTcdSuuszv3I7 nKsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=RABX8J2srv3C6osF1FF6BJqf6QLlRmQ/+dUCynHymZs=; b=l3C3byrYAL6AHRCCqMVzRh36PY2oPM6BhrQDhAJRr/1OEgeEoZBPmGUdGF/O4pQcTi l59elXLpTK9H0XtkqRVNdbCslgcMIF2vA7e2D2ESEIWF8U28u/nX55RoVUDtrtmQEbzB A9i8J/05rKsD1VFqeNo3MB2TMXYnkiFGtpju00qJ9/nxTgfpjwuYkxFxdHC2Z5K0OVJm KsowwEZrHfmma0xjgMvBbWhuTHOxR6Y/tLIPjliowqFYDaPa4H0YAPHOHecF2LR+wVIR WUMSnzsVWj7nHEvToHJSOcm22B+h2vOB2tmd0c1530j6zio+nYDWK7qXtGhszpB+e6vp oQ7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="l//gb6pP"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ja7si462890ejc.324.2021.10.07.14.00.31; Thu, 07 Oct 2021 14:00:55 -0700 (PDT) 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=@infradead.org header.s=casper.20170209 header.b="l//gb6pP"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233168AbhJGU6C (ORCPT + 99 others); Thu, 7 Oct 2021 16:58:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232797AbhJGU6B (ORCPT ); Thu, 7 Oct 2021 16:58:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE538C061570 for ; Thu, 7 Oct 2021 13:56:07 -0700 (PDT) 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.