Signed-off-by: Vladimir Davydov <[email protected]>
---
Changes in v2:
 - use v[mz]alloc_account instead of __vmalloc + GFP_KERNEL_ACCOUNT
 - use __get_free_kmem_pages instead of alloc_kmem_pages + page_address
 - free pages allocated with __get_free_kmem_pages with free_kmem_pages
 - export __get_free_kmem_pages and free_kmem_pages functions

 arch/x86/kernel/ldt.c             |  8 ++++----
 drivers/tty/tty_io.c              |  4 ++--
 fs/fcntl.c                        |  2 +-
 fs/locks.c                        |  2 +-
 fs/namespace.c                    |  4 ++--
 fs/nfsd/vfs.c                     |  2 +-
 fs/pipe.c                         |  2 +-
 fs/select.c                       |  4 ++--
 fs/seq_file.c                     | 10 +++++-----
 ipc/msgutil.c                     |  4 ++--
 ipc/sem.c                         |  6 +++---
 ipc/util.c                        |  4 ++--
 kernel/fairsched.c                |  2 +-
 kernel/posix-timers.c             |  2 +-
 mm/page_alloc.c                   |  3 +++
 net/8021q/vlan.c                  |  2 +-
 net/core/dev.c                    | 10 +++++-----
 net/core/fib_rules.c              |  4 ++--
 net/core/filter.c                 |  2 +-
 net/core/scm.c                    |  4 ++--
 net/core/sock.c                   |  6 +++---
 net/ipv4/devinet.c                |  2 +-
 net/ipv4/fib_trie.c               |  4 ++--
 net/ipv4/netfilter/ip_tables.c    |  6 +++---
 net/ipv4/tcp.c                    |  2 +-
 net/ipv6/addrconf.c               |  2 +-
 net/ipv6/ip6_fib.c                |  2 +-
 net/ipv6/route.c                  |  2 +-
 net/netfilter/ipvs/ip_vs_conn.c   |  2 +-
 net/netfilter/nf_conntrack_core.c |  8 ++++----
 net/netfilter/x_tables.c          |  4 ++--
 net/packet/af_packet.c            | 14 +++++++-------
 32 files changed, 69 insertions(+), 66 deletions(-)

diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
index 79aa97d8fe4c..4a6c8fee47f2 100644
--- a/arch/x86/kernel/ldt.c
+++ b/arch/x86/kernel/ldt.c
@@ -42,9 +42,9 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int 
reload)
        mincount = (mincount + (PAGE_SIZE / LDT_ENTRY_SIZE - 1)) &
                        (~(PAGE_SIZE / LDT_ENTRY_SIZE - 1));
        if (mincount * LDT_ENTRY_SIZE > PAGE_SIZE)
-               newldt = vmalloc(mincount * LDT_ENTRY_SIZE);
+               newldt = vmalloc_account(mincount * LDT_ENTRY_SIZE);
        else
-               newldt = (void *)__get_free_page(GFP_KERNEL);
+               newldt = (void *)__get_free_kmem_pages(GFP_KERNEL_ACCOUNT, 0);
 
        if (!newldt)
                return -ENOMEM;
@@ -83,7 +83,7 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int 
reload)
                if (oldsize * LDT_ENTRY_SIZE > PAGE_SIZE)
                        vfree(oldldt);
                else
-                       put_page(virt_to_page(oldldt));
+                       __free_kmem_pages(virt_to_page(oldldt), 0);
        }
        return 0;
 }
@@ -138,7 +138,7 @@ void destroy_context(struct mm_struct *mm)
                if (mm->context.size * LDT_ENTRY_SIZE > PAGE_SIZE)
                        vfree(mm->context.ldt);
                else
-                       put_page(virt_to_page(mm->context.ldt));
+                       __free_kmem_pages(virt_to_page(mm->context.ldt), 0);
                mm->context.size = 0;
        }
 }
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index e4b03bb2a0a1..91ffc65a1ec4 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -167,7 +167,7 @@ static void proc_set_tty(struct task_struct *tsk, struct 
tty_struct *tty);
 
 struct tty_struct *alloc_tty_struct(void)
 {
-       return kzalloc(sizeof(struct tty_struct), GFP_KERNEL);
+       return kzalloc(sizeof(struct tty_struct), GFP_KERNEL_ACCOUNT);
 }
 
 /**
@@ -1512,7 +1512,7 @@ void tty_free_termios(struct tty_struct *tty)
        /* Stash the termios data */
        tp = tty->driver->termios[idx];
        if (tp == NULL) {
-               tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+               tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL_ACCOUNT);
                if (tp == NULL) {
                        pr_warn("tty: no memory to save termios state.\n");
                        return;
diff --git a/fs/fcntl.c b/fs/fcntl.c
index cfa349cccda2..8e8e40e8be0b 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -783,7 +783,7 @@ static int __init fcntl_init(void)
                ));
 
        fasync_cache = kmem_cache_create("fasync_cache",
-               sizeof(struct fasync_struct), 0, SLAB_PANIC, NULL);
+               sizeof(struct fasync_struct), 0, SLAB_PANIC | SLAB_ACCOUNT, 
NULL);
        return 0;
 }
 
diff --git a/fs/locks.c b/fs/locks.c
index 93c097bd7af4..ad89993d9ecb 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -2650,7 +2650,7 @@ static int __init filelock_init(void)
        int i;
 
        filelock_cache = kmem_cache_create("file_lock_cache",
-                       sizeof(struct file_lock), 0, SLAB_PANIC, NULL);
+                       sizeof(struct file_lock), 0, SLAB_PANIC | SLAB_ACCOUNT, 
NULL);
 
        lg_lock_init(&file_lock_lglock, "file_lock_lglock");
 
diff --git a/fs/namespace.c b/fs/namespace.c
index c4e43369929e..e86482fec6a4 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -183,7 +183,7 @@ static struct mount *alloc_vfsmnt(const char *name)
                        goto out_free_cache;
 
                if (name) {
-                       mnt->mnt_devname = kstrdup(name, GFP_KERNEL);
+                       mnt->mnt_devname = kstrdup(name, GFP_KERNEL_ACCOUNT);
                        if (!mnt->mnt_devname)
                                goto out_free_id;
                }
@@ -2927,7 +2927,7 @@ void __init mnt_init(void)
        init_rwsem(&namespace_sem);
 
        mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct mount),
-                       0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
+                       0, SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT, 
NULL);
 
        printk(KERN_INFO "Mount-cache hash table entries: %lu\n", HASH_SIZE);
 
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 949ec1c44e44..b6fe51ebd48c 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -2280,7 +2280,7 @@ nfsd_racache_init(int cache_size)
 
                raparm = &raparm_hash[i].pb_head;
                for (j = 0; j < nperbucket; j++) {
-                       *raparm = kzalloc(sizeof(struct raparms), GFP_KERNEL);
+                       *raparm = kzalloc(sizeof(struct raparms), 
GFP_KERNEL_ACCOUNT);
                        if (!*raparm)
                                goto out_nomem;
                        raparm = &(*raparm)->p_next;
diff --git a/fs/pipe.c b/fs/pipe.c
index 55b60d7f03d3..57aa78e7c63e 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -801,7 +801,7 @@ struct pipe_inode_info *alloc_pipe_info(void)
 {
        struct pipe_inode_info *pipe;
 
-       pipe = kzalloc(sizeof(struct pipe_inode_info), GFP_KERNEL);
+       pipe = kzalloc(sizeof(struct pipe_inode_info), GFP_KERNEL_ACCOUNT);
        if (pipe) {
                pipe->bufs = kzalloc(sizeof(struct pipe_buffer) * 
PIPE_DEF_BUFFERS, GFP_KERNEL);
                if (pipe->bufs) {
diff --git a/fs/select.c b/fs/select.c
index 739320daf82d..be0744b6410a 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -577,7 +577,7 @@ int core_sys_select(int n, fd_set __user *inp, fd_set 
__user *outp,
        if (size > sizeof(stack_fds) / 6) {
                /* Not enough space in on-stack array; must use kmalloc */
                ret = -ENOMEM;
-               bits = kmalloc(6 * size, GFP_KERNEL);
+               bits = kmalloc(6 * size, GFP_KERNEL_ACCOUNT);
                if (!bits)
                        goto out_nofds;
        }
@@ -900,7 +900,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int 
nfds,
 
                len = min(todo, POLLFD_PER_PAGE);
                size = sizeof(struct poll_list) + sizeof(struct pollfd) * len;
-               walk = walk->next = kmalloc(size, GFP_KERNEL);
+               walk = walk->next = kmalloc(size, GFP_KERNEL_ACCOUNT);
                if (!walk) {
                        err = -ENOMEM;
                        goto out_fds;
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 774afb4b6a26..eced378648bc 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -38,9 +38,9 @@ static void *seq_buf_alloc(unsigned long size)
 {
        void *buf;
 
-       buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
+       buf = kmalloc(size, GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
        if (!buf && size > PAGE_SIZE)
-               buf = vmalloc(size);
+               buf = vmalloc_account(size);
        return buf;
 }
 
@@ -71,7 +71,7 @@ int seq_open(struct file *file, const struct seq_operations 
*op)
        struct seq_file *p = file->private_data;
 
        if (!p) {
-               p = kmalloc(sizeof(*p), GFP_KERNEL);
+               p = kmalloc(sizeof(*p), GFP_KERNEL_ACCOUNT);
                if (!p)
                        return -ENOMEM;
                file->private_data = p;
@@ -607,7 +607,7 @@ static void single_stop(struct seq_file *p, void *v)
 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
                void *data)
 {
-       struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
+       struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL_ACCOUNT);
        int res = -ENOMEM;
 
        if (op) {
@@ -669,7 +669,7 @@ void *__seq_open_private(struct file *f, const struct 
seq_operations *ops,
        void *private;
        struct seq_file *seq;
 
-       private = kzalloc(psize, GFP_KERNEL);
+       private = kzalloc(psize, GFP_KERNEL_ACCOUNT);
        if (private == NULL)
                goto out;
 
diff --git a/ipc/msgutil.c b/ipc/msgutil.c
index 7e7095974d54..28717136e3aa 100644
--- a/ipc/msgutil.c
+++ b/ipc/msgutil.c
@@ -52,7 +52,7 @@ static struct msg_msg *alloc_msg(size_t len)
        size_t alen;
 
        alen = min(len, DATALEN_MSG);
-       msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL);
+       msg = kmalloc(sizeof(*msg) + alen, GFP_KERNEL_ACCOUNT);
        if (msg == NULL)
                return NULL;
 
@@ -64,7 +64,7 @@ static struct msg_msg *alloc_msg(size_t len)
        while (len > 0) {
                struct msg_msgseg *seg;
                alen = min(len, DATALEN_SEG);
-               seg = kmalloc(sizeof(*seg) + alen, GFP_KERNEL);
+               seg = kmalloc(sizeof(*seg) + alen, GFP_KERNEL_ACCOUNT);
                if (seg == NULL)
                        goto out_err;
                *pseg = seg;
diff --git a/ipc/sem.c b/ipc/sem.c
index fc3457eda5a1..fad92717cf01 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1606,7 +1606,7 @@ static inline int get_undo_list(struct sem_undo_list 
**undo_listp)
 
        undo_list = current->sysvsem.undo_list;
        if (!undo_list) {
-               undo_list = kzalloc(sizeof(*undo_list), GFP_KERNEL);
+               undo_list = kzalloc(sizeof(*undo_list), GFP_KERNEL_ACCOUNT);
                if (undo_list == NULL)
                        return -ENOMEM;
                spin_lock_init(&undo_list->lock);
@@ -1691,7 +1691,7 @@ static struct sem_undo *find_alloc_undo(struct 
ipc_namespace *ns, int semid)
 
        /* step 2: allocate new undo structure */
        new = kzalloc(sizeof(struct sem_undo) + sizeof(short)*nsems,
-                       GFP_KERNEL);
+                       GFP_KERNEL_ACCOUNT);
        if (!new) {
                ipc_rcu_putref(sma, ipc_rcu_free);
                return ERR_PTR(-ENOMEM);
@@ -1781,7 +1781,7 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf 
__user *, tsops,
        if (nsops > ns->sc_semopm)
                return -E2BIG;
        if(nsops > SEMOPM_FAST) {
-               sops = kmalloc(sizeof(*sops)*nsops, GFP_KERNEL);
+               sops = kmalloc(sizeof(*sops)*nsops, GFP_KERNEL_ACCOUNT);
                if(sops==NULL)
                        return -ENOMEM;
        }
diff --git a/ipc/util.c b/ipc/util.c
index 470816e2fb57..7c5bdad8b624 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -466,9 +466,9 @@ void *ipc_alloc(int size)
 {
        void *out;
        if(size > PAGE_SIZE)
-               out = vmalloc(size);
+               out = vmalloc_account(size);
        else
-               out = kmalloc(size, GFP_KERNEL);
+               out = kmalloc(size, GFP_KERNEL_ACCOUNT);
        return out;
 }
 
diff --git a/kernel/fairsched.c b/kernel/fairsched.c
index 40d3eff7452e..d3d17126a85c 100644
--- a/kernel/fairsched.c
+++ b/kernel/fairsched.c
@@ -467,7 +467,7 @@ static struct fairsched_dump *fairsched_do_dump(int compat)
 
        nr_nodes = ve_is_super(get_exec_env()) ? nr_nodes + 16 : 1;
 
-       dump = vmalloc(sizeof(*dump) + nr_nodes * sizeof(dump->nodes[0]));
+       dump = vmalloc_account(sizeof(*dump) + nr_nodes * 
sizeof(dump->nodes[0]));
        if (dump == NULL)
                goto out;
 
diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
index a4b1ca7da111..b98cfe429d9b 100644
--- a/kernel/posix-timers.c
+++ b/kernel/posix-timers.c
@@ -370,7 +370,7 @@ static __init int init_posix_timers(void)
 
        posix_timers_cache = kmem_cache_create("posix_timers_cache",
                                        sizeof (struct k_itimer), 0,
-                                       SLAB_PANIC, NULL);
+                                       SLAB_PANIC | SLAB_ACCOUNT, NULL);
        return 0;
 }
 
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 452b50e3d0ce..3c4b74dacab9 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2839,6 +2839,7 @@ unsigned long __get_free_kmem_pages(gfp_t gfp_mask, 
unsigned int order)
                return 0;
        return (unsigned long) page_address(page);
 }
+EXPORT_SYMBOL(__get_free_kmem_pages);
 
 unsigned long get_zeroed_page(gfp_t gfp_mask)
 {
@@ -2909,6 +2910,7 @@ void __free_kmem_pages(struct page *page, unsigned int 
order)
        memcg_kmem_uncharge_pages(page, order);
        __free_pages(page, order);
 }
+EXPORT_SYMBOL(__free_kmem_pages);
 
 void free_kmem_pages(unsigned long addr, unsigned int order)
 {
@@ -2917,6 +2919,7 @@ void free_kmem_pages(unsigned long addr, unsigned int 
order)
                __free_kmem_pages(virt_to_page((void *)addr), order);
        }
 }
+EXPORT_SYMBOL(free_kmem_pages);
 
 static void *make_alloc_exact(unsigned long addr, unsigned order, size_t size)
 {
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index bb8af3967205..f39246e6d588 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -67,7 +67,7 @@ static int vlan_group_prealloc_vid(struct vlan_group *vg,
                return 0;
 
        size = sizeof(struct net_device *) * VLAN_GROUP_ARRAY_PART_LEN;
-       array = kzalloc(size, GFP_KERNEL);
+       array = kzalloc(size, GFP_KERNEL_ACCOUNT);
        if (array == NULL)
                return -ENOBUFS;
 
diff --git a/net/core/dev.c b/net/core/dev.c
index f243badd3f91..be92f4fcb597 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5484,9 +5484,9 @@ static int netif_alloc_netdev_queues(struct net_device 
*dev)
        if (count < 1 || count > 0xffff)
                return -EINVAL;
 
-       tx = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
+       tx = kzalloc(sz, GFP_KERNEL_ACCOUNT | __GFP_NOWARN | __GFP_REPEAT);
        if (!tx) {
-               tx = vzalloc(sz);
+               tx = vzalloc_account(sz);
                if (!tx)
                        return -ENOMEM;
        }
@@ -6087,9 +6087,9 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, 
const char *name,
        /* ensure 32-byte alignment of whole construct */
        alloc_size += NETDEV_ALIGN - 1;
 
-       p = kzalloc(alloc_size, GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
+       p = kzalloc(alloc_size, GFP_KERNEL_ACCOUNT | __GFP_NOWARN | 
__GFP_REPEAT);
        if (!p)
-               p = vzalloc(alloc_size);
+               p = vzalloc_account(alloc_size);
        if (!p) {
                pr_err("alloc_netdev: Unable to allocate device\n");
                return NULL;
@@ -6486,7 +6486,7 @@ static struct hlist_head *netdev_create_hash(void)
        int i;
        struct hlist_head *hash;
 
-       hash = kmalloc(sizeof(*hash) * NETDEV_HASHENTRIES, GFP_KERNEL);
+       hash = kmalloc(sizeof(*hash) * NETDEV_HASHENTRIES, GFP_KERNEL_ACCOUNT);
        if (hash != NULL)
                for (i = 0; i < NETDEV_HASHENTRIES; i++)
                        INIT_HLIST_HEAD(&hash[i]);
diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c
index 2771bcd5bded..011989610dab 100644
--- a/net/core/fib_rules.c
+++ b/net/core/fib_rules.c
@@ -22,7 +22,7 @@ int fib_default_rule_add(struct fib_rules_ops *ops,
 {
        struct fib_rule *r;
 
-       r = kzalloc(ops->rule_size, GFP_KERNEL);
+       r = kzalloc(ops->rule_size, GFP_KERNEL_ACCOUNT);
        if (r == NULL)
                return -ENOMEM;
 
@@ -282,7 +282,7 @@ static int fib_nl_newrule(struct sk_buff *skb, struct 
nlmsghdr* nlh)
        if (err < 0)
                goto errout;
 
-       rule = kzalloc(ops->rule_size, GFP_KERNEL);
+       rule = kzalloc(ops->rule_size, GFP_KERNEL_ACCOUNT);
        if (rule == NULL) {
                err = -ENOMEM;
                goto errout;
diff --git a/net/core/filter.c b/net/core/filter.c
index f4124aee170e..b3216d69fedb 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -734,7 +734,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock 
*sk)
        if (fprog->filter == NULL)
                return -EINVAL;
 
-       fp = sock_kmalloc(sk, fsize+sizeof(*fp), GFP_KERNEL);
+       fp = sock_kmalloc(sk, fsize+sizeof(*fp), GFP_KERNEL_ACCOUNT);
        if (!fp)
                return -ENOMEM;
        if (copy_from_user(fp->insns, fprog->filter, fsize)) {
diff --git a/net/core/scm.c b/net/core/scm.c
index 830407a18361..e7f5e4ef8d0b 100644
--- a/net/core/scm.c
+++ b/net/core/scm.c
@@ -81,7 +81,7 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct 
scm_fp_list **fplp)
 
        if (!fpl)
        {
-               fpl = kmalloc(sizeof(struct scm_fp_list), GFP_KERNEL);
+               fpl = kmalloc(sizeof(struct scm_fp_list), GFP_KERNEL_ACCOUNT);
                if (!fpl)
                        return -ENOMEM;
                *fplp = fpl;
@@ -330,7 +330,7 @@ struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl)
                return NULL;
 
        new_fpl = kmemdup(fpl, offsetof(struct scm_fp_list, fp[fpl->count]),
-                         GFP_KERNEL);
+                         GFP_KERNEL_ACCOUNT);
        if (new_fpl) {
                for (i = 0; i < fpl->count; i++)
                        get_file(fpl->fp[i]);
diff --git a/net/core/sock.c b/net/core/sock.c
index 5124311d8306..737117cccbaf 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2690,7 +2690,7 @@ int proto_register(struct proto *prot, int alloc_slab)
 {
        if (alloc_slab) {
                prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0,
-                                       SLAB_HWCACHE_ALIGN | prot->slab_flags,
+                                       SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT | 
prot->slab_flags,
                                        NULL);
 
                if (prot->slab == NULL) {
@@ -2706,7 +2706,7 @@ int proto_register(struct proto *prot, int alloc_slab)
 
                        prot->rsk_prot->slab = 
kmem_cache_create(prot->rsk_prot->slab_name,
                                                                 
prot->rsk_prot->obj_size, 0,
-                                                                
SLAB_HWCACHE_ALIGN, NULL);
+                                                                
SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT, NULL);
 
                        if (prot->rsk_prot->slab == NULL) {
                                pr_crit("%s: Can't create request sock SLAB 
cache!\n",
@@ -2725,7 +2725,7 @@ int proto_register(struct proto *prot, int alloc_slab)
                                
kmem_cache_create(prot->twsk_prot->twsk_slab_name,
                                                  
prot->twsk_prot->twsk_obj_size,
                                                  0,
-                                                 SLAB_HWCACHE_ALIGN |
+                                                 SLAB_HWCACHE_ALIGN | 
SLAB_ACCOUNT |
                                                        prot->slab_flags,
                                                  NULL);
                        if (prot->twsk_prot->twsk_slab == NULL)
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 8a69d4a71a6e..b9560d7fff01 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -194,7 +194,7 @@ static void devinet_sysctl_unregister(struct in_device 
*idev)
 
 static struct in_ifaddr *inet_alloc_ifa(void)
 {
-       return kzalloc(sizeof(struct in_ifaddr), GFP_KERNEL);
+       return kzalloc(sizeof(struct in_ifaddr), GFP_KERNEL_ACCOUNT);
 }
 
 static void inet_rcu_free_ifa(struct rcu_head *head)
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 0ffe14c1056e..5753a8a5b170 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1718,11 +1718,11 @@ void __init fib_trie_init(void)
 {
        fn_alias_kmem = kmem_cache_create("ip_fib_alias",
                                          sizeof(struct fib_alias),
-                                         0, SLAB_PANIC, NULL);
+                                         0, SLAB_PANIC | SLAB_ACCOUNT, NULL);
 
        trie_leaf_kmem = kmem_cache_create("ip_fib_trie",
                                           LEAF_SIZE,
-                                          0, SLAB_PANIC, NULL);
+                                          0, SLAB_PANIC | SLAB_ACCOUNT, NULL);
 }
 
 struct fib_table *fib_trie_table(u32 id)
diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
index fc8e40a1f99e..fb736df6ba6c 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -922,7 +922,7 @@ static struct xt_counters *alloc_counters(const struct 
xt_table *table)
           (other than comefrom, which userspace doesn't care
           about). */
        countersize = sizeof(struct xt_counters) * private->number;
-       counters = vzalloc(countersize);
+       counters = vzalloc_account(countersize);
 
        if (counters == NULL)
                return ERR_PTR(-ENOMEM);
@@ -1189,7 +1189,7 @@ __do_replace(struct net *net, const char *name, unsigned 
int valid_hooks,
        struct ipt_entry *iter;
 
        ret = 0;
-       counters = vzalloc(num_counters * sizeof(struct xt_counters));
+       counters = vzalloc_account(num_counters * sizeof(struct xt_counters));
        if (!counters) {
                ret = -ENOMEM;
                goto out;
@@ -1344,7 +1344,7 @@ do_add_counters(struct net *net, const void __user *user,
        if (len != size + num_counters * sizeof(struct xt_counters))
                return -EINVAL;
 
-       paddc = vmalloc(len - size);
+       paddc = vmalloc_account(len - size);
        if (!paddc)
                return -ENOMEM;
 
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 2b54ad8910fb..17c324130fb0 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3039,7 +3039,7 @@ void __init tcp_init(void)
        tcp_hashinfo.bind_bucket_cachep =
                kmem_cache_create("tcp_bind_bucket",
                                  sizeof(struct inet_bind_bucket), 0,
-                                 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
+                                 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, 
NULL);
 
        /* Size and allocate the main established and bind bucket
         * hash tables.
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 8bb298fc945d..5015e41c2b53 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -808,7 +808,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr 
*addr,
                goto out;
        }
 
-       ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC);
+       ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC | __GFP_ACCOUNT);
 
        if (ifa == NULL) {
                ADBG("ipv6_add_addr: malloc failed\n");
diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 09693c1f3b2e..760a505b052b 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -1804,7 +1804,7 @@ int __init fib6_init(void)
 
        fib6_node_kmem = kmem_cache_create("fib6_nodes",
                                           sizeof(struct fib6_node),
-                                          0, SLAB_HWCACHE_ALIGN,
+                                          0, SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT,
                                           NULL);
        if (!fib6_node_kmem)
                goto out;
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 94b82d8b3d49..1f0770f6a06d 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -3220,7 +3220,7 @@ int __init ip6_route_init(void)
        ret = -ENOMEM;
        ip6_dst_ops_template.kmem_cachep =
                kmem_cache_create("ip6_dst_cache", sizeof(struct rt6_info), 0,
-                                 SLAB_HWCACHE_ALIGN, NULL);
+                                 SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT, NULL);
        if (!ip6_dst_ops_template.kmem_cachep)
                goto out;
 
diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index e884d1767626..5ae635a41c00 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -1336,7 +1336,7 @@ int __init ip_vs_conn_init(void)
        /* Allocate ip_vs_conn slab cache */
        ip_vs_conn_cachep = kmem_cache_create("ip_vs_conn",
                                              sizeof(struct ip_vs_conn), 0,
-                                             SLAB_HWCACHE_ALIGN, NULL);
+                                             SLAB_HWCACHE_ALIGN | 
SLAB_ACCOUNT, NULL);
        if (!ip_vs_conn_cachep) {
                vfree(ip_vs_conn_tab);
                return -ENOMEM;
diff --git a/net/netfilter/nf_conntrack_core.c 
b/net/netfilter/nf_conntrack_core.c
index 72f3b6b69f89..a59a10861e98 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -1469,8 +1469,8 @@ void nf_ct_free_hashtable(void *hash, unsigned int size)
        if (is_vmalloc_addr(hash))
                vfree(hash);
        else
-               free_pages((unsigned long)hash,
-                          get_order(sizeof(struct hlist_head) * size));
+               free_kmem_pages((unsigned long)hash,
+                               get_order(sizeof(struct hlist_head) * size));
 }
 EXPORT_SYMBOL_GPL(nf_ct_free_hashtable);
 
@@ -1597,11 +1597,11 @@ void *nf_ct_alloc_hashtable(unsigned int *sizep, int 
nulls)
        BUILD_BUG_ON(sizeof(struct hlist_nulls_head) != sizeof(struct 
hlist_head));
        nr_slots = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct 
hlist_nulls_head));
        sz = nr_slots * sizeof(struct hlist_nulls_head);
-       hash = (void *)__get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
+       hash = (void *)__get_free_kmem_pages(GFP_KERNEL_ACCOUNT | __GFP_NOWARN 
| __GFP_ZERO,
                                        get_order(sz));
        if (!hash) {
                printk(KERN_WARNING "nf_conntrack: falling back to vmalloc.\n");
-               hash = vzalloc(sz);
+               hash = vzalloc_account(sz);
        }
 
        if (hash && nulls)
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index 2e93502e73da..36342a6919ad 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -750,9 +750,9 @@ struct xt_table_info *xt_alloc_table_info(unsigned int size)
                return NULL;
 
        if (sz <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER))
-               info = kmalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY);
+               info = kmalloc(sz, GFP_KERNEL_ACCOUNT | __GFP_NOWARN | 
__GFP_NORETRY);
        if (!info) {
-               info = vmalloc(sz);
+               info = vmalloc_account(sz);
                if (!info)
                        return NULL;
        }
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index f62d0d5532fe..52d0d42f12a7 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -3701,8 +3701,8 @@ static void free_pg_vec(struct pgv *pg_vec, unsigned int 
order,
                        if (is_vmalloc_addr(pg_vec[i].buffer))
                                vfree(pg_vec[i].buffer);
                        else
-                               free_pages((unsigned long)pg_vec[i].buffer,
-                                          order);
+                               free_kmem_pages((unsigned long)pg_vec[i].buffer,
+                                               order);
                        pg_vec[i].buffer = NULL;
                }
        }
@@ -3712,10 +3712,10 @@ static void free_pg_vec(struct pgv *pg_vec, unsigned 
int order,
 static char *alloc_one_pg_vec_page(unsigned long order)
 {
        char *buffer = NULL;
-       gfp_t gfp_flags = GFP_KERNEL | __GFP_COMP |
+       gfp_t gfp_flags = GFP_KERNEL_ACCOUNT | __GFP_COMP |
                          __GFP_ZERO | __GFP_NOWARN | __GFP_NORETRY;
 
-       buffer = (char *) __get_free_pages(gfp_flags, order);
+       buffer = (char *) __get_free_kmem_pages(gfp_flags, order);
 
        if (buffer)
                return buffer;
@@ -3723,7 +3723,7 @@ static char *alloc_one_pg_vec_page(unsigned long order)
        /*
         * __get_free_pages failed, fall back to vmalloc
         */
-       buffer = vzalloc((1 << order) * PAGE_SIZE);
+       buffer = vzalloc_account((1 << order) * PAGE_SIZE);
 
        if (buffer)
                return buffer;
@@ -3732,7 +3732,7 @@ static char *alloc_one_pg_vec_page(unsigned long order)
         * vmalloc failed, lets dig into swap here
         */
        gfp_flags &= ~__GFP_NORETRY;
-       buffer = (char *)__get_free_pages(gfp_flags, order);
+       buffer = (char *)__get_free_kmem_pages(gfp_flags, order);
        if (buffer)
                return buffer;
 
@@ -3748,7 +3748,7 @@ static struct pgv *alloc_pg_vec(struct tpacket_req *req, 
int order)
        struct pgv *pg_vec;
        int i;
 
-       pg_vec = kcalloc(block_nr, sizeof(struct pgv), GFP_KERNEL);
+       pg_vec = kcalloc(block_nr, sizeof(struct pgv), GFP_KERNEL_ACCOUNT);
        if (unlikely(!pg_vec))
                goto out;
 
-- 
2.1.4

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to