Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp616416rdb; Fri, 26 Jan 2024 05:57:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBNNCwGkLNbTJstIGfHPCJQdKgOMhyelYoVYlyHSTVFMrQqQkTS4SoJ8ADC9YRg6pRVQIC X-Received: by 2002:ac8:7c48:0:b0:42a:5192:aed0 with SMTP id o8-20020ac87c48000000b0042a5192aed0mr1625575qtv.10.1706277454508; Fri, 26 Jan 2024 05:57:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706277454; cv=pass; d=google.com; s=arc-20160816; b=Mg1RKpVuFmMkj6GiX4YfPMTGxHUD5kEGw9rzTC5hA6bBp8HVJ26/kU/olso7gPMsuk KEd8gJIDPsm/4H/y3/e4QnPCuSd7/mJdnCApoF30wse4Hz7MRhjowdcS83dvYVEj09eh oVVgfRb1DRWrDN8n8EGaxQ3wbft7ph1J3O1lpCXf2owXauDLMqRwyuzuAGOxrj7ijy56 CgX3g3juzR4MN3GR6/H0B8vz9IkVVjFzL4NlDOCDySuJI1KfMzV6R3tiXnNPDZz9ykHY 6RJFgyLHvYWLwJdnL+HV6/7b9+4ftb50RlsP0i4gLf3KwUOQuKz/8sISTUGWTAkRBwjV fjYw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=L9I6zKyaecDW+yXld8UoYqEVvpbYMSKipidpIcy5GJs=; fh=eTd7umz5bDwrA2O8RT65r37r0t9PpqaUSn0Me2ng9gY=; b=a4EqGu3WXQuteSRma/JvYyqZE7NTruAq4iU8u7bsV0FoJEzsFcyxgMduw7IDA2KDBQ +qVoXEO5dAGkpS6IwNCfEsOKc5oU+lLxQF5O1jNxAEsb8PPUoEz7UwiTIq+84adxEfys LjKFEUAQly9mpgWnF/judf8HNT5W0ilbaeCQIYdq48/sBQP3iw4sNbosG5zLUF6tnR4J kH+xKLacGy/v1LBpnduCdTnfkfb+IiTAkYp0dWVg3/qKbUWXIFrlm95QskPHQESAZDeI oj1LpkZT+efS8BGNdepoYpt1TKmPvYeMdBD12DYZQ1f4S42c83G6KlmdTwhoeG5mUAsW r6Jg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W2B2LoTN; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-40153-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40153-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u16-20020a05622a199000b0042a619ef4c2si1266431qtc.94.2024.01.26.05.57.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 05:57:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40153-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=W2B2LoTN; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-40153-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40153-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 324421C2323D for ; Fri, 26 Jan 2024 13:57:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 12AB31CD3F; Fri, 26 Jan 2024 13:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="W2B2LoTN" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82FA61B97F; Fri, 26 Jan 2024 13:56:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706277373; cv=none; b=QjyKOWLFJr3x1THZxuotL/w+FW/8hjyEEpLN9ThCIVtPfxtBvNDvEVTEzafD2SAvJnvhFOwa97k53bslgviWQiM9D3cLmGcJq5K1w9SPynSNhtzaph5OoQZ7MvK9Sob9ZNC3Due1RbP4ihkmc5DPBPOZLtcRK9ZeM5KZf5/Msz4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706277373; c=relaxed/simple; bh=vQ9pXrWvroiooYs41SwiRJil8dTyqvM8/gTLYDeQYJU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oLYiV6nQVbrVKMihm1lmgQRpoAqTpQCONZrEkfhTfPnBARG3u+68VcexTrRnbMjqmswkY0hUuSkfYOfcUnVXcu33VthqQB6/Z5bUpRs7Ovx2udvBIu7wmneYHRMc0iqnHoaSmJUxXNN1k8fgg4nwq07+BUiRVWQJ8cmh+L9dSbw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=W2B2LoTN; arc=none smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706277372; x=1737813372; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vQ9pXrWvroiooYs41SwiRJil8dTyqvM8/gTLYDeQYJU=; b=W2B2LoTN1xtnOoUd688SGqBcHhjGw3EQORZ8i1Z06JHXDqPd3RgH/HG+ D2gpa9zwDLwHHdTq8ey8GaE4MMwhn7IGtgIo58QG7l9o+V3b4L8qbw8hh KdPvAbJq4dgHGEMDvEHURd07FGIZeUAPkIV1qe41E2trSrQU+DaLN5coA 3gD+O9en692O5yYrOmoXurcLgFecV+idkPZ2/7gDy2BgFoHQNjOa80/Xf GlqFQJWTiTM9ktO0ml1A1zHX4jN2aFKGsQPM0BfsMzugH7D0jlw4fg09m /S8yB9dATVkeEfH12VVvvp3kw/5i8DQpPL5IucsZ/D36nOIfMB0Mpt53i Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="15998481" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="15998481" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2024 05:56:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="821142945" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="821142945" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orsmga001.jf.intel.com with ESMTP; 26 Jan 2024 05:56:06 -0800 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Joerg Roedel , Will Deacon , Greg Kroah-Hartman , "Rafael J. Wysocki" , Magnus Karlsson , Maciej Fijalkowski , Alexander Duyck , bpf@vger.kernel.org, netdev@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH net-next 4/7] page_pool: make sure frag API fields don't span between cachelines Date: Fri, 26 Jan 2024 14:54:53 +0100 Message-ID: <20240126135456.704351-5-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126135456.704351-1-aleksander.lobakin@intel.com> References: <20240126135456.704351-1-aleksander.lobakin@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit After commit 5027ec19f104 ("net: page_pool: split the page_pool_params into fast and slow") that made &page_pool contain only "hot" params at the start, cacheline boundary chops frag API fields group in the middle again. To not bother with this each time fast params get expanded or shrunk, let's just align them to `4 * sizeof(long)`, the closest upper pow-2 to their actual size (2 longs + 1 int). This ensures 16-byte alignment for the 32-bit architectures and 32-byte alignment for the 64-bit ones, excluding unnecessary false-sharing. ::page_state_hold_cnt is used quite intensively on hotpath no matter if frag API is used, so move it to the newly created hole in the first cacheline. Signed-off-by: Alexander Lobakin --- include/net/page_pool/types.h | 12 +++++++++++- net/core/page_pool.c | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h index 76481c465375..217e73b7e4fc 100644 --- a/include/net/page_pool/types.h +++ b/include/net/page_pool/types.h @@ -128,12 +128,22 @@ struct page_pool_stats { struct page_pool { struct page_pool_params_fast p; + u32 pages_state_hold_cnt; bool has_init_callback; + /* The following block must stay within one cacheline. On 32-bit + * systems, sizeof(long) == sizeof(int), so that the block size is + * ``3 * sizeof(long)``. On 64-bit systems, the actual size is + * ``2 * sizeof(long) + sizeof(int)``. The closest pow-2 to both of + * them is ``4 * sizeof(long)``, so just use that one for simplicity. + * Having it aligned to a cacheline boundary may be excessive and + * doesn't bring any good. + */ + __cacheline_group_begin(frag) __aligned(4 * sizeof(long)); long frag_users; struct page *frag_page; unsigned int frag_offset; - u32 pages_state_hold_cnt; + __cacheline_group_end(frag); struct delayed_work release_dw; void (*disconnect)(void *pool); diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 4933762e5a6b..be1219816990 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -170,11 +170,20 @@ static void page_pool_producer_unlock(struct page_pool *pool, spin_unlock_bh(&pool->ring.producer_lock); } +static void page_pool_struct_check(void) +{ + CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_users); + CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_page); + CACHELINE_ASSERT_GROUP_MEMBER(struct page_pool, frag, frag_offset); +} + static int page_pool_init(struct page_pool *pool, const struct page_pool_params *params) { unsigned int ring_qsize = 1024; /* Default */ + page_pool_struct_check(); + memcpy(&pool->p, ¶ms->fast, sizeof(pool->p)); memcpy(&pool->slow, ¶ms->slow, sizeof(pool->slow)); -- 2.43.0