From patchwork Wed Sep 5 01:08:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jay Kamat X-Patchwork-Id: 10588141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF88C16B1 for ; Wed, 5 Sep 2018 01:12:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2A5F29C2A for ; Wed, 5 Sep 2018 01:12:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A069829C59; Wed, 5 Sep 2018 01:12:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D7DB29C2A for ; Wed, 5 Sep 2018 01:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726211AbeIEFkQ (ORCPT ); Wed, 5 Sep 2018 01:40:16 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:44754 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725853AbeIEFkQ (ORCPT ); Wed, 5 Sep 2018 01:40:16 -0400 Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8517N67016355; Tue, 4 Sep 2018 18:12:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=rTLbBnCGPzdLCKxAQyUbzt+Nf4Axpj7urDT0jcCo51A=; b=rDMZN+B8MfXU0HIgScKE8hmfAtK+dBsuVgRMPwQ9cIZ9+d1EzjouYz10KG5HKkpSs8N5 5O9lRIQa7wrteMzX1W674qhdmDRqkK2vtDgutNtQj0E1xaWvof7VlXWCbOAUkyAj6vci QEaQdpeDvr7sR8PTMLIlGlrUfIFUsXSFAlQ= Received: from maileast.thefacebook.com ([199.201.65.23]) by mx0a-00082601.pphosted.com with ESMTP id 2ma4w302k5-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 04 Sep 2018 18:12:34 -0700 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.24) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 4 Sep 2018 21:12:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rTLbBnCGPzdLCKxAQyUbzt+Nf4Axpj7urDT0jcCo51A=; b=KEa3DpKrc9niiH8T+jYgfLNat/g/RVOVaCjKNeV8f6TAbFmZL/cc/QIbgGlX4U7zo1aOSkZp812xF/xJkrsEw8kA2a4Y504EfomNeZXF2EaqO2m2mf9YTScRROlySkiS88LDnMNgnkQ7fmuaZyRy2Z3GwvaL2uCAn3ezznvuuUU= Received: from vall.thefacebook.com (2620:10d:c090:180::1:e8b3) by MWHPR15MB1229.namprd15.prod.outlook.com (2603:10b6:320:23::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1101.18; Wed, 5 Sep 2018 01:12:28 +0000 From: To: CC: , Roman Gushchin , Tejun Heo , , , , Subject: [PATCH 1/2] Fix cg_read_strcmp() Date: Tue, 4 Sep 2018 18:08:26 -0700 Message-ID: <20180905010827.27743-2-jgkamat@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180905010827.27743-1-jgkamat@fb.com> References: <20180905010827.27743-1-jgkamat@fb.com> MIME-Version: 1.0 X-Originating-IP: [2620:10d:c090:180::1:e8b3] X-ClientProxiedBy: DM5PR20CA0011.namprd20.prod.outlook.com (2603:10b6:3:93::21) To MWHPR15MB1229.namprd15.prod.outlook.com (2603:10b6:320:23::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31b951bc-84f0-4a02-a868-08d612cca6c0 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:MWHPR15MB1229; X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1229;3:zP8IucEMqCtXXmq838NKOwiktMFMIs35sglqs98N5/tVLdHAV3PDhWLYAEvxtuR7T0xeZ0mWKzzZw1uOYGRNUeolafGQzvjo4VKjjuYAd4UsE3AnBDVZ5mORGLi53OleUrIJSdE6HLxB8B2ur9Eq7YT0F03cyhCyMHDIkccjKy4tkefI4oqbGUxjCPrbHY74/irgPRn9bjlHx+Qh5JIC6efuZjHiqgTokmU9eu857995hP0V/KN4uKys3NxoiBs2;25:NqXK8w+e0gh4sWIW8jwPGBW7EtoYez4apF5qyxtT0EZEHuiCuiPppB2VEBeCKnQ4PCg77TN+cOPNH9lRzQWXrAvCZqlcRM8bETwECSMcD0P3X0Niz/EojgDldGbADF4N/3EzGChBDOaRewpJ8EvlEcQ5qXTfV+XblctmxQx/83TkcRYuyKBnfsq2OE4v3TT+0c+1M/uzAxSJJxFzD9vwUCTLycrqxwyJ7BOElpy8CfLpniVG00xztgc3LL/KUNYwcVU1o/7p6ViadVEjIERVtXO7BvcRav85AhdgPsJwD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RS/fTrR85mjPwvVz3iwtbfqpU9FNioP3XY/GVG5O6tM5IBnPBXSwO7ZYIrlkp4UVWWTKjdHQsQaYGs3ZCcfDSlDqmpL1JGz9IpBNipHJ2Pe7zDI4bMw1m X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(93006095)(93001095)(10201501046)(3002001)(3231311)(11241501184)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201708071742011)(7699016);SRVR:MWHPR15MB1229;BCL:0;PCL:0;RULEID:;SRVR:MWHPR15MB1229; X-Forefront-PRVS: 078693968A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(136003)(366004)(376002)(346002)(39860400002)(396003)(189003)(199004)(33896004)(6916009)(86362001)(8936002)(25786009)(54906003)(16586007)(316002)(6506007)(386003)(5660300001)(69596002)(53936002)(85782001)(53416004)(50226002)(68736007)(81156014)(6512007)(81166006)(16526019)(48376002)(46003)(36756003)(47776003)(9686003)(186003)(446003)(97736004)(76176011)(105586002)(8676002)(4326008)(51416003)(39060400002)(1076002)(106356001)(476003)(2906002)(478600001)(52116002)(6486002)(305945005)(7736002)(11346002)(2616005)(2351001)(52396003)(486006)(2361001)(50466002)(6116002)(85772001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR15MB1229;H:vall.thefacebook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1229;23:GqNTAIZEgXUqxtI7LsYERdbaMi8MTgpNyyjSItbAxAyLqHKtfMsoSpoTREaBD5qcGO//rWWXG4U8Zd8QH6Ux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7cBWTv2pBjlQX1wwjlE8R1VzEHIIxgJWWEDoJl6l+mqELSy/GyDxHLrFPkrAA4dlYY+bc+SnSrKWhjKYnifJeADfEMyfEsNwWk0hbFLZ0Gm2WgKdXua51ThiWA2QEQROQf0u5bGk44uAWFbk9pakapZE=;7:r+LWNRlN/dceHr7aI+u7v1jY7OD+QDmfUVRV/lRCFaO+wqzQv3lkbeUcCv6Z+wvUkxafpe3SuYeE4x04ktzVI2uHbiz92ovCmTiwlsRzoHiTpH2kzG5wiEYB45pgbu0GfKoi2ea1GCHcDUVZjcqHXhPV0Fdi2P1JEVOZrWbVW/x1tglpjAYxccXM2XVkoFUcRi08Crp4+JZxHew8sqEDKpvpJ5aZ6RnB5dhfodwdXXRIuuzzBcleC7VPRKEoAf7s SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1229;20:j6oIUemx2kiKmCPQK4jTWHupKxj85rRvlgu2VN+JqJSsUhHC+AD5Ndu0egGKqX8x16HvAaHEbGyW0NupdiQTwrPtYGiMJi9DB88uox49NQ/XSNdGjZZaHtysn2XavAlv/A+G0tp2khKnr3mDTtjqU4tU3S5Q/AMCqSTzvDkfIqs= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2018 01:12:28.2432 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31b951bc-84f0-4a02-a868-08d612cca6c0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1229 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-04_14:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jay Kamat Fix a couple issues with cg_read_strcmp(), to improve correctness of cgroup tests - Fix cg_read_strcmp() always returning 0 for empty "needle" strings - Fix a memory leak in cg_read_strcmp() Fixes: 84092dbcf901 ("selftests: cgroup: add memory controller self-tests") Signed-off-by: Jay Kamat --- tools/testing/selftests/cgroup/cgroup_util.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index 1e9e3c470561..4aadf38bcd5d 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -91,15 +91,24 @@ int cg_read_strcmp(const char *cgroup, const char *control, { size_t size = strlen(expected) + 1; char *buf; + int ret; + + /* Handle the case of comparing against empty string */ + if (size == 1) + size = 32; buf = malloc(size); if (!buf) return -1; - if (cg_read(cgroup, control, buf, size)) + if (cg_read(cgroup, control, buf, size)) { + free(buf); return -1; + } - return strcmp(expected, buf); + ret = strcmp(expected, buf); + free(buf); + return ret; } int cg_read_strstr(const char *cgroup, const char *control, const char *needle) From patchwork Wed Sep 5 01:08:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jay Kamat X-Patchwork-Id: 10588143 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E282B16B1 for ; Wed, 5 Sep 2018 01:12:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2D7028D16 for ; Wed, 5 Sep 2018 01:12:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B682B28D7E; Wed, 5 Sep 2018 01:12:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C41128D16 for ; Wed, 5 Sep 2018 01:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725890AbeIEFkd (ORCPT ); Wed, 5 Sep 2018 01:40:33 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:56654 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725853AbeIEFkc (ORCPT ); Wed, 5 Sep 2018 01:40:32 -0400 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8517jaq027879; Tue, 4 Sep 2018 18:12:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=XuIiTB9b9mtBqcklf77OU23vQtieLW/xX2Bw62r1FkY=; b=bB/eRSyc2voA0DaQVIVavs+MFXibWd4ebKLiFjm46LrOEQ5U/3nyMxg9KpnDU9eRz6FG Hpbv7G/7Fx0Pqi0lNLqm4YyhIGMVNitegZCfHxHcVG7XcR7vePo3CyCkKeSg8ZftbMwD 4Pe7Bs45jGqWfybwwEBzxoKBqp0sJoxLXRw= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2ma5480139-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 04 Sep 2018 18:12:49 -0700 Received: from NAM01-BY2-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.16) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 4 Sep 2018 18:12:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XuIiTB9b9mtBqcklf77OU23vQtieLW/xX2Bw62r1FkY=; b=JcidG8zRQaO/NmniJhRtXchtf6a0r+rudljwAczQcp9XEA8FBKuc1bZmXqxSVQDa1pvlspakYCjQmWmzvRWBndiS9ASvwSJze2XXd4WTzXtHKD+mLOdyrNBDl4PoPmwy8e5Gin+rFDTN6Gu4d/TSHXsE6pEfu38zCVcVVHc8n60= Received: from vall.thefacebook.com (2620:10d:c090:180::1:e8b3) by MWHPR15MB1229.namprd15.prod.outlook.com (2603:10b6:320:23::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1101.18; Wed, 5 Sep 2018 01:12:31 +0000 From: To: CC: , Roman Gushchin , Tejun Heo , , , , Subject: [PATCH 2/2] Add tests for memory.oom.group Date: Tue, 4 Sep 2018 18:08:27 -0700 Message-ID: <20180905010827.27743-3-jgkamat@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180905010827.27743-1-jgkamat@fb.com> References: <20180905010827.27743-1-jgkamat@fb.com> MIME-Version: 1.0 X-Originating-IP: [2620:10d:c090:180::1:e8b3] X-ClientProxiedBy: DM5PR20CA0011.namprd20.prod.outlook.com (2603:10b6:3:93::21) To MWHPR15MB1229.namprd15.prod.outlook.com (2603:10b6:320:23::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0240567a-d10f-44c5-4475-08d612cca8a2 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:MWHPR15MB1229; X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1229;3:76j2v6fqFbjoJb6KXJCu8WTDnxrV3KV048jP5wepnuTQQhSJK+H1sWB4fjjibljDfRZLu/cEBWEbxWSy7Ob1uHVZE+PYuQCSIfAu9GIT5d338NgxoQ3Czh3B8Xp+nBYoIWmlDcvhe/FVsSiufDDhWmyU7SjfLW9dttoJLYbXICNGmaDjUEXZBGOwKCDTHcodU2riJsf8gn31zYX/F2Q7hBqFw9uh/JtXNtgM9S1Zb4We4tiEvHYdm+L/G3h9gtyX;25:BXj0gjb3ARcHYgM6/gj27SHMpOt5M/JBetvjuXyAc3zNyKlUcgmhO88jRkppSe7Rd60OlnR7ALdpTzDT5L6B0VwRrgpillAodmdktnN9s8SyxrjcAWaC8FTCBk46crKNDDR4rAYK+7bEa5rIado7aCDftBtmDdDP0Le+tXT86ZgVg10pgpbpbCgN2wySMB1JTX+XRi0RoDygvpMlsb+1z0SZgwCa0nt+4cCdHSbFAYmKkmIF6S6kg3QMBKLI2Ol2fVxuOK1nLYkG81Z5Dz9Jxh2MEBkHTzDqoQ5sxc2/g4um1JbyXe8RfNJuuNJxGll71HVtCl5QKgc0/SsBg/dwDA==;31:ZAvrdqMG4FJJJGu/VUF7FxC5Uo054iJlDoKMKgiJzDO6SpEQGod89IBTNJRRt2Hri12ost8XGW1Dap6HTPIn2QhYXSNKAg42M24gIPeBowyhcB53t7Ydt6VGO7nFJHP0kV6BzFiHjxSWYIp1bpYGDnPa3CqFR6nfQ+45dXREAs9/5Mc4edCDTIh8piFSyb0TJvJgcDXhZdrByhTILyUxfWKXRLIhPFZDveXh+15NV5M= X-MS-TrafficTypeDiagnostic: MWHPR15MB1229: X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1229;20:KO03Esh/TxvZZLMpVzaN9hkfSyLnQOsNrNBpzblvuVoIyuF+p0ZumXr7wj0MoPoL8EKI1N6TnUdoEY/wsGarmtNKxyK/X2EIGd4WqUi0txykD5n3iJmTKwo1Gkbwax6wrlUwCwm29HWo+jWTsOwJubDklBMBzTpyBemhVoi+8g/0NHtY5J/Da8CdajicPoLkkPZbxI5bxugZSQ20tGaG7gOBVUgamRGUtlfA3t3wsfJZKL0FI/KcSqjWxj/P8uNO2CptWsqp0AiowJcENwik+LL7YZMYYGYDWGHGAuk8LYvcP9wX07Qbt1e32ITx8EN43vtYHLNY0iTOE2kgrVJSROEnG+UpgrkGAcWC+PxZo6WNFG2WwlmvZY3Q6qwy+ef6gliWyverJ11cUHTE02nM9kIqfbsxBr5mJW6VnsyX5BF5CoTWOb2bYA0LJlaoMEzD7xWOc/KSE2Tx0N0LydpPTLbV2dWs56RsFVndjhPDJBt89mDxnAMiZlXhSSSNC9Hj;4:oSEIov5iNEqiDv/7X/E56sKrOl+LndiKm8OdubXiw2eKB6O6d8U1JvhX8t48HGpr3/Fj9T040/6tUP1e6wh+uvlasdL8P7FX3P+beGzEFm7p9EwKgmj8gEC22l+AlNIPepLs6Sze6U3MVK8W5ZJznKraROq7IK7Bbg0FADo9YdehAuCwQZnzOOwSjvzF6wbexrqrOSJ1vDbsznCJ3hU4aUQ7jTRtnN/tKn5DQvcrV+24J9dThiotuG3t/J40uGdPeVVXKhoRCHMN7CkyWRMaahuT338QBt6RKpTxHifGDZbwyFC4ASRRSO/PKDgrfwxj X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(93006095)(93001095)(10201501046)(3002001)(3231311)(11241501184)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201708071742011)(7699016);SRVR:MWHPR15MB1229;BCL:0;PCL:0;RULEID:;SRVR:MWHPR15MB1229; X-Forefront-PRVS: 078693968A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(136003)(366004)(376002)(346002)(39860400002)(396003)(189003)(199004)(33896004)(575784001)(6916009)(86362001)(8936002)(25786009)(54906003)(16586007)(316002)(6506007)(386003)(5660300001)(69596002)(6666003)(53936002)(85782001)(53416004)(50226002)(68736007)(81156014)(6512007)(81166006)(16526019)(48376002)(46003)(36756003)(47776003)(9686003)(186003)(446003)(97736004)(76176011)(105586002)(8676002)(4326008)(51416003)(39060400002)(1076002)(106356001)(476003)(2906002)(478600001)(52116002)(6486002)(305945005)(7736002)(11346002)(2616005)(2351001)(52396003)(486006)(2361001)(14444005)(50466002)(6116002)(85772001);DIR:OUT;SFP:1102;SCL:1;SRVR:MWHPR15MB1229;H:vall.thefacebook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1229;23:SIf5ithQeuNoypHLDZJnIxAhOhGJerR8+aJJaoEAh5/eWDfaDb+O1Z5sK4odxY3F44w5wU7B1m0POr3BrbuU2mAJvpzMjTYJVADGZCsErdLpLL8jk6/+ayc13A1zsfQswqfpy1AF20d8RAqnxAmMYc1ybzuFF3P+pMse9JHADcxMgbY287Lmdzi5kfHJ13mNdcmjf50DYqAVR7zBWpL6G4eAFMI/hNMjeNDFfocsJI1fayG5MKES2YOfB7L0E88LXhaNsu0AVLGNglr/6XPA8dFy1p1ZdiAstHvUbI7Tp3W29SS9Nt777OuiMDZKSSXq8z2bS5PonHUAPNsGVOfkBP6/cn+5g0K4n9dG86mgtvl0dF6CzrnrsCdSsQaRxp3nhUyqrGbRr2KlH4AYQStKdr8FEQ7jW9aDi/Fff8N14G4pMze+ryV4r3d6CREQMUT+ahzCFQjh05+lsh+zkbncVwEM7DnxOwh4Y4VarF/9KHlZGbjYOfio7JbY+3qqC92vfRSgKQ34I4cmOuF8nAX9g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B7pfBlqwu6e6v6rHbJ1o/DHOrFqMfCldXOkPkgdE7/f/C8itfv SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR15MB1229;20:8QOHF/lhse8UgLouY4kGCXJtc0i5RbFs8VWC8EIdcmxlyaF0EhF2mHU/Z9ZemazxM3Il1Qj8u5ofuZou/aJFXwAkwN/GBA/RMRWcncKlrTX2IfTE/Ee3DKr9l4eBicJ0WRxulCdxU7hJmO+Qo5KWnGXoUhYmRwq90N9X/JtZ7AU= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2018 01:12:31.5713 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0240567a-d10f-44c5-4475-08d612cca8a2 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR15MB1229 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-04_14:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jay Kamat Add tests for memory.oom.group for the following cases: - Killing all processes in a leaf cgroup, but leaving the parent untouched - Killing all processes in a parent and leaf cgroup - Keeping processes marked by OOM_SCORE_ADJ_MIN alive when considered for being killed by the group oom killer. Signed-off-by: Jay Kamat --- tools/testing/selftests/cgroup/cgroup_util.c | 21 ++ tools/testing/selftests/cgroup/cgroup_util.h | 1 + .../selftests/cgroup/test_memcontrol.c | 205 ++++++++++++++++++ 3 files changed, 227 insertions(+) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index 4aadf38bcd5d..6799c69d7f03 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -338,3 +338,24 @@ int is_swap_enabled(void) return cnt > 1; } + +int set_oom_adj_score(int pid, int score) +{ + char path[PATH_MAX]; + int fd, len; + + sprintf(path, "/proc/%d/oom_score_adj", pid); + + fd = open(path, O_WRONLY | O_APPEND); + if (fd < 0) + return fd; + + len = dprintf(fd, "%d", score); + if (len < 0) { + close(fd); + return len; + } + + close(fd); + return 0; +} diff --git a/tools/testing/selftests/cgroup/cgroup_util.h b/tools/testing/selftests/cgroup/cgroup_util.h index fe82a297d4e0..cabd43fd137a 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.h +++ b/tools/testing/selftests/cgroup/cgroup_util.h @@ -39,3 +39,4 @@ extern int get_temp_fd(void); extern int alloc_pagecache(int fd, size_t size); extern int alloc_anon(const char *cgroup, void *arg); extern int is_swap_enabled(void); +extern int set_oom_adj_score(int pid, int score); diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index cf0bddc9d271..017c15a7a935 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -2,6 +2,7 @@ #define _GNU_SOURCE #include +#include #include #include #include @@ -202,6 +203,36 @@ static int alloc_pagecache_50M_noexit(const char *cgroup, void *arg) return 0; } +static int alloc_anon_noexit(const char *cgroup, void *arg) +{ + int ppid = getppid(); + + if (alloc_anon(cgroup, arg)) + return -1; + + while (getppid() == ppid) + sleep(1); + + return 0; +} + +/* + * Wait until processes are killed asynchronously by the OOM killer + * If we exceed a timeout, fail. + */ +static int cg_test_proc_killed(const char *cgroup) +{ + int limit; + + for (limit = 10; limit > 0; limit--) { + if (cg_read_strcmp(cgroup, "cgroup.procs", "") == 0) + return 0; + + usleep(100000); + } + return -1; +} + /* * First, this test creates the following hierarchy: * A memory.min = 50M, memory.max = 200M @@ -964,6 +995,177 @@ static int test_memcg_sock(const char *root) return ret; } +/* + * This test disables swapping and tries to allocate anonymous memory + * up to OOM with memory.group.oom set. Then it checks that all + * processes in the leaf (but not the parent) were killed. + */ +static int test_memcg_oom_group_leaf_events(const char *root) +{ + int ret = KSFT_FAIL; + char *parent, *child; + + parent = cg_name(root, "memcg_test_0"); + child = cg_name(root, "memcg_test_0/memcg_test_1"); + + if (!parent || !child) + goto cleanup; + + if (cg_create(parent)) + goto cleanup; + + if (cg_create(child)) + goto cleanup; + + if (cg_write(parent, "cgroup.subtree_control", "+memory")) + goto cleanup; + + if (cg_write(child, "memory.max", "50M")) + goto cleanup; + + if (cg_write(child, "memory.swap.max", "0")) + goto cleanup; + + if (cg_write(child, "memory.oom.group", "1")) + goto cleanup; + + cg_run_nowait(parent, alloc_anon_noexit, (void *) MB(60)); + cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1)); + cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1)); + if (!cg_run(child, alloc_anon, (void *)MB(100))) + goto cleanup; + + if (cg_test_proc_killed(child)) + goto cleanup; + + if (cg_read_key_long(child, "memory.events", "oom_kill ") <= 0) + goto cleanup; + + if (cg_read_key_long(parent, "memory.events", "oom_kill ") != 0) + goto cleanup; + + ret = KSFT_PASS; + +cleanup: + if (child) + cg_destroy(child); + if (parent) + cg_destroy(parent); + free(child); + free(parent); + + return ret; +} + +/* + * This test disables swapping and tries to allocate anonymous memory + * up to OOM with memory.group.oom set. Then it checks that all + * processes in the parent and leaf were killed. + */ +static int test_memcg_oom_group_parent_events(const char *root) +{ + int ret = KSFT_FAIL; + char *parent, *child; + + parent = cg_name(root, "memcg_test_0"); + child = cg_name(root, "memcg_test_0/memcg_test_1"); + + if (!parent || !child) + goto cleanup; + + if (cg_create(parent)) + goto cleanup; + + if (cg_create(child)) + goto cleanup; + + if (cg_write(parent, "memory.max", "80M")) + goto cleanup; + + if (cg_write(parent, "memory.swap.max", "0")) + goto cleanup; + + if (cg_write(parent, "memory.oom.group", "1")) + goto cleanup; + + cg_run_nowait(parent, alloc_anon_noexit, (void *) MB(60)); + cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1)); + cg_run_nowait(child, alloc_anon_noexit, (void *) MB(1)); + + if (!cg_run(child, alloc_anon, (void *)MB(100))) + goto cleanup; + + if (cg_test_proc_killed(child)) + goto cleanup; + if (cg_test_proc_killed(parent)) + goto cleanup; + + ret = KSFT_PASS; + +cleanup: + if (child) + cg_destroy(child); + if (parent) + cg_destroy(parent); + free(child); + free(parent); + + return ret; +} + +/* + * This test disables swapping and tries to allocate anonymous memory + * up to OOM with memory.group.oom set. Then it checks that all + * processes were killed except those set with OOM_SCORE_ADJ_MIN + */ +static int test_memcg_oom_group_score_events(const char *root) +{ + int ret = KSFT_FAIL; + char *memcg; + int safe_pid; + + memcg = cg_name(root, "memcg_test_0"); + + if (!memcg) + goto cleanup; + + if (cg_create(memcg)) + goto cleanup; + + if (cg_write(memcg, "memory.max", "50M")) + goto cleanup; + + if (cg_write(memcg, "memory.swap.max", "0")) + goto cleanup; + + if (cg_write(memcg, "memory.oom.group", "1")) + goto cleanup; + + safe_pid = cg_run_nowait(memcg, alloc_anon_noexit, (void *) MB(1)); + if (set_oom_adj_score(safe_pid, OOM_SCORE_ADJ_MIN)) + goto cleanup; + + cg_run_nowait(memcg, alloc_anon_noexit, (void *) MB(1)); + if (!cg_run(memcg, alloc_anon, (void *)MB(100))) + goto cleanup; + + if (cg_read_key_long(memcg, "memory.events", "oom_kill ") != 3) + goto cleanup; + + if (kill(safe_pid, SIGKILL)) + return -1; + + ret = KSFT_PASS; + +cleanup: + if (memcg) + cg_destroy(memcg); + free(memcg); + + return ret; +} + + #define T(x) { x, #x } struct memcg_test { int (*fn)(const char *root); @@ -978,6 +1180,9 @@ struct memcg_test { T(test_memcg_oom_events), T(test_memcg_swap_max), T(test_memcg_sock), + T(test_memcg_oom_group_leaf_events), + T(test_memcg_oom_group_parent_events), + T(test_memcg_oom_group_score_events), }; #undef T