Received: by 2002:a25:d80d:0:0:0:0:0 with SMTP id p13csp219740ybg; Sat, 23 May 2020 12:04:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYrUJCK4rRFPNAi13nWRwLGrp9rZC3cTQCnsaERzwkAQmC8IyyxDwJC6YXvI28Oz/1UXoG X-Received: by 2002:a05:6402:22a6:: with SMTP id cx6mr8226558edb.76.1590260648771; Sat, 23 May 2020 12:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590260648; cv=none; d=google.com; s=arc-20160816; b=skVCHKAdnCqBnTwTmVzaVUMfUCRcUzfWfipeBA857ayy9KtLKDaRsqWcHbbYS8fmGP 7GKepex6P7P3YS0B7CAKTq3xc7nEuFuqUdT4r+eIANZI8RbwiyHW6OHHnxyAQYz3fYFH +271JH94XJugb2vMHYDbr4cA64y8ia+R3gCzMALK+aKI8A0yHxeNGMum3oQvkCjJ2nC5 BNk+GOzYs6JStHY7CrnAy533np+SEC1ZfYXWBgSqqymEcvAGjJfarqvo6wzY7TbKLhMy eXm4kfFOnYZnxnysCkM0GlBXoeafIRMSayPEiCpcjcqKwmLhgp6rihAJSUceRpr6apoO cCFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fQihCl0dLbHaElgiRrlXkibi9/E8OKsaJ7lF0uUyO/s=; b=YBLjxC4KM300/9HeR+p90nZyoSdUiGGtslJ2B35t4fSU7TMqU9O63T6DnkRyEkMUNv ybqwQYHWTEYqa+ibNsnqaqkTtJSXzgMcJIH1Qe69dTJ5htjNKZuyLRH2it/IMVkgdCME 4joYkEysxXcSGjeHx/rzB89sTiwaFwvp5LYllJJvvtBitb/pzYQ9FLNv+AgnfUJqQtAz HJhdxrz/Vms+WxsFiFXsMe9E/4QgAccCDLIPtE2ll8sv2dUf5+au7x0rIQDzj4SLl4qO mB2Y+zDSukAyOcsq2zt4lg65o0wmIOfdrAS+enHYJUmbxwyVjuPcHw3a2wHjslEJO+fl x12w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=eaWQu5rI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e9si6884021ejc.702.2020.05.23.12.03.45; Sat, 23 May 2020 12:04:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=eaWQu5rI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388082AbgEWS6v (ORCPT + 99 others); Sat, 23 May 2020 14:58:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387580AbgEWS6F (ORCPT ); Sat, 23 May 2020 14:58:05 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02FB8C061A0E for ; Sat, 23 May 2020 11:58:04 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id n15so6779764pfd.0 for ; Sat, 23 May 2020 11:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fQihCl0dLbHaElgiRrlXkibi9/E8OKsaJ7lF0uUyO/s=; b=eaWQu5rIF65IIe8LNBzP1VhRXuhf/K8YuXmyjWuD3csLufjFBKBEZDaJbIB6RwswAQ rDBP5Ms4v5GriXypOxasHghq7UnINAs0gaI86yQ/hNhK85oUXxh9tCLqJ+1ReVF5l/ix tPRMxxn5OJgrvK94v8gqoHCYdCO3fgQMAXr+vr1QgQvnYsZJ/wdm4/qp2eaVtNDY2sgH LDz+wH7VwwOwdN2+SX1xQCFbPnBR8BZ8SA2j96fkibGQYbL5STDJ4sUUYmLUjN6asTWW kgkWS4yZfdrzVsXNsu8c22UnUv/buUDX4ks7m/nlfPqKjekl11LSVTWWEwpgJg0OiRni cSww== 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:mime-version:content-transfer-encoding; bh=fQihCl0dLbHaElgiRrlXkibi9/E8OKsaJ7lF0uUyO/s=; b=cMtJsw4LyUSXsS+9WxO14YV5qfrjga3v3rnApATcBbdJ1fAPrxd8Z5xC3x9QF4qyBB R6YV7huonWHZz7KgudOB5DGIdI2oXb28+55azeApGS7S0PrS9Rco5e6zWd2yuQJ3JUdn pT8KOn838GnclFc5hA4zk9U6i6sl8257RFk+zrh3l44pHzCDbTMK0zAX+jSYvbdS2kG2 fth7OSoforWVHeNcomgXPzgEzOzc6BIbT/m+fuf6/1DYV6wv1p8kj9+E65qfHgkdurom +dKKGhZa3pzBg9f/RCnv1O5Gp5/bD41TfEsM/Q5kAr8XRGOSqkXzHvgE865C6dIYwnhP juOg== X-Gm-Message-State: AOAM533fUK9ZXYfihbS5urzk7BLF6SOg1eLi4gnGkFdhkx3YIuTep3oG Xc98vXEziubQZFaOFKAjeOWNvA== X-Received: by 2002:a63:3114:: with SMTP id x20mr20316638pgx.52.1590260283492; Sat, 23 May 2020 11:58:03 -0700 (PDT) Received: from x1.lan ([2605:e000:100e:8c61:c94:a67a:9209:cf5f]) by smtp.gmail.com with ESMTPSA id 25sm9297319pjk.50.2020.05.23.11.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 May 2020 11:58:03 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Jens Axboe Subject: [PATCH 03/12] mm: abstract out wake_page_match() from wake_page_function() Date: Sat, 23 May 2020 12:57:46 -0600 Message-Id: <20200523185755.8494-4-axboe@kernel.dk> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200523185755.8494-1-axboe@kernel.dk> References: <20200523185755.8494-1-axboe@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org No functional changes in this patch, just in preparation for allowing more callers. Signed-off-by: Jens Axboe --- include/linux/pagemap.h | 37 +++++++++++++++++++++++++++++++++++++ mm/filemap.c | 35 ++++------------------------------- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a8f7bd8ea1c6..53d980f2208d 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -456,6 +456,43 @@ static inline pgoff_t linear_page_index(struct vm_area_struct *vma, return pgoff; } +/* This has the same layout as wait_bit_key - see fs/cachefiles/rdwr.c */ +struct wait_page_key { + struct page *page; + int bit_nr; + int page_match; +}; + +struct wait_page_queue { + struct page *page; + int bit_nr; + wait_queue_entry_t wait; +}; + +static inline int wake_page_match(struct wait_page_queue *wait_page, + struct wait_page_key *key) +{ + if (wait_page->page != key->page) + return 0; + key->page_match = 1; + + if (wait_page->bit_nr != key->bit_nr) + return 0; + + /* + * Stop walking if it's locked. + * Is this safe if put_and_wait_on_page_locked() is in use? + * Yes: the waker must hold a reference to this page, and if PG_locked + * has now already been set by another task, that task must also hold + * a reference to the *same usage* of this page; so there is no need + * to walk on to wake even the put_and_wait_on_page_locked() callers. + */ + if (test_bit(key->bit_nr, &key->page->flags)) + return -1; + + return 1; +} + extern void __lock_page(struct page *page); extern int __lock_page_killable(struct page *page); extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm, diff --git a/mm/filemap.c b/mm/filemap.c index 80747f1377d5..e891b5bee8fd 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -990,43 +990,16 @@ void __init pagecache_init(void) page_writeback_init(); } -/* This has the same layout as wait_bit_key - see fs/cachefiles/rdwr.c */ -struct wait_page_key { - struct page *page; - int bit_nr; - int page_match; -}; - -struct wait_page_queue { - struct page *page; - int bit_nr; - wait_queue_entry_t wait; -}; - static int wake_page_function(wait_queue_entry_t *wait, unsigned mode, int sync, void *arg) { struct wait_page_key *key = arg; struct wait_page_queue *wait_page = container_of(wait, struct wait_page_queue, wait); + int ret; - if (wait_page->page != key->page) - return 0; - key->page_match = 1; - - if (wait_page->bit_nr != key->bit_nr) - return 0; - - /* - * Stop walking if it's locked. - * Is this safe if put_and_wait_on_page_locked() is in use? - * Yes: the waker must hold a reference to this page, and if PG_locked - * has now already been set by another task, that task must also hold - * a reference to the *same usage* of this page; so there is no need - * to walk on to wake even the put_and_wait_on_page_locked() callers. - */ - if (test_bit(key->bit_nr, &key->page->flags)) - return -1; - + ret = wake_page_match(wait_page, key); + if (ret != 1) + return ret; return autoremove_wake_function(wait, mode, sync, key); } -- 2.26.2