Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1738151rda; Tue, 24 Oct 2023 01:27:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0CZci0vUj5P3QoXZXij6s9owFVgNE5d1WP3C9pwT3TAcg+ajXE737ztse77a3rvjyCJRJ X-Received: by 2002:a05:6808:1995:b0:3b2:f2e9:874 with SMTP id bj21-20020a056808199500b003b2f2e90874mr15169661oib.5.1698136071267; Tue, 24 Oct 2023 01:27:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698136071; cv=none; d=google.com; s=arc-20160816; b=qZJ1PO22zP4Mfhx73APMX2HcanxcfkvYa49jduQ8sTUfNcZs8v/Sxc+2CH+R0QavIp IOZU4vG2QEBYEfP5dACLBUEy6DaMRZmpg3T1dbxpz8nVyUJAH2p4jClwO+ysKLKkSbNb WBltt9nRwO+eQ5KwRJhBQHYVM+pQfoq9xn7bP1P4TnX5qqKU3rjsbcGP/EjF3pP7JPXN 4ST3ZXQ8NLwDB2V6afPUN9E+b2AcsPUIp8cAP5r8tyUP9ZWkTrrqLIz7zySyeih5nOuI uImw+Essqvuci9/unTRGLSVfBprRyHMF0oyWp8znYQtFxTkpJEm+4j8DUmzCew6SDutH Vkpg== 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=yhceSFM1hF3sghD+dtG2lSmmlVSuNVGZPGjZf8ESzpA=; fh=MGAzry9diqUGtnqhZH7y3uGb0vIVhFhH814Wz0msQEg=; b=xzcZjx4jMvA78ZxJKQN1UEiv/rnAoGO+VheNIV2in1s54wuxN1lP4u586qYlTcGv8N /onEr0iAsF4fXsQ6XgZnYpz9PJ66oNyTBgj5dJjnxt6lLZw+ImDKKVwieiFeRz8ge/0A tGqLOdtMFPeEiiSewHaqKCp/DF6x9mDGdCGzAFdsYKnyPM1BykeCx/IS8g1eD7Q1IS5t v6Ql/8Q9hcPwbusX2cslBASzcqi4x4KygHuYKeBNMTRSQyGWhZclmolkIOyXm+N1RBkx 4R7Jk7ja5yDGsKRdQgk+qOj//iGwxVciKzurlaJRnWcw4Tpded9vB7vxVM304N2PqNgm BMgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sYdkngCa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id bx29-20020a056a02051d00b0055793097dbesi8748635pgb.469.2023.10.24.01.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 01:27:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sYdkngCa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 60C378093401; Tue, 24 Oct 2023 01:27:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233719AbjJXI1h (ORCPT + 99 others); Tue, 24 Oct 2023 04:27:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233122AbjJXI1g (ORCPT ); Tue, 24 Oct 2023 04:27:36 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 796F2128 for ; Tue, 24 Oct 2023 01:27:34 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-507c78d258fso6016694e87.2 for ; Tue, 24 Oct 2023 01:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698136052; x=1698740852; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=yhceSFM1hF3sghD+dtG2lSmmlVSuNVGZPGjZf8ESzpA=; b=sYdkngCaxIxVFpRow36WwN4O/t3zWSge5EMhvVmUQsRNXrDSYhlLkNEuuMdsIoT5J1 Bb3d4wsF3Ho843o3O0I1D5hfmby4DubHYnKDgZibS64GRzc4rm8jQDpT0wbIxOG6n/pl bu9lujKq+VE+GIiO8Gk50gGPBLnEehDflSLmoIn61Agn5u66SB0GBPXuPbKHrzDTUWJg sSNPZDJz5k2qYkRp2sqzi20Ad3BIN9JjvtgwKBKAjpfhqi1mTRquSFdkTidS2BqgM9rI dmPBmVjBPQPNvLXR0+n/CuqP7wa41ZqPKiVV7WAotLvteCYvtP81I3fFOvvX+Z5DNBEO YFag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698136052; x=1698740852; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yhceSFM1hF3sghD+dtG2lSmmlVSuNVGZPGjZf8ESzpA=; b=mVK+Zi73EpS02ZALqtzQ17neCPqpATbcNJ9a1Vs4/r7ZwMQAoqWTE5ZR4c909i6oSC uClFjDOMoAkpwYBKUDKBNbFwss0kYYQRw6dq2H/bsDNHZDvKbESQCXruwhpZ/2jx/9PS SxN04Alu5mmMkKrKVtHwxHs6qSfmOOlZCTvOf9sN8K/6txQqHTf0FeUhS8Yb2cSae4vN 1S6PpWvXLTX6BVa4Ri3IYNQEna7/+TKinomywKg1dZoe3a8KMIGpaG5xmBncvES7Gwnn YVhBzD4Byc8K55DCGxlOSQ5rPIXqvSSyei88f5fK5OlLhQlkhftl2vR7rTPbOSbDKelQ waUg== X-Gm-Message-State: AOJu0Yx2ObdmOgh4iz4HlR7CqeInBgfToDDisy5PJedkPBODV7jhILoF dAF0BkwP5nW0YSOW3/hmebrVtbkZXww9SwVY94LmYw== X-Received: by 2002:a19:644d:0:b0:507:9618:dc1f with SMTP id b13-20020a19644d000000b005079618dc1fmr7693069lfj.69.1698136052607; Tue, 24 Oct 2023 01:27:32 -0700 (PDT) MIME-Version: 1.0 References: <20231020095952.11055-1-linyunsheng@huawei.com> <20231020095952.11055-2-linyunsheng@huawei.com> <4da09821-d964-924f-470b-e5c1de18eecf@huawei.com> In-Reply-To: <4da09821-d964-924f-470b-e5c1de18eecf@huawei.com> From: Ilias Apalodimas Date: Tue, 24 Oct 2023 11:26:56 +0300 Message-ID: Subject: Re: [PATCH net-next v12 1/5] page_pool: unify frag_count handling in page_pool_is_last_frag() To: Yunsheng Lin Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Lorenzo Bianconi , Alexander Duyck , Liang Chen , Alexander Lobakin , Jesper Dangaard Brouer , Eric Dumazet Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 24 Oct 2023 01:27:48 -0700 (PDT) On Mon, 23 Oct 2023 at 15:27, Yunsheng Lin wrote: > > On 2023/10/23 19:43, Ilias Apalodimas wrote: > > Hi Yunsheng, > > > > [...] > > > >> + * 1. 'n == 1': no need to actually overwrite it. > >> + * 2. 'n != 1': overwrite it with one, which is the rare case > >> + * for pp_frag_count draining. > >> * > >> - * The main advantage to doing this is that an atomic_read is > >> - * generally a much cheaper operation than an atomic update, > >> - * especially when dealing with a page that may be partitioned > >> - * into only 2 or 3 pieces. > >> + * The main advantage to doing this is that not only we avoid a atomic > >> + * update, as an atomic_read is generally a much cheaper operation than > >> + * an atomic update, especially when dealing with a page that may be > >> + * partitioned into only 2 or 3 pieces; but also unify the pp_frag_count > >> + * handling by ensuring all pages have partitioned into only 1 piece > >> + * initially, and only overwrite it when the page is partitioned into > >> + * more than one piece. > >> */ > >> - if (atomic_long_read(&page->pp_frag_count) == nr) > >> + if (atomic_long_read(&page->pp_frag_count) == nr) { > >> + /* As we have ensured nr is always one for constant case using > >> + * the BUILD_BUG_ON(), only need to handle the non-constant case > >> + * here for pp_frag_count draining, which is a rare case. > >> + */ > >> + BUILD_BUG_ON(__builtin_constant_p(nr) && nr != 1); > >> + if (!__builtin_constant_p(nr)) > >> + atomic_long_set(&page->pp_frag_count, 1); > > > > Aren't we changing the behaviour of the current code here? IIRC is > > atomic_long_read(&page->pp_frag_count) == nr we never updated the atomic > > pp_frag_count and the reasoning was that the next caller can set it > > properly. > > If the next caller is calling the page_pool_alloc_frag(), then yes, > because page_pool_fragment_page() will be used to reset the > page->pp_frag_count, so it does not really matter what is the value > of page->pp_frag_count when we are recycling a page. > > If the next caller is calling page_pool_alloc_pages() directly without > fragmenting a page, the above code is used to ensure that pp_frag_count > is always one when page_pool_alloc_pages() fetches a page from pool->alloc > or pool->ring, because page_pool_fragment_page() is not used to reset the > page->pp_frag_count for page_pool_alloc_pages() and we have removed the > per page_pool PP_FLAG_PAGE_FRAG in page_pool_is_last_frag(). > > As we don't know if the caller is page_pool_alloc_frag() or > page_pool_alloc_pages(), so the above code ensure the page in pool->alloc > or pool->ring always have the pp_frag_count being one. Fair enough, Jakub pulled the series before I managed to ack them, but that's okay. It's been long overdue apologies. FWIW I went through the patches and didn't find anything wrong coding-wise Thanks /Ilias > > > > > > >> + > >> return 0; > >> + } > >> > >> ret = atomic_long_sub_return(nr, &page->pp_frag_count); > >> WARN_ON(ret < 0); > >> + > >> + /* We are the last user here too, reset pp_frag_count back to 1 to > >> + * ensure all pages have been partitioned into 1 piece initially, > >> + * this should be the rare case when the last two fragment users call > >> + * page_pool_defrag_page() currently. > >> + */ > >> + if (unlikely(!ret)) > >> + atomic_long_set(&page->pp_frag_count, 1); > >> + > >> return ret; > >> } > >> > > > > [....] > > > > Thanks > > /Ilias > > > > . > >