From patchwork Fri Feb 24 15:42:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9590609 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 99BCB6020A for ; Fri, 24 Feb 2017 15:48:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CD6822BF1 for ; Fri, 24 Feb 2017 15:48:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EE31286CC; Fri, 24 Feb 2017 15:48:42 +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=unavailable 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 2EFF322BF1 for ; Fri, 24 Feb 2017 15:48:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751552AbdBXPoM (ORCPT ); Fri, 24 Feb 2017 10:44:12 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:34813 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751360AbdBXPn3 (ORCPT ); Fri, 24 Feb 2017 10:43:29 -0500 Received: by mail-pg0-f67.google.com with SMTP id s67so3458936pgb.1; Fri, 24 Feb 2017 07:43:28 -0800 (PST) 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=jZAv6rNiJHeBpDGvVUg72VXOeeJy3egYACTcjy329k0=; b=k0qzn6kgTUONFPbq7K2K3w3TvDnDKho1+CkHlGEu76y3gPYFoYAufXkD9W/ZnUxBnQ 3pjZduXdMDeZDVMpKIyoiYFVt3/PmrSPcPQ2GcUdI5bgwohVelcIArtZSE6b9Nic27LG fYOfiR+ubF8KGB6zE0HRVDvhJStPyTIKblGDTtowH4rbpCTj49CQoC+TilxxATxJAz2d wv8jMSZyB0lBJEKwTYiO+rdDEwxTq+6LdwZ4ZVen45yIaxhEsWNuPs5465cnhC5fzbez BYB4O+IHHsoXaodHV9aqWsSpfKxioJN1TJByelVutr/IjMuSEhqc1j/L7dyYxbgkueiZ mfuA== 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=jZAv6rNiJHeBpDGvVUg72VXOeeJy3egYACTcjy329k0=; b=rSf3TSq3WHTcxd1uS5/V9wPJvloxUxQ5o3Z/O5JaaoVaew676xi7uCGSydWNP48lcy m7+hvChATJgCzyNzy5fIcymU5GMi3STiB6CEKOieFZyMDJgOrMwxPwuBO+Z/S4/QuoNN KrboVTT9nQ6QUVbQ/MzcOz8DSse8bFFCRnHPpb1lHPsnaZGbxCvXgdI0kLCNE0FOIQP0 syrFXuegHjdrdcjWZF1cTT6AK3uhEu3qBSVW/2Y3Mo/SSjpsIrr+C0BU6wuX2zCo/3bB kwvFx3SSaXGQjlLnbvIQHoLVt9K4cppDYz5ySOh0dZJJhjUCtdJTDpmP3cNkXOH1RtLu HKnQ== X-Gm-Message-State: AMke39kVfSe5rT0u036uch7oYczql82Za/6ncPWQ0SS0HvRPuVgMhcBvaTyxiUTswcdvcQ== X-Received: by 10.99.127.14 with SMTP id a14mr4264091pgd.64.1487951008319; Fri, 24 Feb 2017 07:43:28 -0800 (PST) Received: from localhost (li405-222.members.linode.com. [106.187.53.222]) by smtp.gmail.com with ESMTPSA id 128sm15873796pfe.23.2017.02.24.07.43.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Feb 2017 07:43:27 -0800 (PST) From: Ming Lei To: Shaohua Li , Jens Axboe , linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, linux-block@vger.kernel.org, Christoph Hellwig Cc: Ming Lei Subject: [PATCH v1 05/14] md: prepare for managing resync I/O pages in clean way Date: Fri, 24 Feb 2017 23:42:42 +0800 Message-Id: <1487950971-1131-6-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487950971-1131-1-git-send-email-tom.leiming@gmail.com> References: <1487950971-1131-1-git-send-email-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 | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/md/md.h b/drivers/md/md.h index 1d63239a1be4..df18ae05838d 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -720,4 +720,65 @@ 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) + __free_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++) + __free_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 void resync_store_page(struct resync_pages *rp, struct page *page) +{ + if (WARN_ON(!rp->idx)) + return; + rp->pages[--rp->idx] = page; +} + +static inline struct page *resync_fetch_page(struct resync_pages *rp) +{ + if (WARN_ON_ONCE(rp->idx >= RESYNC_PAGES)) + return NULL; + return rp->pages[rp->idx++]; +} + +static inline bool resync_page_available(struct resync_pages *rp) +{ + return rp->idx < RESYNC_PAGES; +} + #endif /* _MD_MD_H */