[Devel] [PATCH rh7 9/9] Charge kmem allocations accounted to UBC in PCS6 to memcg

Vladimir Davydov vdavydov at virtuozzo.com
Tue Apr 26 07:08:44 PDT 2016


Signed-off-by: Vladimir Davydov <vdavydov at virtuozzo.com>
---
 arch/x86/kernel/ldt.c             | 10 +++++++---
 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                |  3 ++-
 kernel/posix-timers.c             |  2 +-
 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    | 11 ++++++++---
 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 |  7 +++++--
 net/netfilter/x_tables.c          |  4 ++--
 net/packet/af_packet.c            | 21 +++++++++++----------
 31 files changed, 80 insertions(+), 66 deletions(-)

diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
index 79aa97d8fe4c..c22c4bdc71b0 100644
--- a/arch/x86/kernel/ldt.c
+++ b/arch/x86/kernel/ldt.c
@@ -33,6 +33,7 @@ static void flush_ldt(void *current_mm)
 
 static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
 {
+	struct page *page;
 	void *oldldt, *newldt;
 	int oldsize;
 
@@ -42,9 +43,12 @@ 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);
-	else
-		newldt = (void *)__get_free_page(GFP_KERNEL);
+		newldt = __vmalloc(mincount * LDT_ENTRY_SIZE,
+			GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM, PAGE_KERNEL);
+	else {
+		page = alloc_kmem_pages(GFP_KERNEL_ACCOUNT, 0);
+		newldt = page ? page_address(page) : NULL;
+	}
 
 	if (!newldt)
 		return -ENOMEM;
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..dd3958f6b9d9 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(size, GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM, PAGE_KERNEL);
 	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..6acc827dc0a1 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(size, GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM, PAGE_KERNEL);
 	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..936b753b14de 100644
--- a/kernel/fairsched.c
+++ b/kernel/fairsched.c
@@ -467,7 +467,8 @@ 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(sizeof(*dump) + nr_nodes * sizeof(dump->nodes[0]),
+			 GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM, PAGE_KERNEL);
 	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/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..37983af6cee8 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 = __vmalloc(sz, GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
 		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 = __vmalloc(alloc_size, GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
 	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..8f29733e5e30 100644
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -922,7 +922,9 @@ 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 = __vmalloc(countersize,
+			     GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM | __GFP_ZERO,
+			     PAGE_KERNEL);
 
 	if (counters == NULL)
 		return ERR_PTR(-ENOMEM);
@@ -1189,7 +1191,9 @@ __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 = __vmalloc(num_counters * sizeof(struct xt_counters),
+			     GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM | __GFP_ZERO,
+			     PAGE_KERNEL);
 	if (!counters) {
 		ret = -ENOMEM;
 		goto out;
@@ -1344,7 +1348,8 @@ 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(len - size,
+			  GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM, PAGE_KERNEL);
 	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..cc7dd12f519c 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -1590,6 +1590,7 @@ i_see_dead_people:
 
 void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls)
 {
+	struct page *page;
 	struct hlist_nulls_head *hash;
 	unsigned int nr_slots, i;
 	size_t sz;
@@ -1597,11 +1598,13 @@ 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,
+	page = alloc_kmem_pages(GFP_KERNEL_ACCOUNT | __GFP_NOWARN | __GFP_ZERO,
 					get_order(sz));
+	hash = page ? page_address(page) : NULL;
 	if (!hash) {
 		printk(KERN_WARNING "nf_conntrack: falling back to vmalloc.\n");
-		hash = vzalloc(sz);
+		hash = __vmalloc(sz, GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM | __GFP_ZERO,
+				 PAGE_KERNEL);
 	}
 
 	if (hash && nulls)
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index 2e93502e73da..94a991bd79a0 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(sz, GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM, PAGE_KERNEL);
 		if (!info)
 			return NULL;
 	}
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index f62d0d5532fe..3b6b9efb661f 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -3711,19 +3711,20 @@ static void free_pg_vec(struct pgv *pg_vec, unsigned int order,
 
 static char *alloc_one_pg_vec_page(unsigned long order)
 {
+	struct page *page;
 	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);
-
-	if (buffer)
-		return buffer;
+	page = alloc_kmem_pages(gfp_flags, order);
+	if (page)
+		return page_address(page);
 
 	/*
 	 * __get_free_pages failed, fall back to vmalloc
 	 */
-	buffer = vzalloc((1 << order) * PAGE_SIZE);
+	buffer = __vmalloc((1 << order) * PAGE_SIZE,
+			   GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
 
 	if (buffer)
 		return buffer;
@@ -3732,9 +3733,9 @@ 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);
-	if (buffer)
-		return buffer;
+	page = alloc_kmem_pages(gfp_flags, order);
+	if (page)
+		return page_address(page);
 
 	/*
 	 * complete and utter failure
@@ -3748,7 +3749,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



More information about the Devel mailing list