Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3820737pxk; Tue, 29 Sep 2020 07:07:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvjHLMm5LIV4fn2R/N/awQxQU71QOX65k2IEpFjcMpf2QO0PVWDgUgfVN7zpSvDVGMeV7l X-Received: by 2002:a05:6402:164d:: with SMTP id s13mr3416885edx.222.1601388473485; Tue, 29 Sep 2020 07:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601388473; cv=none; d=google.com; s=arc-20160816; b=YtwcvAZs4AxyiheXc5wUKf4ukmsZt7zaJKK2wqXnjyGIzzvUzqSbqklQRAmIxNNZ65 0qePmjNiuRCOwhkxj+8Z1dvhEr3ZZJE1j9NTOCfWWr4TpHfgwdNYz+ZO8dAUNiV/u2vX aMn4Nyhuy02807XsOLCM5hWpawKcAxzSEle0AUBS/6kBqUpoinoBYw6PD/VQrNTIvUTB E6BrzmkuQITrNOERoM7T75agHYNs0Duqk6WUcCUR+NbGLgO7rvGGMrdu3ffSFgNEuydZ nIK9+/OgyAWoE+UCFdYjFUJWL7puQjUIormH1XZgqEpNG3qRYC4g65guVjITlWlV0vzB YSsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=viXSxvUTI8HhUOod2bOuMX3/wUHqXf4haaO3VlhNCpQ=; b=lUk1crb2PelAl3baiDTTnupezO8Ac+a8KJFqwiYAcJYlhtQz5BgvrijSo2yCwE2fjp Ko2E15OUOm0xsS9wEtO5gVSxIPTJ17LKcjH238kKEmeGb6mCn//IonQjE6UXDwBVESdX 2p/rLkDDjFRnIDim/s77KRkH17MUODqM2Ztp0tH1luKchEzQRZSDIZyRSfS/IC0KovST 4hTy16aKEBcVE5PZgjajL4s5BG1EflKwD88vR4Cbx5y2KOnosgN9bPgkviTKyfQpT5bY VASnQruKtsf++9ov/1YVN2o2cULi9TRg9tI58p6JzJ+/qXJ7J8E1YLz3lK3QI98w5t7D G8Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=teujRbnG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r10si2620076ejr.168.2020.09.29.07.07.28; Tue, 29 Sep 2020 07:07:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=teujRbnG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729570AbgI2OG2 (ORCPT + 99 others); Tue, 29 Sep 2020 10:06:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728481AbgI2OG2 (ORCPT ); Tue, 29 Sep 2020 10:06:28 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33614C061755 for ; Tue, 29 Sep 2020 07:06:28 -0700 (PDT) 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=viXSxvUTI8HhUOod2bOuMX3/wUHqXf4haaO3VlhNCpQ=; b=teujRbnGhuAVQFaJzPZg7wrFDB 3zeBOvrZ+vk2DrwJw87lkPJjUWurJyxwxPPlhOPyQqvEB/ljnl6sP9jWi+VTcXcy2hFwRjQwCGtbV PQlDh5WBlEJIiU6AQilTAsj+kCeN+iakY4wYjCEfM5W7yXqF0OuamrmxEzFT3AsEbsVRaNH3BwpaM Z+Kqy+tnAHiKrsw6C8zkdDdwXmFy0t3LgtcxhnAjZYrER58he7YhvNkOWPui29sjj1fC7k/NsPEgs qZdGI+Hs77Bc9byL3yHm629h0YxmAdg/BU7yBX2c2M6NCC0J2+GjV2N/Y3OURB+aSCKBRQ3GOPLmV T9WGVDXQ==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kNGGs-0004G1-Op; Tue, 29 Sep 2020 14:06:22 +0000 Date: Tue, 29 Sep 2020 15:06:22 +0100 From: Matthew Wilcox To: Mike Rapoport Cc: Andrew Morton , Nick Piggin , Hugh Dickins , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org, hch@lst.de, rdunlap@infradead.org Subject: Re: [PATCH v2] page_alloc: Fix freeing non-compound pages Message-ID: <20200929140622.GE20115@casper.infradead.org> References: <20200926213919.26642-1-willy@infradead.org> <20200928180307.7573f3b6128b5e3007dfc9f0@linux-foundation.org> <20200929034026.GA20115@casper.infradead.org> <20200929072622.GN2645148@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200929072622.GN2645148@linux.ibm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 29, 2020 at 10:26:22AM +0300, Mike Rapoport wrote: > This sentence presumes existing description/prior knowledge about > put_page(). > > Maybe > > This function can free multi-page allocations that were not allocated > with %__GFP_COMP, unlike put_page() that would free only the first page > in such case. __free_pages() does not ... Thanks. After waking up this morning I did a more extensive rewrite: /** * __free_pages - Free pages allocated with alloc_pages(). * @page: The page pointer returned from alloc_pages(). * @order: The order of the allocation. * * This function can free multi-page allocations that are not compound * pages. It does not check that the @order passed in matches that of * the allocation, so it is easy to leak memory. Freeing more memory * than was allocated will probably emit a warning. * * If the last reference to this page is speculative, it will be released * by put_page() which only frees the first page of a non-compound * allocation. To prevent the remaining pages from being leaked, we free * the subsequent pages here. If you want to use the page's reference * count to decide when to free the allocation, you should allocate a * compound page, and use put_page() instead of __free_pages(). * * Context: May be called in interrupt context or holding a normal * spinlock, but not in NMI context or while holding a raw spinlock. */