Message ID | d47800d9fd5ac7c33d01af04b12b6d43ad23c96e.1676379187.git.christophe.jaillet@wanadoo.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2954155wrn; Tue, 14 Feb 2023 05:00:38 -0800 (PST) X-Google-Smtp-Source: AK7set9e9A5/mZbNiNHcSxTMz+8MZIB5KJr3O5K0/u5fAvtI91Kn81FEYtPaQWeA0EdP9ch5DJGr X-Received: by 2002:aa7:9470:0:b0:5a8:ad0e:5bf1 with SMTP id t16-20020aa79470000000b005a8ad0e5bf1mr1605640pfq.12.1676379638524; Tue, 14 Feb 2023 05:00:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676379638; cv=none; d=google.com; s=arc-20160816; b=nwek4m4xf6fcUm6gqvTgKcjCeCNKijWW9gTGCycLPZEoOuegSxIDpxikDm5WonSSkV N8WU1DWUfZx1Z2kmPEeee9aup0bK65KlnbgEdBhXbSP+PgFHihtKEspwCuQLksrcm/0G JJL4nq6c/1e957qT7XApPlHDgHfn0yvUUj9kPqw+AzoHeA2l5R/LBncju//MoUh0CMC/ 2hQ7yMgXvOikB3lJ3KvsFuJKLPq0FJ2GDbmZs8x65lDRs2FVhrcwwa3w6jYyjniwAuyF XKZKUYeImA1Gtbka8E39f2gECZRQ1TQEpeS8cSpreim/Jc4w12QCHh7d563bxM8vQynW eJmg== 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; bh=yYHKKHR9Dju0aAySqsOZZP5Hdr2PZxHwP2ge5aS3NmM=; b=T7E6oUli7TajtiEb62hh2OgNhMm9Wn3/4GQ1AZt0MTQ5E7L/AsHfBPiqZi/gWB1SF4 6xVEH80kZhNpma6Cdn4ILQ70T8+mRWU6G61kxgIJFeuYxOCVpIriF7gUmGbwM6bZc9dQ 8T+CINiLoN2Ck+0n0n49VbY1n/jOqbnSDPhHd+jLIhaMw4+4346xmOO3dpJRAPKrAEBI 1thzyiPSjsO2G4BsmTq63XQkBcKaBQKBeFplSHeBw06LblQIRlN+Pje6rQ2kEX8dqx2E Yf1OPcWQTYRdwx64gCqn3FPYsnVuC8JY2o1Dh0Wm1FekwYPSceD4vR7Z8jx+ZJiqoxWR ZpXg== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t9-20020aa79469000000b005627f4b21absi14451287pfq.296.2023.02.14.05.00.25; Tue, 14 Feb 2023 05:00:38 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231781AbjBNMyK (ORCPT <rfc822;tebrre53rla2o@gmail.com> + 99 others); Tue, 14 Feb 2023 07:54:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230162AbjBNMyJ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 14 Feb 2023 07:54:09 -0500 Received: from smtp.smtpout.orange.fr (smtp-17.smtpout.orange.fr [80.12.242.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 823DE21280 for <linux-kernel@vger.kernel.org>; Tue, 14 Feb 2023 04:53:57 -0800 (PST) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id Ruokph5lwOJaFRuolpOzce; Tue, 14 Feb 2023 13:53:55 +0100 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 14 Feb 2023 13:53:55 +0100 X-ME-IP: 86.243.2.178 From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org> Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, linux-rdma@vger.kernel.org Subject: [PATCH] RDMA/restrack: Reorder fields in 'struct rdma_restrack_entry' Date: Tue, 14 Feb 2023 13:53:52 +0100 Message-Id: <d47800d9fd5ac7c33d01af04b12b6d43ad23c96e.1676379187.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757811455687226343?= X-GMAIL-MSGID: =?utf-8?q?1757811455687226343?= |
Series |
RDMA/restrack: Reorder fields in 'struct rdma_restrack_entry'
|
|
Commit Message
Christophe JAILLET
Feb. 14, 2023, 12:53 p.m. UTC
Group some variables based on their sizes to reduce hole and avoid padding.
On x86_64, this shrinks the size from 136 to 128 bytes.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Using pahole
Before:
======
struct rdma_restrack_entry {
bool valid; /* 0 1 */
u8 no_track:1; /* 1: 0 1 */
/* XXX 7 bits hole, try to pack */
/* XXX 2 bytes hole, try to pack */
struct kref kref; /* 4 4 */
struct completion comp; /* 8 96 */
/* --- cacheline 1 boundary (64 bytes) was 40 bytes ago --- */
struct task_struct * task; /* 104 8 */
const char * kern_name; /* 112 8 */
enum rdma_restrack_type type; /* 120 4 */
bool user; /* 124 1 */
/* XXX 3 bytes hole, try to pack */
/* --- cacheline 2 boundary (128 bytes) --- */
u32 id; /* 128 4 */
/* size: 136, cachelines: 3, members: 9 */
/* sum members: 126, holes: 2, sum holes: 5 */
/* sum bitfield members: 1 bits, bit holes: 1, sum bit holes: 7 bits */
/* padding: 4 */
/* last cacheline: 8 bytes */
};
After:
=====
struct rdma_restrack_entry {
bool valid; /* 0 1 */
u8 no_track:1; /* 1: 0 1 */
/* XXX 7 bits hole, try to pack */
bool user; /* 2 1 */
/* XXX 1 byte hole, try to pack */
struct kref kref; /* 4 4 */
struct completion comp; /* 8 96 */
/* --- cacheline 1 boundary (64 bytes) was 40 bytes ago --- */
struct task_struct * task; /* 104 8 */
const char * kern_name; /* 112 8 */
enum rdma_restrack_type type; /* 120 4 */
u32 id; /* 124 4 */
/* size: 128, cachelines: 2, members: 9 */
/* sum members: 126, holes: 1, sum holes: 1 */
/* sum bitfield members: 1 bits, bit holes: 1, sum bit holes: 7 bits */
};
---
include/rdma/restrack.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
Comments
On Tue, Feb 14, 2023 at 01:53:52PM +0100, Christophe JAILLET wrote: > diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h > index 8b7c46daeb07..da53fefe6f9e 100644 > --- a/include/rdma/restrack.h > +++ b/include/rdma/restrack.h > @@ -80,6 +80,10 @@ struct rdma_restrack_entry { > * query stage. > */ > u8 no_track : 1; > + /** > + * @user: user resource > + */ > + bool user; Can we combine this into the bitfield above? Jason
Le 14/02/2023 à 14:08, Jason Gunthorpe a écrit : > On Tue, Feb 14, 2023 at 01:53:52PM +0100, Christophe JAILLET wrote: >> diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h >> index 8b7c46daeb07..da53fefe6f9e 100644 >> --- a/include/rdma/restrack.h >> +++ b/include/rdma/restrack.h >> @@ -80,6 +80,10 @@ struct rdma_restrack_entry { >> * query stage. >> */ >> u8 no_track : 1; >> + /** >> + * @user: user resource >> + */ >> + bool user; > > Can we combine this into the bitfield above? > > Jason > Hi, and even above, we have bool valid; I wanted to keep the changes as minimal as possible, but I can change them all in a single bitfield. Do you want code such as: static void rdma_restrack_attach_task(struct rdma_restrack_entry *res, struct task_struct *task) { if (WARN_ON_ONCE(!task)) return; if (res->task) put_task_struct(res->task); get_task_struct(task); res->task = task; res->user = true; <-------- } to be changed with 0/1 instead of false/true? Apparently gcc 11.3 is fine with using true with u8:1, but I don't find it really logical. CJ
On Tue, Feb 14, 2023 at 03:34:21PM +0100, Christophe JAILLET wrote: > Le 14/02/2023 à 14:08, Jason Gunthorpe a écrit : > > On Tue, Feb 14, 2023 at 01:53:52PM +0100, Christophe JAILLET wrote: > > > diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h > > > index 8b7c46daeb07..da53fefe6f9e 100644 > > > --- a/include/rdma/restrack.h > > > +++ b/include/rdma/restrack.h > > > @@ -80,6 +80,10 @@ struct rdma_restrack_entry { > > > * query stage. > > > */ > > > u8 no_track : 1; > > > + /** > > > + * @user: user resource > > > + */ > > > + bool user; > > > > Can we combine this into the bitfield above? > > > > Jason > > > Hi, > > and even above, we have > bool valid; > > I wanted to keep the changes as minimal as possible, but I can change them > all in a single bitfield. IIRC it needs to be checked, I vaugely remember valid can't be a bitfield because it is an atomic > Do you want code such as: > static void rdma_restrack_attach_task(struct rdma_restrack_entry *res, > struct task_struct *task) > { > if (WARN_ON_ONCE(!task)) > return; > > if (res->task) > put_task_struct(res->task); > get_task_struct(task); > res->task = task; > res->user = true; <-------- > } > > to be changed with 0/1 instead of false/true? I'd keep with true/false Ideally the bitfield itself would be bool type too > Apparently gcc 11.3 is fine with using true with u8:1, but I don't find it > really logical. Bool types can be casted to integers in defined ways, it is pretty normal. Jason
On Tue, Feb 14, 2023 at 11:01:00AM -0400, Jason Gunthorpe wrote: > On Tue, Feb 14, 2023 at 03:34:21PM +0100, Christophe JAILLET wrote: > > Le 14/02/2023 à 14:08, Jason Gunthorpe a écrit : > > > On Tue, Feb 14, 2023 at 01:53:52PM +0100, Christophe JAILLET wrote: > > > > diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h > > > > index 8b7c46daeb07..da53fefe6f9e 100644 > > > > --- a/include/rdma/restrack.h > > > > +++ b/include/rdma/restrack.h > > > > @@ -80,6 +80,10 @@ struct rdma_restrack_entry { > > > > * query stage. > > > > */ > > > > u8 no_track : 1; > > > > + /** > > > > + * @user: user resource > > > > + */ > > > > + bool user; > > > > > > Can we combine this into the bitfield above? > > > > > > Jason > > > > > Hi, > > > > and even above, we have > > bool valid; > > > > I wanted to keep the changes as minimal as possible, but I can change them > > all in a single bitfield. > > IIRC it needs to be checked, I vaugely remember valid can't be a > bitfield because it is an atomic I don't remember anything like this. Thanks
Le 15/02/2023 à 12:31, Leon Romanovsky a écrit : > On Tue, Feb 14, 2023 at 11:01:00AM -0400, Jason Gunthorpe wrote: >> On Tue, Feb 14, 2023 at 03:34:21PM +0100, Christophe JAILLET wrote: >>> Le 14/02/2023 à 14:08, Jason Gunthorpe a écrit : >>>> On Tue, Feb 14, 2023 at 01:53:52PM +0100, Christophe JAILLET wrote: >>>>> diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h >>>>> index 8b7c46daeb07..da53fefe6f9e 100644 >>>>> --- a/include/rdma/restrack.h >>>>> +++ b/include/rdma/restrack.h >>>>> @@ -80,6 +80,10 @@ struct rdma_restrack_entry { >>>>> * query stage. >>>>> */ >>>>> u8 no_track : 1; >>>>> + /** >>>>> + * @user: user resource >>>>> + */ >>>>> + bool user; >>>> >>>> Can we combine this into the bitfield above? >>>> >>>> Jason >>>> >>> Hi, >>> >>> and even above, we have >>> bool valid; >>> >>> I wanted to keep the changes as minimal as possible, but I can change them >>> all in a single bitfield. >> >> IIRC it needs to be checked, I vaugely remember valid can't be a >> bitfield because it is an atomic > > I don't remember anything like this. > > Thanks > If I understand code correctly, 'valid' is only used in rdma_restrack_add() and rdma_restrack_del(). I don't think that any atomic behavior is in place in these functions. I'll send in the coming days a v2 which changes 'valid', 'no_track' and 'user' as bool:1. CJ
diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h index 8b7c46daeb07..da53fefe6f9e 100644 --- a/include/rdma/restrack.h +++ b/include/rdma/restrack.h @@ -80,6 +80,10 @@ struct rdma_restrack_entry { * query stage. */ u8 no_track : 1; + /** + * @user: user resource + */ + bool user; /* * @kref: Protect destroy of the resource */ @@ -106,10 +110,6 @@ struct rdma_restrack_entry { * @type: various objects in restrack database */ enum rdma_restrack_type type; - /** - * @user: user resource - */ - bool user; /** * @id: ID to expose to users */