Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2017281imm; Sun, 27 May 2018 23:19:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpFV7KgzghkU2Mj2Qu6Miw8JwIuWiM0ZedJmEUZsgYcPAfZJplGNep4xi2fabs6xp3xhTWk X-Received: by 2002:a63:6e8f:: with SMTP id j137-v6mr8068551pgc.453.1527488376040; Sun, 27 May 2018 23:19:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527488376; cv=none; d=google.com; s=arc-20160816; b=fgyZm/Vo6k+AHfnjarkyOLQnWLGUCc3ouYDsHvinaRIn7VjNgDmRlGRinv1X3nU9AY Cvd3z9lVB7FtlS3G9qpJ7yNivoACX9CEFpm5UesOpH6lG0r9UcNP7pOezoAuQox/WHAh mAVcTniggzOwE3s5QKkqd0muUhaPBGCef5UKk+UEp6mQjNYckDNeuSmlKugM/+Omuap3 y6xNU8fEBwwodnOkakI0cOIos9h9fNidx+EWQaPiaAQ56KtMZOBoO5d8qP3Pi3447MWJ q6lVw6APtW1R7Y7bWh6zK5KhZIi8pSdQH8mSv7X0zJUDAT5LD/Dyc4XKJA2y/PUkYcVg MCSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date :arc-authentication-results; bh=w9EMF1+aeZ9C2Jl94ofHvGSAIFfT+c3zzAZdUPzFlYg=; b=H/UoRA8Wowl5+Xx4TTu2sQJsqIsMWNFyi65rKNM9nEyVSt+h81HxyLqzl9/NLBR+44 XHFdF2Hml20GuQ4kySCdbbUNc3JliIw8DHyQNRa6CaJwrDZaEbX4veOrI3V9oWtMYZPk q21K1JXc4HnFoRF5kSYPgZ6YAuV+U9r+RZEUcQjHNLd/rppiLbQoSl+rUiZLTltZ9iIa Fg8VI7qUppKTJfyPyHmkoUHS59bRM6WLHWYjodfSUE6DJufcPuBOJK5h6nycd5/alQLW 9ISmVnSjbekiwKUdn91SlzjtpkvyAeucwQtRWwHunzyEyvbCQpvOszRPXNfuSnLFrxrZ 7Xmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg8-v6si29743590plb.486.2018.05.27.23.19.21; Sun, 27 May 2018 23:19:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753491AbeE1GTC (ORCPT + 99 others); Mon, 28 May 2018 02:19:02 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:54422 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753447AbeE1GSz (ORCPT ); Mon, 28 May 2018 02:18:55 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4S6G2Tx059042 for ; Mon, 28 May 2018 02:18:54 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j8874ygv9-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 28 May 2018 02:18:53 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 28 May 2018 07:18:50 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 28 May 2018 07:18:49 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4S6Im9u14417982; Mon, 28 May 2018 06:18:48 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A7B89A4057; Mon, 28 May 2018 07:10:02 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3293EA4053; Mon, 28 May 2018 07:10:02 +0100 (BST) Received: from rapoport-lnx (unknown [9.148.8.106]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 28 May 2018 07:10:02 +0100 (BST) Date: Mon, 28 May 2018 09:18:46 +0300 From: Mike Rapoport To: Shuah Khan Cc: Roman Gushchin , Tejun Heo , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] selftests: cgroup/memcontrol: add basic test for socket accounting References: <1527019565-20470-1-git-send-email-rppt@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1527019565-20470-1-git-send-email-rppt@linux.vnet.ibm.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 18052806-0040-0000-0000-0000045E0F09 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052806-0041-0000-0000-000021027925 Message-Id: <20180528061845.GA4805@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-28_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805280077 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Are there any updates on this? On Tue, May 22, 2018 at 11:06:05PM +0300, Mike Rapoport wrote: > The test verifies that when there is active TCP connection, the > memory.stat.sock and memory.current values are close. > > Signed-off-by: Mike Rapoport > Acked-by: Roman Gushchin > --- > v3 changes: > * added changelog > > v2 changes: > * bumped error percentage for comparing memory.current with memory.stat.sock > * added checks that memory.stat.sock == 0 and memory.current >= 0 after TCP > server exits > * simplified error handling > > tools/testing/selftests/cgroup/test_memcontrol.c | 193 +++++++++++++++++++++++ > 1 file changed, 193 insertions(+) > > diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c > index beae06c9c899..cf0bddc9d271 100644 > --- a/tools/testing/selftests/cgroup/test_memcontrol.c > +++ b/tools/testing/selftests/cgroup/test_memcontrol.c > @@ -9,6 +9,12 @@ > #include > #include > #include > +#include > +#include > +#include > +#include > +#include > +#include > > #include "../kselftest.h" > #include "cgroup_util.h" > @@ -772,6 +778,192 @@ static int test_memcg_oom_events(const char *root) > return ret; > } > > +struct tcp_server_args { > + unsigned short port; > + int ctl[2]; > +}; > + > +static int tcp_server(const char *cgroup, void *arg) > +{ > + struct tcp_server_args *srv_args = arg; > + struct sockaddr_in6 saddr = { 0 }; > + socklen_t slen = sizeof(saddr); > + int sk, client_sk, ctl_fd, yes = 1, ret = -1; > + > + close(srv_args->ctl[0]); > + ctl_fd = srv_args->ctl[1]; > + > + saddr.sin6_family = AF_INET6; > + saddr.sin6_addr = in6addr_any; > + saddr.sin6_port = htons(srv_args->port); > + > + sk = socket(AF_INET6, SOCK_STREAM, 0); > + if (sk < 0) > + return ret; > + > + if (setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) > + goto cleanup; > + > + if (bind(sk, (struct sockaddr *)&saddr, slen)) { > + write(ctl_fd, &errno, sizeof(errno)); > + goto cleanup; > + } > + > + if (listen(sk, 1)) > + goto cleanup; > + > + ret = 0; > + if (write(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) { > + ret = -1; > + goto cleanup; > + } > + > + client_sk = accept(sk, NULL, NULL); > + if (client_sk < 0) > + goto cleanup; > + > + ret = -1; > + for (;;) { > + uint8_t buf[0x100000]; > + > + if (write(client_sk, buf, sizeof(buf)) <= 0) { > + if (errno == ECONNRESET) > + ret = 0; > + break; > + } > + } > + > + close(client_sk); > + > +cleanup: > + close(sk); > + return ret; > +} > + > +static int tcp_client(const char *cgroup, unsigned short port) > +{ > + const char server[] = "localhost"; > + struct addrinfo *ai; > + char servport[6]; > + int retries = 0x10; /* nice round number */ > + int sk, ret; > + > + snprintf(servport, sizeof(servport), "%hd", port); > + ret = getaddrinfo(server, servport, NULL, &ai); > + if (ret) > + return ret; > + > + sk = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); > + if (sk < 0) > + goto free_ainfo; > + > + ret = connect(sk, ai->ai_addr, ai->ai_addrlen); > + if (ret < 0) > + goto close_sk; > + > + ret = KSFT_FAIL; > + while (retries--) { > + uint8_t buf[0x100000]; > + long current, sock; > + > + if (read(sk, buf, sizeof(buf)) <= 0) > + goto close_sk; > + > + current = cg_read_long(cgroup, "memory.current"); > + sock = cg_read_key_long(cgroup, "memory.stat", "sock "); > + > + if (current < 0 || sock < 0) > + goto close_sk; > + > + if (current < sock) > + goto close_sk; > + > + if (values_close(current, sock, 10)) { > + ret = KSFT_PASS; > + break; > + } > + } > + > +close_sk: > + close(sk); > +free_ainfo: > + freeaddrinfo(ai); > + return ret; > +} > + > +/* > + * This test checks socket memory accounting. > + * The test forks a TCP server listens on a random port between 1000 > + * and 61000. Once it gets a client connection, it starts writing to > + * its socket. > + * The TCP client interleaves reads from the socket with check whether > + * memory.current and memory.stat.sock are similar. > + */ > +static int test_memcg_sock(const char *root) > +{ > + int bind_retries = 5, ret = KSFT_FAIL, pid, err; > + unsigned short port; > + char *memcg; > + > + memcg = cg_name(root, "memcg_test"); > + if (!memcg) > + goto cleanup; > + > + if (cg_create(memcg)) > + goto cleanup; > + > + while (bind_retries--) { > + struct tcp_server_args args; > + > + if (pipe(args.ctl)) > + goto cleanup; > + > + port = args.port = 1000 + rand() % 60000; > + > + pid = cg_run_nowait(memcg, tcp_server, &args); > + if (pid < 0) > + goto cleanup; > + > + close(args.ctl[1]); > + if (read(args.ctl[0], &err, sizeof(err)) != sizeof(err)) > + goto cleanup; > + close(args.ctl[0]); > + > + if (!err) > + break; > + if (err != EADDRINUSE) > + goto cleanup; > + > + waitpid(pid, NULL, 0); > + } > + > + if (err == EADDRINUSE) { > + ret = KSFT_SKIP; > + goto cleanup; > + } > + > + if (tcp_client(memcg, port) != KSFT_PASS) > + goto cleanup; > + > + waitpid(pid, &err, 0); > + if (WEXITSTATUS(err)) > + goto cleanup; > + > + if (cg_read_long(memcg, "memory.current") < 0) > + goto cleanup; > + > + if (cg_read_key_long(memcg, "memory.stat", "sock ")) > + goto cleanup; > + > + ret = KSFT_PASS; > + > +cleanup: > + cg_destroy(memcg); > + free(memcg); > + > + return ret; > +} > + > #define T(x) { x, #x } > struct memcg_test { > int (*fn)(const char *root); > @@ -785,6 +977,7 @@ struct memcg_test { > T(test_memcg_max), > T(test_memcg_oom_events), > T(test_memcg_swap_max), > + T(test_memcg_sock), > }; > #undef T > > -- > 2.7.4 > -- Sincerely yours, Mike.