From patchwork Tue Aug 17 21:06:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 12442041 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFA1CC4320E for ; Tue, 17 Aug 2021 21:07:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8BFD60295 for ; Tue, 17 Aug 2021 21:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234862AbhHQVIK (ORCPT ); Tue, 17 Aug 2021 17:08:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234753AbhHQVIF (ORCPT ); Tue, 17 Aug 2021 17:08:05 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08A7DC061764 for ; Tue, 17 Aug 2021 14:07:32 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id fa24-20020a17090af0d8b0290178bfa69d97so957716pjb.0 for ; Tue, 17 Aug 2021 14:07:32 -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=8/y368u+b0cKBJ8i6xV8bO2WQ3c9lOKFHW+lrogDRc0=; b=qgFprzxNjNCpyQxDQvYMNMToO1wFKV2eRtKV9mrjKAWB/Q07nE+72GCXuF84z0udm+ XKl6W8HMOTefcQapdbNwvoqvzZOJhPXADskaOM6UDZtDsjwI6CB8gQN0RUCCINPqHBgE OZDZQQxFS8gAvj/bTtrvT7d2c0KfuVGBZaF16QjXfQyivD9OiXe10EczJ+vG5pKytQgV IdEItZlDn1QCqjUgSHw8XuhbUvGu+jvwFPrF5s22y/fC8CTdNpYsSVnnXlsw/T2QoMfC nfYvYbD7LoHiw5hkjxUsJM0of4qYsraASYpm4QTLbuA5GwEygO+DJ/9ib7yITmKrNaEV ecDQ== 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=8/y368u+b0cKBJ8i6xV8bO2WQ3c9lOKFHW+lrogDRc0=; b=X1eQD+e40ggaI4iTuCPFNw8Pq7Efbj/kPefRQEOaMuxRt2FtD0jaCvlWhIXCbhXXb7 hgLuzgXAyZ95Wllus1ktGwImwpZ7+tMEUY99CxBmdm00qza410ERJdX6KHfid2U4wNfa eSnjusSWGQEGwTnc4/90XQjABJskUVUG2EMX9jX2cULpdktRLwkorCGMrUb1U8EI3ghT GZVncFL7Uy3KFXtOjxYQpboO0Nwu9TW7BVe18y3RIo//0PA/LXnwV32ZhjW9D7k4X4M6 EexAcO+msTTrDpouGqLhLJbZH/vxunUGM2ODADVsEjMxB9Xz4I0YOa9TLcY+zIEJ/nI1 TAQg== X-Gm-Message-State: AOAM533hNPonXBZHXWxrcoG/ETX28QV9ZfBXb9TRW4d/45B8TqTcsdlh +FTA/q+FLfjwnKaBM48eeCctxhOK/FBM5w== X-Google-Smtp-Source: ABdhPJx2QJEHbvSgUUhCX5KQryvh3A9rlpieB0JM99o0M/B1PtxC5ZB6MHC+ypPR8ov3iR7WuT7TJw== X-Received: by 2002:aa7:8685:0:b0:3e1:76d8:922e with SMTP id d5-20020aa78685000000b003e176d8922emr5473852pfo.45.1629234451244; Tue, 17 Aug 2021 14:07:31 -0700 (PDT) Received: from relinquished.tfbnw.net ([2620:10d:c090:400::5:df70]) by smtp.gmail.com with ESMTPSA id c9sm4205194pgq.58.2021.08.17.14.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 14:07:30 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com, linux-fsdevel@vger.kernel.org, Al Viro , Linus Torvalds , linux-api@vger.kernel.org Subject: [PATCH v10 12/14] btrfs: send: allocate send buffer with alloc_page() and vmap() for v2 Date: Tue, 17 Aug 2021 14:06:44 -0700 Message-Id: <5ea052d103ec66ef1f782839c5e21d4f6574fcc1.1629234193.git.osandov@fb.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@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 dfe598d12b8c..7242362ecb23 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 */ @@ -7230,6 +7231,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; size_t alloc_size; @@ -7310,10 +7312,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; @@ -7520,7 +7540,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);