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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2466DC4345F for ; Thu, 25 Apr 2024 03:39:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A484B6B0085; Wed, 24 Apr 2024 23:39:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F6BA6B0088; Wed, 24 Apr 2024 23:39:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BDF76B0089; Wed, 24 Apr 2024 23:39:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6D51F6B0085 for ; Wed, 24 Apr 2024 23:39:21 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1BDF31A0B43 for ; Thu, 25 Apr 2024 03:39:21 +0000 (UTC) X-FDA: 82046648922.03.BD51A9E Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf22.hostedemail.com (Postfix) with ESMTP id 7BC6FC0007 for ; Thu, 25 Apr 2024 03:39:17 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=sJ1G0w6v; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714016359; a=rsa-sha256; cv=none; b=3XiGe4LsnrY3Bdd6Vy0YWdimrHg9xqynxB4BIGgN/ll93C1ABiPgN7I5ZfqtMyaAeTm91L RzwKfclHnWCTHB7VQhVVHxI4MvODTZTg6wraejXevEZuHA1SuGfBgKdw5JLUcSqje8crTh egtyqh+iqJsMlyKq0KKzXIKILf7CAn0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=sJ1G0w6v; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714016359; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=K1VU65G3d23POdnTNYbY3DVz5dDx2r5Xy6VTdS9z7XA=; b=Svf+F6tSJzPyHKhb7fykBA2gRgc6GvqLT77rYVH4EkjjRwXNG/DN/cVhLcfTP4tyhBr9wd +FQVeWdUzqztwf/k1JwjGPSBNcZWqArzbBbqSVc7q7xUYLQkRSoqZsVqs6vqqJ4uNLrKe6 skjNjvuASeJjiXESLoT0NihuivevTB8= 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=K1VU65G3d23POdnTNYbY3DVz5dDx2r5Xy6VTdS9z7XA=; b=sJ1G0w6vGeM6W+U5dwJR7sr5ey K68beExox3aRpBNuD+jACfcK5FWzElB59E1l6FUm/r5OknBDWYouwShrcumKKES1BJo/mrUvE0d4I ArOKb1q5m07m0EEzGL8165XXzi4Hhz1AVmvN575DhhOtpKJ4ennpu/JzUq5yIfu5ZQNGm3BQmUcry mqbQXFXAkcxhopzdIFHhw/XG8jTWNnnSyAzX/SwhAmdFpbXzDfiEjph+LCqmR6wjmTJQ5q2bwG1iG k22oeUodkYwzJ9RNHr5UISMu7XeIsH+8+yjIA0uz4Peodyo5ZRYgalEgcbEedmbP/UVWW0IrcyrAT AaVNH6Gg==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzpx5-00000002FBx-0RDl; Thu, 25 Apr 2024 03:39:15 +0000 Date: Thu, 25 Apr 2024 04:39:14 +0100 From: Matthew Wilcox To: Peter Xu Cc: Andrew Morton , linux-mm@kvack.org, Alex Williamson Subject: Re: [PATCH 1/5] mm: Free non-hugetlb large folios in a batch Message-ID: References: <20240405153228.2563754-1-willy@infradead.org> <20240405153228.2563754-2-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7BC6FC0007 X-Stat-Signature: qrzbhd3af6t6ef9g347dmy86gr8hhcw7 X-Rspam-User: X-HE-Tag: 1714016357-111717 X-HE-Meta: U2FsdGVkX1/pkSAlNsII3ESrLlpVyI0ZXzUWNNBgp3//z6hDOYaQe+Moi1Fp+m2meussz4BG7rSIAirt6nJXTEIWeOrFGDCq2dmJBxeVa/PT3K5LQ6N2UxNbvaYcGpAR9eyiiY6E+LHKq5GIPXlEkIUtGTxtsglso5rHGvU6Zer05m5ZXXPO48VTlam4JqyZhIdAMMiqDTpsTJ7sDULLYdUfm/GV9sscPODHTZ+K2OZnBfgdcb+POj9pPWcr1I2JdjB0RS8iMdP6UTMb87d9xQ0YtdS9mMElDFDpknqgYIU+Sxc8O/wv65QBQw8j9lXO3/eZ5Yxfqpfj5jT4MYkdwJIRP93i0Jku5H0GWXyxEuQ3BFO0rybloJzGCtp9xTtFYyoVLHhswo8icYeQdpeVUErym4jUoDjUB31V64YQbd0POUWIbAXlX5tkKTYRkiGcqfO3qi7c1TjSLclF5UqqmvZFwfjz0rr4M08ypGQv/C0MZzRqITbajYnZrVL/wFTc3e8U+teJRMT0gT5sPDI/Yje6oK4xqVPNczQT4Rqv6usgOebZx/ktBCRRvCbwOGpuxQU1hYj2Fh1oVGyADuz5Bz5bG6SNsKe7DfHL9a30emsAGLmzg00NRQJJGI5HaM0RyRiciCdOY/SkP06jDNJCVqltpi9cv7FYBY3JmstDizN4nFHhKrugudeii6wl1NkfPV6YYQhjFFph+z08bV09LOjnm8d5reXfUIZrZaz9gyTlxVpu+44A5ZkqbE3S7Jy8hV9KKBJgt06Vl1cJA4OSmuOUohjOVSqJhA+b3y2nKnLehmdLjXl5oQzR1Whb88d/eKTyuVA7ieSF6qRM6joTKvrzrYIcapyBK1twjmyE8RPO0eN+mxKBLYyS/lLgUN6gpKUjVZZKoLy3gehCj8E9KCkuiCp50hXlB8SQCzlISxRey97GnsrMCSWcWTsN+DJ7HtYevDluTzX7+eIvSym tU5c2vP+ JAUuw5tTtDon3QaBBRoUaQojuj8hcMeRykZ9V/TvKhKoH0PFUYZ9vbOyAMq54ca5+3kc0rcvATBUuNaM33x56M2JWWajUlilm+Jrz64J2elSAFFK+/phsdCsndZ8Nq5bzwKd92WuWnaAuK0+PI4wEqpQ9Ng+95IEPYUlgwUsufQ89EfRadu1lWWWUZEOI4wx2n1H+ 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: List-Subscribe: List-Unsubscribe: On Wed, Apr 24, 2024 at 11:20:28AM -0400, Peter Xu wrote: > On Fri, Apr 05, 2024 at 04:32:23PM +0100, Matthew Wilcox (Oracle) wrote: > > free_unref_folios() can now handle non-hugetlb large folios, so keep > > normal large folios in the batch. hugetlb folios still need to be > > handled specially. I believe that folios freed using put_pages_list() > > cannot be accounted to a memcg (or the small folios would trip the "page > > still charged to cgroup" warning), but put an assertion in to check that. > > There's such user, iommu uses put_pages_list() to free IOMMU pgtables, and > they can be memcg accounted; since 2023 iommu_map switched to use > GFP_KERNEL_ACCOUNT. > > I hit below panic when testing my local branch over mm-everthing when > running some VFIO workloads. > > For this specific vfio use case, see 160912fc3d4a ("vfio/type1: account > iommu allocations"). > > I think we should remove the VM_BUG_ON_FOLIO() line, as the memcg will then > be properly taken care of later in free_pages_prepare(). Fixup attached at > the end that will fix this crash for me. Yes, I think you're right. I was concerned about the deferred split list / memcg charge problem, but (a) page table pages can't ever be on the deferred split list, (b) just passing them through to free_unref_folios() works fine. The problem was that folios_put_refs() was uncharging a batch before passing them to free_unref_folios(). That does bring up the question though ... should we be uncharging these folios as a batch for better performance? Do you have a workload which frees a lot of page tables? Presumably an exit would do that. If so, does adding a call to mem_cgroup_uncharge_folios() before calling free_unref_folios() improve performance in any noticable way? In the meantime, this patch: Reviewed-by: Matthew Wilcox (Oracle) although I think Andrew will just fold it into "mm: free non-hugetlb large folios in a batch" Andrew, if you do do that, please also edit out the last couple of sentences from the commit message: free_unref_folios() can now handle non-hugetlb large folios, so keep normal large folios in the batch. hugetlb folios still need to be handled - specially. I believe that folios freed using put_pages_list() cannot be - accounted to a memcg (or the small folios would trip the "page still - charged to cgroup" warning), but put an assertion in to check that. + specially.