[Devel] [PATCH RHEL7 COMMIT] packet: Never charge 0 kmem in packet_sk_charge()

Konstantin Khorenko khorenko at virtuozzo.com
Fri May 15 14:36:04 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1127.vz7.150.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.vz7.150.10
------>
commit 10dd23e27827e2ab0c1b2f4069a60a1511abde03
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Fri May 15 14:36:03 2020 +0300

    packet: Never charge 0 kmem in packet_sk_charge()
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 net/packet/af_packet.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 30b8e900e936a..1e4d017d851ef 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2547,8 +2547,15 @@ struct packet_sk_charge {
 static struct cg_proto *packet_sk_charge(void)
 {
 	struct packet_sk_charge *psc;
+	unsigned int nr_pages;
 	int err = -ENOMEM;
 
+	nr_pages = DIV_ROUND_UP(ACCESS_ONCE(sysctl_rmem_max), PAGE_SIZE);
+	if (!nr_pages) {
+		/* Caller will assign NULL memcg to socket */
+		return NULL;
+	}
+
 	psc = kmalloc(sizeof(*psc), GFP_KERNEL);
 	if (!psc)
 		goto out;
@@ -2565,7 +2572,7 @@ static struct cg_proto *packet_sk_charge(void)
 	 * It's typically not huge and packet sockets are rare guests in
 	 * containers, so we don't disturb the memory consumption much.
 	 */
-	psc->nr_pages = ACCESS_ONCE(sysctl_rmem_max)/PAGE_SIZE;
+	psc->nr_pages = nr_pages;
 
 	err = memcg_charge_kmem(psc->memcg, GFP_KERNEL, psc->nr_pages);
 	if (!err)


More information about the Devel mailing list