Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4112792ybh; Tue, 6 Aug 2019 06:31:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/ZN5ark+MwblWHowK6QpaBhd+aS+b3lxMWwYpcImB9lLE7bxf7zqQ5R8/rFbCL/hVdMfr X-Received: by 2002:a65:6859:: with SMTP id q25mr3011570pgt.181.1565098284577; Tue, 06 Aug 2019 06:31:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565098284; cv=none; d=google.com; s=arc-20160816; b=pgza1aB+7lgE28Ka9g7Hu5qmAm7/pwQMUY0ewJ/gzaCarfbceXQn5AwH3WQ/CZ4u+v ONfVWGR+m6tNfXhmjHGgf3aQQBM+2dxZxhmRDy08gUYFb85nqtwVoWRWh7KQRHLnWl/t UtKUucaMCaoMXCL6l0t7/sysuMROYavjaOvpK3TvDKImymcpSikMVn1QZ/t70KEyVZx3 9VsJc4wQiBc0kPHq3sk+r/B0NTI17v8HH6CR1IpcTK5UmbvHD4OWM7txbrFjjAzD5dCi 2z8Es3jd6ly3ofBZr9U7v3DvLtRFZouz6TFME5WIeG+Cox1E6khWXLgi1TJxKC9mUY2j 6+Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=E4JlzKHUY5RDe44IFvo6Jw5vITw/HnG7XnunHCYgCmc=; b=Jq7qSGjg3XN7fjKeMH6v/EQaLtF+VmJoeAZqkoDbjjd2/OoqT4fwJ+w9wx4Y68W/vl Xs166XP/DbmpHjX3A427a6DmLIl5FwqV2mOrH1omCzAz5TTrjn+u4Mmd+UXXAgMU3ad3 6GWcWIWOSErP0v4We6HmoX7vDemLpwsBkQr92Oeh53L8drX90M3VDbkkfqvnVTg5+l1L 00bMYnyelBpAil6wFoWnWq27I6P9i1xwgpxVL6vVcIhqxYfGUKxTDY0jRreeQmoWQvXb A/4jdvrG5+Fp7z4IqUMxXza5CZ9ZK8q2qJpfqEFP+JY25dLWglIIwpTDI4FJNntr8yQz p6QA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si47618726pgt.548.2019.08.06.06.31.08; Tue, 06 Aug 2019 06:31:24 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728560AbfHFNaf (ORCPT + 99 others); Tue, 6 Aug 2019 09:30:35 -0400 Received: from smtprelay04.ispgateway.de ([80.67.31.27]:28718 "EHLO smtprelay04.ispgateway.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726036AbfHFNae (ORCPT ); Tue, 6 Aug 2019 09:30:34 -0400 X-Greylist: delayed 349 seconds by postgrey-1.27 at vger.kernel.org; Tue, 06 Aug 2019 09:30:34 EDT Received: from [79.249.13.39] (helo=C02YV1XMLVDM.Speedport_W_724V_01011603_06_003) by smtprelay04.ispgateway.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-SHA256:128) (Exim 4.92) (envelope-from ) id 1huzRf-0007bB-Cx; Tue, 06 Aug 2019 15:24:07 +0200 From: Marc Koderer To: tj@kernel.org, lizefan@huawei.com, hannes@cmpxchg.org Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Koderer Subject: [PATCH] Use kvmalloc in cgroups-v1 Date: Tue, 6 Aug 2019 15:24:12 +0200 Message-Id: <20190806132412.92945-1-marc@koderer.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Df-Sender: bWFyY0Brb2RlcmVyLmNvbQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of using its own logic for k-/vmalloc rely on kvmalloc which is actually doing quite the same. Signed-off-by: Marc Koderer --- kernel/cgroup/cgroup-v1.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index 88006be40ea3..7f83f4121d8d 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -193,25 +193,6 @@ struct cgroup_pidlist { struct delayed_work destroy_dwork; }; -/* - * The following two functions "fix" the issue where there are more pids - * than kmalloc will give memory for; in such cases, we use vmalloc/vfree. - * TODO: replace with a kernel-wide solution to this problem - */ -#define PIDLIST_TOO_LARGE(c) ((c) * sizeof(pid_t) > (PAGE_SIZE * 2)) -static void *pidlist_allocate(int count) -{ - if (PIDLIST_TOO_LARGE(count)) - return vmalloc(array_size(count, sizeof(pid_t))); - else - return kmalloc_array(count, sizeof(pid_t), GFP_KERNEL); -} - -static void pidlist_free(void *p) -{ - kvfree(p); -} - /* * Used to destroy all pidlists lingering waiting for destroy timer. None * should be left afterwards. @@ -244,7 +225,7 @@ static void cgroup_pidlist_destroy_work_fn(struct work_struct *work) */ if (!delayed_work_pending(dwork)) { list_del(&l->links); - pidlist_free(l->list); + kvfree(l->list); put_pid_ns(l->key.ns); tofree = l; } @@ -365,7 +346,7 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type, * show up until sometime later on. */ length = cgroup_task_count(cgrp); - array = pidlist_allocate(length); + array = kvmalloc_array(length, sizeof(pid_t), GFP_KERNEL); if (!array) return -ENOMEM; /* now, populate the array */ @@ -390,12 +371,12 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type, l = cgroup_pidlist_find_create(cgrp, type); if (!l) { - pidlist_free(array); + kvfree(array); return -ENOMEM; } /* store array, freeing old if necessary */ - pidlist_free(l->list); + kvfree(l->list); l->list = array; l->length = length; *lp = l; -- 2.22.0