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.8 required=3.0 tests=BAYES_00, 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 3CFB6C4727D for ; Wed, 23 Sep 2020 06:46:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C16D621D43 for ; Wed, 23 Sep 2020 06:46:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C16D621D43 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 104C86B0003; Wed, 23 Sep 2020 02:46:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B5F46B0055; Wed, 23 Sep 2020 02:46:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE7B76B005A; Wed, 23 Sep 2020 02:46:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0179.hostedemail.com [216.40.44.179]) by kanga.kvack.org (Postfix) with ESMTP id D4A1D6B0003 for ; Wed, 23 Sep 2020 02:46:11 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9E09D3625 for ; Wed, 23 Sep 2020 06:46:11 +0000 (UTC) X-FDA: 77293391742.21.toes95_4a0a49e27154 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 7D186180442C3 for ; Wed, 23 Sep 2020 06:46:11 +0000 (UTC) X-HE-Tag: toes95_4a0a49e27154 X-Filterd-Recvd-Size: 4026 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Sep 2020 06:46:10 +0000 (UTC) IronPort-SDR: z1NZIWhSiFaxFVpRDMmq8oIVDkWBXs7cVxpyYga4TAhSZD3iq5xYqGGaznqEiOsO8MITJ1/zrq 13xQW2Bt+6cA== X-IronPort-AV: E=McAfee;i="6000,8403,9752"; a="148548340" X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="148548340" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2020 23:46:08 -0700 IronPort-SDR: TZx6F52NHUHTq5dPXEVycQENWDLwz0VKfCs12w6Q9u1s+eG/bFm5rgDaLFVs124llTpAH7uz5u wgY3xN5dVtJA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,293,1596524400"; d="scan'208";a="412904578" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 22 Sep 2020 23:46:07 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id BCB26F4; Wed, 23 Sep 2020 09:46:06 +0300 (EEST) Date: Wed, 23 Sep 2020 09:46:06 +0300 From: "Kirill A. Shutemov" To: Matthew Wilcox Cc: Vlastimil Babka , linux-mm@kvack.org, Ira Weiny Subject: Re: Rare memory leakage Message-ID: <20200923064606.l3ajwbbkewvvaimc@black.fi.intel.com> References: <20200922031215.GZ32101@casper.infradead.org> <8f294420-93c9-618a-6128-432b7035642b@suse.cz> <20200922114451.GC32101@casper.infradead.org> <20200922131219.GE32101@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200922131219.GE32101@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 02:12:19PM +0100, Matthew Wilcox wrote: > 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); To be honest, I have not dealt with device drivers much myself, but this looks bogus. We free pages beynd the first one if the first is pinned. How is it correct? -- Kirill A. Shutemov