Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp127287lqs; Mon, 4 Mar 2024 18:10:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWzYqQctTXhi/BelCSAr49LXIWcMrMMFLg7gAouiyRLIJ0PScGmYNKnx+lMoHgMqp4qpYdqrAdpkukofPOZAlOueL1v48juwhCa5/8jVg== X-Google-Smtp-Source: AGHT+IHVypaqDSj33mcUGWNO/Us5dN+zoIsDFq9THafRn330rt+WvNEvEF6S1v3GLz3gRc5F6orx X-Received: by 2002:a05:6a00:198c:b0:6e6:136b:fa9 with SMTP id d12-20020a056a00198c00b006e6136b0fa9mr7857339pfl.29.1709604649796; Mon, 04 Mar 2024 18:10:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709604649; cv=pass; d=google.com; s=arc-20160816; b=uXgFDTRDZvoUOvGCNqnofsaf4gGdELfVkU77QLz1E5eZ+eyL85raRXXiH4RPFOrKf+ 0aKkhwWQttZOk336XVBb8s1IadQIGzu8rPxeJmYd+R1dRGodoOJc8HDM2QjJ9Jq3pi29 cI3uYdLuZEQJeC0tnQrlHUgI7IO2KGGaM/MZWk8yHtyK7kE4quiU+3VXR44jzRyE/I9r 0OdBguoDdLtSjYta8KCm79Z+/PXEXFwAY3zi3BgutGR8+S89fjNtmE2Fgj0cM2tudo/w Dx//3EpaOk5CW6CHig3mT8Q2q7qKcHNL/Z3gkhuOzM2h0qNcEwJZm79fTBu06Wjd47/I GWLw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=G9Y5Scp28ZqCYcu39ok93LJAzx/1WlCB4rvVWoIV5aE=; fh=NrKt44ID3se+X0a6StfCVzm0J0z3enRzoSGpPbIORDw=; b=dCI076VRJBm3ntaxwVqjFm6q81hvmXQodimql3zjwMj+1svtsN80N9a++jzjLAsCfE LiyvNDsoCDP+qtneh5LQ9DwV3QAF6WeEVD4vUv29bkFG3+O7i/ZujMiCsg3dl6bAyBAY ZxsfmtzLbFqHtDh0LDOkKs1VvLLCPV9uoOpD8YYbCR31dkv1IMLIOZwIVTgtxfJrT5xn W9DL8DIPBYPT1ydsGpy19YXMxg7XKDA9YY27javLJaNDvMXUtFvYTqkj27Sqgi3RQDnc lV9Xa0d3M0UFwGcGOTveOyDSKZatg7CUAPLqXAOUvr6hYktodY1SYtiw9KTAs1nX335f n5ug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=NcqkfsWx; arc=pass (i=1 spf=pass spfdomain=flex--almasrymina.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-91524-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91524-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s3-20020a62e703000000b006e580678e00si9150679pfh.50.2024.03.04.18.10.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 18:10:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91524-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=NcqkfsWx; arc=pass (i=1 spf=pass spfdomain=flex--almasrymina.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-91524-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91524-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 623E8B24C98 for ; Tue, 5 Mar 2024 02:03:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4524C26AFB; Tue, 5 Mar 2024 02:02:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NcqkfsWx" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F72C1803E for ; Tue, 5 Mar 2024 02:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709604127; cv=none; b=tJ8tY6cSgv8UX9E2XeMJDH6M342/bg7T5/ty4BhRRXAzujIaBt/qKcAqwsuYfhPCr2uQ+BsxsCNA/+aFC5ZrpYl/zfrQUafwxzGYZ/3THcnG9Xb/gX0xUggS/QP7E0mDfR5vDuyBDdkXUXV9TQ0ESYJL8px+h7rcCXOBu2D9+PU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709604127; c=relaxed/simple; bh=j/IwFTAQYqvdz7NJGn1fdITXlRNyG53+OSdMfig6/Ik=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=o1KsDPi7y7AwozfgcMPmcdJj3BgCo/Tle2ecmh9WtxS1sR6+Bg0x5sZRxMBeO1h8OtskMFPswwoRZa4L4Z01YizGih5tKK8/jA7733nYoHPvhQ7by0mm11xXnNAcKidrP4rSqKMfaPDuA+WQKqKlcFc9iBlFdCiOXkHEBeHs6JA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NcqkfsWx; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dcdc3db67f0so7076855276.1 for ; Mon, 04 Mar 2024 18:02:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709604124; x=1710208924; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=G9Y5Scp28ZqCYcu39ok93LJAzx/1WlCB4rvVWoIV5aE=; b=NcqkfsWxY92T8H72Q9KWic205+OP/btpDnXvreJr99ioZjxLcpxGPAPeHdA8VbxZ9N yOWwBMB60bBDxr3ekQV5X8SGGpELD4G3vBDA9jgtIz6weGM8jItW6iJVoHzDFibxE4Ho 2FO3BL6ft8GdJ0PfeY/82lad8Oqt9ta1nWdW7mHZqasIaVAwwvCGlcgAcQ3pM2QjkzsI caL/oV9hEk+9QotKVpWtwdvXnJjmY5XTTjQ+besky1m+C4CTf8HPr34KflMzuDOkATIx eVMO29Wh/O5oamxGbEsuEt2k6QfaXNNU5L1HcHA/21lrfFSdKPFmxK9GRqgVa7TCA/8X ZyLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709604124; x=1710208924; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=G9Y5Scp28ZqCYcu39ok93LJAzx/1WlCB4rvVWoIV5aE=; b=sLGEcWK7VWD8r7vmFra9QYJwpiGJPyY52cpI2zp2LmH7hl0qempuhFmNOx9vNFF0a4 FCVgF2rzqUA/86nrciLya3dOQPxeZa5BV3M+SaPrsld2GpJajHNFgxKi/Z3NunUcm3mY 4SrcJhYcRGK0t08kmLf265mN0g+HwrQt6kBYMiLpiq4fOL1H7WikebHJj1zwcv1NVpm+ 6eCfwmzdbhZj8o7tMF7+OZ6tAELiCio9EAQP5lBjIo9+DMZjcYxADD9zRtD5NsWofrEc 5IKuWcIq56XfkKj+gDAWu/BOZ5KS9pL1a69YCyWvUcBH2JxqcMBAe9bk6FVVD6ylYJZS PyVw== X-Forwarded-Encrypted: i=1; AJvYcCVDISoA/oyP0DaR0/qXQL7DI2GeycKbMJjcIxFnmuVS5qRf8g3gJihCoBqlax97k/OHC1wa1MzwEwp1LXSVFf0x0YaLKnBiNc1RXTUM X-Gm-Message-State: AOJu0YyqcXV8U46yixQXpkdevY+TTGOeXoLH2VP6+3ZlIJvYNkBt2sxy fnI0p2UeellOaUZx7rAJ0tD9QVAZ5qjuGx/rujyayH+waPQ4n7f2u+XCYXPTotfH/dT0FkQL9Q4 mZCs1plTnDEhyP8xbMrEHig== X-Received: from almasrymina.svl.corp.google.com ([2620:15c:2c4:200:b614:914c:63cd:3830]) (user=almasrymina job=sendgmr) by 2002:a25:690d:0:b0:dcc:5463:49a8 with SMTP id e13-20020a25690d000000b00dcc546349a8mr245459ybc.6.1709604123917; Mon, 04 Mar 2024 18:02:03 -0800 (PST) Date: Mon, 4 Mar 2024 18:01:38 -0800 In-Reply-To: <20240305020153.2787423-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240305020153.2787423-1-almasrymina@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240305020153.2787423-4-almasrymina@google.com> Subject: [RFC PATCH net-next v6 03/15] net: page_pool: factor out page_pool recycle check From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Andreas Larsson , Jesper Dangaard Brouer , Ilias Apalodimas , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Arnd Bergmann , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , David Ahern , Willem de Bruijn , Shuah Khan , Sumit Semwal , "=?UTF-8?q?Christian=20K=C3=B6nig?=" , Pavel Begunkov , David Wei , Jason Gunthorpe , Yunsheng Lin , Shailend Chand , Harshitha Ramamurthy , Shakeel Butt , Jeroen de Borst , Praveen Kaligineedi Content-Type: text/plain; charset="UTF-8" The check is duplicated in 2 places, factor it out into a common helper. Signed-off-by: Mina Almasry --- net/core/page_pool.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 8776fcad064a..fe9de4ecce94 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -684,6 +684,11 @@ static bool page_pool_recycle_in_cache(struct page *page, return true; } +static bool __page_pool_page_can_be_recycled(const struct page *page) +{ + return page_ref_count(page) == 1 && !page_is_pfmemalloc(page); +} + /* If the page refcnt == 1, this will try to recycle the page. * if PP_FLAG_DMA_SYNC_DEV is set, we'll try to sync the DMA area for * the configured size min(dma_sync_size, pool->max_len). @@ -705,7 +710,7 @@ __page_pool_put_page(struct page_pool *pool, struct page *page, * page is NOT reusable when allocated when system is under * some pressure. (page_is_pfmemalloc) */ - if (likely(page_ref_count(page) == 1 && !page_is_pfmemalloc(page))) { + if (likely(__page_pool_page_can_be_recycled(page))) { /* Read barrier done in page_ref_count / READ_ONCE */ if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV) @@ -820,7 +825,7 @@ static struct page *page_pool_drain_frag(struct page_pool *pool, if (likely(page_pool_unref_page(page, drain_count))) return NULL; - if (page_ref_count(page) == 1 && !page_is_pfmemalloc(page)) { + if (__page_pool_page_can_be_recycled(page)) { if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV) page_pool_dma_sync_for_device(pool, page, -1); -- 2.44.0.rc1.240.g4c46232300-goog