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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6C26C71133 for ; Fri, 25 Aug 2023 04:10:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240889AbjHYEKG (ORCPT ); Fri, 25 Aug 2023 00:10:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240684AbjHYEJ7 (ORCPT ); Fri, 25 Aug 2023 00:09:59 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6F091FCE for ; Thu, 24 Aug 2023 21:09:56 -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=9AcvZSxbpImY+QilwnlW7s4QTbMInM9uihUNGJjwdrU=; b=cAMCZehh5ClWBMQce2ZuCMk8fG e71WxYyp3sgEjdkuiE0zMFtRxqyXix9iEicFES4G9a63BBP3426wWIiCd+Rfx8FpF95iYHdJscLpa /xeqOsiCiMCsTO85X+5h6+0jm2d9FR0XvBnkklyy8V9ph6n9sJ7drtoZjjXvFa/SDmFYKQh1Cirf/ U/vmMElX6LfqEMhBcS/oLgXPBrNv0AOcEdTPq3cJNbiW6NTlhOHgxp6Uiv1becLHj2zdCTh+glVea OkYtiZEyTi3oETlxN8UuyMilBaFrH9Yf9kma97XkhBRWXPIB16RLcAIa8VRBLwmwJuYp6Gkypg7bQ lZFkKhMg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qZO8N-00Evmw-OC; Fri, 25 Aug 2023 04:09:19 +0000 Date: Fri, 25 Aug 2023 05:09:19 +0100 From: Matthew Wilcox To: Ryan Roberts Cc: Will Deacon , "Aneesh Kumar K.V" , Andrew Morton , Nick Piggin , Peter Zijlstra , Christian Borntraeger , Sven Schnelle , Arnd Bergmann , David Hildenbrand , Yu Zhao , "Kirill A. Shutemov" , Yin Fengwei , Yang Shi , "Huang, Ying" , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 4/4] mm/mmu_gather: Store and process pages in contig ranges Message-ID: References: <20230810103332.3062143-1-ryan.roberts@arm.com> <20230810103332.3062143-5-ryan.roberts@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230810103332.3062143-5-ryan.roberts@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 10, 2023 at 11:33:32AM +0100, Ryan Roberts wrote: > +void folios_put_refs(struct folio_range *folios, int nr) > +{ > + int i; > + LIST_HEAD(pages_to_free); > + struct lruvec *lruvec = NULL; > + unsigned long flags = 0; > + unsigned int lock_batch; > + > + for (i = 0; i < nr; i++) { > + struct folio *folio = page_folio(folios[i].start); > + int refs = folios[i].end - folios[i].start; > + > + /* > + * Make sure the IRQ-safe lock-holding time does not get > + * excessive with a continuous string of pages from the > + * same lruvec. The lock is held only if lruvec != NULL. > + */ > + if (lruvec && ++lock_batch == SWAP_CLUSTER_MAX) { > + unlock_page_lruvec_irqrestore(lruvec, flags); > + lruvec = NULL; > + } > + > + if (is_huge_zero_page(&folio->page)) > + continue; > + > + if (folio_is_zone_device(folio)) { > + if (lruvec) { > + unlock_page_lruvec_irqrestore(lruvec, flags); > + lruvec = NULL; > + } > + if (put_devmap_managed_page(&folio->page)) > + continue; > + if (folio_put_testzero(folio)) We're only putting one ref for the zone_device folios? Surely this should be ref_sub_and_test like below? > + free_zone_device_page(&folio->page); > + continue; > + } > + > + if (!folio_ref_sub_and_test(folio, refs)) > + continue; > + > + if (folio_test_large(folio)) { > + if (lruvec) { > + unlock_page_lruvec_irqrestore(lruvec, flags); > + lruvec = NULL; > + } > + __folio_put_large(folio); > + continue; > + } > + > + if (folio_test_lru(folio)) { > + struct lruvec *prev_lruvec = lruvec; > + > + lruvec = folio_lruvec_relock_irqsave(folio, lruvec, > + &flags); > + if (prev_lruvec != lruvec) > + lock_batch = 0; > + > + lruvec_del_folio(lruvec, folio); > + __folio_clear_lru_flags(folio); > + } > + > + /* > + * In rare cases, when truncation or holepunching raced with > + * munlock after VM_LOCKED was cleared, Mlocked may still be > + * found set here. This does not indicate a problem, unless > + * "unevictable_pgs_cleared" appears worryingly large. > + */ > + if (unlikely(folio_test_mlocked(folio))) { > + __folio_clear_mlocked(folio); > + zone_stat_sub_folio(folio, NR_MLOCK); > + count_vm_event(UNEVICTABLE_PGCLEARED); > + } You'll be glad to know I've factored out a nice little helper for that.