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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 AA449C4363D for ; Tue, 22 Sep 2020 03:43:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5276323A34 for ; Tue, 22 Sep 2020 03:43:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5276323A34 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B75956B00B1; Mon, 21 Sep 2020 23:43:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B27636B00B2; Mon, 21 Sep 2020 23:43:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3BCA6B00B3; Mon, 21 Sep 2020 23:43:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0002.hostedemail.com [216.40.44.2]) by kanga.kvack.org (Postfix) with ESMTP id 8B8946B00B1 for ; Mon, 21 Sep 2020 23:43:18 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 48031180AD806 for ; Tue, 22 Sep 2020 03:43:18 +0000 (UTC) X-FDA: 77289302076.09.part22_05097862714a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 2CD8E180AD804 for ; Tue, 22 Sep 2020 03:43:18 +0000 (UTC) X-HE-Tag: part22_05097862714a X-Filterd-Recvd-Size: 2713 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 03:43:16 +0000 (UTC) IronPort-SDR: ZZmp3d3masZzx6rxEkNIwyItsBTUFgSF3EnTRo2pFglceRpowBZqMuIBY8YlC7nY3VTUguKsig QxmGSeXdDTCQ== X-IronPort-AV: E=McAfee;i="6000,8403,9751"; a="140528615" X-IronPort-AV: E=Sophos;i="5.77,289,1596524400"; d="scan'208";a="140528615" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2020 20:43:15 -0700 IronPort-SDR: IhtsFqXptVLn/64gc5oUNZH7ocyBsbImrGXVB13Soletzf5DFBTcSnomWCxqKOPAHTahB/VZw+ PI0BFpOnccZQ== X-IronPort-AV: E=Sophos;i="5.77,289,1596524400"; d="scan'208";a="304801463" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2020 20:43:14 -0700 Date: Mon, 21 Sep 2020 20:43:14 -0700 From: Ira Weiny To: Matthew Wilcox Cc: linux-mm@kvack.org Subject: Re: Rare memory leakage Message-ID: <20200922034314.GR2540965@iweiny-DESK2.sc.intel.com> References: <20200922031215.GZ32101@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200922031215.GZ32101@casper.infradead.org> User-Agent: Mutt/1.11.1 (2018-12-01) 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 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? Ira > convert it to a compound page. Then the put_page() > by Thread A will free P1. > > Better ideas? >