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=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 1D47FC2D0E2 for ; Tue, 22 Sep 2020 13:12:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 622302399A for ; Tue, 22 Sep 2020 13:12:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="AH7KDxVe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 622302399A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7B91190007D; Tue, 22 Sep 2020 09:12:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7437C900063; Tue, 22 Sep 2020 09:12:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60A2090007D; Tue, 22 Sep 2020 09:12:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0235.hostedemail.com [216.40.44.235]) by kanga.kvack.org (Postfix) with ESMTP id 45445900063 for ; Tue, 22 Sep 2020 09:12:27 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id F007F1EE6 for ; Tue, 22 Sep 2020 13:12:26 +0000 (UTC) X-FDA: 77290736292.11.crown81_41001602714e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id C6E40180F8B81 for ; Tue, 22 Sep 2020 13:12:26 +0000 (UTC) X-HE-Tag: crown81_41001602714e X-Filterd-Recvd-Size: 3524 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 13:12:26 +0000 (UTC) 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=mgM5uzaSNrajO/zmXuTMlF0IG2+kugTiW7N4HeNawOI=; b=AH7KDxVe9BrQDobyPPfRLZw1iV bIcjb7hiMNUPfC4JRWu9NUEEyzqpmdVeWcnSegoVX73Bms5Qoc61KhSAACLFSVOJsN8Vusbhy93z3 QigFq+bs8cxEaKiBqpKnPheLltJbrC9eY+VHQho5Aln6iz0NfxnhXN8KGPLb/W8NzyVsEiEg2Ricf upbxPBoNALYh6XbLqmmo4Kjl3BXKsVr288YDCmqIoAwCYyBD630AWvQydo2N9FEKJVRpVZ06FHnQL MwjHS5n2pY7ZE//x2lKJLwl9UvTsLhJa76Zb4geTssmaA8LOVZrzN++Q7X1Q7CgnIAYR362tDWMQT EuZZD5fQ==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKi5k-0003Tz-3k; Tue, 22 Sep 2020 13:12:20 +0000 Date: Tue, 22 Sep 2020 14:12:19 +0100 From: Matthew Wilcox To: Vlastimil Babka Cc: linux-mm@kvack.org, Ira Weiny , "Kirill A. Shutemov" Subject: Re: Rare memory leakage Message-ID: <20200922131219.GE32101@casper.infradead.org> References: <20200922031215.GZ32101@casper.infradead.org> <8f294420-93c9-618a-6128-432b7035642b@suse.cz> <20200922114451.GC32101@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200922114451.GC32101@casper.infradead.org> 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, Sep 22, 2020 at 12:44:51PM +0100, Matthew Wilcox wrote: > I've just kicked off a test run using this: > > +/* > + * Have to be careful when freeing a non-compound allocation in case somebody > + * else takes a temporary reference on the first page and then calls put_page() > + */ > void __free_pages(struct page *page, unsigned int order) > { > - if (put_page_testzero(page)) > - free_the_page(page, order); > + if (likely(page_ref_freeze(page, 1))) > + goto free; > + if (likely(order == 0 || PageHead(page))) { > + if (put_page_testzero(page)) > + goto free; > + return; > + } > + > + prep_compound_page(page, order); > + put_page(page); > + return; > +free: > + free_the_page(page, order); > } > EXPORT_SYMBOL(__free_pages); > > > > Better ideas? > > > > IMHO, alloc_pages() with order > 0 and without __GFP_COMP is a weird beast. In > > that case it would be probably best to refcount each base page separately. I > > don't know how many assumptions this would break :/ > > You sound like a man who's never dealt with device drivers. Multiorder, > non-compound allocations are the norm in that world. This seems easier to reason about: +/* + * If we free a non-compound allocation, another thread may have a + * transient 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 + while (order-- > 0) + free_the_page(page + 1 << order, order); } EXPORT_SYMBOL(__free_pages);