From patchwork Fri Aug 21 07:39:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 11728543 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 74A42739 for ; Fri, 21 Aug 2020 07:41:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B75D2087D for ; Fri, 21 Aug 2020 07:41:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=osandov-com.20150623.gappssmtp.com header.i=@osandov-com.20150623.gappssmtp.com header.b="USCEiov+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728497AbgHUHly (ORCPT ); Fri, 21 Aug 2020 03:41:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728125AbgHUHka (ORCPT ); Fri, 21 Aug 2020 03:40:30 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C40BC061348 for ; Fri, 21 Aug 2020 00:40:30 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id mt12so461675pjb.4 for ; Fri, 21 Aug 2020 00:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4GBiuBiabcY66Xi/9ClqfYhrJxdtjYE/DsOa+EGbDCM=; b=USCEiov+fhm+HnznZWXrt6cguny7h+jJYBPetlZjSTgkZ3qakw8LWXxjB2WHHSnoKU ZLPgTWqTBSFNWkKSthevTUmhwQDakKSBspZEaFjtn7TZuaMhbm4DVcdUSq0yOsoBQJpV dO89xgOiOXXApnnGePXKu2CDGvZFQM7NmjEO370iCdpMlFHRgeFGw1F4Gdg1bxXHRRTC sfWDYKkfHiG3qTjehVGQql74AgmDIKvfWj7fNHrrhur7PG4vXdrxzuevxqzwk2aO89x/ /434lzT+xJio8JSt/2t5LriV0I1XjWqRXrTMXrKlSRx1lIVYNg3bRKcjeoth2ZwJ/4Pu AimQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4GBiuBiabcY66Xi/9ClqfYhrJxdtjYE/DsOa+EGbDCM=; b=HDpsctkYQCjfZzH2dAOwygqQS1n+mrpAzvANEMDevkxAzrXXlS+I/yjgRB4c2SZRD9 IxtljKrfgia5nJvZqdXpkFFvyYIvLI954FFK2Q+wXNEntcxt+yBI1XkaKoZ9Un9Rs1aO ZnooT6oLtBlZ29GAKwGekaBS9ZipLkrqaZVA9TI5MxIlhiU7wNq8rTtt4K/VvM34PInT XRpSeYzdJPE3wfRZcchj6/X+Sodmc8pAaPuRyjSwZR0nDwTRzmQEyWRxRRbzF57nsZ0z LRjc4gNVvGS7JJtNTrTeGvK+A6xvP+c/JGIjX2ByehKOogYSvQhVoXp5Cswb/h50dnFw uU3A== X-Gm-Message-State: AOAM530OWmUlQBsV/2zFhuJJySK8S6KO5JK9v5w46xKXIynS8k67CJaw ogrNhX8PC3qJVYWroYaGGp4efmrCZ4Cw5w== X-Google-Smtp-Source: ABdhPJxItbccacYGbgmb6CD+tSwEulVyKHRbP8i53kk0o3R1tP7G2pM+vzmWSr9qOPIos0Gfu/u+Mw== X-Received: by 2002:a17:902:8608:: with SMTP id f8mr1473957plo.66.1597995629660; Fri, 21 Aug 2020 00:40:29 -0700 (PDT) Received: from exodia.tfbnw.net ([2620:10d:c090:400::5:f2a4]) by smtp.gmail.com with ESMTPSA id jb1sm1080875pjb.9.2020.08.21.00.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 00:40:28 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH 7/9] btrfs: send: allocate send buffer with alloc_page() and vmap() for v2 Date: Fri, 21 Aug 2020 00:39:57 -0700 Message-Id: X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Omar Sandoval For encoded writes, we need the raw pages for reading compressed data directly via a bio. So, replace kvmalloc() with vmap() so we have access to the raw pages. 144k is large enough that it usually gets allocated with vmalloc(), anyways. Signed-off-by: Omar Sandoval --- fs/btrfs/send.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c index c0f81d302f49..efa6f8f27e4d 100644 --- a/fs/btrfs/send.c +++ b/fs/btrfs/send.c @@ -81,6 +81,7 @@ struct send_ctx { char *send_buf; u32 send_size; u32 send_max_size; + struct page **send_buf_pages; u64 total_send_size; u64 cmd_send_size[BTRFS_SEND_C_MAX + 1]; u64 flags; /* 'flags' member of btrfs_ioctl_send_args is u64 */ @@ -7072,6 +7073,7 @@ long btrfs_ioctl_send(struct file *mnt_file, struct btrfs_ioctl_send_args *arg) struct btrfs_root *clone_root; struct send_ctx *sctx = NULL; u32 i; + u32 send_buf_num_pages = 0; u64 *clone_sources_tmp = NULL; int clone_sources_to_rollback = 0; unsigned alloc_size; @@ -7152,10 +7154,28 @@ long btrfs_ioctl_send(struct file *mnt_file, struct btrfs_ioctl_send_args *arg) if (sctx->flags & BTRFS_SEND_FLAG_STREAM_V2) { sctx->send_max_size = ALIGN(SZ_16K + BTRFS_MAX_COMPRESSED, PAGE_SIZE); + send_buf_num_pages = sctx->send_max_size >> PAGE_SHIFT; + sctx->send_buf_pages = kcalloc(send_buf_num_pages, + sizeof(*sctx->send_buf_pages), + GFP_KERNEL); + if (!sctx->send_buf_pages) { + send_buf_num_pages = 0; + ret = -ENOMEM; + goto out; + } + for (i = 0; i < send_buf_num_pages; i++) { + sctx->send_buf_pages[i] = alloc_page(GFP_KERNEL); + if (!sctx->send_buf_pages[i]) { + ret = -ENOMEM; + goto out; + } + } + sctx->send_buf = vmap(sctx->send_buf_pages, send_buf_num_pages, + VM_MAP, PAGE_KERNEL); } else { sctx->send_max_size = BTRFS_SEND_BUF_SIZE_V1; + sctx->send_buf = kvmalloc(sctx->send_max_size, GFP_KERNEL); } - sctx->send_buf = kvmalloc(sctx->send_max_size, GFP_KERNEL); if (!sctx->send_buf) { ret = -ENOMEM; goto out; @@ -7363,7 +7383,16 @@ long btrfs_ioctl_send(struct file *mnt_file, struct btrfs_ioctl_send_args *arg) fput(sctx->send_filp); kvfree(sctx->clone_roots); - kvfree(sctx->send_buf); + if (sctx->flags & BTRFS_SEND_FLAG_STREAM_V2) { + vunmap(sctx->send_buf); + for (i = 0; i < send_buf_num_pages; i++) { + if (sctx->send_buf_pages[i]) + __free_page(sctx->send_buf_pages[i]); + } + kfree(sctx->send_buf_pages); + } else { + kvfree(sctx->send_buf); + } name_cache_free(sctx);