Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp610823lqp; Thu, 21 Mar 2024 10:09:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeVcNUPD1k9obki/lhx5me2tZGUJDBX64uAZlnvyEd+gK6BglAQThJ7QmRET72A2a+pa9jRwd9JAYQkxnYTxlg/UXlYCTe7m2T4Wk63g== X-Google-Smtp-Source: AGHT+IHI0nJZaO07O0IkB5sppul0Jv5/LVmRUyVtr8cV9utEwg06p0PozEzrHD7+o3gzh4R+Cdbj X-Received: by 2002:a05:6a20:43a5:b0:1a3:66b1:fad2 with SMTP id i37-20020a056a2043a500b001a366b1fad2mr5204969pzl.13.1711040940708; Thu, 21 Mar 2024 10:09:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711040940; cv=pass; d=google.com; s=arc-20160816; b=eQsXknJr0KYqMgCEcjpieShZMXJHomprNz8l2yFktzyg6LhgTlmoiM3sDvjo+zvmL0 M5WnZQXzi5/myMmAVVpOK0tMV9wgmjnZX53/pH0PeLQL+xt0Jhx+xbYPl2jachXm/Ig4 UTaZZHWW0F8ATgDa/waRkzFztLtGghi6eEoEAN/15W971tNdibAuNCDmiz4Zl8A+ge/R uqBkbhGdCX77uDM0wVNqsfReW9HdtE2k+4ib09wB/I7Ecb11MWn9WJoB6E5f4ipS+ORy pErh7ZIu/NVx7gBtbUn0mThx3i/A37z/7JhFGrOISO3YnhMFMr+CkGtd4aMYaBOJZrcn thhw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=grrtrTSALnjlmhusaSmHuxgXHvy0PaqBERbW2XOksq0=; fh=smj1+IZujXiiBWQPOPcy2FzTFvSfcA84M//ihXQ940Q=; b=F538TxKgVBSczmDC2qBDU4CAguc5HIkFiNXhPCX0vc23lcdx+o/bjRJIAokXQ6VOsW JM9h0xKkkiGYt/Weligo+TStk543p7XkFOzSpl6ABAHxNcuhvbHup/5wmClbn4pbwAEE FTS925xwh6PXYq6zjtEQmYJvTcBiKXCswDr8zd8Oapa2kpUdynnnJGItqa385jFKwUd6 uBJ9iraBibIWWf5HKOTTc7ywy7aiXWms3jhSP815YXybwXl/N0Atb6egpRrSr/v/cQCX dqoE9q+YLAgbrLMbYs2jgcb/h23FqV16xWlgnxqr8Ep2DuBNaJ9u4j5jrP9nwtBmVt3+ JyOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=KvEPlgWf; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-110459-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110459-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p186-20020a6342c3000000b005dcbb6b06bbsi137903pga.292.2024.03.21.10.09.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 10:09:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110459-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=KvEPlgWf; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-110459-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110459-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2F013281419 for ; Thu, 21 Mar 2024 17:08:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 455E31369A6; Thu, 21 Mar 2024 17:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="KvEPlgWf" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66344136987; Thu, 21 Mar 2024 17:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711040676; cv=none; b=qt9bviJcKKW3Up84bm87z6LegY4SJWV3r/CSDIP4vieK8ldMajdKpAKYFYQQM+zB3EanUgvRsFKlhajWlbMaBeRo6Nr4LyjR0VwEzeLJPA7LH7xRKfrGBv9BPYOz+8k8+a1Qz2r/F1soKqc01otNm/0y3r2CPlLcdbS3kf5ypVs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711040676; c=relaxed/simple; bh=3a9JT906FSpCQ7vJqxUgfHklkTuG5j6K5wk2J4O7OhU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qyKmGMjcA+RUQm0P5E49w5sHuuqsffLNm6tfh2eeYS7d8RayIKC1l5fXtv2SFnUJDiNNv2C+is0VeFWhLQ50gQPp4xD13/ovoyOe8sajAWRgbwBZCu91BIc7VY4jjYLdE3jVErp4P2KRD3IOWmwO+E6AqXvQOjVuUkDbZeX2Uzg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=KvEPlgWf; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org 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=grrtrTSALnjlmhusaSmHuxgXHvy0PaqBERbW2XOksq0=; b=KvEPlgWfmkZUIIq92E2QZaaPjt VZnhAGfpOn0TI3GH3pJGkjjDKFGgCnRVoZXS0BnLBMeD1ysCOzMVESTZFH2ZdWFKAFjnnJlrR5uI5 zf/WrZhxkWHn8GwTIdG1zh3HdqNwj7dYkA4xHqWXF2ODLbgR0RW1k0j0tjtwj8yFbkmKVhWzVS3Y6 TOQjkHw4Zx3NY/0ztZG4Etw6zBRqBCBnusj92jv7s9yw0pEcoFBeAfAg1WXXNifPuRvLrVhXYEOSk xN0Lo7fv/rEgNH7tG5XAA+oXF4lQKAZALSzMZaggWOEPJTF9gdOPdlAxh7rTpUSFkYhhy2AZFvZTI zY4tyT5A==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnLpl-00000007AzI-40SJ; Thu, 21 Mar 2024 17:04:06 +0000 Date: Thu, 21 Mar 2024 17:04:05 +0000 From: Matthew Wilcox To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, liam.howlett@oracle.com, penguin-kernel@i-love.sakura.ne.jp, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, jhubbard@nvidia.com, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, songmuchun@bytedance.com, jbaron@akamai.com, aliceryhl@google.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org Subject: Re: [PATCH v6 20/37] mm: fix non-compound multi-order memory accounting in __free_pages Message-ID: References: <20240321163705.3067592-1-surenb@google.com> <20240321163705.3067592-21-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Mar 21, 2024 at 04:48:53PM +0000, Matthew Wilcox wrote: > On Thu, Mar 21, 2024 at 09:36:42AM -0700, Suren Baghdasaryan wrote: > > +++ b/mm/page_alloc.c > > @@ -4700,12 +4700,15 @@ void __free_pages(struct page *page, unsigned int order) > > { > > /* get PageHead before we drop reference */ > > int head = PageHead(page); > > + struct alloc_tag *tag = pgalloc_tag_get(page); > > > > if (put_page_testzero(page)) > > free_the_page(page, order); > > - else if (!head) > > + else if (!head) { > > + pgalloc_tag_sub_pages(tag, (1 << order) - 1); > > while (order-- > 0) > > free_the_page(page + (1 << order), order); > > + } > > Why do you need these new functions instead of just: > > + else if (!head) { > + pgalloc_tag_sub(page, (1 << order) - 1); > while (order-- > 0) > free_the_page(page + (1 << order), order); > + } Actually, I'm not sure this is safe (I don't fully understand codetags, so it may be safe). What can happen is that the put_page() can come in before the pgalloc_tag_sub(), and then that page can be allocated again. Will that cause confusion?