Received: by 10.223.164.202 with SMTP id h10csp665486wrb; Wed, 22 Nov 2017 13:19:41 -0800 (PST) X-Google-Smtp-Source: AGs4zMYN5SMuIbePHwKAKoqKfhaZEKe1fcyyXsI8/71SMG1EUnSjB9OBgZvI36fihX+b9C0HRvyM X-Received: by 10.101.66.66 with SMTP id d2mr3643110pgq.244.1511385580958; Wed, 22 Nov 2017 13:19:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511385580; cv=none; d=google.com; s=arc-20160816; b=kbTzvWxcCYXTgXcxJv56/ebKK7qHl5Q4jUaoTgJ3yt/Sh56cy3Z2JWEJtqn4aTXNTW ZS7xwDVTlAqr0EFPpla/UUsJCNUSaRWUszdsEluTX3cS7dvd0ppxLhTSrY6J1Ay8uFzC q+V7IuD8d+dF2lmI+hcJce2H6c7ZYMgkd4Bc8g6wFVsiBtNoWZlz+G9OYE8lULhrljSE 75Xhd75mhx3ykyyiFDPEcx8Dwd/eEkfstctsQC54wcftWdJkbr8K7/nEJ4ndyt6QM+5V bvT41BHQiz9o2f4GArLeCIyTjG/B93lTCk0t8Ht8gwQyX2Ws6R2jjMhkS3jhVZCTHl8p Pzxw== 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=DSRaz3CJdJ7Iecd+YMwPAFabSEfn/MDBD4PSCZ2k0nM=; b=bi3u7Ex43ho4LASPo6GOTvqweCZRg4cr2mER4uFizbyfCwDiG5whKNBs9w+/knqogt 1QPZ6CwlCKokXudbz4dYKPIk72C8irIwyxCJhNZUC0xBm7mK8Gjet1LunBmuOz6jRdX9 bu6sfNQMIC+ZqeDIh/eFpbrNSWix1Pu4pEQCPBoDQSViw2JHADS+AyvMp5jqa0F5n8S6 fu1GA1U+fFZiTMOwHqY3IxBNgjcAOrzTnbt3k7lEbVESToKRsFDoGwYVwQXzQ5Ju81yn 9qZXJhheHjFj0mn5xRDAYIqsBsbfPDiKc4LQfE3vP8RZyOwSPbiVKEHDU03q3BquuMeE iIqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=OrJbKbYn; 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 r8si14105959pgq.305.2017.11.22.13.19.28; Wed, 22 Nov 2017 13:19:40 -0800 (PST) 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=OrJbKbYn; 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 S1752163AbdKVVO0 (ORCPT + 77 others); Wed, 22 Nov 2017 16:14:26 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:48015 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751836AbdKVVIT (ORCPT ); Wed, 22 Nov 2017 16:08:19 -0500 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=DSRaz3CJdJ7Iecd+YMwPAFabSEfn/MDBD4PSCZ2k0nM=; b=OrJbKbYnwhYhnlSMp/Ha35hA2 wGFSuYa3pkZYln5F8UKZ6UjpQMhBzKuBR4RUmOY53Jx2QHYc7VzhQ8qDZI/yaqsCLYdY9eFlxw8f8 UYq05v3WUijeHgtTl/64umqqarCdYzzPjuarV7cheVI167F7UbDm6B8Z/LqhCgkIev99RKlB5MkkK lpXoEvFZw9SPM40gBRBzD/tJmhGrW3ucXbKoPVoa96oxmSxXhYF0RZyuD2kzxoWNQUhSXPdSbgqVK KcXdnjb0Y24h3EbDzMf1Z3i+h4e000reKMHt0KNIcIvpRPhK8df3R1F6PqBYJPKJGmFBqsfN8+pOQ 51wEpu1Zg==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eHcFm-0007wb-W3; Wed, 22 Nov 2017 21:08:19 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH 41/62] shmem: Convert shmem_wait_for_pins to XArray Date: Wed, 22 Nov 2017 13:07:18 -0800 Message-Id: <20171122210739.29916-42-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171122210739.29916-1-willy@infradead.org> References: <20171122210739.29916-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 As with shmem_tag_pins(), hold the lock around the entire loop instead of acquiring & dropping it for each entry we're going to untag. Signed-off-by: Matthew Wilcox --- mm/shmem.c | 59 +++++++++++++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 302fcb62ba1f..e4d28743a666 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2636,9 +2636,7 @@ static void shmem_tag_pins(struct address_space *mapping) */ static int shmem_wait_for_pins(struct address_space *mapping) { - struct radix_tree_iter iter; - void **slot; - pgoff_t start; + XA_STATE(xas, 0); struct page *page; int error, scan; @@ -2646,7 +2644,9 @@ static int shmem_wait_for_pins(struct address_space *mapping) error = 0; for (scan = 0; scan <= LAST_SCAN; scan++) { - if (!radix_tree_tagged(&mapping->pages, SHMEM_TAG_PINNED)) + unsigned int tagged = 0; + + if (!xa_tagged(&mapping->pages, SHMEM_TAG_PINNED)) break; if (!scan) @@ -2654,45 +2654,36 @@ static int shmem_wait_for_pins(struct address_space *mapping) else if (schedule_timeout_killable((HZ << scan) / 200)) scan = LAST_SCAN; - start = 0; - rcu_read_lock(); - radix_tree_for_each_tagged(slot, &mapping->pages, &iter, - start, SHMEM_TAG_PINNED) { - - page = radix_tree_deref_slot(slot); - if (radix_tree_exception(page)) { - if (radix_tree_deref_retry(page)) { - slot = radix_tree_iter_retry(&iter); - continue; - } - - page = NULL; - } - - if (page && - page_count(page) - page_mapcount(page) != 1) { - if (scan < LAST_SCAN) - goto continue_resched; - + xas_set(&xas, 0); + xa_lock_irq(&mapping->pages); + xas_for_each_tag(&mapping->pages, &xas, page, ULONG_MAX, + SHMEM_TAG_PINNED) { + bool clear = true; + if (xa_is_value(page)) + continue; + if (page_count(page) - page_mapcount(page) != 1) { /* * On the last scan, we clean up all those tags * we inserted; but make a note that we still * found pages pinned. */ - error = -EBUSY; + if (scan == LAST_SCAN) + error = -EBUSY; + else + clear = false; } + if (clear) + xas_clear_tag(&mapping->pages, &xas, + SHMEM_TAG_PINNED); + if (++tagged % XA_CHECK_SCHED) + continue; - xa_lock_irq(&mapping->pages); - radix_tree_tag_clear(&mapping->pages, - iter.index, SHMEM_TAG_PINNED); + xas_pause(&xas); xa_unlock_irq(&mapping->pages); -continue_resched: - if (need_resched()) { - slot = radix_tree_iter_resume(slot, &iter); - cond_resched_rcu(); - } + cond_resched(); + xa_lock_irq(&mapping->pages); } - rcu_read_unlock(); + xa_unlock_irq(&mapping->pages); } return error; -- 2.15.0 From 1584762088953890608@xxx Wed Nov 22 10:35:01 +0000 2017 X-GM-THRID: 1584761262155631511 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread