Received: by 2002:a05:7412:b112:b0:f9:3106:f1c0 with SMTP id az18csp17222rdb; Sun, 17 Dec 2023 18:41:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoc5Rhd9TFIDC3IJ7/mkO1XKaPq0tpaWmJnga/pDKuWh6Vm65sgkhtdsNZJskxgydh1Mj0 X-Received: by 2002:a50:bae3:0:b0:553:4d8f:cde4 with SMTP id x90-20020a50bae3000000b005534d8fcde4mr347484ede.37.1702867302894; Sun, 17 Dec 2023 18:41:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702867302; cv=none; d=google.com; s=arc-20160816; b=OIXZRTvlmYRE/wjCDef6jgXjRG9ABbEV4pYbcqkRUX49Rd1QnHUA24OlhV+eHYHB9N JtE/4cZqohN8Xr4zVSPh8fM8XRWLtzRwfYhehJKYhMHQDkZTBZVNY7OTqVm7Xxyg6O4L nqpcwMltlDcipJ8DA8E4Tup9JuWGKzJdvmUAkBMZsPZwvxuzU9+XZ55KlMcTEkTLsogR fzonNoYSNRvx2Hq6xfHbl98AFgGjmGsPbR+EBpJL65I8KDvOty28bfa+MQrlUh7wtWXw OcX7CwtXhBPgO3ZvRgXRLtsQplGhdQ76xMfQSWo3TFSTvniy3HW9WmVkeGhZ1Qru8KL8 HRrQ== ARC-Message-Signature: i=1; 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=goaaxpdo4bsNfCqF/IRbg9OCDHUZobJiFZIImpZ+yx8=; fh=8Y9D+7Eqr15uC+q4uaUvZHfnG7pix6ubnhqqWosbV7w=; b=WkjntE6r5zeUsb0gLsygvedKyLJKJm3jEWiulmpwSx3wCSo9T6rcbTe1qDA0NR6NBt VnT0/gMcaqwplYVzNyfZl/gosUNv3a3r49w/UV4k62ZA8cCiKVMhWfre4ZozkOmYDzmw FH+LLY11oL5jELEEBWYWGv2VCRstEpUFMs3290l08y51Bxl0V+TyfrRmTHW60RcYjFWl ab9s0HNnLylVbCTThXgltk2UpBjJVFyhxPigRf01V7/bCFKzvEAEKNXpcZi08r1nfz3V rL/tFAgREsCz0u3Y9LEmWm2OkP84j+SJrLQYuIw/Cgb8k/SMEMGTneC2tsyaMxEyk28G LoBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KiDuVyBp; spf=pass (google.com: domain of linux-kernel+bounces-2926-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2926-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t1-20020a056402524100b0054d02689345si9475291edd.92.2023.12.17.18.41.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 18:41:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2926-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KiDuVyBp; spf=pass (google.com: domain of linux-kernel+bounces-2926-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2926-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 am.mirrors.kernel.org (Postfix) with ESMTPS id A40F11F21512 for ; Mon, 18 Dec 2023 02:41:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C61C87475; Mon, 18 Dec 2023 02:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KiDuVyBp" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 D84DA525A for ; Mon, 18 Dec 2023 02:40:33 +0000 (UTC) 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-yw1-f202.google.com with SMTP id 00721157ae682-5cb6271b225so31273397b3.1 for ; Sun, 17 Dec 2023 18:40:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702867233; x=1703472033; 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=goaaxpdo4bsNfCqF/IRbg9OCDHUZobJiFZIImpZ+yx8=; b=KiDuVyBpSqAKZrXxIilkzfl0cIDoRr8K2tNUpCk96bIY3jZlBZ3owgVr+8xxrMA4xD PEQ6gYqYaWutJFGoAZqVd96kn8iCfMvff8epiyGuWh8Y6EhM4OLH2gf49lxm5mT6lhir PVlh3GHgdja4tPnHgCrb8MAr30phqimI0FNSj8sIM/QvNPdeBPqENdKkVVfPwtwZvNXS Vkd52KPOGUDGseTKG5zWL9vq/HGu5AlXF2ltdh/EABWBVn79dszDVJfDdLF2wQbXT/zE tQfHitMpxSL+ZGcfuOrtSZczEL5Bi/sbdvI6ayCBsgZTZjc5o8bsDjdvUmqOObHVakQo 7QlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702867233; x=1703472033; 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=goaaxpdo4bsNfCqF/IRbg9OCDHUZobJiFZIImpZ+yx8=; b=QJTLGX+iSksYH29EOr7j8lmhwsBxAzGfAnoM5llnMCGF5roJOAdt11MDbq3kqsSc0o y00EhmeRrHV1Yl/nVEbUBM9umoNQTZZ6fwoj22qg4HOIs1NPtzgexxTfa/0UEF8nY1sj WqIgYXxN9t+gz/pbWWmYo2NZRLYLrrasVlfFF//TTv4y5CXMFlXWqVouWM4z/MLV/ejT TWDXBmJo2wT7e66guHS9Vy2kBvIN4oXdJaDkyzgakjfvTe4ItdPJYUCvKpM4tv5mCHBu UfCLDuu1alKM3USe6FsLiOzh6qaURp5r10wfiyPjgWPqXoD+jNa1MyvsY8KsTMwhvULe 1iNA== X-Gm-Message-State: AOJu0YxBwI00qv1/ERHfcZFdaJR9VIOb7/4jYQYejDQL5xdhYVNWd+3h HOSSWdoez7XsLJjTplFPGSACfnZ8K/z6bW5dyA== X-Received: from almasrymina.svl.corp.google.com ([2620:15c:2c4:200:5cbf:3534:fb34:758e]) (user=almasrymina job=sendgmr) by 2002:a05:690c:83:b0:5d7:29d7:8a35 with SMTP id be3-20020a05690c008300b005d729d78a35mr1936565ywb.5.1702867232915; Sun, 17 Dec 2023 18:40:32 -0800 (PST) Date: Sun, 17 Dec 2023 18:40:09 -0800 In-Reply-To: <20231218024024.3516870-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: <20231218024024.3516870-1-almasrymina@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231218024024.3516870-3-almasrymina@google.com> Subject: [RFC PATCH net-next v5 02/14] net: page_pool: factor out page_pool recycle check From: Mina Almasry To: Mathieu Desnoyers , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , 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 , Jesper Dangaard Brouer , Ilias Apalodimas , Steven Rostedt , Masami Hiramatsu , Arnd Bergmann , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , 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 45bb4210412d..0edb9251d98d 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -657,6 +657,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). @@ -678,7 +683,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) @@ -793,7 +798,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.43.0.472.g3155946c3a-goog