mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-08 13:44:56 +02:00
quota2: reduce memory footprint for anonymous counters
48/64 bytes (32/64-bit arch, resp.) per counter.
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
- build: support for Linux 2.6.31-rc1
|
- build: support for Linux 2.6.31-rc1
|
||||||
- quota2: support nameless counters
|
- quota2: support anonymous counters
|
||||||
|
- quota2: reduce memory footprint for anonymous counters
|
||||||
|
|
||||||
|
|
||||||
Xtables-addons 1.17 (June 16 2009)
|
Xtables-addons 1.17 (June 16 2009)
|
||||||
|
@@ -21,6 +21,9 @@
|
|||||||
#include "xt_quota2.h"
|
#include "xt_quota2.h"
|
||||||
#include "compat_xtables.h"
|
#include "compat_xtables.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @lock: lock to protect quota writers from each other
|
||||||
|
*/
|
||||||
struct xt_quota_counter {
|
struct xt_quota_counter {
|
||||||
u_int64_t quota;
|
u_int64_t quota;
|
||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
@@ -72,19 +75,24 @@ static int quota_proc_write(struct file *file, const char __user *input,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct xt_quota_counter *
|
static struct xt_quota_counter *
|
||||||
q2_new_counter(const struct xt_quota_mtinfo2 *q)
|
q2_new_counter(const struct xt_quota_mtinfo2 *q, bool anon)
|
||||||
{
|
{
|
||||||
struct xt_quota_counter *e;
|
struct xt_quota_counter *e;
|
||||||
|
unsigned int size;
|
||||||
|
|
||||||
e = kmalloc(sizeof(*e), GFP_KERNEL);
|
/* Do not need all the procfs things for anonymous counters. */
|
||||||
|
size = anon ? offsetof(typeof(*e), list) : sizeof(*e);
|
||||||
|
e = kmalloc(size, GFP_KERNEL);
|
||||||
if (e == NULL)
|
if (e == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
e->quota = q->quota;
|
e->quota = q->quota;
|
||||||
spin_lock_init(&e->lock);
|
spin_lock_init(&e->lock);
|
||||||
|
if (!anon) {
|
||||||
INIT_LIST_HEAD(&e->list);
|
INIT_LIST_HEAD(&e->list);
|
||||||
atomic_set(&e->ref, 1);
|
atomic_set(&e->ref, 1);
|
||||||
strncpy(e->name, q->name, sizeof(e->name));
|
strncpy(e->name, q->name, sizeof(e->name));
|
||||||
|
}
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +107,7 @@ q2_get_counter(const struct xt_quota_mtinfo2 *q)
|
|||||||
struct xt_quota_counter *e;
|
struct xt_quota_counter *e;
|
||||||
|
|
||||||
if (*q->name == '\0')
|
if (*q->name == '\0')
|
||||||
return q2_new_counter(q);
|
return q2_new_counter(q, true);
|
||||||
|
|
||||||
spin_lock_bh(&counter_list_lock);
|
spin_lock_bh(&counter_list_lock);
|
||||||
list_for_each_entry(e, &counter_list, list)
|
list_for_each_entry(e, &counter_list, list)
|
||||||
@@ -109,7 +117,7 @@ q2_get_counter(const struct xt_quota_mtinfo2 *q)
|
|||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
e = q2_new_counter(q);
|
e = q2_new_counter(q, false);
|
||||||
if (e == NULL)
|
if (e == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user