Skip to content

Commit 846e463

Browse files
edumazetkuba-moo
authored andcommitted
net/sched: get rid of qdisc->padded
kmalloc() of sufficiently big portion of memory is cache-aligned in regular conditions. If some debugging options are used, there is no reason qdisc structures would need 64-byte alignment if most other kernel structures are not aligned. This get rid of QDISC_ALIGN and QDISC_ALIGNTO. Addition of privdata field will help implementing the reverse of qdisc_priv() and documents where the private data is. Signed-off-by: Eric Dumazet <[email protected]> Cc: Allen Pais <[email protected]> Acked-by: Cong Wang <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 036dfd8 commit 846e463

File tree

3 files changed

+10
-23
lines changed

3 files changed

+10
-23
lines changed

include/net/pkt_sched.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ struct qdisc_walker {
1919
int (*fn)(struct Qdisc *, unsigned long cl, struct qdisc_walker *);
2020
};
2121

22-
#define QDISC_ALIGNTO 64
23-
#define QDISC_ALIGN(len) (((len) + QDISC_ALIGNTO-1) & ~(QDISC_ALIGNTO-1))
24-
2522
static inline void *qdisc_priv(struct Qdisc *q)
2623
{
27-
return (char *) q + QDISC_ALIGN(sizeof(struct Qdisc));
24+
return &q->privdata;
2825
}
2926

3027
/*

include/net/sch_generic.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct Qdisc {
9191
struct net_rate_estimator __rcu *rate_est;
9292
struct gnet_stats_basic_cpu __percpu *cpu_bstats;
9393
struct gnet_stats_queue __percpu *cpu_qstats;
94-
int padded;
94+
int pad;
9595
refcount_t refcnt;
9696

9797
/*
@@ -112,6 +112,9 @@ struct Qdisc {
112112
/* for NOLOCK qdisc, true if there are no enqueued skbs */
113113
bool empty;
114114
struct rcu_head rcu;
115+
116+
/* private data */
117+
long privdata[] ____cacheline_aligned;
115118
};
116119

117120
static inline void qdisc_refcount_inc(struct Qdisc *qdisc)

net/sched/sch_generic.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,8 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
802802
const struct Qdisc_ops *ops,
803803
struct netlink_ext_ack *extack)
804804
{
805-
void *p;
806805
struct Qdisc *sch;
807-
unsigned int size = QDISC_ALIGN(sizeof(*sch)) + ops->priv_size;
806+
unsigned int size = sizeof(*sch) + ops->priv_size;
808807
int err = -ENOBUFS;
809808
struct net_device *dev;
810809

@@ -815,22 +814,10 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
815814
}
816815

817816
dev = dev_queue->dev;
818-
p = kzalloc_node(size, GFP_KERNEL,
819-
netdev_queue_numa_node_read(dev_queue));
817+
sch = kzalloc_node(size, GFP_KERNEL, netdev_queue_numa_node_read(dev_queue));
820818

821-
if (!p)
819+
if (!sch)
822820
goto errout;
823-
sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p);
824-
/* if we got non aligned memory, ask more and do alignment ourself */
825-
if (sch != p) {
826-
kfree(p);
827-
p = kzalloc_node(size + QDISC_ALIGNTO - 1, GFP_KERNEL,
828-
netdev_queue_numa_node_read(dev_queue));
829-
if (!p)
830-
goto errout;
831-
sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p);
832-
sch->padded = (char *) sch - (char *) p;
833-
}
834821
__skb_queue_head_init(&sch->gso_skb);
835822
__skb_queue_head_init(&sch->skb_bad_txq);
836823
qdisc_skb_head_init(&sch->q);
@@ -873,7 +860,7 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
873860

874861
return sch;
875862
errout1:
876-
kfree(p);
863+
kfree(sch);
877864
errout:
878865
return ERR_PTR(err);
879866
}
@@ -941,7 +928,7 @@ void qdisc_free(struct Qdisc *qdisc)
941928
free_percpu(qdisc->cpu_qstats);
942929
}
943930

944-
kfree((char *) qdisc - qdisc->padded);
931+
kfree(qdisc);
945932
}
946933

947934
static void qdisc_free_cb(struct rcu_head *head)

0 commit comments

Comments
 (0)