Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2450793imm; Sat, 16 Jun 2018 19:08:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLQr+cm+4bwT83OqDSm/N9ElFgu1d21U5fiJzkfFlD7xU3z7Vux17bm6BgH0PM6tkvFuTTb X-Received: by 2002:a65:6390:: with SMTP id h16-v6mr6662593pgv.382.1529201294480; Sat, 16 Jun 2018 19:08:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529201294; cv=none; d=google.com; s=arc-20160816; b=Tn92AHlOVBVtfksBrjM2+PWS6Lsfxv9D7BvH34vEXTUML6X/fpo/8MASc4wYIRAeNC LM3owYpZaMcW1plg7aITXdlnATYA8YEg8g8OzcJhWE+Pb212uJBjK0TgMKLRKp/B9b/f 9naVLlIKbOj5GuZSLclhMgBmQGIsOAYh19VPTup7rBF4iVam+ItIcIlFbDPNA602w8/W n3IrMQ8uWojQNNhSbmrahjLuC6q9uuAPAfefL9Dl8oGVo4VE0bqCgy6MP1HE2fhsClZ2 Qk0DOEjQMUUev8aZQKGwluusNbRoVoAjSwxacIOEfnrIP8G+ayRJg0u7J5UVRNeOKVIL vVIA== 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=3dt1i9NP1EXxETQ4D4nD6mkkx/fkw3evvLQHvoVxbqY=; b=MVX9w8ISrpZTsxDHLVBRwxuJ3SNp4cKfh5cQPBm9MQddThqjD9zLEu/PbCcUrwJnMC biJfDCmCrYjlOoYcvwLQ5h0pdhYbtA+ngcld78Csft6tkrQBHxdoF+lR4RoAaBGYa9VD 7ZZCqI33JXbu6uHQXmCQscK+Axsv+34+yqEo39Guy2FBCDparEBNKYZOkx2nGTtGUx50 0qZ8aPdgI3WQIqOiXlR4bq7C1mM8N1R2Vj1QaOfRECUJBpGS2eNuweMc3Tv8PX6VeAlx ycGShxVVoORURrv7B9AxWvtBtDIM5AMMAqK/IM8kDP04P+q9KhnVX+RRuskBBrMSmJXd oUcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=hBhoTyth; 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 l14-v6si7211462pgs.155.2018.06.16.19.07.59; Sat, 16 Jun 2018 19:08:14 -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=hBhoTyth; 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 S934566AbeFQCGs (ORCPT + 99 others); Sat, 16 Jun 2018 22:06:48 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:59542 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934107AbeFQCBP (ORCPT ); Sat, 16 Jun 2018 22:01:15 -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=3dt1i9NP1EXxETQ4D4nD6mkkx/fkw3evvLQHvoVxbqY=; b=hBhoTythSko0pFY65cmmmSvgH k2HXrqUZ3It06bxZLbP7ijoSrRGWitmutjXTJjSfEIh/TXudmVVJCox6fMusITIZRrLbt0BM/toUB wQV2ThXABL0BEAUAZxy4SKjGCeKLU/M4k9EBHd1u+G7r0ud03kQYqSAniHfKkfsmx9rfQxWhJ3PVW ZfYMttSmUwDZWba0W5tMCQU7tkUNyFbjSmDt3fHI8Ah9GJaEqt9wuHSBUynvZVteNowLlgFFZ/IGA lVwubIOV2QQ3nwZu0pXN/riLYUln9uL77TLx7Kd9ODbWvQrW2Q2lk8l6zqGAmtgo2zT1pfO65DeHC rIr54DZvg==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUN0C-0001SF-Af; Sun, 17 Jun 2018 02:01:12 +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 v14 55/74] memfd: Convert memfd_tag_pins to XArray Date: Sat, 16 Jun 2018 19:00:33 -0700 Message-Id: <20180617020052.4759-56-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180617020052.4759-1-willy@infradead.org> References: <20180617020052.4759-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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