Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1160131rda; Mon, 23 Oct 2023 04:43:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG41Cgv17kcuCy+KJBd3UADBkTLn4SUIYHLIFxqFVE71enf/pCx3LLZWdVVtC9u8EU7cHpM X-Received: by 2002:a05:6a21:9988:b0:13f:c40c:379 with SMTP id ve8-20020a056a21998800b0013fc40c0379mr8450508pzb.13.1698061429204; Mon, 23 Oct 2023 04:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698061429; cv=none; d=google.com; s=arc-20160816; b=GFIoS+9hbbVpBqQZIfMTnoX1LrsZezR2Ab4pXvv9vvRUU53wk9AjDNdToh5V4xYWIB 0BWNXtk7Bp+sfY9PR65f7qi8L4fONHysojUJ6I4SNn/mJSpFy66bmH5xM1V0hsUZ9OWA UPIRjM5g8uNuLUMm0zxuSmAjZ+35RUB+rkXbby6hRLWDPzcGINThfa9CYVFFujjlgKOA Jf9AW0J6Clsh+f0sxHJHI/wBqUaB1ADENdQmR+mTmTL4GVROMdqnBEvP9jHN475Hnroo /E6MgAFx14mXK58xAlcmEHtmu0UB0qN93sNMtey2JWr6kiH37CMQH04HZJDjc8snhxZ+ MwKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/lK2Os4ki3ybOrLldklG2GHNhaGnXGVR5XIYnYtMlps=; fh=MGAzry9diqUGtnqhZH7y3uGb0vIVhFhH814Wz0msQEg=; b=N2pdkCf2O2aMHlHaXnQeekS+n5BLCzLEnVYXNw3G0TdV1LQ0UNBfKewGIUoGizGUHi gs/fV1roq6zYRReDy7rZmy3Tag2gQ9etpbO0EkwXq3CYXmvGqkeuxCmdFgI805Q/rhXv tPk2z8/PUm4XyJyAEkvbjvKNifVz9dEBPvkWLJbt/VXlS4zrOCTeytbF5vvLp7E9lG9g 2T8yES3cDiHhHdaa+29ELupOwqOTX3S/qrrs+4TLOwJAE/W01ODp8AIqghzhMS52WSzO fvW1rofqy01wku8GIrhe0i5s7bixE+lm6BO2MPoQJFKU0pHPyD/pct9rttIfyEodE3Uv jDSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=At2P8Uxx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id ch10-20020a056a0208ca00b0053074c54c3fsi6424267pgb.868.2023.10.23.04.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 04:43:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=At2P8Uxx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id E913480B1FB2; Mon, 23 Oct 2023 04:43:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234368AbjJWLnc (ORCPT + 99 others); Mon, 23 Oct 2023 07:43:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234320AbjJWLnT (ORCPT ); Mon, 23 Oct 2023 07:43:19 -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 2562010C7 for ; Mon, 23 Oct 2023 04:43:15 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-533d31a8523so4623611a12.1 for ; Mon, 23 Oct 2023 04:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698061393; x=1698666193; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=/lK2Os4ki3ybOrLldklG2GHNhaGnXGVR5XIYnYtMlps=; b=At2P8Uxxzv6GI6YeQtOqwWEEtGW7rpN+HK5vowzXObtwm1phbFN8RTQzN0JAUI7ui9 6bu0hDr+YIOvp6vhkNWaVKzfG3jIzduVH9cKsBQyefNKj3eBHU8mYht5BHrH6tCg9hLn bUJiP9X/LZy8B6m5URFKaoSTpTM4oDbOY+s9EqjBa48+U3dvItekLOtmDxr/qT96F3dD 59q1SYJYk/lRmBez6MhdqMdzMzaP5YP/3BcwgSfu2aguyS/IcXWNJPn0VzFSrQmWbzft iaF2JXeQ6GiA9xDrZ7gQvZ6kOas0lwIYrz5Fvh4JqDQLb82y2iYXuM1ZkP3pTE2zC1ni drvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698061393; x=1698666193; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/lK2Os4ki3ybOrLldklG2GHNhaGnXGVR5XIYnYtMlps=; b=JO+QjS12ORs4cqGA3UgG7j1fEeotN2uRlZvFQmpUukXaplCwvp9/6QFyxO65CGYuCe BTB94HgaAWBO4H2zgqLEBv9WQEOTD1tBC6NQz5pKHGXzt1b6sEoosIGXaxYeKGUNTjJn ZOb/8GhFCfThxhdcqYjaq6ys+kByRpUNRoXYo+wJQgqyEars81D4qQrAQKA1kKBwEDfS XcEYymiE05blVTTD8i6WHdqgCRShgx/S+kfmTVkaovNUPKNC0H0yX4i7iyKitYvCF9qg LIxIwS73f9FlAvfSeAN8NnWInbK8nQtc2hFSX6cPVQkh4ZyTi39F0oQ1W/vv2Js+i6XT GcIg== X-Gm-Message-State: AOJu0YzqDfUNnUV4jeymD/1/ZkAz6asqk5/jVoGGYBU5cajrsaCYUfSh OS/xYLMJdxRm6Dd6ZmV/ibHQVw== X-Received: by 2002:a05:6402:5114:b0:53f:efbc:e42b with SMTP id m20-20020a056402511400b0053fefbce42bmr5172581edd.34.1698061393557; Mon, 23 Oct 2023 04:43:13 -0700 (PDT) Received: from hades (ppp046103219117.access.hol.gr. [46.103.219.117]) by smtp.gmail.com with ESMTPSA id y26-20020aa7d51a000000b0053dda7926fcsm6146215edq.60.2023.10.23.04.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 04:43:13 -0700 (PDT) Date: Mon, 23 Oct 2023 14:43:10 +0300 From: Ilias Apalodimas 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 Subject: Re: [PATCH net-next v12 1/5] page_pool: unify frag_count handling in page_pool_is_last_frag() Message-ID: References: <20231020095952.11055-1-linyunsheng@huawei.com> <20231020095952.11055-2-linyunsheng@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231020095952.11055-2-linyunsheng@huawei.com> 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 04:43:46 -0700 (PDT) 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. > + > 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