From patchwork Thu Mar 16 16:12:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9628865 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 67DF460244 for ; Thu, 16 Mar 2017 16:15:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59879283F9 for ; Thu, 16 Mar 2017 16:15:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E6BB2841E; Thu, 16 Mar 2017 16:15:44 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 08068283F9 for ; Thu, 16 Mar 2017 16:15:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751185AbdCPQPk (ORCPT ); Thu, 16 Mar 2017 12:15:40 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34942 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755141AbdCPQOe (ORCPT ); Thu, 16 Mar 2017 12:14:34 -0400 Received: by mail-pf0-f194.google.com with SMTP id x63so6154438pfx.2; Thu, 16 Mar 2017 09:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=V1Qo6lOZLd0csjg8FeAx7rIX0t4JWOaLq7wKOYisbIM=; b=nMuxMCcCi2VC7PZkxckzFbaoOKpkx3p/xs1v1nY3ymLh8mm6DciXY0hy7FPzPGG0na faZgU3Id2vqADitqGEEa/cC9p0d4hVC5PzAryahIzu51c/Rwaou4YUFdzJi+IckjALYJ m8ZXBoAf7NnKB6ADnigrl5kvks1bC1whikCfB+BCFHlP0eRmDeRA65EFvLPnWt3VL+nm N8FaXwB22eDFYhKp0ySkYAv/6AYbncc4OGq04dLyJv4GVvnuOLkGFHL4qCwAD7+WPYbA IfaHjxbtvE11SKacjES1+jaLEq+P+mB6/CB3F9a6gxuqQpGXhFwCV3Dxa9tLdPVkUa3Y xlUA== 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; bh=V1Qo6lOZLd0csjg8FeAx7rIX0t4JWOaLq7wKOYisbIM=; b=ooEqSzR93E34BlR0NCKs2adZ8WVSQjvaQLjl/5LWBzn3d5+TOaFLfpOHi0FtoMk6i9 vWo/gDelXCSm69I3jGVr0xyrD2Q3dWmCzvMPIpC4fuFhbvMh9ENOXiMmjQkbOXn745F5 YxhMSfUgFeKB1rhx39mEkEK96/7xWvB+FT61bsX7zaffEmXMZ00gqU+SUGgy9CjKgZS7 v9L6DGK3z8Y/nhyROJsTVlbuFUDge/GdxMo+rpzO+4fkQTsq3DifuoDetWp2cw7Y/+vI DETnSJOF7k53ZydFd7Nth06WGi6G0JbTi/ltfwptTIBNCk4LijDzlYBhZZyyEAg2kGHe Dpiw== X-Gm-Message-State: AFeK/H3bAc3DXy0ykYe9xCyvXbSxeBCFKaXrA3P4+cqsNqdBuofJIVcgaDVul0G8DVWpTg== X-Received: by 10.98.69.141 with SMTP id n13mr11199510pfi.216.1489680858394; Thu, 16 Mar 2017 09:14:18 -0700 (PDT) Received: from localhost ([103.192.224.52]) by smtp.gmail.com with ESMTPSA id z26sm11564305pgc.57.2017.03.16.09.14.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 Mar 2017 09:14:17 -0700 (PDT) From: Ming Lei To: Shaohua Li , Jens Axboe , linux-raid@vger.kernel.org, linux-block@vger.kernel.org, Christoph Hellwig Cc: Ming Lei Subject: [PATCH v3 03/14] md: prepare for managing resync I/O pages in clean way Date: Fri, 17 Mar 2017 00:12:24 +0800 Message-Id: <20170316161235.27110-4-tom.leiming@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170316161235.27110-1-tom.leiming@gmail.com> References: <20170316161235.27110-1-tom.leiming@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now resync I/O use bio's bec table to manage pages, this way is very hacky, and may not work any more once multipage bvec is introduced. So introduce helpers and new data structure for managing resync I/O pages more cleanly. Signed-off-by: Ming Lei --- drivers/md/md.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/md/md.h b/drivers/md/md.h index 1d63239a1be4..20c48032493b 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -720,4 +720,54 @@ static inline void mddev_check_writesame(struct mddev *mddev, struct bio *bio) #define RESYNC_BLOCK_SIZE (64*1024) #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE) +/* for managing resync I/O pages */ +struct resync_pages { + unsigned idx; /* for get/put page from the pool */ + void *raid_bio; + struct page *pages[RESYNC_PAGES]; +}; + +static inline int resync_alloc_pages(struct resync_pages *rp, + gfp_t gfp_flags) +{ + int i; + + for (i = 0; i < RESYNC_PAGES; i++) { + rp->pages[i] = alloc_page(gfp_flags); + if (!rp->pages[i]) + goto out_free; + } + + return 0; + + out_free: + while (--i >= 0) + put_page(rp->pages[i]); + return -ENOMEM; +} + +static inline void resync_free_pages(struct resync_pages *rp) +{ + int i; + + for (i = 0; i < RESYNC_PAGES; i++) + put_page(rp->pages[i]); +} + +static inline void resync_get_all_pages(struct resync_pages *rp) +{ + int i; + + for (i = 0; i < RESYNC_PAGES; i++) + get_page(rp->pages[i]); +} + +static inline struct page *resync_fetch_page(struct resync_pages *rp, + unsigned idx) +{ + if (WARN_ON_ONCE(idx >= RESYNC_PAGES)) + return NULL; + return rp->pages[idx]; +} + #endif /* _MD_MD_H */