Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4109709imm; Mon, 11 Jun 2018 07:10:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKKYYbq9wLFFoOcmdIiFSCI71gmDGmEDDed09sVei42BUllIbIkGycyCtMr9vwhWWTe1+20 X-Received: by 2002:a65:6290:: with SMTP id f16-v6mr15136451pgv.155.1528726204699; Mon, 11 Jun 2018 07:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726204; cv=none; d=google.com; s=arc-20160816; b=UoinlFk/CM0AKcByS+mqZt1G+W/QSx+F8pO/8Nh/LDJl3m8PegUcFO17lE7Lv3vqLh kFJq+lD1C8OB9d/uf6KkKKyG+rbIlVIlLHzkknPo7n8ko0ZeDXJXoWn/zQf2zVVxqL3u wwegtCKrQpv1AwHysKYbnMMIHJtMI/RZfNPXd7ErfydRxJ6hji9PzUtopWqr735v+Dc5 FE9A5vQzCdUl8gCKhe0TXiwFCeCo4XPoeQZWOy04n5E+xd/WIlA6INZNOnlhAQHzVVZC rLUR7bSKb4ms5mX+ZAzF82aZEYUL4Ac5122C99DM87DPkDl7g7JSInnp4Lk6QZWjES48 eTig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=uFo/5SSJuJU2uEENvH3dxtsPOTxtY7hbgSaYCUX4Usk=; b=h3snAYcNdvFeVPZ2bxOc/8LWP+7Zq7oucceTVUSoAx7PpuucWPU1L+u7GC+HuA69gP oEfn3SJcuZLiRO2IsP7yFBxcZ47w5IvU78n8xhaiUa/GQIhwgheuR+QqOIH0HhjuQO4T Qv1AwErT8cpC7zq2dkOslXbO5gk9b74w3DGQr4HMcTPH0JM6er7B2Zqal0eQyykk8i4x TjlufK1xOqSIufXqdctZ6W6BWZY7u/vh9K9TDadCX6XIf+bXNlfc1LcO1E+hYS8a5icV PVYV4w9TvoXVEk9uxVOMEyrsrTNMRecfn224iFEWrDICxZVipw2G/0u+he4PYozP+KBp VczQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=h11/Wzvm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2-v6si50900025pgs.349.2018.06.11.07.09.49; Mon, 11 Jun 2018 07:10:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=h11/Wzvm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933657AbeFKOHS (ORCPT + 99 others); Mon, 11 Jun 2018 10:07:18 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:46338 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933617AbeFKOHH (ORCPT ); Mon, 11 Jun 2018 10:07:07 -0400 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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++) { -- 2.17.1