From patchwork Mon Jul 16 16:03:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Ryabinin X-Patchwork-Id: 10527147 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 059CD60348 for ; Mon, 16 Jul 2018 16:02:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE13328BF9 for ; Mon, 16 Jul 2018 16:02:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF66128C7D; Mon, 16 Jul 2018 16:02:37 +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 0903F28BF9 for ; Mon, 16 Jul 2018 16:02:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727618AbeGPQaj (ORCPT ); Mon, 16 Jul 2018 12:30:39 -0400 Received: from mail-db5eur01on0135.outbound.protection.outlook.com ([104.47.2.135]:25850 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727479AbeGPQaj (ORCPT ); Mon, 16 Jul 2018 12:30:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mSYdj9MmgsfqwZxbIxmcAjjOnx3Ll3TwwcRcm2BK0xU=; b=D62ydY6hrcovm4i/A/poDzlUSincIalgJ5O9L0NTPQUZqgjJrbWeJronv2vzJGJNAoGK7c0LsxIkFUJuM/U/4AbKhtCdYSYxaGEcQimnbKdS9Ub72CSwhcf/ncPmII2ca+PgBxjzCAqQWyV0SAKD2fd0hRRQKSvHh0TSU21gDv4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=aryabinin@virtuozzo.com; Received: from i7.sw.ru (185.231.240.5) by AM6PR08MB3255.eurprd08.prod.outlook.com (2603:10a6:209:47::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.952.17; Mon, 16 Jul 2018 16:02:30 +0000 From: Andrey Ryabinin To: Miklos Szeredi Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Andrey Ryabinin Subject: [PATCH 1/2] fs/fuse, splice: use kvmalloc to allocate array of pipe_buffer structs. Date: Mon, 16 Jul 2018 19:03:43 +0300 Message-Id: <20180716160344.7015-1-aryabinin@virtuozzo.com> X-Mailer: git-send-email 2.16.4 MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1PR0501CA0032.eurprd05.prod.outlook.com (2603:10a6:800:60::18) To AM6PR08MB3255.eurprd08.prod.outlook.com (2603:10a6:209:47::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 77905076-a122-4a95-bde0-08d5eb35893c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:AM6PR08MB3255; X-Microsoft-Exchange-Diagnostics: 1; AM6PR08MB3255; 3:PAv05TwGWPCqGaCs1yz9I13/YYERiIuwTE8CgiE4ZjrHYIddLGWwwmdD+I8Ja2JQqlKGT5mfR2r/jFmDREMB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ipBd7FAGS3ZULQlNH85bMYneKj1mTSbdBTDcb8fMd7mj1TIkbQ8MPc+I2RnXmAfasyOW9yNdE66iC9+bzq08MAW2ViontIRx3aGB9iMttJ6CK0o7DvUyOI1epywqG/xzlDA73RWZPMkWBt6r2BJbBo74maCxM/+abn8ggLGjuBsqZ8kWByFKQVAg0MJRqEgwQbtRZl5O6D8Y1RAjBui+XnyLpYTJduxLozbPU4E5C8SKmbJyptmyMuJ6Vh21OguAiP24u/n; 4:v97lSkGkqV7bmgvMsTvK81BwlYwXomGXeuml1eIrFRMA7PJdLbS3+skA6jeO8ObUmyINLBTr8bGPut+ZiaBAjd+ac2pUVrAy6owI/y2p5xFcYyNup58ZkyaB0qQKtd4FPvO5mGAqCkaWX6YbBhVohGxJ/EwDlFujxzsK629KdWwVrJ7M3004C/u9T3bzcveSTWiulp1FnZcf+n8uh2OPbjiEtqWw0+S76SG81T+wQCdSFIwgEKqVaWYK0wwGoTsB0AeLiKd4PPXLFXAIyfJO4A== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(10201501046)(3231311)(944501410)(52105095)(3002001)(93006095)(93001095)(149027)(150027)(6041310)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011)(7699016); SRVR:AM6PR08MB3255; BCL:0; PCL:0; RULEID:; SRVR:AM6PR08MB3255; X-Forefront-PRVS: 073515755F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(39840400004)(396003)(136003)(366004)(376002)(346002)(199004)(189003)(68736007)(305945005)(53416004)(6666003)(53936002)(36756003)(6512007)(1076002)(47776003)(48376002)(66066001)(4326008)(5660300001)(25786009)(6916009)(107886003)(50466002)(105586002)(106356001)(97736004)(3846002)(16586007)(6116002)(81166006)(478600001)(8936002)(81156014)(8676002)(6486002)(2906002)(26005)(386003)(316002)(6506007)(486006)(16526019)(476003)(186003)(50226002)(14444005)(52116002)(2616005)(86362001)(51416003)(7736002)(956004); DIR:OUT; SFP:1102; SCL:1; SRVR:AM6PR08MB3255; H:i7.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM6PR08MB3255; 23:Diiknn6dzPndrldRt4s5XaU+IRC5rK0aRME6wAC5x?= =?us-ascii?Q?mZOXlW0VCxgpAh+WrecMlZ6kBCFFHlJpylz2oQxXIoxVxFxOHlWoKvA/em40?= =?us-ascii?Q?iDqDuQhxlns4pksCySB6hVirOIIA0VoaiRVdkD+QmGQjdo0jhOqC+EJu7YHH?= =?us-ascii?Q?lYoLI16rgxP552mqUGtLoiZ7c4tbFlNtP7GDd72k4mZeOBEZ9J2mkjZqGqR4?= =?us-ascii?Q?PEukMlMiHmdH768r8xAVnWY3LmSg2/bajZgpYeo0tDyfPJWcXm9aGTWph1RX?= =?us-ascii?Q?/OXYmO48+UhmpQeR+vrgLhiS3kcs+8VSz05TjmHC4pUcTqknNintkSoSRyE8?= =?us-ascii?Q?l3x1jxVLV0kPYUahTyY0fowAV+XWagCCkHPi1I4uI7/UZMd1TLWqsy1qpLtZ?= =?us-ascii?Q?hTjFdCy64nhxDg1AJ6TsZ9b9jxO2BgKs8UAI5SaS+/VNlelKnRR+u4YfyYSm?= =?us-ascii?Q?8oBf/8kqA91PFZaZWmWvs8sbO+QVetiSOC0xRf7p3gnenDSNBESz/SX5i/0+?= =?us-ascii?Q?W3ogLz3gPUA4ytb7JOLmum5gzv2+7kVKJdLpfBB8HRU9cUZ3d5/nt1HsclII?= =?us-ascii?Q?Ki0YkVtNXxvH+xe59Aip7YbxNnkBUL4P5bWrr2W40lF3YgAe4muC315v4n++?= =?us-ascii?Q?Fx1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+xq2d/xcjcFY8nuLH5f7o+69yz7UwfQKDekpwbMn; 20:Ax69wtcjCsF2lQG2M3n8vbYCNcAb0tQDmtF15nvCWKcla16YQcvZ8u/m/8cmyAvg756a8A2qcJ9WxvGumGEsdXwKZv4Lq2SGtrSOsLau98qUCJMV8V4kec4VTOqcZlC0SiGj2e8Lt57IY8c+k4RIqEgnOKYQ0R8nqqHX8TRJu30= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2018 16:02:30.6313 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 77905076-a122-4a95-bde0-08d5eb35893c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3255 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The amount of pipe->buffers is basically controlled by userspace by fcntl(... F_SETPIPE_SZ ...) so it could be large. High order allocations could be slow (if memory is heavily fragmented) or may fail if the order is larger than PAGE_ALLOC_COSTLY_ORDER. Since the 'bufs' doesn't need to be physically contiguous, use the kvmalloc_array() to allocate memory. If high order page isn't available, the kvamalloc*() will fallback to 0-order. Signed-off-by: Andrey Ryabinin --- fs/fuse/dev.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index c6b88fa85e2e..74900571546d 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1362,8 +1362,8 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos, if (!fud) return -EPERM; - bufs = kmalloc_array(pipe->buffers, sizeof(struct pipe_buffer), - GFP_KERNEL); + bufs = kvmalloc_array(pipe->buffers, sizeof(struct pipe_buffer), + GFP_KERNEL); if (!bufs) return -ENOMEM; @@ -1396,7 +1396,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos, for (; page_nr < cs.nr_segs; page_nr++) put_page(bufs[page_nr].page); - kfree(bufs); + kvfree(bufs); return ret; } @@ -1944,8 +1944,8 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe, if (!fud) return -EPERM; - bufs = kmalloc_array(pipe->buffers, sizeof(struct pipe_buffer), - GFP_KERNEL); + bufs = kvmalloc_array(pipe->buffers, sizeof(struct pipe_buffer), + GFP_KERNEL); if (!bufs) return -ENOMEM; @@ -2003,7 +2003,7 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe, pipe_buf_release(pipe, &bufs[idx]); out: - kfree(bufs); + kvfree(bufs); return ret; }