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 65A03C2D0E2 for ; Tue, 22 Sep 2020 11:04:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B414120B1F for ; Tue, 22 Sep 2020 11:04:54 +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="e15tWNU0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B414120B1F 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 DF11590005E; Tue, 22 Sep 2020 07:04:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA39C90005C; Tue, 22 Sep 2020 07:04:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBABC90005E; Tue, 22 Sep 2020 07:04:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B5BA790005C for ; Tue, 22 Sep 2020 07:04:53 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 735DF362A for ; Tue, 22 Sep 2020 11:04:53 +0000 (UTC) X-FDA: 77290414866.17.arm55_1b0c1f22714d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 2AA16180D0186 for ; Tue, 22 Sep 2020 11:04:53 +0000 (UTC) X-HE-Tag: arm55_1b0c1f22714d X-Filterd-Recvd-Size: 2954 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 11:04:52 +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=CSyZaDx31MiaKLXF/Tmeat1IpjyMODzbS4WzyZ/Nowc=; b=e15tWNU09CJPoNM8Iok+GoeBmP LQRarP6bwzRHY6u6mDkE3ocIqYTJjnxjYDL53RsHqOcTcHjybODNJwXA9qSr1t4KjrLabpMcF7vEO G0cLMACob9D1kX2u0QoG1SJoSbaRg8i23JZVcUhIsTKIP1XDFNeWAdcGJVu1oHsma2tE9uGHC9c6o aqo7CAxFBZg1Ur8L9UcqcQ5erX79sbh8s1AaJEEoQBuT4J0gLi5jr6hkOYYqGEsLJ/g5/pAuTjau8 TXzjiUE87OC7YtHQWSEx5pkkXL0vW8IYUHNef8tjWKiGvlqcxtqjjyltJFE8UxkN16qs3aIpDnZiF oOWg7VFA==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKg6I-00047M-VE; Tue, 22 Sep 2020 11:04:47 +0000 Date: Tue, 22 Sep 2020 12:04:46 +0100 From: Matthew Wilcox To: Ira Weiny Cc: linux-mm@kvack.org Subject: Re: Rare memory leakage Message-ID: <20200922110446.GA32101@casper.infradead.org> References: <20200922031215.GZ32101@casper.infradead.org> <20200922034314.GR2540965@iweiny-DESK2.sc.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200922034314.GR2540965@iweiny-DESK2.sc.intel.com> 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 Mon, Sep 21, 2020 at 08:43:14PM -0700, Ira Weiny wrote: > On Tue, Sep 22, 2020 at 04:12:15AM +0100, Matthew Wilcox wrote: > > This is a fun little race. > > > > Dramatis personae: Pages P0, P1 are consecutive and aligned. > > Threads A, B, C. > > > > Page P0 is allocated to the page cache. > > Page P1 is free. > > > > Thread A calls find_get_entry() > > P0 is returned from xas_load() > > > > Thread B removes the page from the page cache (eg truncate, invalidatepage). > > P0 is buddy-merged with P1. > > > > Thread C calls alloc_pages, order 1, does not specify GFP_COMP. P0 now > > has refcount 1. > > > > Thread A calls page_cache_get_speculative(). P0 has refcount 2. > > > > Thread C calls __free_page(P0, 1) > > put_page_testzero is _false_. Do not call free_the_page(). > > > > Thread A calls put_page(P0) > > We free P0 and nobody knows to free P1. > > > > > > Weird solution: In __free_page(), if put_page_testzero() fails and page > > is not PageHead, > > I'm not an expert, so I'm probably off here, but if Thread C calls > __free_page(P0, 1) wouldn't that be on PageHead? So how would you know to > convert it to a compound page? Only compound pages get PageHead set. A regular multiorder allocation without GFP_COMP set does not have PageHead. void prep_compound_page(struct page *page, unsigned int order) { ... __SetPageHead(page);