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 X-Spam-Level: X-Spam-Status: No, score=-4.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 399FDC4346E for ; Tue, 29 Sep 2020 04:47:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9BACF207F7 for ; Tue, 29 Sep 2020 04:46:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="KoNHW/UU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BACF207F7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E37736B005C; Tue, 29 Sep 2020 00:46:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE82C6B005D; Tue, 29 Sep 2020 00:46:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB0666B0062; Tue, 29 Sep 2020 00:46:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id B59F56B005C for ; Tue, 29 Sep 2020 00:46:58 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 72FAA8249980 for ; Tue, 29 Sep 2020 04:46:58 +0000 (UTC) X-FDA: 77314864116.02.air84_480ebe327187 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 4EADF10143A0B for ; Tue, 29 Sep 2020 04:46:58 +0000 (UTC) X-HE-Tag: air84_480ebe327187 X-Filterd-Recvd-Size: 4001 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Sep 2020 04:46:57 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9D3D220BED; Tue, 29 Sep 2020 04:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601354816; bh=2JNWFFvPkQNc9xCN+nF98rnXbVrQkiwRrBXG/E5KEk8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KoNHW/UUp9UyLBeBeS36wRdwvVFTd0PNBptoUsT0g8GDrHs6XzDM4pL+Z2EAm8VWi zTzu2xltWbytaRQj/OL/K3SFKDlywj2HE3dqQAxDnDKB9oalDb47atfGcWejqApmIj WhhTPbck9eFkNgvi/bKlWI7vFVtFGO0XuKC/o6nE= Date: Mon, 28 Sep 2020 21:46:56 -0700 From: Andrew Morton To: Matthew Wilcox Cc: Nick Piggin , Hugh Dickins , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] page_alloc: Fix freeing non-compound pages Message-Id: <20200928214656.be4a0f29961589c074e518fa@linux-foundation.org> In-Reply-To: <20200929011719.GD30994@casper.infradead.org> References: <20200926213919.26642-1-willy@infradead.org> <20200928180307.7573f3b6128b5e3007dfc9f0@linux-foundation.org> <20200929011719.GD30994@casper.infradead.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Tue, 29 Sep 2020 02:17:19 +0100 Matthew Wilcox wrote: > On Mon, Sep 28, 2020 at 06:03:07PM -0700, Andrew Morton wrote: > > On Sat, 26 Sep 2020 22:39:19 +0100 "Matthew Wilcox (Oracle)" wrote: > > > > > Here is a very rare race which leaks memory: > > > > Not worth a cc:stable? > > Yes, it probably should have been. Have you a feeling for how often this occurs? > I just assume the stablebot will > pick up anything that has a Fixes: tag. We asked them not to do that for mm/ patches. Crazy stuff was getting backported. > > > > > > --- a/mm/page_alloc.c > > > +++ b/mm/page_alloc.c > > > @@ -4947,6 +4947,9 @@ void __free_pages(struct page *page, unsigned int order) > > > { > > > if (put_page_testzero(page)) > > > free_the_page(page, order); > > > + else if (!PageHead(page)) > > > + while (order-- > 0) > > > + free_the_page(page + (1 << order), order); > > > > Well that's weird and scary looking. `page' has non-zero refcount yet > > we go and free random followon pages. Methinks it merits an > > explanatory comment? > > Well, poot. I lost that comment in the shuffling of patches. In a > different tree, I have: > > @@ -4943,10 +4943,19 @@ static inline void free_the_page(struct page *page, unsi > gned int order) > __free_pages_ok(page, order); > } > > +/* > + * If we free a non-compound allocation, another thread may have a "non-compound, higher-order", I suggest? > + * speculative reference to the first page. It has no way of knowing > + * about the rest of the allocation, so we have to free all but the > + * first page here. > + */ > void __free_pages(struct page *page, unsigned int order) > { > if (put_page_testzero(page)) > free_the_page(page, order); > + else if (!PageHead(page)) > + while (order-- > 0) > + free_the_page(page + (1 << order), order); > } > EXPORT_SYMBOL(__free_pages); > > > Although I'm now thinking of making that comment into kernel-doc and > turning it into advice to the caller rather than an internal note to > other mm developers. hm. But what action could the caller take? The explanatory comment seems OK to me.