From patchwork Mon Jun 11 14:06:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10457997 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 55FDD6020F for ; Mon, 11 Jun 2018 14:11:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FB9E28658 for ; Mon, 11 Jun 2018 14:11:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3ADCD28820; Mon, 11 Jun 2018 14:11:09 +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=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9654228658 for ; Mon, 11 Jun 2018 14:10:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D41966B0295; Mon, 11 Jun 2018 10:07:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C77056B0297; Mon, 11 Jun 2018 10:07:08 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B446B6B0298; Mon, 11 Jun 2018 10:07:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id 626B96B0295 for ; Mon, 11 Jun 2018 10:07:08 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id z9-v6so10263061pfe.23 for ; Mon, 11 Jun 2018 07:07:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=uFo/5SSJuJU2uEENvH3dxtsPOTxtY7hbgSaYCUX4Usk=; b=pIV6s8JLYWxNmEeQxsdSajx+sQuuIpphQUKo3a4gISie8uH0Sn9g20g8eyRs0qTxD8 rVvaqJtzc7NYO5RPFvrWhy7CwLnckHUlTqwxG51UMfuTw5+as1ckvgnAo6RU/th9b2Ni YHhXeOm4qquTV1SYjYrGmlRwudrCNXpGYuufUCtrfhyuulxtAr1sCWPNVLvdonm8apUH e5lK+6UwGb1OQXuvxBEPX5ymrigNkokLI6gUpujUfcRPRx7sm5rbUBsQJT9K7w01+q4G lOZOjbx95MbI95COwbxAW1VSTZz9VLSMWgUQQV9rnkOEjowuJgz4JQ5kVPBbG5VvKUy3 1XEg== X-Gm-Message-State: APt69E3Qcb6uxVzgQzqYRX0ecvT0JoLNYBPrk3arbKKlxBwfbxjd9Uu/ Za50oMh3xdbr2vrOSSxY/oADxsMSRw1dPa9vWpY5n2HlBfgLHak5GYLyAWdrVmwS+sF9R9CO59W 01y3yzx8ajs7ItQLsBqgBzXilVoPsTm3fla5IMTpKosYv+e+k7vtxv1Z6hLGoL4xqhg== X-Received: by 2002:a17:902:b7c4:: with SMTP id v4-v6mr18771652plz.188.1528726028101; Mon, 11 Jun 2018 07:07:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJp4UooXRPJ0vn8lFvuiVjJkk3t4mzadzLHz35TiDUH8+cs7FJ/yJ/mIqKVwTD4fxicHjFT X-Received: by 2002:a17:902:b7c4:: with SMTP id v4-v6mr18771586plz.188.1528726027345; Mon, 11 Jun 2018 07:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726027; cv=none; d=google.com; s=arc-20160816; b=VoQ7ZYYTVReshBVmp7JImK5SLN78ycDKwMEIB7CFdgsdRlAPs2JH90rgmTyWBzTDAl veWEBdHzrxnAKZEGyv/7QEGPPYT6knDDPIq7wReQundQV0u9yjc/Hq6zuMLOWEgXcarW iL5A51B+3Y5CcPFCyjgYfhACUzRb9Gm3J9hNdxD3O0vVa7ph12XXNvC97R8ALyV59/Y0 dVett9lsdPUGPXz8TncSXCHcLPm9rOFq70pVbNZ/6YovdAcuDkdnCvYu3WZkfGyGJSq1 TVxRcCAFaxYnrbzysenjNLMNxIPO907VwLAHaJDu1eCjwd0133CC6bSbHMSf2ZBvunu+ TJiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=uFo/5SSJuJU2uEENvH3dxtsPOTxtY7hbgSaYCUX4Usk=; b=LU+dBg9e2m5qhY74NFV71xyYkYMWSHmxO7Wcm+H4GNNB4mrgy9VtgLg2PDM+vOburD JX9W66fT4PQ38UgxeAaAEAYn/OTRxlRv5xkX9pyv0lGzXa3/Jsdc8vzQodUMZ0TI2v2C 4RfyzLHUbuMCiKB/zI16ZLECduyUe7H9xJ6/nMZ1Lq10aPCZKKX5qrTm+zbc9/KIHjeM PORsavbtg3b2Xncnp/u3wcEESCxe0sL6DJizgfo+yMcs8dfmhlPRu0kQ8QQatS+sA45W lztP3yxfUQhXpt5IWngZmVPiLRFiBVtHNFmJRujWmELbOgr7gIVDtqAWXoPPG8OTjs9q sRKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=h11/Wzvm; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id o26-v6si24587140pfe.44.2018.06.11.07.07.07 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 07:07:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=h11/Wzvm; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=uFo/5SSJuJU2uEENvH3dxtsPOTxtY7hbgSaYCUX4Usk=; b=h11/WzvmVYmTtHuxhP/vXbtHq dKADqvsRxXl3BJUcHv4IJ4p53cP8HUWx0xJoRetj5/5VCDmt8hVU0HdVm2kcwAwPzg+En+wCwWxKi uJWkUFzGDnYeIV+1jDwQWRefnU02Yi/t19Tj3ZzGTNxpPqOKSIrzDzy9Pve8abGtDfy0Q6aM2zLk+ K6MQc5B7k+R+t4QjA8KqHzfR41NDaHt2R6qQLftliEQ98cbP+/72kTpi79eovTAl38RsebkSL37LT DXDqeC+ty1LaJ1XDDrBO3EEA9zVYHYoNeDoIEJhtbS+i4uzf2n0lnS6kVMZI6WZN99pnPfPmvGwfL xYyZMRotg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNTO-0004vy-Fc; Mon, 11 Jun 2018 14:07:06 +0000 From: Matthew Wilcox To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Jan Kara , Jeff Layton , Lukas Czerner , Ross Zwisler , Christoph Hellwig , Goldwyn Rodrigues , Nicholas Piggin , Ryusuke Konishi , linux-nilfs@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v13 54/72] memfd: Convert memfd_tag_pins to XArray Date: Mon, 11 Jun 2018 07:06:21 -0700 Message-Id: <20180611140639.17215-55-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180611140639.17215-1-willy@infradead.org> References: <20180611140639.17215-1-willy@infradead.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Matthew Wilcox Switch to a batch-processing model like memfd_wait_for_pins() and use the xa_state previously set up by memfd_wait_for_pins(). Signed-off-by: Matthew Wilcox Reviewed-by: Mike Kravetz --- mm/memfd.c | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/mm/memfd.c b/mm/memfd.c index e7d6be725b7a..636de8d5c7c3 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -28,37 +28,29 @@ #define MEMFD_TAG_PINNED PAGECACHE_TAG_TOWRITE #define LAST_SCAN 4 /* about 150ms max */ -static void memfd_tag_pins(struct address_space *mapping) +static void memfd_tag_pins(struct xa_state *xas) { - struct radix_tree_iter iter; - void __rcu **slot; - pgoff_t start; struct page *page; + unsigned int tagged = 0; lru_add_drain(); - start = 0; - rcu_read_lock(); - - radix_tree_for_each_slot(slot, &mapping->i_pages, &iter, start) { - page = radix_tree_deref_slot(slot); - if (!page || radix_tree_exception(page)) { - if (radix_tree_deref_retry(page)) { - slot = radix_tree_iter_retry(&iter); - continue; - } - } else if (page_count(page) - page_mapcount(page) > 1) { - xa_lock_irq(&mapping->i_pages); - radix_tree_tag_set(&mapping->i_pages, iter.index, - MEMFD_TAG_PINNED); - xa_unlock_irq(&mapping->i_pages); - } - if (need_resched()) { - slot = radix_tree_iter_resume(slot, &iter); - cond_resched_rcu(); - } + xas_lock_irq(xas); + xas_for_each(xas, page, ULONG_MAX) { + if (xa_is_value(page)) + continue; + if (page_count(page) - page_mapcount(page) > 1) + xas_set_tag(xas, MEMFD_TAG_PINNED); + + if (++tagged % XA_CHECK_SCHED) + continue; + + xas_pause(xas); + xas_unlock_irq(xas); + cond_resched(); + xas_lock_irq(xas); } - rcu_read_unlock(); + xas_unlock_irq(xas); } /* @@ -76,7 +68,7 @@ static int memfd_wait_for_pins(struct address_space *mapping) struct page *page; int error, scan; - memfd_tag_pins(mapping); + memfd_tag_pins(&xas); error = 0; for (scan = 0; scan <= LAST_SCAN; scan++) {