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 <edumazet@google.com>
Cc: Allen Pais <allen.lkml@gmail.com>
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Eric Dumazet 2020-10-07 09:51:11 -07:00 committed by Jakub Kicinski
parent 036dfd8322
commit 846e463a70
3 changed files with 10 additions and 23 deletions

View File

@ -19,12 +19,9 @@ struct qdisc_walker {
int (*fn)(struct Qdisc *, unsigned long cl, struct qdisc_walker *); int (*fn)(struct Qdisc *, unsigned long cl, struct qdisc_walker *);
}; };
#define QDISC_ALIGNTO 64
#define QDISC_ALIGN(len) (((len) + QDISC_ALIGNTO-1) & ~(QDISC_ALIGNTO-1))
static inline void *qdisc_priv(struct Qdisc *q) static inline void *qdisc_priv(struct Qdisc *q)
{ {
return (char *) q + QDISC_ALIGN(sizeof(struct Qdisc)); return &q->privdata;
} }
/* /*

View File

@ -91,7 +91,7 @@ struct Qdisc {
struct net_rate_estimator __rcu *rate_est; struct net_rate_estimator __rcu *rate_est;
struct gnet_stats_basic_cpu __percpu *cpu_bstats; struct gnet_stats_basic_cpu __percpu *cpu_bstats;
struct gnet_stats_queue __percpu *cpu_qstats; struct gnet_stats_queue __percpu *cpu_qstats;
int padded; int pad;
refcount_t refcnt; refcount_t refcnt;
/* /*
@ -112,6 +112,9 @@ struct Qdisc {
/* for NOLOCK qdisc, true if there are no enqueued skbs */ /* for NOLOCK qdisc, true if there are no enqueued skbs */
bool empty; bool empty;
struct rcu_head rcu; struct rcu_head rcu;
/* private data */
long privdata[] ____cacheline_aligned;
}; };
static inline void qdisc_refcount_inc(struct Qdisc *qdisc) static inline void qdisc_refcount_inc(struct Qdisc *qdisc)

View File

@ -802,9 +802,8 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
const struct Qdisc_ops *ops, const struct Qdisc_ops *ops,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
void *p;
struct Qdisc *sch; struct Qdisc *sch;
unsigned int size = QDISC_ALIGN(sizeof(*sch)) + ops->priv_size; unsigned int size = sizeof(*sch) + ops->priv_size;
int err = -ENOBUFS; int err = -ENOBUFS;
struct net_device *dev; struct net_device *dev;
@ -815,22 +814,10 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
} }
dev = dev_queue->dev; dev = dev_queue->dev;
p = kzalloc_node(size, GFP_KERNEL, sch = kzalloc_node(size, GFP_KERNEL, netdev_queue_numa_node_read(dev_queue));
netdev_queue_numa_node_read(dev_queue));
if (!p) if (!sch)
goto errout; goto errout;
sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p);
/* if we got non aligned memory, ask more and do alignment ourself */
if (sch != p) {
kfree(p);
p = kzalloc_node(size + QDISC_ALIGNTO - 1, GFP_KERNEL,
netdev_queue_numa_node_read(dev_queue));
if (!p)
goto errout;
sch = (struct Qdisc *) QDISC_ALIGN((unsigned long) p);
sch->padded = (char *) sch - (char *) p;
}
__skb_queue_head_init(&sch->gso_skb); __skb_queue_head_init(&sch->gso_skb);
__skb_queue_head_init(&sch->skb_bad_txq); __skb_queue_head_init(&sch->skb_bad_txq);
qdisc_skb_head_init(&sch->q); qdisc_skb_head_init(&sch->q);
@ -873,7 +860,7 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,
return sch; return sch;
errout1: errout1:
kfree(p); kfree(sch);
errout: errout:
return ERR_PTR(err); return ERR_PTR(err);
} }
@ -941,7 +928,7 @@ void qdisc_free(struct Qdisc *qdisc)
free_percpu(qdisc->cpu_qstats); free_percpu(qdisc->cpu_qstats);
} }
kfree((char *) qdisc - qdisc->padded); kfree(qdisc);
} }
static void qdisc_free_cb(struct rcu_head *head) static void qdisc_free_cb(struct rcu_head *head)