From patchwork Fri Jan 27 10:16:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 49159 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp755847wrn; Fri, 27 Jan 2023 02:19:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXuAnblXoMB9RSaAWJ4pUadrUPFddNPJ1BsjruwUufJs3NljOwtei3kyjPGMIKtYAuKLOiK1 X-Received: by 2002:a17:906:944a:b0:7c1:23f2:5b51 with SMTP id z10-20020a170906944a00b007c123f25b51mr58141650ejx.60.1674814739227; Fri, 27 Jan 2023 02:18:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674814739; cv=none; d=google.com; s=arc-20160816; b=q2RTUvl8gkDjPTBFPgA52vzu6MYFi6FZjIsOvaffOcDV0+Rk1BYesOHDxN37qhr2gc F/bxvZEo/zMM+AyP66DuBONC2LOingfKvrvgwqCTNlnwFI7ViwSQxGCssHVk+WJlahN1 Wx46LxoAcj4OkPAL6FzQUS/Wr+qz5bsgVQgPI9xv1IANBda+CQVLohXr3VOdk02nH+i9 /7g8X00tleUK4eqPmdkZc7yrRd21edWDR/qIHoFEuo4rwqWwAHeqBNvz6Mm0PDK11P/g hjjQr5RZQR7X6mSgEbwUz/DQ2AqiKKqxzp3n82zuyw8jq/1EF4TfElQ6mDIUP12lWp5V 81FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=4tXAzYx6U2zYvFQaL0R9LDwvLsVYQ0QOtKqWLpi2ZpY=; b=ydTTylgQnvC/h8NjRyLJh4cXzGnff0W8Arz2wdOUPAOA/2pH891mVvtMOcD8sOcOVn v/SIqHTBwXnjB96qcdknha43lIiwXz2+aXcLDzrb938+zPzXkr7TMkM7EjyBMdBnr+Gr o7RB2X+tCkPDpsm3PfhFZ9S5OAHVnu0vG8DQZi7kP8k9Zziceh7fV2E3saZ9xsasster 4QtpAhZKpVOxFb7fbmerl58o/hpbd0a2iwMLpxHcCGBzXTnMwGsyUwGMLjXQIaNtFbpB UsMeIBNDajc770Mqy9drrBHfYn8NObug/7DVSLnuNoSzIvgb/ENJkN3EJKkKhaVexVa+ dShg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="taG/DcTL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay16-20020a170907901000b0087bdacdb25esi945520ejc.299.2023.01.27.02.18.35; Fri, 27 Jan 2023 02:18:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="taG/DcTL"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233070AbjA0KRJ (ORCPT + 99 others); Fri, 27 Jan 2023 05:17:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233022AbjA0KRG (ORCPT ); Fri, 27 Jan 2023 05:17:06 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E43712065 for ; Fri, 27 Jan 2023 02:16:53 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id ss4so12313323ejb.11 for ; Fri, 27 Jan 2023 02:16:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4tXAzYx6U2zYvFQaL0R9LDwvLsVYQ0QOtKqWLpi2ZpY=; b=taG/DcTLzWRqxJ67PXr4isASG3VtleUdmICNBQ5dB1fbIhAkjeAPCLn+pedlUYRyev /9S1EfpKEjergkzhAObSRpDaXifNzAc0T8m+T2Oq1JLTCHVW7q+72ux1tw5QyS3Sa1Dj 2SwMPsCzm2m9dcz/2cewiYM7u963IUZ9GJLJOARXogBnRFibHfbUjmVwMcs/SyRq3CZV /2uBkkkSizbILaPWBNQtp6DukBX+gifschimBTyLeYF/iAn13U7k4rcDaL5T+Ce6wHkz R/9VMf0Bj78oDfA2NjI8MA+M2PhanmuYxQTd1R+JN9mCALbMw7XUWbBmRZIAHT2SqL0B iakg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4tXAzYx6U2zYvFQaL0R9LDwvLsVYQ0QOtKqWLpi2ZpY=; b=Bsr0RLwXjGZ2lyAOuANGU/mKtRHgAQc47EH4+Tj3rpcHKnYcRdc0I1X3j9XJ1ZNpTa Vq8rcIRIOsBmKwOGwiP2USPE4RC/dt2V+MtnWlEJJTLOp/C8IyHJYteLaEM3NzloUiEk LfA6lm7mS4BXDjV2gJdZt+kcylL6DDp9IvCtc42Hxo3bdtCK/UENxZX6qngZ2oWqVAeH KwGsCKVmxzS3CU7LbxDL4OaJaAVL72+QP6KSdwFRyW7Yxn2NOmgXH5AG8FkkhPzjE4qo qBY4Qf2WJxLzSlq2m4yodepm2tbfRO3eOkGAFSluCVWLZL3fl7Wu7Nu44UOWNYgzspif RHng== X-Gm-Message-State: AFqh2kqQR3ILAox5qNK0HYOSbPKGsGiiZ5lDk8aogkt+EIiRnRkxui7I Q1l76MUUooYqH6pB1CxnJeeiIQ== X-Received: by 2002:a17:907:8999:b0:877:83ea:2bfc with SMTP id rr25-20020a170907899900b0087783ea2bfcmr31382892ejc.39.1674814612066; Fri, 27 Jan 2023 02:16:52 -0800 (PST) Received: from localhost.localdomain ([2a02:85f:fc9d:e4b5:fb9c:6b1a:cf38:9393]) by smtp.gmail.com with ESMTPSA id h16-20020a50ed90000000b0049ef04ad502sm2073718edr.40.2023.01.27.02.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 02:16:51 -0800 (PST) From: Ilias Apalodimas To: netdev@vger.kernel.org Cc: alexander.duyck@gmail.com, Ilias Apalodimas , Jesper Dangaard Brouer , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org Subject: [PATCH] page_pool: add a comment explaining the fragment counter usage Date: Fri, 27 Jan 2023 12:16:27 +0200 Message-Id: <20230127101627.891614-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756170539859719364?= X-GMAIL-MSGID: =?utf-8?q?1756170539859719364?= When reading the page_pool code the first impression is that keeping two separate counters, one being the page refcnt and the other being fragment pp_frag_count, is counter-intuitive. However without that fragment counter we don't know when to reliably destroy or sync the outstanding DMA mappings. So let's add a comment explaining this part. Signed-off-by: Ilias Apalodimas --- include/net/page_pool.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/net/page_pool.h b/include/net/page_pool.h index 813c93499f20..115dbce6d431 100644 --- a/include/net/page_pool.h +++ b/include/net/page_pool.h @@ -277,6 +277,14 @@ void page_pool_put_defragged_page(struct page_pool *pool, struct page *page, unsigned int dma_sync_size, bool allow_direct); +/* pp_frag_count is our number of outstanding DMA maps. We can't rely on the + * page refcnt for that as we don't know who might be holding page references + * and we can't reliably destroy or sync DMA mappings of the fragments. + * + * When pp_frag_count reaches 0 we can either recycle the page, if the page + * refcnt is 1, or return it back to the memory allocator and destroy any + * mappings we have. + */ static inline void page_pool_fragment_page(struct page *page, long nr) { atomic_long_set(&page->pp_frag_count, nr);