From patchwork Fri Apr 9 22:37:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12195161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A928C433ED for ; Fri, 9 Apr 2021 22:38:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B1622610F9 for ; Fri, 9 Apr 2021 22:38:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1622610F9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4C9A46B0071; Fri, 9 Apr 2021 18:38:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 453F46B0072; Fri, 9 Apr 2021 18:38:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A8486B0073; Fri, 9 Apr 2021 18:38:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 0791C6B0071 for ; Fri, 9 Apr 2021 18:38:24 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B233B8248047 for ; Fri, 9 Apr 2021 22:38:23 +0000 (UTC) X-FDA: 78014293686.21.1F0773E Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by imf29.hostedemail.com (Postfix) with ESMTP id B6C4E130 for ; Fri, 9 Apr 2021 22:38:21 +0000 (UTC) Received: by mail-ed1-f44.google.com with SMTP id 18so8288458edx.3 for ; Fri, 09 Apr 2021 15:38:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NBKBwFnLR6KheF+0+jTnrdx81GBF+PEZpOcMgLUdP0I=; b=W1SpzBr5VGt1yI8OVet7JNwyQm2q9X2pWCDcvFSfcZ07HPhQceF6KzZ5mbDJIJZ1aV Txv16UHGcpfmPGSDf7rJzoGYWnFWV92x76mLDFW2rzULiftzt1+5ZG/560Rz+DLaMqZ9 NEnxZYqxRo3oPLaOsUahu4t5FC25hFQEJZgbrzYvNOmzoi4+45JI/esqRESX8hKYMW8Z lzWlrxD1HHsm/ptbAyKheL9ocJLYTiksY+d+K6X3OfQDPakCFiXHAtYa6VwCpi9j8ifs VCboDp74nEko2Ufm5eBjS6L7JigVEO9ofZSZVnYUmC6Gvi5kLKba6vgg6U+4FPfrCgTu RIcw== X-Gm-Message-State: AOAM530NSiVkDntZbqzEGEMoNgeM9veTe4s5fNIp5LZQ9moKcTuEvOEC r3kOlhUZVN3sxWBM0VCs6To= X-Google-Smtp-Source: ABdhPJwtnHH8zpJEzm27S9Tc0XAdPpGrPGHLvRaejF34zvtOUNDL6mxmVFoz2jOa3QSgVZRWgp5IlQ== X-Received: by 2002:a05:6402:51cd:: with SMTP id r13mr19553933edd.116.1618007902253; Fri, 09 Apr 2021 15:38:22 -0700 (PDT) Received: from msft-t490s.teknoraver.net (net-93-66-21-119.cust.vodafonedsl.it. [93.66.21.119]) by smtp.gmail.com with ESMTPSA id s20sm2108726edu.93.2021.04.09.15.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 15:38:21 -0700 (PDT) From: Matteo Croce To: netdev@vger.kernel.org, linux-mm@kvack.org Cc: Ayush Sawal , Vinay Kumar Yadav , Rohit Maheshwari , "David S. Miller" , Jakub Kicinski , Thomas Petazzoni , Marcin Wojtas , Russell King , Mirko Lindner , Stephen Hemminger , Tariq Toukan , Jesper Dangaard Brouer , Ilias Apalodimas , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Boris Pismenny , Arnd Bergmann , Andrew Morton , "Peter Zijlstra (Intel)" , Vlastimil Babka , Yu Zhao , Will Deacon , Michel Lespinasse , Fenghua Yu , Roman Gushchin , Hugh Dickins , Peter Xu , Jason Gunthorpe , Guoqing Jiang , Jonathan Lemon , Alexander Lobakin , Cong Wang , wenxu , Kevin Hao , Aleksandr Nogikh , Jakub Sitnicki , Marco Elver , Willem de Bruijn , Miaohe Lin , Yunsheng Lin , Guillaume Nault , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, bpf@vger.kernel.org, Matthew Wilcox , Eric Dumazet , David Ahern , Lorenzo Bianconi , Saeed Mahameed , Andrew Lunn , Paolo Abeni Subject: [PATCH net-next v3 1/5] xdp: reduce size of struct xdp_mem_info Date: Sat, 10 Apr 2021 00:37:57 +0200 Message-Id: <20210409223801.104657-2-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210409223801.104657-1-mcroce@linux.microsoft.com> References: <20210409223801.104657-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B6C4E130 X-Stat-Signature: yyo1psinj6ybgqweidd339fiayt1b57n Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=mail-ed1-f44.google.com; client-ip=209.85.208.44 X-HE-DKIM-Result: none/none X-HE-Tag: 1618007901-979644 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Jesper Dangaard Brouer It is possible to compress/reduce the size of struct xdp_mem_info. This change reduce struct xdp_mem_info from 8 bytes to 4 bytes. The member xdp_mem_info.id can be reduced to u16, as the mem_id_ht rhashtable in net/core/xdp.c is already limited by MEM_ID_MAX=0xFFFE which can safely fit in u16. The member xdp_mem_info.type could be reduced more than u16, as it stores the enum xdp_mem_type, but due to alignment it is only reduced to u16. Signed-off-by: Jesper Dangaard Brouer --- include/net/xdp.h | 4 ++-- net/core/xdp.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/net/xdp.h b/include/net/xdp.h index a5bc214a49d9..c35864d59113 100644 --- a/include/net/xdp.h +++ b/include/net/xdp.h @@ -48,8 +48,8 @@ enum xdp_mem_type { #define XDP_XMIT_FLAGS_MASK XDP_XMIT_FLUSH struct xdp_mem_info { - u32 type; /* enum xdp_mem_type, but known size type */ - u32 id; + u16 type; /* enum xdp_mem_type, but known size type */ + u16 id; }; struct page_pool; diff --git a/net/core/xdp.c b/net/core/xdp.c index 05354976c1fc..3dd47ed83778 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -35,11 +35,11 @@ static struct rhashtable *mem_id_ht; static u32 xdp_mem_id_hashfn(const void *data, u32 len, u32 seed) { - const u32 *k = data; - const u32 key = *k; + const u16 *k = data; + const u16 key = *k; BUILD_BUG_ON(sizeof_field(struct xdp_mem_allocator, mem.id) - != sizeof(u32)); + != sizeof(u16)); /* Use cyclic increasing ID as direct hash key */ return key; @@ -49,7 +49,7 @@ static int xdp_mem_id_cmp(struct rhashtable_compare_arg *arg, const void *ptr) { const struct xdp_mem_allocator *xa = ptr; - u32 mem_id = *(u32 *)arg->key; + u16 mem_id = *(u16 *)arg->key; return xa->mem.id != mem_id; }