Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1647675pxv; Sat, 10 Jul 2021 10:33:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMorUrLyNPGwscC3xPDivjrcubUNHc0Q95HGfNIwH2WxWHV1wQcc9IFtidB4vDXDZpbc7s X-Received: by 2002:a02:ca41:: with SMTP id i1mr18297619jal.70.1625938392946; Sat, 10 Jul 2021 10:33:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625938392; cv=none; d=google.com; s=arc-20160816; b=RPCLBWzj/Dw+NdN7T7ZnhCNU+1nX0Nsbht7Ld2O2BE2tB5NJC8ZJIeUVcyh6ywL2Ld 22WDvSqtj5o90xrXf1PpCLYg6dKh2aaH9buRZQ7nv5+xIotyi1L7MC3BUzofpLOVrKGs aU2vD+zddAeS46CxWDHz7wHfjSsKbSEMA9+zJgNxIzP0ZOUwP2iq/tki/uWG6clh5GzN eWV1/c2cDyGs8AHRzK6knvIBtqjBrz4vpNElagcFIpP+Yco47E2bAQoP0cWmKPI6xt4q er3FYl2YnGJwTyMN0rqJzuN/kRyIffq2V3ZzUKW9J8TKsgVxaNqgt0duzLIMLFBQVJmo 7Vaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Zduc9jpX7e7ip13ou3ijSJWzMOCnUHnEmxXUSbY5bJU=; b=X43fJfHjt72xxuvGOiWXJ51KKnbTv8In3XcUlX7oKvSjz3/j5mRPuf4S9dLlSisA47 VyoO0i0s8oyGLaK+i/tFS0ED0+s+jC/ikNdUNSG12i8o88+pKBADS//o0PVx+cMpMbOW 6h4EOSAKZivr3WmSdCRPgeMMiDSsN/sTVZkX4PSI3eMKxQCQAuX89wFKomL9MSQOYSC+ KnjdxD3cjeXaoACcgMLCsQYqH5DdcAWdQeehgS1pxQuei+qG4bVhkw5xPhn7Xb+oYJZF jlt9w31o+w24WQSKgwLPIbkr4WLAbbuDdp263AI534L1t+MvMurzTLiL1oMnL6WpYlAU kp5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="C/P2TgL9"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si11737343iol.91.2021.07.10.10.33.00; Sat, 10 Jul 2021 10:33:12 -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=@gmail.com header.s=20161025 header.b="C/P2TgL9"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229771AbhGJRej (ORCPT + 99 others); Sat, 10 Jul 2021 13:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbhGJRei (ORCPT ); Sat, 10 Jul 2021 13:34:38 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78A2AC0613DD; Sat, 10 Jul 2021 10:31:53 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id l2so19320051edt.1; Sat, 10 Jul 2021 10:31:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Zduc9jpX7e7ip13ou3ijSJWzMOCnUHnEmxXUSbY5bJU=; b=C/P2TgL9cTJl1yI9f+phOSafGQBnJS5mZXs9udeyY4KKHXeif1izj9c0XCynBI6Gow jzeskIMwthwCHcyYcivZOSh2G1l05+Qe6rnKXQy4WsBmAmxGDOJl80BD2s773df1fR1j qQxZnZXKWhUfY6NxzcEfzIFOimmG1sHPH5xQAveYfd//7aHZP7A97QXhhCsDbDrBS6sJ cKy3pKveko5G5SF9OGb/tCuTfF1P6Encmj96T96QzHHVnUHbGhLi9qE/nXU6xRUvUPNj k+OMs2RqAYaNYAy3U+WOK5Rq6qm6M/0o7BjuF6o8k00IdGdS+LfD1u0HxV6Z8ZXCBwoL bQ/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Zduc9jpX7e7ip13ou3ijSJWzMOCnUHnEmxXUSbY5bJU=; b=uEDUPoYT7AX9jWXCVOfgs2EP8JCLgr8HLWSYnr4MCTzR5Gw9RnTMIPokKnIQL0Q1wr CXBIpKWM5t3J/0McFStBHm9NRgT0HHnS/zS2Orqz2WP8vdgtasnCvr80kEZkFXoxpT1Y fhFWmM9xIcvjXyNCOGWatTqqONprdlW40YsyqPmc1PxP3ziUbllBtNYgbSYnjZ4PA6zq jjf1jy6fBpkBpMVFxzw3bwFvRLS+im8WJ9Rjr61gMre2KEJjtZLy88FazNTsgx8E4bQF O8JENA/Gy/X0nnEsLXHKH+hiDJRB+N8yKx+aSaeHOt6RCFZ2jw3oWXFzbQziAtoOVmva TgkA== X-Gm-Message-State: AOAM533cN1B2c6jfIdwkc3IGxmKSwYXYPRAjSWJ5fZWfdSTecAJzlgVs QE6u+uk8vu3Jho3dePrwCDJvT8a1YMc7fqjL8sM= X-Received: by 2002:a05:6402:40c4:: with SMTP id z4mr55523898edb.364.1625938311902; Sat, 10 Jul 2021 10:31:51 -0700 (PDT) MIME-Version: 1.0 References: <1625903002-31619-1-git-send-email-linyunsheng@huawei.com> <1625903002-31619-4-git-send-email-linyunsheng@huawei.com> In-Reply-To: <1625903002-31619-4-git-send-email-linyunsheng@huawei.com> From: Alexander Duyck Date: Sat, 10 Jul 2021 10:31:41 -0700 Message-ID: Subject: Re: [PATCH rfc v2 3/5] page_pool: add page recycling support based on elevated refcnt To: Yunsheng Lin Cc: David Miller , Jakub Kicinski , Russell King - ARM Linux , Marcin Wojtas , linuxarm@openeuler.org, yisen.zhuang@huawei.com, Salil Mehta , thomas.petazzoni@bootlin.com, hawk@kernel.org, Ilias Apalodimas , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrew Morton , Peter Zijlstra , Will Deacon , Matthew Wilcox , Vlastimil Babka , fenghua.yu@intel.com, guro@fb.com, Peter Xu , Feng Tang , Jason Gunthorpe , Matteo Croce , Hugh Dickins , Jonathan Lemon , Alexander Lobakin , Willem de Bruijn , wenxu@ucloud.cn, Cong Wang , Kevin Hao , nogikh@google.com, Marco Elver , Netdev , LKML , bpf Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 10, 2021 at 12:44 AM Yunsheng Lin wrote: > @@ -419,6 +471,20 @@ static __always_inline struct page * > __page_pool_put_page(struct page_pool *pool, struct page *page, > unsigned int dma_sync_size, bool allow_direct) > { > + int bias = page_pool_get_pagecnt_bias(page); > + > + /* Handle the elevated refcnt case first */ > + if (bias) { > + /* It is not the last user yet */ > + if (!page_pool_bias_page_recyclable(page, bias)) > + return NULL; > + > + if (likely(!page_is_pfmemalloc(page))) > + goto recyclable; > + else > + goto unrecyclable; > + } > + So this part is still broken. Anything that takes a reference to the page and holds it while this is called will cause it to break. For example with the recent fixes we put in place all it would take is a skb_clone followed by pskb_expand_head and this starts leaking memory. One of the key bits in order for pagecnt_bias to work is that you have to deduct the bias once there are no more parties using it. Otherwise you leave the reference count artificially inflated and the page will never be freed. It works fine for the single producer single consumer case but once you introduce multiple consumers this is going to fall apart.